^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) ================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) bpftool-btf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) ================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) -------------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) tool for inspection of BTF data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) -------------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) :Manual section: 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) SYNOPSIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) ========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) **bpftool** [*OPTIONS*] **btf** *COMMAND*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *COMMANDS* := { **dump** | **help** }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) BTF COMMANDS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) =============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) | **bpftool** **btf** { **show** | **list** } [**id** *BTF_ID*]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) | **bpftool** **btf dump** *BTF_SRC* [**format** *FORMAT*]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) | **bpftool** **btf help**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) | *BTF_SRC* := { **id** *BTF_ID* | **prog** *PROG* | **map** *MAP* [{**key** | **value** | **kv** | **all**}] | **file** *FILE* }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) | *FORMAT* := { **raw** | **c** }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) | *MAP* := { **id** *MAP_ID* | **pinned** *FILE* }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) | *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) DESCRIPTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) ===========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) **bpftool btf { show | list }** [**id** *BTF_ID*]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) Show information about loaded BTF objects. If a BTF ID is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) specified, show information only about given BTF object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) otherwise list all BTF objects currently loaded on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) Since Linux 5.8 bpftool is able to discover information about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) processes that hold open file descriptors (FDs) against BTF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) objects. On such kernels bpftool will automatically emit this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) information as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) **bpftool btf dump** *BTF_SRC*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) Dump BTF entries from a given *BTF_SRC*.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) When **id** is specified, BTF object with that ID will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) loaded and all its BTF types emitted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) When **map** is provided, it's expected that map has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) associated BTF object with BTF types describing key and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) value. It's possible to select whether to dump only BTF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) type(s) associated with key (**key**), value (**value**),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) both key and value (**kv**), or all BTF types present in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) associated BTF object (**all**). If not specified, **kv**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) is assumed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) When **prog** is provided, it's expected that program has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) associated BTF object with BTF types.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) When specifying *FILE*, an ELF file is expected, containing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .BTF section with well-defined BTF binary format data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) typically produced by clang or pahole.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) **format** option can be used to override default (raw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) output format. Raw (**raw**) or C-syntax (**c**) output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) formats are supported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) **bpftool btf help**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) Print short help message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) OPTIONS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) =======
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) .. include:: common_options.rst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) EXAMPLES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) ========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) **# bpftool btf dump id 1226**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) [1] PTR '(anon)' type_id=2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) [2] STRUCT 'dummy_tracepoint_args' size=16 vlen=2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) 'pad' type_id=3 bits_offset=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 'sock' type_id=4 bits_offset=64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) [3] INT 'long long unsigned int' size=8 bits_offset=0 nr_bits=64 encoding=(none)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) [4] PTR '(anon)' type_id=5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) [5] FWD 'sock' fwd_kind=union
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) This gives an example of default output for all supported BTF kinds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) **$ cat prog.c**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct fwd_struct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) enum my_enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) VAL1 = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) VAL2 = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) typedef struct my_struct my_struct_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct my_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) const unsigned int const_int_field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) int bitfield_field: 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) char arr_field[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) const struct fwd_struct *restrict fwd_field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) enum my_enum enum_field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) volatile my_struct_t *typedef_ptr_field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) union my_union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) int a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct my_struct b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct my_struct struct_global_var __attribute__((section("data_sec"))) = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) .bitfield_field = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) .enum_field = VAL1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) int global_var __attribute__((section("data_sec"))) = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) __attribute__((noinline))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) int my_func(union my_union *arg1, int arg2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static int static_var __attribute__((section("data_sec"))) = 123;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static_var++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return static_var;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) **$ bpftool btf dump file prog.o**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) [1] PTR '(anon)' type_id=2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) [2] UNION 'my_union' size=48 vlen=2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 'a' type_id=3 bits_offset=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 'b' type_id=4 bits_offset=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) [3] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) [4] STRUCT 'my_struct' size=48 vlen=6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 'const_int_field' type_id=5 bits_offset=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 'bitfield_field' type_id=3 bits_offset=32 bitfield_size=4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 'arr_field' type_id=8 bits_offset=40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 'fwd_field' type_id=10 bits_offset=192
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 'enum_field' type_id=14 bits_offset=256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 'typedef_ptr_field' type_id=15 bits_offset=320
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) [5] CONST '(anon)' type_id=6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) [6] INT 'unsigned int' size=4 bits_offset=0 nr_bits=32 encoding=(none)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) [7] INT 'char' size=1 bits_offset=0 nr_bits=8 encoding=SIGNED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) [8] ARRAY '(anon)' type_id=7 index_type_id=9 nr_elems=16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) [9] INT '__ARRAY_SIZE_TYPE__' size=4 bits_offset=0 nr_bits=32 encoding=(none)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) [10] RESTRICT '(anon)' type_id=11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) [11] PTR '(anon)' type_id=12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) [12] CONST '(anon)' type_id=13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) [13] FWD 'fwd_struct' fwd_kind=union
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) [14] ENUM 'my_enum' size=4 vlen=2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 'VAL1' val=3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 'VAL2' val=7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) [15] PTR '(anon)' type_id=16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) [16] VOLATILE '(anon)' type_id=17
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) [17] TYPEDEF 'my_struct_t' type_id=4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) [18] FUNC_PROTO '(anon)' ret_type_id=3 vlen=2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 'arg1' type_id=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 'arg2' type_id=3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) [19] FUNC 'my_func' type_id=18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) [20] VAR 'struct_global_var' type_id=4, linkage=global-alloc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) [21] VAR 'global_var' type_id=3, linkage=global-alloc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) [22] VAR 'my_func.static_var' type_id=3, linkage=static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) [23] DATASEC 'data_sec' size=0 vlen=3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) type_id=20 offset=0 size=48
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) type_id=21 offset=0 size=4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) type_id=22 offset=52 size=4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) The following commands print BTF types associated with specified map's key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) value, both key and value, and all BTF types, respectively. By default, both
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) key and value types will be printed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) **# bpftool btf dump map id 123 key**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) [39] TYPEDEF 'u32' type_id=37
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) **# bpftool btf dump map id 123 value**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) [86] PTR '(anon)' type_id=87
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) **# bpftool btf dump map id 123 kv**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) [39] TYPEDEF 'u32' type_id=37
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) [86] PTR '(anon)' type_id=87
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) **# bpftool btf dump map id 123 all**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) [1] PTR '(anon)' type_id=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) [2866] ARRAY '(anon)' type_id=52 index_type_id=51 nr_elems=4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) All the standard ways to specify map or program are supported:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) **# bpftool btf dump map id 123**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) **# bpftool btf dump map pinned /sys/fs/bpf/map_name**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) **# bpftool btf dump prog id 456**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) **# bpftool btf dump prog tag b88e0a09b1d9759d**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) **# bpftool btf dump prog pinned /sys/fs/bpf/prog_name**