public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Holger Freyther <automatic+kernel@freyther.de>
To: linux-kernel@vger.kernel.org
Cc: Holger Hans Peter Freyther <holgar+kernel@google.com>
Subject: [RFC 6/6] perf probe: Make it possible to add a C++ uprobe
Date: Mon, 14 May 2018 12:19:40 +0800	[thread overview]
Message-ID: <20180514041940.96126-7-automatic+kernel@freyther.de> (raw)
In-Reply-To: <20180514041940.96126-1-automatic+kernel@freyther.de>

From: Holger Hans Peter Freyther <holgar+kernel@google.com>

If the linkage name looks like a common C++ ABI name use it instead of
the original function name. This makes adding a uprobe for a C++ symbol
possible.

./perf probe -x ./cxx-example  "std::vector<int, std::allocator<int> >::at"
Added new event:
  probe_foo:_ZNSt6vectorIiSaIiEE2atEm (on _ZN... in /cxx-example)

You can now use it in all perf tools, such as:

	perf record -e probe_foo:_ZNSt6vectorIiSaIiEE2atEm -aR sleep 1

Signed-off-by: Holger Hans Peter Freyther <holgar+kernel@google.com>
---
 tools/perf/util/probe-finder.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 4ba4b18..4cfa3de 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -1317,6 +1317,7 @@ static int add_probe_trace_event(Dwarf_Die *sc_die, struct probe_finder *pf)
 	struct perf_probe_point *pp = &pf->pev->point;
 	struct probe_trace_event *tev;
 	struct perf_probe_arg *args = NULL;
+	const char *linkage_name;
 	int ret, i;
 
 	/* Check number of tevs */
@@ -1333,6 +1334,16 @@ static int add_probe_trace_event(Dwarf_Die *sc_die, struct probe_finder *pf)
 	if (ret < 0)
 		goto end;
 
+	/*
+	 * Adding a C++ name like std::vector<int, std::allocator<int> >::at
+	 * will fail. Check if we want to use the linkage name instead.
+	 */
+	linkage_name = die_get_linkage_name(&pf->sp_die);
+	if (linkage_name && strncmp(linkage_name, "_Z", 2) == 0) {
+		free(pp->function);
+		pp->function = strdup(linkage_name);
+	}
+
 	tev->point.realname = strdup(dwarf_diename(sc_die));
 	if (!tev->point.realname) {
 		ret = -ENOMEM;
-- 
2.7.4

  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 ` [RFC 2/6] perf probe: Parse linerange for C++ functions Holger Freyther
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 ` Holger Freyther [this message]
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-7-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox