1 // SPDX-License-Identifier: GPL-2.0
6 #include <bpf/libbpf.h>
8 #include "trace_helpers.h"
10 int main(int ac, char **argv)
12 struct bpf_object *obj = NULL;
13 struct bpf_link *links[20];
14 long key, next_key, value;
15 struct bpf_program *prog;
20 if (load_kallsyms()) {
21 printf("failed to process /proc/kallsyms\n");
25 snprintf(filename, sizeof(filename), "%s.bpf.o", argv[0]);
26 obj = bpf_object__open_file(filename, NULL);
27 if (libbpf_get_error(obj)) {
28 fprintf(stderr, "ERROR: opening BPF object file failed\n");
33 /* load BPF program */
34 if (bpf_object__load(obj)) {
35 fprintf(stderr, "ERROR: loading BPF object file failed\n");
39 map_fd = bpf_object__find_map_fd_by_name(obj, "my_map");
41 fprintf(stderr, "ERROR: finding a map in obj file failed\n");
45 bpf_object__for_each_program(prog, obj) {
46 links[j] = bpf_program__attach(prog);
47 if (libbpf_get_error(links[j])) {
48 fprintf(stderr, "bpf_program__attach failed\n");
55 for (i = 0; i < 5; i++) {
57 printf("kprobing funcs:");
58 while (bpf_map_get_next_key(map_fd, &key, &next_key) == 0) {
59 bpf_map_lookup_elem(map_fd, &next_key, &value);
60 assert(next_key == value);
61 sym = ksym_search(value);
64 printf("ksym not found. Is kallsyms loaded?\n");
68 printf(" %s", sym->name);
73 while (bpf_map_get_next_key(map_fd, &key, &next_key) == 0)
74 bpf_map_delete_elem(map_fd, &next_key);
79 for (j--; j >= 0; j--)
80 bpf_link__destroy(links[j]);
82 bpf_object__close(obj);