• Quentin Monnet's avatar
    tools: bpftool: implement "bpftool btf show|list" · 4d374ba0
    Quentin Monnet authored
    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: default avatarQuentin Monnet <quentin.monnet@netronome.com>
    Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    4d374ba0
btf.c 19 KB