linux/tools/perf
Namhyung Kim bc10db8eb8 perf annotate-data: Support stack variables
Local variables are allocated in the stack and the location list
should look like base register(s) and an offset.  Extend the
die_find_variable_by_reg() to handle the following expressions

 * DW_OP_breg{0..31}
 * DW_OP_bregx
 * DW_OP_fbreg

Ususally DWARF subprogram entries have frame base information and
use it to locate stack variable like below:

 <2><43d1575>: Abbrev Number: 62 (DW_TAG_variable)
    <43d1576>   DW_AT_location    : 2 byte block: 91 7c         (DW_OP_fbreg: -4)  <--- here
    <43d1579>   DW_AT_name        : (indirect string, offset: 0x2c00c9): i
    <43d157d>   DW_AT_decl_file   : 1
    <43d157e>   DW_AT_decl_line   : 78
    <43d157f>   DW_AT_type        : <0x43d19d7>

I found some differences on saving the frame base between gcc and clang.
The gcc uses the CFA to get the base so it needs to check the current
frame's CFI info.  In this case, stack offset needs to be adjusted from
the start of the CFA.

 <1><1bb8d>: Abbrev Number: 102 (DW_TAG_subprogram)
    <1bb8e>   DW_AT_name        : (indirect string, offset: 0x74d41): kernel_init
    <1bb92>   DW_AT_decl_file   : 2
    <1bb92>   DW_AT_decl_line   : 1440
    <1bb94>   DW_AT_decl_column : 18
    <1bb95>   DW_AT_prototyped  : 1
    <1bb95>   DW_AT_type        : <0xcc>
    <1bb99>   DW_AT_low_pc      : 0xffffffff81bab9e0
    <1bba1>   DW_AT_high_pc     : 0x1b2
    <1bba9>   DW_AT_frame_base  : 1 byte block: 9c      (DW_OP_call_frame_cfa)  <------ here
    <1bbab>   DW_AT_call_all_calls: 1
    <1bbab>   DW_AT_sibling     : <0x1bf5a>

While clang sets it to a register directly and it can check the register
and offset in the instruction directly.

 <1><43d1542>: Abbrev Number: 60 (DW_TAG_subprogram)
    <43d1543>   DW_AT_low_pc      : 0xffffffff816a7c60
    <43d154b>   DW_AT_high_pc     : 0x98
    <43d154f>   DW_AT_frame_base  : 1 byte block: 56    (DW_OP_reg6 (rbp))  <---------- here
    <43d1551>   DW_AT_GNU_all_call_sites: 1
    <43d1551>   DW_AT_name        : (indirect string, offset: 0x3bce91): foo
    <43d1555>   DW_AT_decl_file   : 1
    <43d1556>   DW_AT_decl_line   : 75
    <43d1557>   DW_AT_prototyped  : 1
    <43d1557>   DW_AT_type        : <0x43c7332>
    <43d155b>   DW_AT_external    : 1

Also it needs to update the offset after finding the type like global
variables since the offset was from the frame base.  Factor out
match_var_offset() to check global and local variables in the same way.

The type stats are improved too:

  Annotate data type stats:
  total 294, ok 160 (54.4%), bad 134 (45.6%)
  -----------------------------------------------------------
          30 : no_sym
          32 : no_mem_ops
          51 : no_var
          14 : no_typeinfo
           7 : bad_offset

