mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-05 08:09:07 +08:00
libbpf: Add btf__load_vmlinux_btf/btf__load_module_btf
Add two new APIs: btf__load_vmlinux_btf and btf__load_module_btf. btf__load_vmlinux_btf is just an alias to the existing API named libbpf_find_kernel_btf, rename to be more precisely and consistent with existing BTF APIs. btf__load_module_btf can be used to load module BTF, add it for completeness. These two APIs are useful for implementing tracing tools and introspection tools. This is part of the effort towards libbpf 1.0 ([0]). [0] Closes: https://github.com/libbpf/libbpf/issues/280 Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20210730114012.494408-1-hengqi.chen@gmail.com
This commit is contained in:
committed by
Andrii Nakryiko
parent
512b472d97
commit
e65d128903
14
src/btf.c
14
src/btf.c
@@ -4036,7 +4036,7 @@ static void btf_dedup_merge_hypot_map(struct btf_dedup *d)
|
||||
*/
|
||||
if (d->hypot_adjust_canon)
|
||||
continue;
|
||||
|
||||
|
||||
if (t_kind == BTF_KIND_FWD && c_kind != BTF_KIND_FWD)
|
||||
d->map[t_id] = c_id;
|
||||
|
||||
@@ -4409,7 +4409,7 @@ static int btf_dedup_remap_types(struct btf_dedup *d)
|
||||
* Probe few well-known locations for vmlinux kernel image and try to load BTF
|
||||
* data out of it to use for target BTF.
|
||||
*/
|
||||
struct btf *libbpf_find_kernel_btf(void)
|
||||
struct btf *btf__load_vmlinux_btf(void)
|
||||
{
|
||||
struct {
|
||||
const char *path_fmt;
|
||||
@@ -4455,6 +4455,16 @@ struct btf *libbpf_find_kernel_btf(void)
|
||||
return libbpf_err_ptr(-ESRCH);
|
||||
}
|
||||
|
||||
struct btf *libbpf_find_kernel_btf(void) __attribute__((alias("btf__load_vmlinux_btf")));
|
||||
|
||||
struct btf *btf__load_module_btf(const char *module_name, struct btf *vmlinux_btf)
|
||||
{
|
||||
char path[80];
|
||||
|
||||
snprintf(path, sizeof(path), "/sys/kernel/btf/%s", module_name);
|
||||
return btf__parse_split(path, vmlinux_btf);
|
||||
}
|
||||
|
||||
int btf_type_visit_type_ids(struct btf_type *t, type_id_visit_fn visit, void *ctx)
|
||||
{
|
||||
int i, n, err;
|
||||
|
||||
Reference in New Issue
Block a user