linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH perf/core 0/4] perf-probe fixes for C++
@ 2016-09-23 15:34 Masami Hiramatsu
  2016-09-23 15:34 ` [PATCH perf/core 1/4] perf-probe: Ignore the error of finding inline instance Masami Hiramatsu
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Masami Hiramatsu @ 2016-09-23 15:34 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Masami Hiramatsu, linux-kernel, Thomas Gleixner, Jiri Olsa,
	Peter Zijlstra, Ingo Molnar, Namhyung Kim, David Ahern

Hi,

Here is a series of patches for fixing several issues when
probing on C++ binaries.

- Ignore inlined function definition if it has no instance [1/4]
- Skip (inlined/normal) functions which entry address is 0 [2/4]
- Cut off the filename for group name if it includes characters
  which can not be used for C symbol name [3/4]
- Search mangled symbol name from debuginfo [4/4]

So, with this series, perf-probe can handle "mangled symbol" or
"method name" as below;
  ----
  $ ./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

  $ ./perf probe -x /usr/lib64/libstdc++.so.6 -D is_open
  p:probe_libstdc/is_open /usr/lib64/libstdc++.so.6.0.22:0x8ca80
  p:probe_libstdc/is_open_1 /usr/lib64/libstdc++.so.6.0.22:0x8ca70
  p:probe_libstdc/is_open_2 /usr/lib64/libstdc++.so.6.0.22:0x8ca60
  p:probe_libstdc/is_open_3 /usr/lib64/libstdc++.so.6.0.22:0xb0ad0
  p:probe_libstdc/is_open_4 /usr/lib64/libstdc++.so.6.0.22:0xecca9
  ----

Jiri and Thomas, could you try this if you need it?

TODO:
 - Support demangled method name(in short), like std::basic_fstream::is_open.

Thank you,

---

Masami Hiramatsu (4):
      perf-probe: Ignore the error of finding inline instance
      perf-probe: Skip if the function address is 0
      perf-probe: Fix to cut off incompatible chars from group name
      perf-probe: Match linkage name with mangled name


 tools/perf/util/dwarf-aux.c    |   28 ++++++++++++++++++++++++++--
 tools/perf/util/dwarf-aux.h    |    3 +++
 tools/perf/util/probe-event.c  |   10 +++++++---
 tools/perf/util/probe-finder.c |   17 ++++++++++++++---
 4 files changed, 50 insertions(+), 8 deletions(-)

--
Masami Hiramatsu

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH perf/core 1/4] perf-probe: Ignore the error of finding inline instance
  2016-09-23 15:34 [PATCH perf/core 0/4] perf-probe fixes for C++ Masami Hiramatsu
@ 2016-09-23 15:34 ` 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
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Masami Hiramatsu @ 2016-09-23 15:34 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Masami Hiramatsu, linux-kernel, Thomas Gleixner, Jiri Olsa,
	Peter Zijlstra, Ingo Molnar, Namhyung Kim, David Ahern

Ignore the error when the perf probe failed to find inline function
instances. This can happen when we search a method in c++ debuginfo.
If there is completely no instance in target, perf probe can return
an error.

E.g. without this fix:
  ----
  $ ./perf probe -x /usr/lib64/libstdc++.so.6 -vD showmanyc
  probe-definition(0): showmanyc
  symbol:showmanyc file:(null) line:0 offset:0 return:0 lazy:(null)
  0 arguments
  symbol:catch file:(null) line:0 offset:0 return:0 lazy:(null)
  symbol:throw file:(null) line:0 offset:0 return:0 lazy:(null)
  symbol:rethrow file:(null) line:0 offset:0 return:0 lazy:(null)
  Open Debuginfo file: /usr/lib/debug/usr/lib64/libstdc++.so.6.0.22.debug
  Try to find probe point from debuginfo.
  Matched function: showmanyc
  An error occurred in debuginfo analysis (-2).
  Trying to use symbols.
  Failed to find symbol showmanyc in /usr/lib64/libstdc++.so.6.0.22
    Error: Failed to add events. Reason: No such file or directory (Code: -2)
  ----

