perf probe: Fix to avoid crashing if DW_AT_decl_file is NULL
authorMasami Hiramatsu (Google) <mhiramat@kernel.org>
Tue, 1 Nov 2022 13:48:30 +0000 (22:48 +0900)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 3 Nov 2022 12:24:46 +0000 (09:24 -0300)
commit98e4c68ddcaf3721df9bef809775a8e3562cb6f9
treead08eef840c71feef1c18d539195608750392930
parent940da138b03ecb5bca68ef51dc1141f115100eed
perf probe: Fix to avoid crashing if DW_AT_decl_file is NULL

Since clang generates DWARF5 which sets DW_AT_decl_file as 0,
dwarf_decl_file() thinks that is invalid and returns NULL.  In that case
'perf probe' SIGSEGVs because it doesn't expect a NULL decl_file.

This adds a dwarf_decl_file() return value check to avoid such SEGV with
clang generated DWARF5 info.

Without this, 'perf probe' crashes:

  $ perf probe -k $BIN_PATH/vmlinux -s $SRC_PATH -L vfs_read:10
  Segmentation fault
  $

With this, it just warns about it:

  $ perf probe -k $BIN_PATH/vmlinux -s $SRC_PATH -L vfs_read:10
  Debuginfo analysis failed.
    Error: Failed to show lines.
  $

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Link: https://lore.kernel.org/r/166731051077.2100653.15626653369345128302.stgit@devnote3
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/dwarf-aux.c
tools/perf/util/probe-finder.c