tools/lib/bpf/btf_dump.c
Source file repositories/reference/linux-study-clean/tools/lib/bpf/btf_dump.c
File Facts
- System
- Linux kernel
- Corpus path
tools/lib/bpf/btf_dump.c- Extension
.c- Size
- 72219 bytes
- Lines
- 2618
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source 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 or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdbool.hstddef.hstdlib.hstring.hctype.hendian.herrno.hlimits.hlinux/err.hlinux/btf.hlinux/kernel.hbtf.hhashmap.hlibbpf.hlibbpf_internal.h
Detected Declarations
struct btf_dump_type_aux_statestruct btf_dump_datastruct btf_dumpstruct id_stackenum btf_dump_type_order_stateenum btf_dump_type_emit_statefunction str_hash_fnfunction str_equal_fnfunction btf_dump_printffunction btf_dump_resizefunction btf_dump_free_namesfunction btf_dump__freefunction btf_dump__dump_typefunction btf_dump_mark_referencedfunction btf_dump_add_emit_queue_idfunction btf_dump_order_typefunction btf_dump_is_blacklistedfunction btf_dump_emit_typefunction declarationfunction typesfunction btf_is_struct_packedfunction btf_dump_emit_bit_paddingfunction btf_dump_emit_struct_fwdfunction btf_dump_emit_struct_deffunction btf_dump_emit_missing_aliasesfunction btf_dump_emit_enum_fwdfunction btf_dump_emit_enum32_valfunction btf_dump_emit_enum64_valfunction btf_dump_emit_enum_deffunction btf_dump_emit_fwd_deffunction btf_dump_emit_typedef_deffunction btf_dump_push_decl_stack_idfunction typefunction btf_dump_emit_type_declfunction btf_dump_emit_modsfunction btf_dump_drop_modsfunction btf_dump_emit_namefunction btf_dump_emit_type_chainfunction argfunction btf_dump_emit_type_castfunction btf_dump_name_dupsfunction btf_dump_data_pfxfunction btf_dump_data_delimfunction btf_dump_get_bitfield_valuefunction btf_dump_bitfield_check_zerofunction btf_dump_bitfield_datafunction btf_dump_base_type_check_zerofunction ptr_is_aligned
Annotated Snippet
struct btf_dump_type_aux_state {
/* topological sorting state */
enum btf_dump_type_order_state order_state: 2;
/* emitting state used to determine the need for forward declaration */
enum btf_dump_type_emit_state emit_state: 2;
/* whether forward declaration was already emitted */
__u8 fwd_emitted: 1;
/* whether unique non-duplicate name was already assigned */
__u8 name_resolved: 1;
/* whether type is referenced from any other type */
__u8 referenced: 1;
};
/* indent string length; one indent string is added for each indent level */
#define BTF_DATA_INDENT_STR_LEN 32
/*
* Common internal data for BTF type data dump operations.
*/
struct btf_dump_data {
const void *data_end; /* end of valid data to show */
bool compact;
bool skip_names;
bool emit_zeroes;
bool emit_strings;
__u8 indent_lvl; /* base indent level */
char indent_str[BTF_DATA_INDENT_STR_LEN];
/* below are used during iteration */
int depth;
bool is_array_member;
bool is_array_terminated;
bool is_array_char;
};
struct btf_dump {
const struct btf *btf;
btf_dump_printf_fn_t printf_fn;
void *cb_ctx;
int ptr_sz;
bool strip_mods;
bool skip_anon_defs;
int last_id;
/* per-type auxiliary state */
struct btf_dump_type_aux_state *type_states;
size_t type_states_cap;
/* per-type optional cached unique name, must be freed, if present */
const char **cached_names;
size_t cached_names_cap;
/* topo-sorted list of dependent type definitions */
__u32 *emit_queue;
int emit_queue_cap;
int emit_queue_cnt;
/*
* stack of type declarations (e.g., chain of modifiers, arrays,
* funcs, etc)
*/
__u32 *decl_stack;
int decl_stack_cap;
int decl_stack_cnt;
/* maps struct/union/enum name to a number of name occurrences */
struct hashmap *type_names;
/*
* maps typedef identifiers and enum value names to a number of such
* name occurrences
*/
struct hashmap *ident_names;
/*
* data for typed display; allocated if needed.
*/
struct btf_dump_data *typed_dump;
};
static size_t str_hash_fn(long key, void *ctx)
{
return str_hash((void *)key);
}
static bool str_equal_fn(long a, long b, void *ctx)
{
return strcmp((void *)a, (void *)b) == 0;
}
static const char *btf_name_of(const struct btf_dump *d, __u32 name_off)
{
return btf__name_by_offset(d->btf, name_off);
}
Annotation
- Immediate include surface: `stdbool.h`, `stddef.h`, `stdlib.h`, `string.h`, `ctype.h`, `endian.h`, `errno.h`, `limits.h`.
- Detected declarations: `struct btf_dump_type_aux_state`, `struct btf_dump_data`, `struct btf_dump`, `struct id_stack`, `enum btf_dump_type_order_state`, `enum btf_dump_type_emit_state`, `function str_hash_fn`, `function str_equal_fn`, `function btf_dump_printf`, `function btf_dump_resize`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
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.