aboutsummaryrefslogtreecommitdiffstats
path: root/tools/bpf/bpftool/xlated_dumper.c
diff options
context:
space:
mode:
authorQuentin Monnet <quentin@isovalent.com>2023-04-05 14:21:19 +0100
committerAlexei Starovoitov <ast@kernel.org>2023-04-05 21:27:27 -0700
commit7483a7a70a12d7c00c9f80574d533b01689d39a7 (patch)
tree48cade4a372739780e2bf09db0a13ff3c7aa400d /tools/bpf/bpftool/xlated_dumper.c
parentbpftool: Support "opcodes", "linum", "visual" simultaneously (diff)
downloadlinux-7483a7a70a12d7c00c9f80574d533b01689d39a7.tar.xz
linux-7483a7a70a12d7c00c9f80574d533b01689d39a7.zip
bpftool: Support printing opcodes and source file references in CFG
Add support for displaying opcodes or/and file references (filepath, line and column numbers) when dumping the control flow graphs of loaded BPF programs with bpftool. The filepaths in the records are absolute. To avoid blocks on the graph to get too wide, we truncate them when they get too long (but we always keep the entire file name). In the unlikely case where the resulting file name is ambiguous, it remains possible to get the full path with a regular dump (no CFG). Signed-off-by: Quentin Monnet <quentin@isovalent.com> Link: https://lore.kernel.org/r/20230405132120.59886-7-quentin@isovalent.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/bpf/bpftool/xlated_dumper.c')
-rw-r--r--tools/bpf/bpftool/xlated_dumper.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/tools/bpf/bpftool/xlated_dumper.c b/tools/bpf/bpftool/xlated_dumper.c
index 2ee83561b945..da608e10c843 100644
--- a/tools/bpf/bpftool/xlated_dumper.c
+++ b/tools/bpf/bpftool/xlated_dumper.c
@@ -361,7 +361,8 @@ void dump_xlated_plain(struct dump_data *dd, void *buf, unsigned int len,
}
void dump_xlated_for_graph(struct dump_data *dd, void *buf_start, void *buf_end,
- unsigned int start_idx)
+ unsigned int start_idx,
+ bool opcodes, bool linum)
{
const struct bpf_insn_cbs cbs = {
.cb_print = print_insn_for_graph,
@@ -405,7 +406,7 @@ void dump_xlated_for_graph(struct dump_data *dd, void *buf_start, void *buf_end,
linfo = bpf_prog_linfo__lfind(prog_linfo, insn_off, 0);
if (linfo && linfo != last_linfo) {
- btf_dump_linfo_dotlabel(btf, linfo);
+ btf_dump_linfo_dotlabel(btf, linfo, linum);
last_linfo = linfo;
}
}
@@ -413,6 +414,16 @@ void dump_xlated_for_graph(struct dump_data *dd, void *buf_start, void *buf_end,
printf("%d: ", insn_off);
print_bpf_insn(&cbs, cur, true);
+ if (opcodes) {
+ printf("\\ \\ \\ \\ ");
+ fprint_hex(stdout, cur, 8, " ");
+ if (double_insn && cur <= insn_end - 1) {
+ printf(" ");
+ fprint_hex(stdout, cur + 1, 8, " ");
+ }
+ printf("\\l\\\n");
+ }
+
if (cur != insn_end)
printf("| ");
}