From d370c423e6da54a5c3b8bc99ae824942a7791da1 Mon Sep 17 00:00:00 2001 From: Feng Yang Date: Fri, 6 Sep 2024 11:05:42 +0800 Subject: [PATCH] libbpf-tools: funcinterval: add ensure_core_btf and cleanup_core_btf Signed-off-by: Feng Yang --- libbpf-tools/funcinterval.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libbpf-tools/funcinterval.c b/libbpf-tools/funcinterval.c index ac6f1def8ec0..fb597ba85755 100644 --- a/libbpf-tools/funcinterval.c +++ b/libbpf-tools/funcinterval.c @@ -14,6 +14,7 @@ #include "funcinterval.h" #include "trace_helpers.h" #include "uprobe_helpers.h" +#include "btf_helpers.h" static volatile sig_atomic_t exiting; const char *attach_type[] = {"KPROBE", "UPROBE", "TRACEPOINT"}; @@ -281,6 +282,7 @@ static int attach_tracepoint(struct funcinterval_bpf *obj, const char *library, int main(int argc, char *argv[]) { + LIBBPF_OPTS(bpf_object_open_opts, open_opts); static const struct argp argp = { .options = opts, .parser = parse_arg, @@ -297,7 +299,13 @@ int main(int argc, char *argv[]) libbpf_set_print(libbpf_print_fn); - obj = funcinterval_bpf__open(); + err = ensure_core_btf(&open_opts); + if (err) { + fprintf(stderr, "failed to fetch necessary BTF for CO-RE: %s\n", strerror(-err)); + return 1; + } + + obj = funcinterval_bpf__open_opts(&open_opts); if (!obj) { fprintf(stderr, "Failed to open BPF object\n"); return 1; @@ -386,6 +394,7 @@ int main(int argc, char *argv[]) cleanup: funcinterval_bpf__destroy(obj); + cleanup_core_btf(&open_opts); return err != 0; } \ No newline at end of file