android_kernel_xiaomi_sm8350/tools/perf/util
Leo Yan 25b338db0c perf probe: Correct demangled symbols in C++ program
[ Upstream commit 314909f13cc12d47c468602c37dace512d225eeb ]

An issue can be observed when probe C++ demangled symbol with steps:

  # nm test_cpp_mangle | grep print_data
    0000000000000c94 t _GLOBAL__sub_I__Z10print_datai
    0000000000000afc T _Z10print_datai
    0000000000000b38 T _Z10print_dataR5Point

  # perf probe -x /home/niayan01/test_cpp_mangle -F --demangle
    ...
    print_data(Point&)
    print_data(int)
    ...

  # perf --debug verbose=3 probe -x test_cpp_mangle --add "test=print_data(int)"
    probe-definition(0): test=print_data(int)
    symbol:print_data(int) file:(null) line:0 offset:0 return:0 lazy:(null)
    0 arguments
    Open Debuginfo file: /home/niayan01/test_cpp_mangle
    Try to find probe point from debuginfo.
    Symbol print_data(int) address found : afc
    Matched function: print_data [2ccf]
    Probe point found: print_data+0
    Found 1 probe_trace_events.
    Opening /sys/kernel/tracing//uprobe_events write=1
    Opening /sys/kernel/tracing//README write=0
    Writing event: p:probe_test_cpp_mangle/test /home/niayan01/test_cpp_mangle:0xb38
    ...

When tried to probe symbol "print_data(int)", the log shows:

    Symbol print_data(int) address found : afc

The found address is 0xafc - which is right with verifying the output
result from nm. Afterwards when write event, the command uses offset
0xb38 in the last log, which is a wrong address.

The dwarf_diename() gets a common function name, in above case, it
returns string "print_data". As a result, the tool parses the offset
based on the common name. This leads to probe at the wrong symbol
"print_data(Point&)".

To fix the issue, use the die_get_linkage_name() function to retrieve
the distinct linkage name - this is the mangled name for the C++ case.
Based on this unique name, the tool can get a correct offset for
probing. Based on DWARF doc, it is possible the linkage name is missed
in the DIE, it rolls back to use dwarf_diename().

After:

  # perf --debug verbose=3 probe -x test_cpp_mangle --add "test=print_data(int)"
    probe-definition(0): test=print_data(int)
    symbol:print_data(int) file:(null) line:0 offset:0 return:0 lazy:(null)
    0 arguments
    Open Debuginfo file: /home/niayan01/test_cpp_mangle
    Try to find probe point from debuginfo.
    Symbol print_data(int) address found : afc
    Matched function: print_data [2d06]
    Probe point found: print_data+0
    Found 1 probe_trace_events.
    Opening /sys/kernel/tracing//uprobe_events write=1
    Opening /sys/kernel/tracing//README write=0
    Writing event: p:probe_test_cpp_mangle/test /home/niayan01/test_cpp_mangle:0xafc
    Added new event:
      probe_test_cpp_mangle:test (on print_data(int) in /home/niayan01/test_cpp_mangle)

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

            perf record -e probe_test_cpp_mangle:test -aR sleep 1

  # perf --debug verbose=3 probe -x test_cpp_mangle --add "test2=print_data(Point&)"
    probe-definition(0): test2=print_data(Point&)
    symbol:print_data(Point&) file:(null) line:0 offset:0 return:0 lazy:(null)
    0 arguments
    Open Debuginfo file: /home/niayan01/test_cpp_mangle
    Try to find probe point from debuginfo.
    Symbol print_data(Point&) address found : b38
    Matched function: print_data [2ccf]
    Probe point found: print_data+0
    Found 1 probe_trace_events.
    Opening /sys/kernel/tracing//uprobe_events write=1
    Parsing probe_events: p:probe_test_cpp_mangle/test /home/niayan01/test_cpp_mangle:0x0000000000000afc
    Group:probe_test_cpp_mangle Event:test probe:p
    Opening /sys/kernel/tracing//README write=0
    Writing event: p:probe_test_cpp_mangle/test2 /home/niayan01/test_cpp_mangle:0xb38
    Added new event:
      probe_test_cpp_mangle:test2 (on print_data(Point&) in /home/niayan01/test_cpp_mangle)

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

            perf record -e probe_test_cpp_mangle:test2 -aR sleep 1

