-
Hello, thanks for these examples to help newbies like me get into BPF! IssueI am trying to write some uprobes for tracing nginx and am struggling to build the bpf program. More specifically, when including nginx header files in order to parse data, the build does not register my 64-bit architecture and wants to include Any suggestions as to how to fix this is greatly appreciated. Codenginx.bpf.c #include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include "ngx_http.h"
char LICENSE[] SEC("license") = "Dual BSD/GPL";
SEC("uprobe//usr/sbin/nginx:ngx_http_finalize_request")
int handle_ngx_http_finalize_request(struct pt_regs* ctx)
{
int pid = bpf_get_current_pid_tgid() >> 32;
bpf_printk("Is this getting triggered? %d.\n", pid);
return 0;
} nginx.c #include <stdio.h>
#include <unistd.h>
#include <sys/resource.h>
#include <bpf/libbpf.h>
#include "nginx.skel.h"
static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va_list args)
{
return vfprintf(stderr, format, args);
}
int main(int argc, char **argv)
{
struct nginx_bpf *skel;
int err;
libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
libbpf_set_print(libbpf_print_fn);
skel = nginx_bpf__open_and_load();
if (!skel) {
fprintf(stderr, "Failed to open and load BPF skeleton\n");
return 1;
}
err = nginx_bpf__attach(skel);
if (err) {
fprintf(stderr, "Failed to auto-attach BPF skeleton: %d\n", err);
goto cleanup;
}
printf("Successfully started!\n");
for (;;) {
sleep(1);
}
cleanup:
nginx_bpf__destroy(skel);
return -err;
} error message
System Information
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Avoid including sys/types.h would be my recommendation. As you said, it's not libbpf problem. BPF-side code can't include a lot of system-wide headers. |
Beta Was this translation helpful? Give feedback.
-
Interesting. This seems to limit the capabilities of uprobes quite a lot? How is this achieved in bpftrace? The following certainly works:
I did manage to build the program by forcing it to use PS: Read all the posts in your blog! Very informative - looking forward to reading more! |
Beta Was this translation helpful? Give feedback.
Avoid including sys/types.h would be my recommendation. As you said, it's not libbpf problem. BPF-side code can't include a lot of system-wide headers.