1 |
From cf129830ee820f7fc90b98df193cd49d49344d09 Mon Sep 17 00:00:00 2001 |
2 |
From: Adrian Hunter <adrian.hunter@intel.com> |
3 |
Date: Tue, 10 Jan 2023 20:56:59 +0200 |
4 |
Subject: perf auxtrace: Fix address filter duplicate symbol selection |
5 |
|
6 |
From: Adrian Hunter <adrian.hunter@intel.com> |
7 |
|
8 |
commit cf129830ee820f7fc90b98df193cd49d49344d09 upstream. |
9 |
|
10 |
When a match has been made to the nth duplicate symbol, return |
11 |
success not error. |
12 |
|
13 |
Example: |
14 |
|
15 |
Before: |
16 |
|
17 |
$ cat file.c |
18 |
cat: file.c: No such file or directory |
19 |
$ cat file1.c |
20 |
#include <stdio.h> |
21 |
|
22 |
static void func(void) |
23 |
{ |
24 |
printf("First func\n"); |
25 |
} |
26 |
|
27 |
void other(void); |
28 |
|
29 |
int main() |
30 |
{ |
31 |
func(); |
32 |
other(); |
33 |
return 0; |
34 |
} |
35 |
$ cat file2.c |
36 |
#include <stdio.h> |
37 |
|
38 |
static void func(void) |
39 |
{ |
40 |
printf("Second func\n"); |
41 |
} |
42 |
|
43 |
void other(void) |
44 |
{ |
45 |
func(); |
46 |
} |
47 |
|
48 |
$ gcc -Wall -Wextra -o test file1.c file2.c |
49 |
$ perf record -e intel_pt//u --filter 'filter func @ ./test' -- ./test |
50 |
Multiple symbols with name 'func' |
51 |
#1 0x1149 l func |
52 |
which is near main |
53 |
#2 0x1179 l func |
54 |
which is near other |
55 |
Disambiguate symbol name by inserting #n after the name e.g. func #2 |
56 |
Or select a global symbol by inserting #0 or #g or #G |
57 |
Failed to parse address filter: 'filter func @ ./test' |
58 |
Filter format is: filter|start|stop|tracestop <start symbol or address> [/ <end symbol or size>] [@<file name>] |
59 |
Where multiple filters are separated by space or comma. |
60 |
$ perf record -e intel_pt//u --filter 'filter func #2 @ ./test' -- ./test |
61 |
Failed to parse address filter: 'filter func #2 @ ./test' |
62 |
Filter format is: filter|start|stop|tracestop <start symbol or address> [/ <end symbol or size>] [@<file name>] |
63 |
Where multiple filters are separated by space or comma. |
64 |
|
65 |
After: |
66 |
|
67 |
$ perf record -e intel_pt//u --filter 'filter func #2 @ ./test' -- ./test |
68 |
First func |
69 |
Second func |
70 |
[ perf record: Woken up 1 times to write data ] |
71 |
[ perf record: Captured and wrote 0.016 MB perf.data ] |
72 |
$ perf script --itrace=b -Ftime,flags,ip,sym,addr --ns |
73 |
1231062.526977619: tr strt 0 [unknown] => 558495708179 func |
74 |
1231062.526977619: tr end call 558495708188 func => 558495708050 _init |
75 |
1231062.526979286: tr strt 0 [unknown] => 55849570818d func |
76 |
1231062.526979286: tr end return 55849570818f func => 55849570819d other |
77 |
|
78 |
Fixes: 1b36c03e356936d6 ("perf record: Add support for using symbols in address filters") |
79 |
Reported-by: Dmitrii Dolgov <9erthalion6@gmail.com> |
80 |
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> |
81 |
Tested-by: Dmitry Dolgov <9erthalion6@gmail.com> |
82 |
Cc: Adrian Hunter <adrian.hunter@intel.com> |
83 |
Cc: Ian Rogers <irogers@google.com> |
84 |
Cc: Jiri Olsa <jolsa@kernel.org> |
85 |
Cc: Namhyung Kim <namhyung@kernel.org> |
86 |
Cc: stable@vger.kernel.org |
87 |
Link: https://lore.kernel.org/r/20230110185659.15979-1-adrian.hunter@intel.com |
88 |
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> |
89 |
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
90 |
--- |
91 |
tools/perf/util/auxtrace.c | 2 +- |
92 |
1 file changed, 1 insertion(+), 1 deletion(-) |
93 |
|
94 |
--- a/tools/perf/util/auxtrace.c |
95 |
+++ b/tools/perf/util/auxtrace.c |
96 |
@@ -2610,7 +2610,7 @@ static int find_dso_sym(struct dso *dso, |
97 |
*size = sym->start - *start; |
98 |
if (idx > 0) { |
99 |
if (*size) |
100 |
- return 1; |
101 |
+ return 0; |
102 |
} else if (dso_sym_match(sym, sym_name, &cnt, idx)) { |
103 |
print_duplicate_syms(dso, sym_name); |
104 |
return -EINVAL; |