This is because one of showmanyc is defined as inline but no instance
found. With this fix, it is succeeded to show as below.
  ----
  $ ./perf probe -x /usr/lib64/libstdc++.so.6 -D showmanyc
  p:probe_libstdc++/showmanyc /usr/lib64/libstdc++.so.6.0.22:0xb0e50
  p:probe_libstdc++/showmanyc_1 /usr/lib64/libstdc++.so.6.0.22:0xc7c40
  p:probe_libstdc++/showmanyc_2 /usr/lib64/libstdc++.so.6.0.22:0xecfa0
  p:probe_libstdc++/showmanyc_3 /usr/lib64/libstdc++.so.6.0.22:0x115fc0
  p:probe_libstdc++/showmanyc_4 /usr/lib64/libstdc++.so.6.0.22:0x121a90
  ----

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 tools/perf/util/probe-finder.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 8daca4f..5fe8325 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -988,7 +988,8 @@ static int probe_point_search_cb(Dwarf_Die *sp_die, void *data)
 	if (pp->file && strtailcmp(pp->file, dwarf_decl_file(sp_die)))
 		return DWARF_CB_OK;
 
-	pr_debug("Matched function: %s\n", dwarf_diename(sp_die));
+	pr_debug("Matched function: %s [%lx]\n", dwarf_diename(sp_die),
+		 (unsigned long)dwarf_dieoffset(sp_die));
 	pf->fname = dwarf_decl_file(sp_die);
 	if (pp->line) { /* Function relative line */
 		dwarf_decl_line(sp_die, &pf->lno);
@@ -1011,7 +1012,7 @@ static int probe_point_search_cb(Dwarf_Die *sp_die, void *data)
 		param->retval = die_walk_instances(sp_die,
 					probe_point_inline_cb, (void *)pf);
 		/* This could be a non-existed inline definition */
-		if (param->retval == -ENOENT && strisglob(pp->function))
+		if (param->retval == -ENOENT)
 			param->retval = 0;
 	}
 

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH perf/core 2/4] perf-probe: Skip if the function address is 0
  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-23 15:35 ` 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
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Masami Hiramatsu @ 2016-09-23 15:35 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Masami Hiramatsu, linux-kernel, Thomas Gleixner, Jiri Olsa,
	Peter Zijlstra, Ingo Molnar, Namhyung Kim, David Ahern

Skip probes if the entry address of the target function is 0.
This can happen if we handles c++ debuginfo.

E.g. without this fix, below case still fail.
  ----
  $ ./perf probe -x /usr/lib64/libstdc++.so.6 -vD is_open
  probe-definition(0): is_open
  symbol:is_open file:(null) line:0 offset:0 return:0 lazy:(null)
  0 arguments
  symbol:catch file:(null) line:0 offset:0 return:0 lazy:(null)
  symbol:throw file:(null) line:0 offset:0 return:0 lazy:(null)
  symbol:rethrow file:(null) line:0 offset:0 return:0 lazy:(null)
  Open Debuginfo file: /usr/lib/debug/usr/lib64/libstdc++.so.6.0.22.debug
  Try to find probe point from debuginfo.
  Matched function: is_open [295df]
  found inline addr: 0x8ca80
  Probe point found: is_open+0
  found inline addr: 0x8ca70
  Probe point found: is_open+0
  found inline addr: 0x8ca60
  Probe point found: is_open+0
  Matched function: is_open [6527f]
  Matched function: is_open [9fe8a]
  Probe point found: is_open+0
  Matched function: is_open [19710b]
  found inline addr: 0xecca9
  Probe point found: stdio_filebuf+57
  found inline addr: 0x0
  Probe point found: swap+0
  Matched function: is_open [19fc9d]
  Probe point found: is_open+0
  Found 7 probe_trace_events.
  p:probe_libstdc++/is_open /usr/lib64/libstdc++.so.6.0.22:0x8ca80
  p:probe_libstdc++/is_open_1 /usr/lib64/libstdc++.so.6.0.22:0x8ca70
  p:probe_libstdc++/is_open_2 /usr/lib64/libstdc++.so.6.0.22:0x8ca60
  p:probe_libstdc++/is_open_3 /usr/lib64/libstdc++.so.6.0.22:0xb0ad0
  p:probe_libstdc++/is_open_4 /usr/lib64/libstdc++.so.6.0.22:0xecca9
  Failed to synthesize probe trace event.
    Error: Failed to add events. Reason: Invalid argument (Code: -22)
  ----
This is because some instances have entry_pc == 0 (see 19710b and
19fc9d). With this fix, those are skipped.

  ----
  $ ./perf probe -x /usr/lib64/libstdc++.so.6 -D is_open
  p:probe_libstdc++/is_open /usr/lib64/libstdc++.so.6.0.22:0x8ca80
  p:probe_libstdc++/is_open_1 /usr/lib64/libstdc++.so.6.0.22:0x8ca70
  p:probe_libstdc++/is_open_2 /usr/lib64/libstdc++.so.6.0.22:0x8ca60
  p:probe_libstdc++/is_open_3 /usr/lib64/libstdc++.so.6.0.22:0xb0ad0
  p:probe_libstdc++/is_open_4 /usr/lib64/libstdc++.so.6.0.22:0xecca9
  ----

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 tools/perf/util/probe-finder.c |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 5fe8325..df4debe 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -955,6 +955,11 @@ static int probe_point_inline_cb(Dwarf_Die *in_die, void *data)
 				   dwarf_diename(in_die));
 			return -ENOENT;
 		}
+		if (addr == 0) {
+			pr_debug("%s has no valid entry address. skipped.\n",
+				 dwarf_diename(in_die));
+			return -ENOENT;
+		}
 		pf->addr = addr;
 		pf->addr += pp->offset;
 		pr_debug("found inline addr: 0x%jx\n",
@@ -998,8 +1003,13 @@ static int probe_point_search_cb(Dwarf_Die *sp_die, void *data)
 	} else if (die_is_func_instance(sp_die)) {
 		/* Instances always have the entry address */
 		dwarf_entrypc(sp_die, &pf->addr);
+		/* But in some case the entry address is 0 */
+		if (pf->addr == 0) {
+			pr_debug("%s has no entry PC. Skipped\n",
+				 dwarf_diename(sp_die));
+			param->retval = 0;
 		/* Real function */
-		if (pp->lazy_line)
+		} else if (pp->lazy_line)
 			param->retval = find_probe_point_lazy(sp_die, pf);
 		else {
 			skip_prologue(sp_die, pf);

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH perf/core 3/4] perf-probe: Fix to cut off incompatible chars from group name
  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-23 15:35 ` [PATCH perf/core 2/4] perf-probe: Skip if the function address is 0 Masami Hiramatsu
