Skip to content

Commit 4d374ba

Browse files
qmonnetAlexei Starovoitov
authored andcommitted
tools: bpftool: implement "bpftool btf show|list"
Add a "btf list" (alias: "btf show") subcommand to bpftool in order to dump all BTF objects loaded on a system. When running the command, hash tables are built in bpftool to retrieve all the associations between BTF objects and BPF maps and programs. This allows for printing all such associations when listing the BTF objects. The command is added at the top of the subcommands for "bpftool btf", so that typing only "bpftool btf" also comes down to listing the programs. We could not have this with the previous command ("dump"), which required a BTF object id, so it should not break any previous behaviour. This also makes the "btf" command behaviour consistent with "prog" or "map". Bash completion is updated to use "bpftool btf" instead of "bpftool prog" to list the BTF ids, as it looks more consistent. Example output (plain): # bpftool btf show 9: size 2989B prog_ids 21 map_ids 15 17: size 2847B prog_ids 36 map_ids 30,29,28 26: size 2847B Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com> Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 09d7c2e commit 4d374ba

File tree

3 files changed

+363
-6
lines changed

3 files changed

+363
-6
lines changed

tools/bpf/bpftool/Documentation/bpftool-btf.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ SYNOPSIS
1919
BTF COMMANDS
2020
=============
2121

22+
| **bpftool** **btf** { **show** | **list** } [**id** *BTF_ID*]
2223
| **bpftool** **btf dump** *BTF_SRC* [**format** *FORMAT*]
2324
| **bpftool** **btf help**
2425
|
@@ -29,6 +30,12 @@ BTF COMMANDS
2930
3031
DESCRIPTION
3132
===========
33+
**bpftool btf { show | list }** [**id** *BTF_ID*]
34+
Show information about loaded BTF objects. If a BTF ID is
35+
specified, show information only about given BTF object,
36+
otherwise list all BTF objects currently loaded on the
37+
system.
38+
3239
**bpftool btf dump** *BTF_SRC*
3340
Dump BTF entries from a given *BTF_SRC*.
3441

tools/bpf/bpftool/bash-completion/bpftool

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ _bpftool_get_prog_tags()
7373

7474
_bpftool_get_btf_ids()
7575
{
76-
COMPREPLY+=( $( compgen -W "$( bpftool -jp prog 2>&1 | \
77-
command sed -n 's/.*"btf_id": \(.*\),\?$/\1/p' )" -- "$cur" ) )
76+
COMPREPLY+=( $( compgen -W "$( bpftool -jp btf 2>&1 | \
77+
command sed -n 's/.*"id": \(.*\),$/\1/p' )" -- "$cur" ) )
7878
}
7979

8080
_bpftool_get_obj_map_names()
@@ -670,7 +670,7 @@ _bpftool()
670670
map)
671671
_bpftool_get_map_ids
672672
;;
673-
dump)
673+
$command)
674674
_bpftool_get_btf_ids
675675
;;
676676
esac
@@ -698,9 +698,21 @@ _bpftool()
698698
;;
699699
esac
700700
;;
701+
show|list)
702+
case $prev in
703+
$command)
704+
COMPREPLY+=( $( compgen -W "id" -- "$cur" ) )
705+
;;
706+
id)
707+
_bpftool_get_btf_ids
708+
;;
709+
esac
710+
return 0
711+
;;
701712
*)
702713
[[ $prev == $object ]] && \
703-
COMPREPLY=( $( compgen -W 'dump help' -- "$cur" ) )
714+
COMPREPLY=( $( compgen -W 'dump help show list' \
715+
-- "$cur" ) )
704716
;;
705717
esac
706718
;;

0 commit comments

Comments
 (0)