diff --git a/BTF-playground/Makefile b/BTF-playground/Makefile index 05b9c57..554b606 100644 --- a/BTF-playground/Makefile +++ b/BTF-playground/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 USER_TARGETS := btf_module_read +USER_TARGETS += btf_module_ids #BPF_TARGETS := ktrace01_kern LIB_DIR = ../lib diff --git a/BTF-playground/btf_module_ids.c b/BTF-playground/btf_module_ids.c new file mode 100644 index 0000000..4fdd28e --- /dev/null +++ b/BTF-playground/btf_module_ids.c @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include /* Notice libbpf BTF include */ + +#include + +static const struct option long_options[] = { + { "debug", no_argument, NULL, 'd' }, + { 0, 0, NULL, 0 } +}; + +int print_all_levels(enum libbpf_print_level level, + const char *format, va_list args) +{ + return vfprintf(stderr, format, args); +} + +#define pr_err(fmt, ...) \ + fprintf(stderr, "%s:%d - " fmt, __FILE__, __LINE__, ##__VA_ARGS__) + +int main(int argc, char **argv) +{ + int opt, longindex = 0; + int err = 0; + + /* Parse commands line args */ + while ((opt = getopt_long(argc, argv, "d", + long_options, &longindex)) != -1) { + switch (opt) { + case 'd': + libbpf_set_print(print_all_levels); + break; + default: + pr_err("Unrecognized option '%s'\n", argv[optind - 1]); + return EXIT_FAILURE; + } + } + argc -= optind; + argv += optind; + + if (err) + return EXIT_FAILURE; + return EXIT_SUCCESS; +}