BTF-playground: Boilerplate for btf_module_ids.c

Signed-off-by: Jesper Dangaard Brouer <netoptimizer@brouer.com>
This commit is contained in:
Jesper Dangaard Brouer
2022-08-31 10:43:44 +02:00
parent f3de9c2e47
commit 2d73471c2c
2 changed files with 55 additions and 0 deletions
+1
View File
@@ -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
+54
View File
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: GPL-2.0+
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <getopt.h>
#include <bpf/libbpf.h>
#include <bpf/bpf.h>
#include <bpf/btf.h> /* Notice libbpf BTF include */
#include <linux/err.h>
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;
}