linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Masami Hiramatsu <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: hpa@zytor.com, linux-kernel@vger.kernel.org, namhyung@kernel.org,
	mingo@kernel.org, peterz@infradead.org, mhiramat@kernel.org,
	acme@redhat.com, dsahern@gmail.com, jolsa@kernel.org,
	tglx@linutronix.de
Subject: [tip:perf/core] perf probe: Match linkage name with mangled name
Date: Thu, 29 Sep 2016 11:20:51 -0700	[thread overview]
Message-ID: <tip-d5a00296a63fdd049273f86d0a0cdef6b230f8e6@git.kernel.org> (raw)
In-Reply-To: <147464493162.29804.16715053505069382443.stgit@devbox>

Commit-ID:  d5a00296a63fdd049273f86d0a0cdef6b230f8e6
Gitweb:     http://git.kernel.org/tip/d5a00296a63fdd049273f86d0a0cdef6b230f8e6
Author:     Masami Hiramatsu <mhiramat@kernel.org>
AuthorDate: Sat, 24 Sep 2016 00:35:31 +0900
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 29 Sep 2016 11:17:08 -0300

perf probe: Match linkage name with mangled name

Match linkage name with mangled name if exists. The linkage_name is used
for storing mangled name of the object.

Thus, this allows 'perf probe' to find appropriate probe point from
mangled symbol as below.

E.g. without this fix:
  ----
  $ perf probe -x /usr/lib64/libstdc++.so.6 \
    -D _ZNKSt15basic_fstreamXXIwSt11char_traitsIwEE7is_openEv
  Probe point '_ZNKSt15basic_fstreamXXIwSt11char_traitsIwEE7is_openEv'
  not found.
    Error: Failed to add events.
  ----

With this fix, perf probe can find the correct one.
  ----
  $ perf probe -x /usr/lib64/libstdc++.so.6 \
    -D _ZNKSt15basic_fstreamXXIwSt11char_traitsIwEE7is_openEv
  p:probe_libstdc/_ZNKSt15basic_fstreamXXIwSt11char_traitsIwEE7is_openEv
  /usr/lib64/libstdc++.so.6.0.22:0x8ca60
  ----

Committer notes:

After the fix, setting it for real (no -D/--definition, that amounts to
a --dry-run):

  # perf probe -x /usr/lib64/libstdc++.so.6 _ZNKSt15basic_fstreamXXIwSt11char_traitsIwEE7is_openEv
  Added new event:
    probe_libstdc:_ZNKSt15basic_fstreamXXIwSt11char_traitsIwEE7is_openEv (on _ZNKSt15basic_fstreamXXIwSt11char_traitsIwEE7is_openEv in /usr/lib64/libstdc++.so.6.0.22)

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

	perf record -e probe_libstdc:_ZNKSt15basic_fstreamXXIwSt11char_traitsIwEE7is_openEv -aR sleep 1

  # perf probe -l probe_libstdc:*
    probe_libstdc:_ZNKSt15basic_fstreamXXIwSt11char_traitsIwEE7is_openEv (on is_open@libstdc++-v3/include/fstream in /usr/lib64/libstdc++.so.6.0.22)
  #

Reported-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/147464493162.29804.16715053505069382443.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/dwarf-aux.c | 28 ++++++++++++++++++++++++++--
 tools/perf/util/dwarf-aux.h |  3 +++
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c
index faec899..41e068e 100644
--- a/tools/perf/util/dwarf-aux.c
+++ b/tools/perf/util/dwarf-aux.c
@@ -130,6 +130,22 @@ int cu_walk_functions_at(Dwarf_Die *cu_die, Dwarf_Addr addr,
 }
 
 /**
+ * die_get_linkage_name - Get the linkage name of the object
+ * @dw_die: A DIE of the object
+ *
+ * Get the linkage name attiribute of given @dw_die.
+ * For C++ binary, the linkage name will be the mangled symbol.
+ */
+const char *die_get_linkage_name(Dwarf_Die *dw_die)
+{
+	Dwarf_Attribute attr;
+
+	if (dwarf_attr_integrate(dw_die, DW_AT_linkage_name, &attr) == NULL)
+		return NULL;
+	return dwarf_formstring(&attr);
+}
+
+/**
  * die_compare_name - Compare diename and tname
  * @dw_die: a DIE
  * @tname: a string of target name
@@ -145,18 +161,26 @@ bool die_compare_name(Dwarf_Die *dw_die, const char *tname)
 }
 
 /**
- * die_match_name - Match diename and glob
+ * die_match_name - Match diename/linkage name and glob
  * @dw_die: a DIE
  * @glob: a string of target glob pattern
  *
  * Glob matching the name of @dw_die and @glob. Return false if matching fail.
+ * This also match linkage name.
  */
 bool die_match_name(Dwarf_Die *dw_die, const char *glob)
 {
 	const char *name;
 
 	name = dwarf_diename(dw_die);
-	return name ? strglobmatch(name, glob) : false;
+	if (name && strglobmatch(name, glob))
+		return true;
+	/* fall back to check linkage name */
+	name = die_get_linkage_name(dw_die);
+	if (name && strglobmatch(name, glob))
+		return true;
+
+	return false;
 }
 
 /**
diff --git a/tools/perf/util/dwarf-aux.h b/tools/perf/util/dwarf-aux.h
index 8b6d2f8..8ac53bf 100644
--- a/tools/perf/util/dwarf-aux.h
+++ b/tools/perf/util/dwarf-aux.h
@@ -38,6 +38,9 @@ int cu_find_lineinfo(Dwarf_Die *cudie, unsigned long addr,
 int cu_walk_functions_at(Dwarf_Die *cu_die, Dwarf_Addr addr,
 			 int (*callback)(Dwarf_Die *, void *), void *data);
 
+/* Get DW_AT_linkage_name (should be NULL for C binary) */
+const char *die_get_linkage_name(Dwarf_Die *dw_die);
+
 /* Ensure that this DIE is a subprogram and definition (not declaration) */
 bool die_is_func_def(Dwarf_Die *dw_die);
 

  reply	other threads:[~2016-09-29 18:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-23 15:34 [PATCH perf/core 0/4] perf-probe fixes for C++ Masami Hiramatsu
2016-09-23 15:34 ` [PATCH perf/core 1/4] perf-probe: Ignore the error of finding inline instance Masami Hiramatsu
2016-09-29 18:19   ` [tip:perf/core] perf probe: " tip-bot for Masami Hiramatsu
2016-09-23 15:35 ` [PATCH perf/core 2/4] perf-probe: Skip if the function address is 0 Masami Hiramatsu
2016-09-29 18:19   ` [tip:perf/core] perf probe: " tip-bot for Masami Hiramatsu
2016-09-23 15:35 ` [PATCH perf/core 3/4] perf-probe: Fix to cut off incompatible chars from group name Masami Hiramatsu
2016-09-29 18:20   ` [tip:perf/core] perf probe: " tip-bot for Masami Hiramatsu
2016-09-23 15:35 ` [PATCH perf/core 4/4] perf-probe: Match linkage name with mangled name Masami Hiramatsu
2016-09-29 18:20   ` tip-bot for Masami Hiramatsu [this message]
2016-09-25 11:14 ` [PATCH perf/core 0/4] perf-probe fixes for C++ Jiri Olsa
2016-09-27 18:11   ` Masami Hiramatsu

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=tip-d5a00296a63fdd049273f86d0a0cdef6b230f8e6@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=acme@redhat.com \
    --cc=dsahern@gmail.com \
    --cc=hpa@zytor.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).