Reviewed-by: Ian Rogers <irogers@google.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Link: https://lore.kernel.org/r/20240117062657.985479-9-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2024-01-22 12:08:20 -08:00
..
arch perf tools improvements and fixes for v6.8: 2024-01-19 14:25:23 -08:00
bench libperf cpumap: Replace usage of perf_cpu_map__new(NULL) with perf_cpu_map__new_online_cpus() 2023-12-12 14:55:13 -03:00
dlfilters perf dlfilter: Add a test for object_code() 2023-09-30 00:09:06 -07:00
Documentation perf tools improvements and fixes for v6.8: 2024-01-19 14:25:23 -08:00
include/perf perf dlfilter: Add al_cleanup() 2023-08-15 16:41:49 -03:00
jvmti
pmu-events perf vendor events intel: Update sapphirerapids events to v1.17 2024-01-04 17:38:18 -03:00
python
scripts perf scripts python arm-cs-trace-disasm.py: Do not ignore disam first sample 2023-12-20 14:31:59 -03:00
tests perf test: raise limit to 20 percent for perf_stat_--bpf-counters_test 2024-01-22 12:08:19 -08:00
trace Merge remote-tracking branch 'torvalds/master' into perf-tools-next 2023-12-18 21:37:07 -03:00
ui perf TUI: Don't ignore job control 2024-01-04 18:29:17 -03:00
util perf annotate-data: Support stack variables 2024-01-22 12:08:20 -08:00
.gitignore perf build: Shellcheck support for OUTPUT directory 2023-12-05 15:46:43 -03:00
Build
builtin-annotate.c perf annotate: Add --insn-stat option for debugging 2023-12-23 22:40:17 -03:00
builtin-bench.c perf tools changes for v6.6: 2023-09-09 20:06:17 -07:00
builtin-buildid-cache.c perf buildid-cache: Fix use of uninitialized value 2023-10-12 10:01:56 -07:00
builtin-buildid-list.c
builtin-c2c.c libperf cpumap: Rename perf_cpu_map__empty() to perf_cpu_map__has_any_cpu_or_is_empty() 2023-12-12 14:55:13 -03:00
builtin-config.c perf path: Make mkpath thread safe, remove 16384 bytes from .bss 2023-05-28 10:24:14 -03:00
builtin-daemon.c perf tools: Add missing else to cmd_daemon subcommand condition 2023-06-27 12:09:44 -07:00
builtin-data.c
builtin-diff.c perf diff: Replaces some ',' as separator with the more usual ';' 2023-07-20 11:43:45 -03:00
builtin-evlist.c
builtin-ftrace.c libperf cpumap: Replace usage of perf_cpu_map__new(NULL) with perf_cpu_map__new_online_cpus() 2023-12-12 14:55:13 -03:00
builtin-help.c perf path: Make mkpath thread safe, remove 16384 bytes from .bss 2023-05-28 10:24:14 -03:00
builtin-inject.c perf record: Lazy load kernel symbols 2023-11-09 13:49:32 -03:00
builtin-kallsyms.c perf symbol: Remove now unused symbol_conf.sort_by_name 2023-06-23 21:48:49 -07:00
builtin-kmem.c perf callchain: Use pthread keys for tls callchain_cursor 2023-06-12 15:57:54 -03:00
builtin-kvm.c perf evsel: Introduce evsel__name_is() method to check if the evsel name is equal to a given string 2023-04-24 14:28:11 -03:00
builtin-kwork.c perf kwork: Fix a build error on 32-bit 2023-11-21 10:02:38 -08:00
builtin-list.c perf list: Fix JSON segfault by setting the used skip_duplicate_pmus callback 2023-12-05 11:16:00 -08:00
builtin-lock.c perf lock: Fix a memory leak on an error path 2023-11-27 10:21:27 -03:00
builtin-mem.c perf addr_location: Add init/exit/copy functions 2023-06-12 15:57:53 -03:00
builtin-probe.c perf probe: Dynamically allocate params memory 2023-05-28 10:24:02 -03:00
builtin-record.c perf record: Reduce memory for recording PERF_RECORD_LOST_SAMPLES event 2024-01-03 17:55:01 -03:00
builtin-report.c perf report: Support data type profiling 2023-12-23 22:39:42 -03:00
builtin-sched.c libperf rc_check: Add RC_CHK_EQUAL 2023-10-25 13:37:22 -07:00
builtin-script.c perf: script: fix missing ',' for fields option 2023-10-17 12:40:51 -07:00
builtin-stat.c perf stat: Combine the -A/--no-aggr and --no-merge options 2023-12-14 18:24:38 -03:00
builtin-timechart.c perf addr_location: Add init/exit/copy functions 2023-06-12 15:57:53 -03:00
builtin-top.c perf top: Uniform the event name for the hybrid machine 2023-12-14 19:13:10 -03:00
builtin-trace.c perf env: Introduce perf_env__arch_strerrno() 2023-12-04 16:42:09 -03:00
builtin-version.c perf version: Add status of bpf skeletons 2023-09-18 16:46:15 -07:00
builtin.h
check-headers.sh perf tools: Add get_unaligned_leNN() 2023-10-17 12:40:02 -07:00
command-list.txt
CREDITS
design.txt
Makefile
Makefile.config perf build: Check whether pkg-config is installed when libtraceevent is linked 2024-01-22 12:08:19 -08:00
Makefile.perf Merge remote-tracking branch 'torvalds/master' into perf-tools-next 2023-12-18 21:37:07 -03:00
MANIFEST tools perf: Add arm64 sysreg files to MANIFEST 2023-11-22 11:17:53 -08:00
perf-archive.sh perf archive: Add new option '--unpack' to expand tarballs 2023-12-20 13:20:45 -03:00
perf-completion.sh perf shell completion: Support completion of metrics/metricgroups 2023-09-11 10:26:36 -03:00
perf-iostat.sh
perf-read-vdso.c
perf-sys.h
perf.c perf tools: Add --debug-file option to redirect debug output 2023-11-28 14:14:53 -03:00
perf.h