@ 2016-09-23 15:35 ` 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-25 11:14 ` [PATCH perf/core 0/4] perf-probe fixes for C++ Jiri Olsa
  4 siblings, 1 reply; 11+ messages in thread
From: Masami Hiramatsu @ 2016-09-23 15:35 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Masami Hiramatsu, linux-kernel, Thomas Gleixner, Jiri Olsa,
	Peter Zijlstra, Ingo Molnar, Namhyung Kim, David Ahern

Cut off the characters which can not use for group name of uprobes
when making it based on executable filename.

For example, if the exec name is libstdc++.so, without this fix
perf probe generates "probe_libstdc++" as the group name, but
it is failed to set because '+' can not be used for group name.

With this fix perf accepts only alphabet, number or '_' for group
name, thus perf generates "probe_libstdc" as the group name.

E.g. with this fix, you can see the event name has no "+".
  ----
  $ ./perf probe -x /usr/lib64/libstdc++.so.6 -D is_open
  p:probe_libstdc/is_open /usr/lib64/libstdc++.so.6.0.22:0x8ca80
  p:probe_libstdc/is_open_1 /usr/lib64/libstdc++.so.6.0.22:0x8ca70
  p:probe_libstdc/is_open_2 /usr/lib64/libstdc++.so.6.0.22:0x8ca60
  p:probe_libstdc/is_open_3 /usr/lib64/libstdc++.so.6.0.22:0xb0ad0
  p:probe_libstdc/is_open_4 /usr/lib64/libstdc++.so.6.0.22:0xecca9
  ----

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 tools/perf/util/probe-event.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index bc60ce4..fcfbef0 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -213,9 +213,13 @@ static int convert_exec_to_group(const char *exec, char **result)
 		goto out;
 	}
 
