Skip to contentSkip to conversation

perf annotate: Fix printing of unaugmented disassembled instructions from BPF

tip:perf/urgent tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Aug 8, 2019 perf events

lore
Share & tools
lore
#0 lore raw
Commit-ID:  85127775a65fc58e69af0c44513937d471ccbe7b
Gitweb:     https://git.kernel.org/tip/85127775a65fc58e69af0c44513937d471ccbe7b
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Tue, 6 Aug 2019 11:24:09 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 8 Aug 2019 15:40:56 -0300

perf annotate: Fix printing of unaugmented disassembled instructions from BPF

The code to disassemble BPF programs uses binutil's disassembling routines, and those use in turn fprintf to print to a memstream FILE, adding a newline at the end of each line, which ends up confusing the TUI routines called from:

annotate_browser__write()
annotate_line__write()
annotate_browser__printf()
ui_browser__vprintf()
SLsmg_vprintf()

The SLsmg_vprintf() function in the slang library gets confused with the terminating newline, so make the disasm_line__parse() function that parses the lines produced by the BPF specific disassembler (that uses binutil's libopcodes) and the lines produced by the objdump based disassembler used for everything else (and that doesn't adds this terminating newline) trim the end of the line in addition of the beginning.

This way when disasm_line->ops.raw, i.e. for instructions without a special scnprintf() method, we'll not have that \n getting in the way of filling the screen right after the instruction with spaces to avoid leaving what was on the screen before and thus garbling the annotation screen, breaking scrolling, etc.

Cc Adrian Hunter <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Song Liu <[email protected]>
Fixes 6987561c9e86 ("perf annotate: Enable annotation of BPF programs")
---
 tools/perf/util/annotate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/annotate.c +1 -1
index ac9ad2330f93..163536720149 100644
@@ -1122,7 +1122,7 @@ static int disasm_line__parse(char *line, const char **namep, char **rawp)
 		goto out;
 
 	(*rawp)[0] = tmp;
-	*rawp = skip_spaces(*rawp);
+	*rawp = strim(*rawp);
 
 	return 0;