Fixes: fb1587d869 ("perf probe: List probes with line number and file name")
Signed-off-by: Leo Yan <leo.yan@arm.com>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Link: https://lore.kernel.org/r/20241012141432.877894-1-leo.yan@arm.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-12-14 19:44:31 +01:00
..
c++
cs-etm-decoder
include
intel-pt-decoder perf intel-pt: Fix CYC timestamps after standalone CBR 2023-05-17 11:35:56 +02:00
libunwind
scripting-engines
annotate.c perf annotate bpf: Don't enclose non-debug code with an assert() 2023-09-23 10:59:57 +02:00
annotate.h
archinsn.h
arm-spe-pkt-decoder.c
arm-spe-pkt-decoder.h
arm-spe.c
arm-spe.h
auxtrace.c perf auxtrace: Fix address filter entire kernel size 2023-05-17 11:35:56 +02:00
auxtrace.h
block-range.c
block-range.h
bpf-event.c perf env: Avoid recursively taking env->bpf_progs.lock 2024-01-25 14:34:31 -08:00
bpf-event.h perf env: Avoid recursively taking env->bpf_progs.lock 2024-01-25 14:34:31 -08:00
bpf-loader.c
bpf-loader.h
bpf-prologue.c
bpf-prologue.h
bpf_map.c
bpf_map.h
branch.c
branch.h
Build
build-id.c
build-id.h
cache.h
cacheline.c
cacheline.h
call-path.c
call-path.h
callchain.c
callchain.h
cap.c
cap.h
cgroup.c
cgroup.h
cloexec.c
cloexec.h
color.c
color.h
color_config.c
comm.c
comm.h
compress.h
config.c
config.h
copyfile.c
copyfile.h
counts.c
counts.h
cpu-set-sched.h
cpumap.c
cpumap.h
cputopo.c
cputopo.h
cs-etm.c perf cs-etm: Don't flush when packet_queue fills up 2024-12-14 19:44:31 +01:00
cs-etm.h
data-convert-bt.c
data-convert-bt.h
data-convert.h
data.c perf tools: Fix resources leak in perf_data__open_dir() 2023-01-18 11:41:58 +01:00
data.h perf tools: Add missing headers needed by util/data.h 2022-06-14 18:11:34 +02:00
db-export.c
db-export.h
debug.c perf script: Fix hex dump character output 2022-01-27 09:19:54 +01:00
debug.h
demangle-java.c
demangle-java.h
demangle-rust.c
demangle-rust.h
dso.c perf dso: Fix memory leak in dso__new_map() 2021-07-28 13:30:54 +02:00
dso.h
dsos.c
dsos.h
dump-insn.c
dump-insn.h
dwarf-aux.c perf dwarf-aux: Fix off-by-one in die_get_varname() 2023-07-27 08:37:17 +02:00
dwarf-aux.h
dwarf-regs.c
env.c perf env: Avoid recursively taking env->bpf_progs.lock 2024-01-25 14:34:31 -08:00
env.h perf env: Avoid recursively taking env->bpf_progs.lock 2024-01-25 14:34:31 -08:00
event.c
event.h
events_stats.h
evlist.c perf bpf: Decouple creating the evlist from adding the SB event 2024-01-25 14:34:31 -08:00
evlist.h perf bpf: Decouple creating the evlist from adding the SB event 2024-01-25 14:34:31 -08:00
evsel.c perf evsel: Fix duplicate initialization of data->id in evsel__parse_sample() 2024-03-26 18:22:19 -04:00
evsel.h
evsel_config.h
evsel_fprintf.c
evsel_fprintf.h
evswitch.c
evswitch.h
expr.h
expr.y
find-map.c
genelf.c perf genelf: Set ELF program header addresses properly 2024-01-25 14:34:31 -08:00
genelf.h perf jit: Include program header in ELF files 2022-09-28 11:04:07 +02:00
genelf_debug.c
generate-cmdlist.sh
get_current_dir_name.c perf tools: Fixup get_current_dir_name() compilation 2022-10-15 07:54:36 +02:00
get_current_dir_name.h
group.h
header.c perf env: Avoid recursively taking env->bpf_progs.lock 2024-01-25 14:34:31 -08:00
header.h
help-unknown-cmd.c
help-unknown-cmd.h
hist.c
hist.h perf hist: Fix memory leak of a perf_hpp_fmt 2021-12-08 09:01:10 +01:00
intel-bts.c
intel-bts.h
intel-pt.c perf intel-pt: Fix segfault in intel_pt_print_info() with uClibc 2022-10-26 13:22:59 +02:00
intel-pt.h
intlist.c
intlist.h
jit.h
jitdump.c
jitdump.h
kvm-stat.h
levenshtein.c
levenshtein.h
llvm-utils.c perf llvm: Fix inadvertent file creation 2023-03-11 16:43:49 +01:00
llvm-utils.h
lzma.c perf lzma: Close lzma stream on exit 2021-07-28 13:30:54 +02:00
machine.c perf machine: Initialize srcline string member in add_location struct 2021-09-22 12:26:41 +02:00
machine.h
map.c Revert "perf map: Fix dso->nsinfo refcounting" 2021-08-04 12:27:40 +02:00
map.h
map_groups.h
map_symbol.h
mem-events.c
mem-events.h
mem2node.c
mem2node.h
memswap.c
memswap.h
metricgroup.c
metricgroup.h
mmap.c
mmap.h
namespaces.c
namespaces.h
ordered-events.c
ordered-events.h
parse-branch-options.c
parse-branch-options.h
parse-events.c
parse-events.h
parse-events.l
parse-events.y
parse-regs-options.c
parse-regs-options.h
path.c
path.h
perf-hooks-list.h
perf-hooks.c
perf-hooks.h
PERF-VERSION-GEN
perf_event_attr_fprintf.c
perf_regs.c
perf_regs.h
pmu.c
pmu.h
pmu.l
pmu.y
print_binary.c
print_binary.h
probe-event.c perf probe: Fix ppc64 'perf probe add events failed' case 2022-02-16 12:52:50 +01:00
probe-event.h
probe-file.c perf probe-file: Delete namelist in del_events() on the error path 2021-07-28 13:30:54 +02:00
probe-file.h
probe-finder.c perf probe: Correct demangled symbols in C++ program 2024-12-14 19:44:31 +01:00
probe-finder.h
pstack.c
pstack.h
python-ext-sources
python.c
rb_resort.h
rblist.c
rblist.h
record.c
record.h
rlimit.c
rlimit.h
rwsem.c
rwsem.h
s390-cpumcf-kernel.h
s390-cpumsf-kernel.h
s390-cpumsf.c
s390-cpumsf.h
s390-sample-raw.c
sample-raw.c
sample-raw.h
session.c perf session: Remap buf if there is no space for event 2022-04-15 14:18:38 +02:00
session.h
setns.c
setup.py
smt.c
smt.h
sort.c perf report: Fix condition in sort__sym_cmp() 2024-08-19 05:33:31 +02:00
sort.h
srccode.c
srccode.h
srcline.c
srcline.h
stat-display.c perf stat: Avoid metric-only segv 2024-03-26 18:22:20 -04:00
stat-shadow.c
stat.c
stat.h
strbuf.c
strbuf.h
strfilter.c
strfilter.h
string.c
string2.h
strlist.c
strlist.h
svghelper.c
svghelper.h
symbol-elf.c perf symbols: Fix return incorrect build_id size in elf_read_build_id() 2023-05-17 11:36:00 +02:00
symbol-minimal.c
symbol.c perf symbols: Fix symbol size calculation condition 2022-03-23 09:12:07 +01:00
symbol.h
symbol_conf.h
symbol_fprintf.c
symsrc.h
synthetic-events.c
synthetic-events.h
syscalltbl.c
syscalltbl.h
target.c
target.h
term.c
term.h
thread-stack.c
thread-stack.h
thread.c
thread.h
thread_map.c perf thread_map: Free strlist on normal path in thread_map__new_by_tid_str() 2024-03-26 18:22:20 -04:00
thread_map.h
time-utils.c perf time-utils: Fix 32-bit nsec parsing 2024-11-08 16:20:31 +01:00
time-utils.h
tool.h
top.c
top.h perf top: Move sb_evlist to 'struct perf_top' 2024-01-25 14:34:31 -08:00
trace-event-info.c
trace-event-parse.c
trace-event-read.c
trace-event-scripting.c
trace-event.c
trace-event.h
trigger.h
tsc.c
tsc.h
units.c
units.h
unwind-libdw.c perf unwind: Set userdata for all __report_module() paths 2021-05-28 13:10:27 +02:00
unwind-libdw.h
unwind-libunwind-local.c
unwind-libunwind.c
unwind.h
usage.c
util.c perf report: Fix memory leaks around perf_tip() 2021-12-08 09:01:10 +01:00
util.h perf report: Fix memory leaks around perf_tip() 2021-12-08 09:01:10 +01:00
values.c
values.h
vdso.c
vdso.h
xyarray.c
zlib.c
zstd.c