-	ptr2 = strpbrk(ptr1, "-._");
-	if (ptr2)
-		*ptr2 = '\0';
+	for (ptr2 = ptr1; ptr2 != '\0'; ptr2++) {
+		if (!isalnum(*ptr2) && *ptr2 != '_') {
+			*ptr2 = '\0';
+			break;
+		}
+	}
+
 	ret = e_snprintf(buf, 64, "%s_%s", PERFPROBE_GROUP, ptr1);
 	if (ret < 0)
 		goto out;

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH perf/core 4/4] perf-probe: Match linkage name with mangled name
  2016-09-23 15:34 [PATCH perf/core 0/4] perf-probe fixes for C++ Masami Hiramatsu
                   ` (2 preceding siblings ...)
  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-23 15:35 ` Masami Hiramatsu
  2016-09-29 18:20   ` [tip:perf/core] perf probe: " tip-bot for Masami Hiramatsu
  2016-09-25 11:14 ` [PATCH perf/core 0/4] perf-probe fixes for C++ Jiri Olsa
  4 siblings, 1 reply; 11+ messages in thread
From: Masami Hiramatsu @ 2016-09-23 15:35 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Masami Hiramatsu, linux-kernel, Thomas Gleixner, Jiri Olsa,
	Peter Zijlstra, Ingo Molnar, Namhyung Kim, David Ahern

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
  ----

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 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);
 

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH perf/core 0/4] perf-probe fixes for C++
  2016-09-23 15:34 [PATCH perf/core 0/4] perf-probe fixes for C++ Masami Hiramatsu
                   ` (3 preceding siblings ...)
  2016-09-23 15:35 ` [PATCH perf/core 4/4] perf-probe: Match linkage name with mangled name Masami Hiramatsu
@ 2016-09-25 11:14 ` Jiri Olsa
  2016-09-27 18:11   ` Masami Hiramatsu
  4 siblings, 1 reply; 11+ messages in thread
From: Jiri Olsa @ 2016-09-25 11:14 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Arnaldo Carvalho de Melo, linux-kernel, Thomas Gleixner,
	Peter Zijlstra, Ingo Molnar, Namhyung Kim, David Ahern

On Sat, Sep 24, 2016 at 12:34:47AM +0900, Masami Hiramatsu wrote:
> Hi,
> 
> Here is a series of patches for fixing several issues when
> probing on C++ binaries.
> 
> - Ignore inlined function definition if it has no instance [1/4]
> - Skip (inlined/normal) functions which entry address is 0 [2/4]
> - Cut off the filename for group name if it includes characters
>   which can not be used for C symbol name [3/4]
> - Search mangled symbol name from debuginfo [4/4]
> 
> So, with this series, perf-probe can handle "mangled symbol" or
> "method name" as below;
>   ----
>   $ ./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
> 
>   $ ./perf probe -x /usr/lib64/libstdc++.so.6 -D is_open
>   p:probe_libstdc/is_open /usr/lib64/libstdc++.so.6.0.22:0x8ca80
>   p:probe_libstdc/is_open_1 /usr/lib64/libstdc++.so.6.0.22:0x8ca70
>   p:probe_libstdc/is_open_2 /usr/lib64/libstdc++.so.6.0.22:0x8ca60
>   p:probe_libstdc/is_open_3 /usr/lib64/libstdc++.so.6.0.22:0xb0ad0
>   p:probe_libstdc/is_open_4 /usr/lib64/libstdc++.so.6.0.22:0xecca9
>   ----
> 
> Jiri and Thomas, could you try this if you need it?

tried examples from changelogs and it works for me

Tested-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

