tools/testing/selftests/bpf/prog_tests/btf_dump.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/btf_dump.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/btf_dump.c- Extension
.c- Size
- 34065 bytes
- Lines
- 1097
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
test_progs.hbpf/btf.h
Detected Declarations
struct test_ctxstruct btf_dump_string_ctxfunction btf_dump_printffunction btf_dump_all_typesfunction test_btf_dump_casefunction strerrorfunction test_ctx__freefunction test_ctx__initfunction test_ctx__dump_and_comparefunction test_btf_dump_incrementalfunction test_btf_dump_type_tagsfunction btf_dump_snprintffunction btf_dump_datafunction test_btf_dump_int_datafunction test_btf_dump_float_datafunction test_btf_dump_char_datafunction test_btf_dump_typedef_datafunction test_btf_dump_enum_datafunction test_btf_dump_struct_datafunction test_btf_dump_var_datafunction btf_dump_one_stringfunction btf_dump_stringsfunction test_btf_dump_string_datafunction test_btf_datasecfunction test_btf_dump_datasec_datafunction test_btf_dump
Annotated Snippet
"(struct file_operations){\n"
" .owner = (struct module *)0xffffffffffffffff,\n"
" .fop_flags = (fop_flags_t)4294967295,";
ASSERT_STRNEQ(str, cmpstr, strlen(cmpstr), "file_operations");
}
/* struct with char array */
TEST_BTF_DUMP_DATA(btf, d, "struct", str, struct bpf_prog_info, BTF_F_COMPACT,
"(struct bpf_prog_info){.name = (char[16])['f','o','o',],}",
{ .name = "foo",});
TEST_BTF_DUMP_DATA(btf, d, "struct", str, struct bpf_prog_info,
BTF_F_COMPACT | BTF_F_NONAME,
"{['f','o','o',],}",
{.name = "foo",});
TEST_BTF_DUMP_DATA(btf, d, "struct", str, struct bpf_prog_info, 0,
"(struct bpf_prog_info){\n"
" .name = (char[16])[\n"
" 'f',\n"
" 'o',\n"
" 'o',\n"
" ],\n"
"}",
{.name = "foo",});
/* leading null char means do not display string */
TEST_BTF_DUMP_DATA(btf, d, "struct", str, struct bpf_prog_info, BTF_F_COMPACT,
"(struct bpf_prog_info){}",
{.name = {'\0', 'f', 'o', 'o'}});
/* handle non-printable characters */
TEST_BTF_DUMP_DATA(btf, d, "struct", str, struct bpf_prog_info, BTF_F_COMPACT,
"(struct bpf_prog_info){.name = (char[16])[1,2,3,],}",
{ .name = {1, 2, 3, 0}});
/* struct with non-char array */
TEST_BTF_DUMP_DATA(btf, d, "struct", str, struct __sk_buff, BTF_F_COMPACT,
"(struct __sk_buff){.cb = (__u32[5])[1,2,3,4,5,],}",
{ .cb = {1, 2, 3, 4, 5,},});
TEST_BTF_DUMP_DATA(btf, d, "struct", str, struct __sk_buff,
BTF_F_COMPACT | BTF_F_NONAME,
"{[1,2,3,4,5,],}",
{ .cb = { 1, 2, 3, 4, 5},});
TEST_BTF_DUMP_DATA(btf, d, "struct", str, struct __sk_buff, 0,
"(struct __sk_buff){\n"
" .cb = (__u32[5])[\n"
" 1,\n"
" 2,\n"
" 3,\n"
" 4,\n"
" 5,\n"
" ],\n"
"}",
{ .cb = { 1, 2, 3, 4, 5},});
/* For non-char, arrays, show non-zero values only */
TEST_BTF_DUMP_DATA(btf, d, "struct", str, struct __sk_buff, BTF_F_COMPACT,
"(struct __sk_buff){.cb = (__u32[5])[0,0,1,0,0,],}",
{ .cb = { 0, 0, 1, 0, 0},});
TEST_BTF_DUMP_DATA(btf, d, "struct", str, struct __sk_buff, 0,
"(struct __sk_buff){\n"
" .cb = (__u32[5])[\n"
" 0,\n"
" 0,\n"
" 1,\n"
" 0,\n"
" 0,\n"
" ],\n"
"}",
{ .cb = { 0, 0, 1, 0, 0},});
/* struct with bitfields */
TEST_BTF_DUMP_DATA_C(btf, d, "struct", str, struct bpf_insn, BTF_F_COMPACT,
{.code = (__u8)1,.dst_reg = (__u8)0x2,.src_reg = (__u8)0x3,.off = (__s16)4,.imm = (__s32)5,});
TEST_BTF_DUMP_DATA(btf, d, "struct", str, struct bpf_insn,
BTF_F_COMPACT | BTF_F_NONAME,
"{1,0x2,0x3,4,5,}",
{ .code = 1, .dst_reg = 0x2, .src_reg = 0x3, .off = 4,
.imm = 5,});
TEST_BTF_DUMP_DATA(btf, d, "struct", str, struct bpf_insn, 0,
"(struct bpf_insn){\n"
" .code = (__u8)1,\n"
" .dst_reg = (__u8)0x2,\n"
" .src_reg = (__u8)0x3,\n"
" .off = (__s16)4,\n"
" .imm = (__s32)5,\n"
"}",
{.code = 1, .dst_reg = 2, .src_reg = 3, .off = 4, .imm = 5});
/* zeroed bitfields should not be displayed */
TEST_BTF_DUMP_DATA(btf, d, "struct", str, struct bpf_insn, BTF_F_COMPACT,
"(struct bpf_insn){.dst_reg = (__u8)0x1,}",
{ .code = 0, .dst_reg = 1});
Annotation
- Immediate include surface: `test_progs.h`, `bpf/btf.h`.
- Detected declarations: `struct test_ctx`, `struct btf_dump_string_ctx`, `function btf_dump_printf`, `function btf_dump_all_types`, `function test_btf_dump_case`, `function strerror`, `function test_ctx__free`, `function test_ctx__init`, `function test_ctx__dump_and_compare`, `function test_btf_dump_incremental`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.