tools/bpf/bpftool/btf.c
Source file repositories/reference/linux-study-clean/tools/bpf/bpftool/btf.c
File Facts
- System
- Linux kernel
- Corpus path
tools/bpf/bpftool/btf.c- Extension
.c- Size
- 36469 bytes
- Lines
- 1564
- 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
errno.hfcntl.hlinux/err.hstdbool.hstdio.hstdlib.hstring.hunistd.hlinux/btf.hsys/types.hsys/stat.hbpf/bpf.hbpf/btf.hbpf/hashmap.hbpf/libbpf.hjson_writer.hmain.h
Detected Declarations
struct sort_datumstruct ptr_arrayfunction btf_kind_safefunction dump_btf_typefunction dump_btf_rawfunction ptr_array_pushfunction ptr_array_freefunction cmp_kfuncsfunction dump_btf_kfuncsfunction __printffunction btf_type_rankfunction hasherfunction btf_name_hasherfunction btf_type_disambig_hashfunction btf_type_comparefunction dump_btf_cfunction btf_is_kernel_modulefunction do_dumpfunction btf_parse_fdfunction build_btf_type_tablefunction build_btf_tablesfunction show_btf_plainfunction show_btf_jsonfunction show_btffunction do_showfunction do_helpfunction do_btf
Annotated Snippet
struct sort_datum {
int index;
int type_rank;
const char *sort_name;
const char *own_name;
__u64 disambig_hash;
};
static const char *btf_int_enc_str(__u8 encoding)
{
switch (encoding) {
case 0:
return "(none)";
case BTF_INT_SIGNED:
return "SIGNED";
case BTF_INT_CHAR:
return "CHAR";
case BTF_INT_BOOL:
return "BOOL";
default:
return "UNKN";
}
}
static const char *btf_var_linkage_str(__u32 linkage)
{
switch (linkage) {
case BTF_VAR_STATIC:
return "static";
case BTF_VAR_GLOBAL_ALLOCATED:
return "global";
case BTF_VAR_GLOBAL_EXTERN:
return "extern";
default:
return "(unknown)";
}
}
static const char *btf_func_linkage_str(const struct btf_type *t)
{
switch (btf_vlen(t)) {
case BTF_FUNC_STATIC:
return "static";
case BTF_FUNC_GLOBAL:
return "global";
case BTF_FUNC_EXTERN:
return "extern";
default:
return "(unknown)";
}
}
static const char *btf_str(const struct btf *btf, __u32 off)
{
if (!off)
return "(anon)";
return btf__name_by_offset(btf, off) ? : "(invalid)";
}
static int btf_kind_safe(int kind)
{
return kind <= BTF_KIND_MAX ? kind : BTF_KIND_UNKN;
}
static int dump_btf_type(const struct btf *btf, __u32 id,
const struct btf_type *t)
{
json_writer_t *w = json_wtr;
int kind = btf_kind(t);
if (json_output) {
jsonw_start_object(w);
jsonw_uint_field(w, "id", id);
jsonw_string_field(w, "kind", btf_kind_str[btf_kind_safe(kind)]);
jsonw_string_field(w, "name", btf_str(btf, t->name_off));
} else {
printf("[%u] %s '%s'", id, btf_kind_str[btf_kind_safe(kind)],
btf_str(btf, t->name_off));
}
switch (kind) {
case BTF_KIND_INT: {
__u32 v = *(__u32 *)(t + 1);
const char *enc;
enc = btf_int_enc_str(BTF_INT_ENCODING(v));
if (json_output) {
jsonw_uint_field(w, "size", t->size);
jsonw_uint_field(w, "bits_offset", BTF_INT_OFFSET(v));
Annotation
- Immediate include surface: `errno.h`, `fcntl.h`, `linux/err.h`, `stdbool.h`, `stdio.h`, `stdlib.h`, `string.h`, `unistd.h`.
- Detected declarations: `struct sort_datum`, `struct ptr_array`, `function btf_kind_safe`, `function dump_btf_type`, `function dump_btf_raw`, `function ptr_array_push`, `function ptr_array_free`, `function cmp_kfuncs`, `function dump_btf_kfuncs`, `function __printf`.
- 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.