> 
> TODO:
>  - Support demangled method name(in short), like std::basic_fstream::is_open.
> 
> Thank you,
> 
> ---
> 
> Masami Hiramatsu (4):
>       perf-probe: Ignore the error of finding inline instance
>       perf-probe: Skip if the function address is 0
>       perf-probe: Fix to cut off incompatible chars from group name
>       perf-probe: Match linkage name with mangled name
> 
> 
>  tools/perf/util/dwarf-aux.c    |   28 ++++++++++++++++++++++++++--
>  tools/perf/util/dwarf-aux.h    |    3 +++
>  tools/perf/util/probe-event.c  |   10 +++++++---
>  tools/perf/util/probe-finder.c |   17 ++++++++++++++---
>  4 files changed, 50 insertions(+), 8 deletions(-)
> 
> --
> Masami Hiramatsu

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH perf/core 0/4] perf-probe fixes for C++
  2016-09-25 11:14 ` [PATCH perf/core 0/4] perf-probe fixes for C++ Jiri Olsa
@ 2016-09-27 18:11   ` Masami Hiramatsu
  0 siblings, 0 replies; 11+ messages in thread
From: Masami Hiramatsu @ 2016-09-27 18:11 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Arnaldo Carvalho de Melo, linux-kernel, Thomas Gleixner,
	Peter Zijlstra, Ingo Molnar, Namhyung Kim, David Ahern

On Sun, 25 Sep 2016 13:14:21 +0200
Jiri Olsa <jolsa@redhat.com> wrote:

> On Sat, Sep 24, 2016 at 12:34:47AM +0900, Masami Hiramatsu wrote:
> > Hi,
> > 
> > Here is a series of patches for fixing several issues when
> > probing on C++ binaries.
> > 
> > - Ignore inlined function definition if it has no instance [1/4]
> > - Skip (inlined/normal) functions which entry address is 0 [2/4]
> > - Cut off the filename for group name if it includes characters
> >   which can not be used for C symbol name [3/4]
> > - Search mangled symbol name from debuginfo [4/4]
> > 
> > So, with this series, perf-probe can handle "mangled symbol" or
> > "method name" as below;
> >   ----
> >   $ ./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
> > 
> >   $ ./perf probe -x /usr/lib64/libstdc++.so.6 -D is_open
> >   p:probe_libstdc/is_open /usr/lib64/libstdc++.so.6.0.22:0x8ca80
> >   p:probe_libstdc/is_open_1 /usr/lib64/libstdc++.so.6.0.22:0x8ca70
> >   p:probe_libstdc/is_open_2 /usr/lib64/libstdc++.so.6.0.22:0x8ca60
> >   p:probe_libstdc/is_open_3 /usr/lib64/libstdc++.so.6.0.22:0xb0ad0
> >   p:probe_libstdc/is_open_4 /usr/lib64/libstdc++.so.6.0.22:0xecca9
> >   ----
> > 
> > Jiri and Thomas, could you try this if you need it?
> 
> tried examples from changelogs and it works for me
> 
> Tested-by: Jiri Olsa <jolsa@kernel.org>

Thanks Jiri!



> 
> thanks,
> jirka
> 
> > 
> > TODO:
> >  - Support demangled method name(in short), like std::basic_fstream::is_open.
> > 
> > Thank you,
> > 
> > ---
> > 
> > Masami Hiramatsu (4):
> >       perf-probe: Ignore the error of finding inline instance
> >       perf-probe: Skip if the function address is 0
> >       perf-probe: Fix to cut off incompatible chars from group name
> >       perf-probe: Match linkage name with mangled name
> > 
> > 
> >  tools/perf/util/dwarf-aux.c    |   28 ++++++++++++++++++++++++++--
> >  tools/perf/util/dwarf-aux.h    |    3 +++
> >  tools/perf/util/probe-event.c  |   10 +++++++---
> >  tools/perf/util/probe-finder.c |   17 ++++++++++++++---
> >  4 files changed, 50 insertions(+), 8 deletions(-)
> > 
> > --
> > Masami Hiramatsu


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [tip:perf/core] perf probe: Ignore the error of finding inline instance
  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-bot for Masami Hiramatsu
  0 siblings, 0 replies; 11+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2016-09-29 18:19 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mhiramat, jolsa, dsahern, linux-kernel, namhyung, acme, mingo,
	hpa, peterz, tglx

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

