Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.PHONY: all clean build ebpf go-build vmlinux build-libbpf test
.PHONY: all clean build ebpf ebpf-debug go-build vmlinux build-libbpf test debug

EBPF_CFLAGS ?=

# Default target
all: vmlinux ebpf go-build
Expand All @@ -15,7 +17,14 @@ vmlinux:

# eBPF compilation
ebpf: vmlinux
clang -g -O2 -D__TARGET_ARCH_x86 -I./bpf -I./dest/libbpf/usr/include -idirafter /usr/include/x86_64-linux-gnu -c bpf/php.bpf.c -target bpf -o bpf/php.bpf.o
clang -g -O2 -D__TARGET_ARCH_x86 $(EBPF_CFLAGS) -I./bpf -I./dest/libbpf/usr/include -idirafter /usr/include/x86_64-linux-gnu -c bpf/php.bpf.c -target bpf -o bpf/php.bpf.o

# eBPF compilation with debug (enables bpf_trace_printk)
ebpf-debug:
$(MAKE) ebpf EBPF_CFLAGS=-DDEBUG

# Debug build (eBPF with -DDEBUG + go binary)
debug: ebpf-debug go-build

# Go build
go-build:
Expand Down
13 changes: 11 additions & 2 deletions bpf/php.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

#define MAX_STR_LEN 512

#ifdef DEBUG
#define debug_printk(fmt, ...) \
({ \
static const char ____fmt[] = fmt; \
bpf_trace_printk(____fmt, sizeof(____fmt), ##__VA_ARGS__); \
})
#else
#define debug_printk(fmt, ...) ((void)0)
#endif

char filename[MAX_STR_LEN];


Expand All @@ -19,8 +29,7 @@ int BPF_USDT(compile_file_return, char *arg0, char *arg1)
{
u64 ts = bpf_ktime_get_ns();

static const char fmtstr[] = "compile file return: %s, %s\n";
bpf_trace_printk(fmtstr, sizeof(fmtstr), arg0, arg1);
debug_printk("compile file return: %s, %s\n", arg0, arg1);


bpf_probe_read_user_str(&filename, sizeof(filename), arg0);
Expand Down
Loading