]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
bpftool: btf: Support dumping a specific types from file
authorDaniel Xu <dxu@dxuuu.xyz>
Fri, 13 Dec 2024 19:44:11 +0000 (12:44 -0700)
committerAndrii Nakryiko <andrii@kernel.org>
Fri, 13 Dec 2024 22:35:42 +0000 (14:35 -0800)
commita812d92ed2aee2d57dccb12b289377265f4ce5e7
treeeb26ce0f526530d0c5a7de45056e62cb10f6912a
parent7f5819e1ace85632cf58c43ab6c38d2d4b0aa161
bpftool: btf: Support dumping a specific types from file

Some projects, for example xdp-tools [0], prefer to check in a minimized
vmlinux.h rather than the complete file which can get rather large.

However, when you try to add a minimized version of a complex struct (eg
struct xfrm_state), things can get quite complex if you're trying to
manually untangle and deduplicate the dependencies.

This commit teaches bpftool to do a minimized dump of a specific types by
providing a optional root_id argument(s).

Example usage:

    $ ./bpftool btf dump file ~/dev/linux/vmlinux | rg "STRUCT 'xfrm_state'"
    [12643] STRUCT 'xfrm_state' size=912 vlen=58

    $ ./bpftool btf dump file ~/dev/linux/vmlinux root_id 12643 format c
    #ifndef __VMLINUX_H__
    #define __VMLINUX_H__

    [..]

    struct xfrm_type_offload;

    struct xfrm_sec_ctx;

    struct xfrm_state {
            possible_net_t xs_net;
            union {
                    struct hlist_node gclist;
                    struct hlist_node bydst;
            };
            union {
                    struct hlist_node dev_gclist;
                    struct hlist_node bysrc;
            };
            struct hlist_node byspi;
    [..]

[0]: https://github.com/xdp-project/xdp-tools/blob/master/headers/bpf/vmlinux.h

Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/04feb860c0a56a7da66f923551484e1483a72074.1734119028.git.dxu@dxuuu.xyz
tools/bpf/bpftool/Documentation/bpftool-btf.rst
tools/bpf/bpftool/btf.c