perf probe: Ignore the error of finding inline instance

Ignore the error when the perf probe failed to find inline function
instances. This can happen when we search a method in C++ debuginfo.  If
there is completely no instance in target, perf probe can return an
error.

E.g. without this fix:
  ----
  $ perf probe -x /usr/lib64/libstdc++.so.6 -vD showmanyc
  probe-definition(0): showmanyc
  symbol:showmanyc file:(null) line:0 offset:0 return:0 lazy:(null)
  0 arguments
  symbol:catch file:(null) line:0 offset:0 return:0 lazy:(null)
  symbol:throw file:(null) line:0 offset:0 return:0 lazy:(null)
  symbol:rethrow file:(null) line:0 offset:0 return:0 lazy:(null)
  Open Debuginfo file: /usr/lib/debug/usr/lib64/libstdc++.so.6.0.22.debug
  Try to find probe point from debuginfo.
  Matched function: showmanyc
  An error occurred in debuginfo analysis (-2).
  Trying to use symbols.
  Failed to find symbol showmanyc in /usr/lib64/libstdc++.so.6.0.22
    Error: Failed to add events. Reason: No such file or directory (Code: -2)
  ----

This is because one of showmanyc is defined as inline but no instance
found. With this fix, it is succeeded to show as below.
  ----
  $ perf probe -x /usr/lib64/libstdc++.so.6 -D showmanyc
  p:probe_libstdc++/showmanyc /usr/lib64/libstdc++.so.6.0.22:0xb0e50
  p:probe_libstdc++/showmanyc_1 /usr/lib64/libstdc++.so.6.0.22:0xc7c40
  p:probe_libstdc++/showmanyc_2 /usr/lib64/libstdc++.so.6.0.22:0xecfa0
  p:probe_libstdc++/showmanyc_3 /usr/lib64/libstdc++.so.6.0.22:0x115fc0
  p:probe_libstdc++/showmanyc_4 /usr/lib64/libstdc++.so.6.0.22:0x121a90
  ----

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>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/147464489775.29804.3190419491209875936.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/probe-finder.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 8daca4f..5fe8325 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -988,7 +988,8 @@ static int probe_point_search_cb(Dwarf_Die *sp_die, void *data)
 	if (pp->file && strtailcmp(pp->file, dwarf_decl_file(sp_die)))
 		return DWARF_CB_OK;
 
-	pr_debug("Matched function: %s\n", dwarf_diename(sp_die));
+	pr_debug("Matched function: %s [%lx]\n", dwarf_diename(sp_die),
+		 (unsigned long)dwarf_dieoffset(sp_die));
 	pf->fname = dwarf_decl_file(sp_die);
 	if (pp->line) { /* Function relative line */
 		dwarf_decl_line(sp_die, &pf->lno);
@@ -1011,7 +1012,7 @@ static int probe_point_search_cb(Dwarf_Die *sp_die, void *data)
 		param->retval = die_walk_instances(sp_die,
 					probe_point_inline_cb, (void *)pf);
 		/* This could be a non-existed inline definition */
-		if (param->retval == -ENOENT && strisglob(pp->function))
+		if (param->retval == -ENOENT)
 			param->retval = 0;
 	}
 

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [tip:perf/core] perf probe: Skip if the function address is 0
  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-bot for Masami Hiramatsu
  0 siblings, 0 replies; 11+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2016-09-29 18:19 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: jolsa, hpa, linux-kernel, mingo, dsahern, acme, mhiramat, tglx,
	peterz, namhyung

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

perf probe: Skip if the function address is 0

Skip probes if the entry address of the target function is 0.  This can
happen when we're handling C++ debuginfo files.

