Commit 9b79f027 authored by Quentin Monnet's avatar Quentin Monnet Committed by Alexei Starovoitov

bpftool: Support "opcodes", "linum", "visual" simultaneously

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: default avatarQuentin Monnet <quentin@isovalent.com>
Link: https://lore.kernel.org/r/20230405132120.59886-6-quentin@isovalent.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 05a06be7
...@@ -28,8 +28,8 @@ PROG COMMANDS ...@@ -28,8 +28,8 @@ PROG COMMANDS
============= =============
| **bpftool** **prog** { **show** | **list** } [*PROG*] | **bpftool** **prog** { **show** | **list** } [*PROG*]
| **bpftool** **prog dump xlated** *PROG* [{**file** *FILE* | **opcodes** | **visual** | **linum**}] | **bpftool** **prog dump xlated** *PROG* [{ **file** *FILE* | [**opcodes**] [**linum**] [**visual**] }]
| **bpftool** **prog dump jited** *PROG* [{**file** *FILE* | **opcodes** | **linum**}] | **bpftool** **prog dump jited** *PROG* [{ **file** *FILE* | [**opcodes**] [**linum**] }]
| **bpftool** **prog pin** *PROG* *FILE* | **bpftool** **prog pin** *PROG* *FILE*
| **bpftool** **prog** { **load** | **loadall** } *OBJ* *PATH* [**type** *TYPE*] [**map** {**idx** *IDX* | **name** *NAME*} *MAP*] [**dev** *NAME*] [**pinmaps** *MAP_DIR*] [**autoattach**] | **bpftool** **prog** { **load** | **loadall** } *OBJ* *PATH* [**type** *TYPE*] [**map** {**idx** *IDX* | **name** *NAME*} *MAP*] [**dev** *NAME*] [**pinmaps** *MAP_DIR*] [**autoattach**]
| **bpftool** **prog attach** *PROG* *ATTACH_TYPE* [*MAP*] | **bpftool** **prog attach** *PROG* *ATTACH_TYPE* [*MAP*]
...@@ -88,7 +88,7 @@ DESCRIPTION ...@@ -88,7 +88,7 @@ DESCRIPTION
programs. On such kernels bpftool will automatically emit this programs. On such kernels bpftool will automatically emit this
information as well. information as well.
**bpftool prog dump xlated** *PROG* [{ **file** *FILE* | **opcodes** | **visual** | **linum** }] **bpftool prog dump xlated** *PROG* [{ **file** *FILE* | [**opcodes**] [**linum**] [**visual**] }]
Dump eBPF instructions of the programs from the kernel. By Dump eBPF instructions of the programs from the kernel. By
default, eBPF will be disassembled and printed to standard default, eBPF will be disassembled and printed to standard
output in human-readable format. In this case, **opcodes** output in human-readable format. In this case, **opcodes**
...@@ -109,7 +109,7 @@ DESCRIPTION ...@@ -109,7 +109,7 @@ DESCRIPTION
be displayed. If **linum** is specified, the filename, line be displayed. If **linum** is specified, the filename, line
number and line column will also be displayed. number and line column will also be displayed.
**bpftool prog dump jited** *PROG* [{ **file** *FILE* | **opcodes** | **linum** }] **bpftool prog dump jited** *PROG* [{ **file** *FILE* | [**opcodes**] [**linum**] }]
Dump jited image (host machine code) of the program. Dump jited image (host machine code) of the program.
If *FILE* is specified image will be written to a file, If *FILE* is specified image will be written to a file,
......
...@@ -271,7 +271,7 @@ _bpftool() ...@@ -271,7 +271,7 @@ _bpftool()
# Deal with simplest keywords # Deal with simplest keywords
case $prev in case $prev in
help|hex|opcodes|visual|linum) help|hex)
return 0 return 0
;; ;;
tag) tag)
...@@ -369,13 +369,16 @@ _bpftool() ...@@ -369,13 +369,16 @@ _bpftool()
return 0 return 0
;; ;;
*) *)
# "file" is not compatible with other keywords here
if _bpftool_search_list 'file'; then
return 0
fi
if ! _bpftool_search_list 'linum opcodes visual'; then
_bpftool_once_attr 'file' _bpftool_once_attr 'file'
fi
_bpftool_once_attr 'linum opcodes'
if _bpftool_search_list 'xlated' && [[ "$json" == 0 ]]; then if _bpftool_search_list 'xlated' && [[ "$json" == 0 ]]; then
COMPREPLY+=( $( compgen -W 'opcodes visual linum' -- \ _bpftool_once_attr 'visual'
"$cur" ) )
else
COMPREPLY+=( $( compgen -W 'opcodes linum' -- \
"$cur" ) )
fi fi
return 0 return 0
;; ;;
......
...@@ -905,6 +905,7 @@ static int do_dump(int argc, char **argv) ...@@ -905,6 +905,7 @@ static int do_dump(int argc, char **argv)
if (nb_fds < 1) if (nb_fds < 1)
goto exit_free; goto exit_free;
while (argc) {
if (is_prefix(*argv, "file")) { if (is_prefix(*argv, "file")) {
NEXT_ARG(); NEXT_ARG();
if (!argc) { if (!argc) {
...@@ -932,10 +933,14 @@ static int do_dump(int argc, char **argv) ...@@ -932,10 +933,14 @@ static int do_dump(int argc, char **argv)
} else if (is_prefix(*argv, "linum")) { } else if (is_prefix(*argv, "linum")) {
linum = true; linum = true;
NEXT_ARG(); NEXT_ARG();
} else {
usage();
goto exit_close;
}
} }
if (argc) { if (filepath && (opcodes || visual || linum)) {
usage(); p_err("'file' is not compatible with 'opcodes', 'visual', or 'linum'");
goto exit_close; goto exit_close;
} }
if (json_output && visual) { if (json_output && visual) {
...@@ -2419,8 +2424,8 @@ static int do_help(int argc, char **argv) ...@@ -2419,8 +2424,8 @@ static int do_help(int argc, char **argv)
fprintf(stderr, fprintf(stderr,
"Usage: %1$s %2$s { show | list } [PROG]\n" "Usage: %1$s %2$s { show | list } [PROG]\n"
" %1$s %2$s dump xlated PROG [{ file FILE | opcodes | visual | linum }]\n" " %1$s %2$s dump xlated PROG [{ file FILE | [opcodes] [linum] [visual] }]\n"
" %1$s %2$s dump jited PROG [{ file FILE | opcodes | linum }]\n" " %1$s %2$s dump jited PROG [{ file FILE | [opcodes] [linum] }]\n"
" %1$s %2$s pin PROG FILE\n" " %1$s %2$s pin PROG FILE\n"
" %1$s %2$s { load | loadall } OBJ PATH \\\n" " %1$s %2$s { load | loadall } OBJ PATH \\\n"
" [type TYPE] [dev NAME] \\\n" " [type TYPE] [dev NAME] \\\n"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment