Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpftool: Add inline annotations when dumping program CFGs #4817

Closed
wants to merge 5 commits into from

Conversation

kernel-patches-bot
Copy link

Pull request for series with
subject: bpftool: Add inline annotations when dumping program CFGs
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=733732

@kernel-patches-bot
Copy link
Author

Upstream branch: 55fbae0
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=733732
version: 1

@kernel-patches-bot
Copy link
Author

Upstream branch: 496f4f1
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=733732
version: 1

@kernel-patches-bot
Copy link
Author

Upstream branch: e993607
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=733732
version: 1

@kernel-patches-bot
Copy link
Author

Upstream branch: 8d27596
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=733732
version: 1

@kernel-patches-bot
Copy link
Author

Upstream branch: 8d27596
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=733732
version: 1

@kernel-patches-bot
Copy link
Author

Upstream branch: 8cfee11
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=733732
version: 1

@kernel-patches-bot
Copy link
Author

Upstream branch: 5f5a7d8
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=733732
version: 1

@kernel-patches-bot
Copy link
Author

Upstream branch: 5f5a7d8
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=734111
version: 2

@kernel-patches-bot
Copy link
Author

Upstream branch: f1cb927
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=734111
version: 2

@kernel-patches-bot
Copy link
Author

Upstream branch: 7283137
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=734111
version: 2

The documentation states that when line_info is available when dumping a
program, the source line will be displayed "by default". There is no
notion of "default" here: the line is always displayed if available,
there is no way currently to turn it off.

In the next sentence, the documentation states that if "linum" is used
on the command line, the relevant filename, line, and column will be
displayed "on top of the source line". This is incorrect, as they are
currently displayed on the right side of the source line (or on top of
the eBPF instruction, not the source).

This commit fixes the documentation to address these points.

Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Acked-by: Stanislav Fomichev <sdf@google.com>
When dumping the control flow graphs for programs using the 16-byte long
load instruction, we need to skip the second part of this instruction
when looking for the next instruction to process. Otherwise, we end up
printing "BUG_ld_00" from the kernel disassembler in the CFG.

Fixes: efcef17 ("tools: bpftool: generate .dot graph from CFG information")
Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Acked-by: Stanislav Fomichev <sdf@google.com>
We support dumping the control flow graph of loaded programs to the DOT
format with bpftool, but so far this feature wouldn't display the source
code lines available through BTF along with the eBPF bytecode. Let's add
support for these annotations, to make it easier to read the graph.

In prog.c, we move the call to dump_xlated_cfg() in order to pass and
use the full struct dump_data, instead of creating a minimal one in
draw_bb_node().

We pass the pointer to this struct down to dump_xlated_for_graph() in
xlated_dumper.c, where most of the logics is added. We deal with BTF
mostly like we do for plain or JSON output, except that we cannot use a
"nr_skip" value to skip a given number of linfo records (we don't
process the BPF instructions linearly, and apart from the root of the
graph we don't know how many records we should skip, so we just store
the last linfo and make sure the new one we find is different before
printing it).

When printing the source instructions to the label of a DOT graph node,
there are a few subtleties to address. We want some special newline
markers, and there are some characters that we must escape. To deal with
them, we introduce a new dedicated function btf_dump_linfo_dotlabel() in
btf_dumper.c. We'll reuse this function in a later commit to format the
filepath, line, and column references as well.

Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Acked-by: Stanislav Fomichev <sdf@google.com>
@kernel-patches-bot
Copy link
Author

Upstream branch: d08ab82
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=734111
version: 2

When dumping a program, the keywords "opcodes" (for printing the raw
opcodes), "linum" (for displaying the filename, line number, column
number along with the source code), and "visual" (for generating the
control flow graph for translated programs) are mutually exclusive. But
there's no reason why they should be. Let's make it possible to pass
several of them at once. The "file FILE" option, which makes bpftool
output a binary image to a file, remains incompatible with the others.

Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Acked-by: Stanislav Fomichev <sdf@google.com>
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.

Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Acked-by: Stanislav Fomichev <sdf@google.com>
@kernel-patches-bot
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=734111 expired. Closing PR.

@kernel-patches-bot kernel-patches-bot deleted the series/733732=>bpf-next branch March 30, 2023 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants