summaryrefslogtreecommitdiffstats
path: root/tools/bpf/bpftool/cfg.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/cfg.c
parent9b79f02722bbf24f060b2ab79513ad6e22c8e2f0 (diff)
downloadlinux-stable-7483a7a70a12d7c00c9f80574d533b01689d39a7.tar.gz
linux-stable-7483a7a70a12d7c00c9f80574d533b01689d39a7.tar.bz2
linux-stable-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/cfg.c')
-rw-r--r--tools/bpf/bpftool/cfg.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/tools/bpf/bpftool/cfg.c b/tools/bpf/bpftool/cfg.c
index 9fdc1f0cdd6e..eec437cca2ea 100644
--- a/tools/bpf/bpftool/cfg.c
+++ b/tools/bpf/bpftool/cfg.c
@@ -381,7 +381,8 @@ static void cfg_destroy(struct cfg *cfg)
}
static void
-draw_bb_node(struct func_node *func, struct bb_node *bb, struct dump_data *dd)
+draw_bb_node(struct func_node *func, struct bb_node *bb, struct dump_data *dd,
+ bool opcodes, bool linum)
{
const char *shape;
@@ -401,7 +402,8 @@ draw_bb_node(struct func_node *func, struct bb_node *bb, struct dump_data *dd)
unsigned int start_idx;
printf("{\\\n");
start_idx = bb->head - func->start;
- dump_xlated_for_graph(dd, bb->head, bb->tail, start_idx);
+ dump_xlated_for_graph(dd, bb->head, bb->tail, start_idx,
+ opcodes, linum);
printf("}");
}
@@ -427,12 +429,14 @@ static void draw_bb_succ_edges(struct func_node *func, struct bb_node *bb)
}
}
-static void func_output_bb_def(struct func_node *func, struct dump_data *dd)
+static void
+func_output_bb_def(struct func_node *func, struct dump_data *dd,
+ bool opcodes, bool linum)
{
struct bb_node *bb;
list_for_each_entry(bb, &func->bbs, l) {
- draw_bb_node(func, bb, dd);
+ draw_bb_node(func, bb, dd, opcodes, linum);
}
}
@@ -452,7 +456,8 @@ static void func_output_edges(struct func_node *func)
func_idx, ENTRY_BLOCK_INDEX, func_idx, EXIT_BLOCK_INDEX);
}
-static void cfg_dump(struct cfg *cfg, struct dump_data *dd)
+static void
+cfg_dump(struct cfg *cfg, struct dump_data *dd, bool opcodes, bool linum)
{
struct func_node *func;
@@ -460,14 +465,15 @@ static void cfg_dump(struct cfg *cfg, struct dump_data *dd)
list_for_each_entry(func, &cfg->funcs, l) {
printf("subgraph \"cluster_%d\" {\n\tstyle=\"dashed\";\n\tcolor=\"black\";\n\tlabel=\"func_%d ()\";\n",
func->idx, func->idx);
- func_output_bb_def(func, dd);
+ func_output_bb_def(func, dd, opcodes, linum);
func_output_edges(func);
printf("}\n");
}
printf("}\n");
}
-void dump_xlated_cfg(struct dump_data *dd, void *buf, unsigned int len)
+void dump_xlated_cfg(struct dump_data *dd, void *buf, unsigned int len,
+ bool opcodes, bool linum)
{
struct bpf_insn *insn = buf;
struct cfg cfg;
@@ -476,7 +482,7 @@ void dump_xlated_cfg(struct dump_data *dd, void *buf, unsigned int len)
if (cfg_build(&cfg, insn, len))
return;
- cfg_dump(&cfg, dd);
+ cfg_dump(&cfg, dd, opcodes, linum);
cfg_destroy(&cfg);
}