From: Holger Freyther <automatic+kernel@freyther.de>
To: linux-kernel@vger.kernel.org
Cc: Holger Hans Peter Freyther <holgar+kernel@google.com>
Subject: [RFC 2/6] perf probe: Parse linerange for C++ functions
Date: Mon, 14 May 2018 12:19:36 +0800 [thread overview]
Message-ID: <20180514041940.96126-3-automatic+kernel@freyther.de> (raw)
In-Reply-To: <20180514041940.96126-1-automatic+kernel@freyther.de>
From: Holger Hans Peter Freyther <holgar+kernel@google.com>
perf probe --funcs will demangle C++ symbols by default but these
functions can not be used for listing sourcecode. Modify the scanner
to start searching for a line number only after a single ':'.
./perf probe -x ./cxx-example -L \
"std::vector<int, std::allocator<int> >::at:1"
Signed-off-by: Holger Hans Peter Freyther <holgar+kernel@google.com>
---
tools/perf/util/probe-event.c | 57 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 56 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index e1dbc98..39a2d47 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -1237,6 +1237,59 @@ static bool is_c_func_name(const char *name)
return true;
}
+/* Symbols in demangled CXX function names */
+static inline bool is_cxx_symbol(const char symbol)
+{
+ switch (symbol) {
+ case '_':
+ case ' ':
+ case '&':
+ case '*':
+ case '@':
+ case ',':
+ case ':':
+ case '<':
+ case '>':
+ case '(':
+ case ')':
+ return true;
+ default:
+ return false;
+ }
+}
+
+/* Is name a C++ name? */
+static bool is_cxx_func_name(const char *name)
+{
+ /* C name or a mangled name */
+ if (is_c_func_name(name))
+ return true;
+ while (*++name != '\0') {
+ if (!isalpha(*name) && !isdigit(*name) && !is_cxx_symbol(*name))
+ return false;
+ }
+ return true;
+}
+
+/*
+ * Find the first ':' that isn't part of a C++ namespace or class
+ * name.
+ */
+static char *first_non_cxx_ns(char *name)
+{
+ while (*name) {
+ char cur = *name, nxt = *(name + 1);
+
+ if (cur == ':' && nxt == ':')
+ name += 2;
+ else if (cur == ':')
+ return name;
+
+ name += 1;
+ }
+ return NULL;
+}
+
/*
* Stuff 'lr' according to the line range described by 'arg'.
* The line range syntax is described by:
@@ -1255,7 +1308,7 @@ int parse_line_range_desc(const char *arg, struct line_range *lr)
lr->start = 0;
lr->end = INT_MAX;
- range = strchr(name, ':');
+ range = first_non_cxx_ns(name);
if (range) {
*range++ = '\0';
@@ -1309,6 +1362,8 @@ int parse_line_range_desc(const char *arg, struct line_range *lr)
lr->file = name;
else if (is_c_func_name(name))/* We reuse it for checking funcname */
lr->function = name;
+ else if (is_cxx_func_name(name))
+ lr->function = name;
else { /* Invalid name */
semantic_error("'%s' is not a valid function name.\n", name);
err = -EINVAL;
--
2.7.4
next prev parent reply other threads:[~2018-05-14 4:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-14 4:19 [RFC 0/6] perf probe: Attempt to improve C++ probing Holger Freyther
2018-05-14 4:19 ` [RFC 1/6] perf probe: Do not exclude mangled C++ funcs Holger Freyther
2018-05-14 4:19 ` Holger Freyther [this message]
2018-05-14 4:19 ` [RFC 3/6] perf probe: Make listing of C++ functions work Holger Freyther
2018-05-14 4:19 ` [RFC 4/6] perf probe: Show variables for C++ functions Holger Freyther
2018-05-14 4:19 ` [RFC 5/6] perf probe: Make listing of variables work " Holger Freyther
2018-05-14 4:19 ` [RFC 6/6] perf probe: Make it possible to add a C++ uprobe Holger Freyther
2018-05-14 13:08 ` [RFC 0/6] perf probe: Attempt to improve C++ probing Masami Hiramatsu
2018-05-14 13:31 ` Masami Hiramatsu
2018-05-15 14:10 ` Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180514041940.96126-3-automatic+kernel@freyther.de \
--to=automatic+kernel@freyther.de \
--cc=holgar+kernel@google.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.