tools/bpf/bpftool/btf_dumper.c
Source file repositories/reference/linux-study-clean/tools/bpf/bpftool/btf_dumper.c
File Facts
- System
- Linux kernel
- Corpus path
tools/bpf/bpftool/btf_dumper.c- Extension
.c- Size
- 21964 bytes
- Lines
- 907
- 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
ctype.hstdio.hstring.hunistd.hasm/byteorder.hlinux/bitops.hlinux/btf.hlinux/err.hbpf/btf.hbpf/bpf.hjson_writer.hmain.h
Detected Declarations
function dump_prog_id_as_func_ptrfunction btf_dumper_ptrfunction btf_dumper_modifierfunction btf_dumper_enumfunction btf_dumper_enum64function is_str_arrayfunction btf_dumper_arrayfunction btf_int128_printfunction btf_int128_shiftfunction btf_dumper_bitfieldfunction btf_dumper_int_bitsfunction btf_dumper_intfunction BITS_PER_BYTE_MASKEDfunction btf_dumper_structfunction btf_dumper_varfunction btf_dumper_datasecfunction btf_dumper_do_typefunction btf_dumper_typefunction __btf_dumper_type_onlyfunction btf_dump_funcfunction btf_dumper_type_onlyfunction btf_dump_linfo_plainfunction btf_dump_linfo_jsonfunction dotlabel_putsfunction btf_dump_linfo_dotlabel
Annotated Snippet
if (value == enums[i].val) {
jsonw_string(d->jw,
btf__name_by_offset(d->btf,
enums[i].name_off));
return 0;
}
}
jsonw_int(d->jw, value);
return 0;
}
static int btf_dumper_enum64(const struct btf_dumper *d,
const struct btf_type *t,
const void *data)
{
const struct btf_enum64 *enums = btf_enum64(t);
__u32 val_lo32, val_hi32;
__u64 value;
__u32 i;
value = *(__u64 *)data;
val_lo32 = (__u32)value;
val_hi32 = value >> 32;
for (i = 0; i < btf_vlen(t); i++) {
if (val_lo32 == enums[i].val_lo32 && val_hi32 == enums[i].val_hi32) {
jsonw_string(d->jw,
btf__name_by_offset(d->btf,
enums[i].name_off));
return 0;
}
}
jsonw_int(d->jw, value);
return 0;
}
static bool is_str_array(const struct btf *btf, const struct btf_array *arr,
const char *s)
{
const struct btf_type *elem_type;
const char *end_s;
if (!arr->nelems)
return false;
elem_type = btf__type_by_id(btf, arr->type);
/* Not skipping typedef. typedef to char does not count as
* a string now.
*/
while (elem_type && btf_is_mod(elem_type))
elem_type = btf__type_by_id(btf, elem_type->type);
if (!elem_type || !btf_is_int(elem_type) || elem_type->size != 1)
return false;
if (btf_int_encoding(elem_type) != BTF_INT_CHAR &&
strcmp("char", btf__name_by_offset(btf, elem_type->name_off)))
return false;
end_s = s + arr->nelems;
while (s < end_s) {
if (!*s)
return true;
if (*s <= 0x1f || *s >= 0x7f)
return false;
s++;
}
/* '\0' is not found */
return false;
}
static int btf_dumper_array(const struct btf_dumper *d, __u32 type_id,
const void *data)
{
const struct btf_type *t = btf__type_by_id(d->btf, type_id);
struct btf_array *arr = (struct btf_array *)(t + 1);
long long elem_size;
int ret = 0;
__u32 i;
if (is_str_array(d->btf, arr, data)) {
jsonw_string(d->jw, data);
return 0;
}
elem_size = btf__resolve_size(d->btf, arr->type);
if (elem_size < 0)
Annotation
- Immediate include surface: `ctype.h`, `stdio.h`, `string.h`, `unistd.h`, `asm/byteorder.h`, `linux/bitops.h`, `linux/btf.h`, `linux/err.h`.
- Detected declarations: `function dump_prog_id_as_func_ptr`, `function btf_dumper_ptr`, `function btf_dumper_modifier`, `function btf_dumper_enum`, `function btf_dumper_enum64`, `function is_str_array`, `function btf_dumper_array`, `function btf_int128_print`, `function btf_int128_shift`, `function btf_dumper_bitfield`.
- 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.