Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf annotate: Make sure to call symbol__annotate2() in TUI

The symbol__annotate2() initializes some data structures needed by TUI.
It has a logic to prevent calling it multiple times by checking if it
has the annotated source. But data type profiling uses a different
code (symbol__annotate) to allocate the annotated lines in advance.
So TUI missed to call symbol__annotate2() when it shows the annotation
browser.

Make symbol__annotate() reentrant and handle that situation properly.
This fixes a crash in the annotation browser started by perf report in
TUI like below.

$ perf report -s type,sym --tui
# and press 'a' key and then move down

Fixes: 81e57deec325 ("perf report: Support data type profiling")
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240405211800.1412920-2-namhyung@kernel.org

+4 -1
+1 -1
tools/perf/ui/browsers/annotate.c
··· 970 970 if (dso->annotate_warned) 971 971 return -1; 972 972 973 - if (not_annotated) { 973 + if (not_annotated || !sym->annotate2) { 974 974 err = symbol__annotate2(ms, evsel, &browser.arch); 975 975 if (err) { 976 976 char msg[BUFSIZ];
+3
tools/perf/util/annotate.c
··· 2461 2461 if (parch) 2462 2462 *parch = arch; 2463 2463 2464 + if (!list_empty(&notes->src->source)) 2465 + return 0; 2466 + 2464 2467 args.arch = arch; 2465 2468 args.ms = *ms; 2466 2469 if (annotate_opts.full_addr)