perf srcline: Fix handling of inline functions
authorIan Rogers <irogers@google.com>
Thu, 15 Jun 2023 02:50:41 +0000 (19:50 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 16 Jun 2023 00:54:02 +0000 (21:54 -0300)
commite90208e9ffe6cbeb3c14cba14082137bcb633ffe
tree7bd5c1c67ea97976cfea6da74112af2c4f19afaa
parent701677b95764c06bb058c92be11c3a4ad25ab5f2
perf srcline: Fix handling of inline functions

We write an address then a ',' to addr2line. With inline data we
generally get back (// are my comments):
0x1234    // address
foo       // function name
foo.c:123 // filename:line
bar       // function name
bar.c:123 // filename:line
0x000000000000000 // sentinel address created by ','
??        // unknown function name
??:0      // unknown filename:line

The code was assuming the inline data also had the address, which is
incorrect. This means the first inline function name (bar above) needs
to be checked to see if it is the sentinel, otherwise to be treated as
a function name. The regression was caused by the addition of
addresses as the kernel is reporting a symbol at address 0 (used by
GNU binutils when it interprets ',').

Committer testing:

Using:

  # perf trace --call-graph=dwarf -e lock:contention_*
  <SNIP>
  1244.615 TaskCon~ller #/2645281 lock:contention_begin(lock_addr: 0xffff8e6748da5ab0, flags: 2)
                                       __preempt_count_dec_and_test (inlined)
                                       trace_contention_begin (inlined)
                                       trace_contention_begin (inlined)
                                       rwsem_down_read_slowpath ([kernel.kallsyms])
                                       __preempt_count_dec_and_test (inlined)
                                       trace_contention_begin (inlined)
                                       trace_contention_begin (inlined)
                                       rwsem_down_read_slowpath ([kernel.kallsyms])
                                       __down_read_common (inlined)
                                       __down_read (inlined)
                                       down_read ([kernel.kallsyms])
                                       arch_static_branch (inlined)
                                       static_key_false (inlined)
                                       __mmap_lock_trace_acquire_returned (inlined)
                                       mmap_read_lock (inlined)
                                       do_user_addr_fault ([kernel.kallsyms])
                                       arch_local_irq_disable (inlined)
                                       handle_page_fault (inlined)
                                       exc_page_fault ([kernel.kallsyms])
                                       asm_exc_page_fault ([kernel.kallsyms])
                                       [0x4def008] (/usr/lib64/firefox/libxul.so)
  1244.619 TaskCon~ller #/2645281 lock:contention_end(lock_addr: 0xffff8e6748da5ab0)
                                       __preempt_count_dec_and_test (inlined)
                                       trace_contention_end (inlined)
                                       trace_contention_end (inlined)
                                       rwsem_down_read_slowpath ([kernel.kallsyms])
                                       __preempt_count_dec_and_test (inlined)
                                       trace_contention_end (inlined)
                                       trace_contention_end (inlined)
                                       rwsem_down_read_slowpath ([kernel.kallsyms])
                                       __down_read_common (inlined)
                                       __down_read (inlined)
                                       down_read ([kernel.kallsyms])
                                       arch_static_branch (inlined)
                                       static_key_false (inlined)
                                       __mmap_lock_trace_acquire_returned (inlined)
                                       mmap_read_lock (inlined)
                                       do_user_addr_fault ([kernel.kallsyms])
                                       arch_local_irq_disable (inlined)
                                       handle_page_fault (inlined)
                                       exc_page_fault ([kernel.kallsyms])
                                       asm_exc_page_fault ([kernel.kallsyms])
  <SNIP>

Fixes: 8dc26b6f718a8118 ("perf srcline: Make sentinel reading for binutils addr2line more robust")
Reported-by: Arnaldo Carvalho de Melo <acme@kernel.org>
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: llvm@lists.linux.dev
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Tom Rix <trix@redhat.com>
Link: https://lore.kernel.org/r/20230615025041.1982072-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/srcline.c