E.g. without this fix, below case still fail.
  ----
  $ ./perf probe -x /usr/lib64/libstdc++.so.6 -vD is_open
  probe-definition(0): is_open
  symbol:is_open file:(null) line:0 offset:0 return:0 lazy:(null)
  0 arguments
  symbol:catch file:(null) line:0 offset:0 return:0 lazy:(null)
  symbol:throw file:(null) line:0 offset:0 return:0 lazy:(null)
  symbol:rethrow file:(null) line:0 offset:0 return:0 lazy:(null)
  Open Debuginfo file: /usr/lib/debug/usr/lib64/libstdc++.so.6.0.22.debug
  Try to find probe point from debuginfo.
  Matched function: is_open [295df]
  found inline addr: 0x8ca80
  Probe point found: is_open+0
  found inline addr: 0x8ca70
  Probe point found: is_open+0
  found inline addr: 0x8ca60
  Probe point found: is_open+0
  Matched function: is_open [6527f]
  Matched function: is_open [9fe8a]
  Probe point found: is_open+0
  Matched function: is_open [19710b]
  found inline addr: 0xecca9
  Probe point found: stdio_filebuf+57
  found inline addr: 0x0
  Probe point found: swap+0
  Matched function: is_open [19fc9d]
  Probe point found: is_open+0
  Found 7 probe_trace_events.
  p:probe_libstdc++/is_open /usr/lib64/libstdc++.so.6.0.22:0x8ca80
  p:probe_libstdc++/is_open_1 /usr/lib64/libstdc++.so.6.0.22:0x8ca70
  p:probe_libstdc++/is_open_2 /usr/lib64/libstdc++.so.6.0.22:0x8ca60
  p:probe_libstdc++/is_open_3 /usr/lib64/libstdc++.so.6.0.22:0xb0ad0
  p:probe_libstdc++/is_open_4 /usr/lib64/libstdc++.so.6.0.22:0xecca9
  Failed to synthesize probe trace event.
    Error: Failed to add events. Reason: Invalid argument (Code: -22)
  ----
This is because some instances have entry_pc == 0 (see 19710b and
19fc9d). With this fix, those are skipped.

  ----
  $ ./perf probe -x /usr/lib64/libstdc++.so.6 -D is_open
  p:probe_libstdc++/is_open /usr/lib64/libstdc++.so.6.0.22:0x8ca80
  p:probe_libstdc++/is_open_1 /usr/lib64/libstdc++.so.6.0.22:0x8ca70
  p:probe_libstdc++/is_open_2 /usr/lib64/libstdc++.so.6.0.22:0x8ca60
  p:probe_libstdc++/is_open_3 /usr/lib64/libstdc++.so.6.0.22:0xb0ad0
  p:probe_libstdc++/is_open_4 /usr/lib64/libstdc++.so.6.0.22:0xecca9
  ----

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>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/147464490707.29804.14277897643725143867.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/probe-finder.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 5fe8325..df4debe 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -955,6 +955,11 @@ static int probe_point_inline_cb(Dwarf_Die *in_die, void *data)
 				   dwarf_diename(in_die));
 			return -ENOENT;
 		}
