Skip to content

Commit 69a2a89

Browse files
authored
Merge pull request #24 from egmc/debug-build
add debug build process
2 parents 9b93266 + 3f8b60f commit 69a2a89

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

Makefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
.PHONY: all clean build ebpf go-build vmlinux build-libbpf test
1+
.PHONY: all clean build ebpf ebpf-debug go-build vmlinux build-libbpf test debug
2+
3+
EBPF_CFLAGS ?=
24

35
# Default target
46
all: vmlinux ebpf go-build
@@ -15,7 +17,14 @@ vmlinux:
1517

1618
# eBPF compilation
1719
ebpf: vmlinux
18-
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
20+
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
21+
22+
# eBPF compilation with debug (enables bpf_trace_printk)
23+
ebpf-debug:
24+
$(MAKE) ebpf EBPF_CFLAGS=-DDEBUG
25+
26+
# Debug build (eBPF with -DDEBUG + go binary)
27+
debug: ebpf-debug go-build
1928

2029
# Go build
2130
go-build:

bpf/php.bpf.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44

55
#define MAX_STR_LEN 512
66

7+
#ifdef DEBUG
8+
#define debug_printk(fmt, ...) \
9+
({ \
10+
static const char ____fmt[] = fmt; \
11+
bpf_trace_printk(____fmt, sizeof(____fmt), ##__VA_ARGS__); \
12+
})
13+
#else
14+
#define debug_printk(fmt, ...) ((void)0)
15+
#endif
16+
717
char filename[MAX_STR_LEN];
818

919

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

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

2534

2635
bpf_probe_read_user_str(&filename, sizeof(filename), arg0);

0 commit comments

Comments
 (0)