Skip to content

Commit 262c614

Browse files
TianyouLinamhyung
authored andcommitted
perf annotate: fix a crash when annotate the same symbol with 's' and 'T'
When perf report with annotation for a symbol, press 's' and 'T', then exit the annotate browser. Once annotate the same symbol, the annotate browser will crash. The browser.arch was required to be correctly updated when data type feature was enabled by 'T'. Usually it was initialized by symbol__annotate2 function. If a symbol has already been correctly annotated at the first time, it should not call the symbol__annotate2 function again, thus the browser.arch will not get initialized. Then at the second time to show the annotate browser, the data type needs to be displayed but the browser.arch is empty. Stack trace as below: Perf: Segmentation fault -------- backtrace -------- #0 0x55d365 in ui__signal_backtrace setup.c:0 #1 0x7f5ff1a3e930 in __restore_rt libc.so.6[3e930] #2 0x570f08 in arch__is perf[570f08] #3 0x562186 in annotate_get_insn_location perf[562186] #4 0x562626 in __hist_entry__get_data_type annotate.c:0 #5 0x56476d in annotation_line__write perf[56476d] torvalds#6 0x54e2db in annotate_browser__write annotate.c:0 torvalds#7 0x54d061 in ui_browser__list_head_refresh perf[54d061] torvalds#8 0x54dc9e in annotate_browser__refresh annotate.c:0 torvalds#9 0x54c03d in __ui_browser__refresh browser.c:0 torvalds#10 0x54ccf8 in ui_browser__run perf[54ccf8] torvalds#11 0x54eb92 in __hist_entry__tui_annotate perf[54eb92] torvalds#12 0x552293 in do_annotate hists.c:0 torvalds#13 0x55941c in evsel__hists_browse hists.c:0 torvalds#14 0x55b00f in evlist__tui_browse_hists perf[55b00f] torvalds#15 0x42ff02 in cmd_report perf[42ff02] torvalds#16 0x494008 in run_builtin perf.c:0 torvalds#17 0x494305 in handle_internal_command perf.c:0 torvalds#18 0x410547 in main perf[410547] torvalds#19 0x7f5ff1a295d0 in __libc_start_call_main libc.so.6[295d0] torvalds#20 0x7f5ff1a29680 in __libc_start_main@@GLIBC_2.34 libc.so.6[29680] torvalds#21 0x410b75 in _start perf[410b75] Fixes: 1d4374a ("perf annotate: Add 'T' hot key to toggle data type display") Reviewed-by: James Clark <[email protected]> Tested-by: Namhyung Kim <[email protected]> Signed-off-by: Tianyou Li <[email protected]> Signed-off-by: Namhyung Kim <[email protected]>
1 parent 0e6c07a commit 262c614

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

tools/perf/ui/browsers/annotate.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,18 @@ static s64 annotate_browser__curr_hot_offset(struct annotate_browser *browser)
862862
return al ? al->offset : 0;
863863
}
864864

865+
static void annotate_browser__symbol_annotate_error(struct annotate_browser *browser, int err)
866+
{
867+
struct map_symbol *ms = browser->b.priv;
868+
struct symbol *sym = ms->sym;
869+
struct dso *dso = map__dso(ms->map);
870+
char msg[BUFSIZ];
871+
872+
dso__set_annotate_warned(dso);
873+
symbol__strerror_disassemble(ms, err, msg, sizeof(msg));
874+
ui__error("Couldn't annotate %s:\n%s", sym->name, msg);
875+
}
876+
865877
static int annotate_browser__run(struct annotate_browser *browser,
866878
struct evsel *evsel,
867879
struct hist_browser_timer *hbt)
@@ -1175,10 +1187,7 @@ int __hist_entry__tui_annotate(struct hist_entry *he, struct map_symbol *ms,
11751187
if (not_annotated || !sym->annotate2) {
11761188
err = symbol__annotate2(ms, evsel, &browser.arch);
11771189
if (err) {
1178-
char msg[BUFSIZ];
1179-
dso__set_annotate_warned(dso);
1180-
symbol__strerror_disassemble(ms, err, msg, sizeof(msg));
1181-
ui__error("Couldn't annotate %s:\n%s", sym->name, msg);
1190+
annotate_browser__symbol_annotate_error(&browser, err);
11821191
return -1;
11831192
}
11841193

@@ -1187,6 +1196,12 @@ int __hist_entry__tui_annotate(struct hist_entry *he, struct map_symbol *ms,
11871196
if (!annotation__has_source(notes))
11881197
ui__warning("Annotation has no source code.");
11891198
}
1199+
} else {
1200+
err = evsel__get_arch(evsel, &browser.arch);
1201+
if (err) {
1202+
annotate_browser__symbol_annotate_error(&browser, err);
1203+
return -1;
1204+
}
11901205
}
11911206

11921207
/* Copy necessary information when it's called from perf top */

tools/perf/util/annotate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ void symbol__calc_percent(struct symbol *sym, struct evsel *evsel)
980980
annotation__calc_percent(notes, evsel, symbol__size(sym));
981981
}
982982

983-
static int evsel__get_arch(struct evsel *evsel, struct arch **parch)
983+
int evsel__get_arch(struct evsel *evsel, struct arch **parch)
984984
{
985985
struct perf_env *env = evsel__env(evsel);
986986
const char *arch_name = perf_env__arch(env);

tools/perf/util/annotate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,4 +585,6 @@ void debuginfo_cache__delete(void);
585585
int annotation_br_cntr_entry(char **str, int br_cntr_nr, u64 *br_cntr,
586586
int num_aggr, struct evsel *evsel);
587587
int annotation_br_cntr_abbr_list(char **str, struct evsel *evsel, bool header);
588+
589+
int evsel__get_arch(struct evsel *evsel, struct arch **parch);
588590
#endif /* __PERF_ANNOTATE_H */

0 commit comments

Comments
 (0)