+		if (addr == 0) {
+			pr_debug("%s has no valid entry address. skipped.\n",
+				 dwarf_diename(in_die));
+			return -ENOENT;
+		}
 		pf->addr = addr;
 		pf->addr += pp->offset;
 		pr_debug("found inline addr: 0x%jx\n",
@@ -998,8 +1003,13 @@ static int probe_point_search_cb(Dwarf_Die *sp_die, void *data)
 	} else if (die_is_func_instance(sp_die)) {
 		/* Instances always have the entry address */
 		dwarf_entrypc(sp_die, &pf->addr);
+		/* But in some case the entry address is 0 */
+		if (pf->addr == 0) {
+			pr_debug("%s has no entry PC. Skipped\n",
+				 dwarf_diename(sp_die));
+			param->retval = 0;
 		/* Real function */
-		if (pp->lazy_line)
+		} else if (pp->lazy_line)
 			param->retval = find_probe_point_lazy(sp_die, pf);
 		else {
 			skip_prologue(sp_die, pf);

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [tip:perf/core] perf probe: Fix to cut off incompatible chars from group name
  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-bot for Masami Hiramatsu
  0 siblings, 0 replies; 11+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2016-09-29 18:20 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, hpa, tglx, mhiramat, linux-kernel, acme, dsahern, peterz,
	namhyung, jolsa

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

perf probe: Fix to cut off incompatible chars from group name

Cut off the characters which can not use for group name of uprobes
when making it based on executable filename.

For example, if the exec name is libstdc++.so, without this fix
perf probe generates "probe_libstdc++" as the group name, but
it is failed to set because '+' can not be used for group name.

With this fix perf accepts only alphabet, number or '_' for group
name, thus perf generates "probe_libstdc" as the group name.

E.g. with this fix, you can see the event name has no "+".
  ----
  $ ./perf probe -x /usr/lib64/libstdc++.so.6 -D is_open
  p:probe_libstdc/is_open /usr/lib64/libstdc++.so.6.0.22:0x8ca80
  p:probe_libstdc/is_open_1 /usr/lib64/libstdc++.so.6.0.22:0x8ca70
  p:probe_libstdc/is_open_2 /usr/lib64/libstdc++.so.6.0.22:0x8ca60
  p:probe_libstdc/is_open_3 /usr/lib64/libstdc++.so.6.0.22:0xb0ad0
  p:probe_libstdc/is_open_4 /usr/lib64/libstdc++.so.6.0.22:0xecca9
  ----

Committer note:

Before this fix:

  # perf probe -x /usr/lib64/libstdc++.so.6 is_open
  Failed to write event: Invalid argument
    Error: Failed to add events.
  #

After the fix:

  # perf probe -x /usr/lib64/libstdc++.so.6 is_open
  Added new events:
    probe_libstdc:is_open (on is_open in /usr/lib64/libstdc++.so.6.0.22)
    probe_libstdc:is_open_1 (on is_open in /usr/lib64/libstdc++.so.6.0.22)
    probe_libstdc:is_open_2 (on is_open in /usr/lib64/libstdc++.so.6.0.22)
    probe_libstdc:is_open_3 (on is_open in /usr/lib64/libstdc++.so.6.0.22)
    probe_libstdc:is_open_4 (on is_open in /usr/lib64/libstdc++.so.6.0.22)

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

	  perf record -e probe_libstdc:is_open_4 -aR sleep 1

  # perf probe -l probe_libstdc:*
    probe_libstdc:is_open (on is_open@libstdc++-v3/include/fstream in /usr/lib64/libstdc++.so.6.0.22)
    probe_libstdc:is_open_1 (on is_open@libstdc++-v3/include/fstream in /usr/lib64/libstdc++.so.6.0.22)
    probe_libstdc:is_open_2 (on is_open@libstdc++-v3/include/fstream in /usr/lib64/libstdc++.so.6.0.22)
    probe_libstdc:is_open_3 (on is_open@src/c++98/basic_file.cc in /usr/lib64/libstdc++.so.6.0.22)
    probe_libstdc:is_open_4 (on stdio_filebuf:5@include/ext/stdio_filebuf.h in /usr/lib64/libstdc++.so.6.0.22)
  #

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>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/147464491667.29804.9553638175441827970.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/probe-event.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index bc60ce4..fcfbef0 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -213,9 +213,13 @@ static int convert_exec_to_group(const char *exec, char **result)
 		goto out;
 	}
 
-	ptr2 = strpbrk(ptr1, "-._");
-	if (ptr2)
-		*ptr2 = '\0';
+	for (ptr2 = ptr1; ptr2 != '\0'; ptr2++) {
+		if (!isalnum(*ptr2) && *ptr2 != '_') {
+			*ptr2 = '\0';
+			break;
+		}
+	}
+
 	ret = e_snprintf(buf, 64, "%s_%s", PERFPROBE_GROUP, ptr1);
 	if (ret < 0)
 		goto out;

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [tip:perf/core] perf probe: Match linkage name with mangled name
  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
  0 siblings, 0 replies; 11+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2016-09-29 18:20 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, linux-kernel, namhyung, mingo, peterz, mhiramat, acme,
	dsahern, jolsa, tglx

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);
 

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-09-29 18:21 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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:perf/core] perf probe: " tip-bot for Masami Hiramatsu
2016-09-25 11:14 ` [PATCH perf/core 0/4] perf-probe fixes for C++ Jiri Olsa
2016-09-27 18:11   ` Masami Hiramatsu

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).