diff --git a/Makefile b/Makefile index c12d3a13705..04611506f2c 100644 --- a/Makefile +++ b/Makefile @@ -51,9 +51,11 @@ ifeq ($(TARGET_ARCH),arm64) endif BPF_TARGET_ARCH ?= x86 +__BPF_DEBUG_FLAGS := ifeq ($(DEBUG),1) NOOPT=1 NOSTRIP=1 + __BPF_DEBUG_FLAGS += DEBUG=1 endif # GO_BUILD_LDFLAGS is initialized to empty use EXTRA_GO_BUILD_LDFLAGS to add link flags @@ -147,11 +149,11 @@ tetragon-bpf: tetragon-bpf-container endif tetragon-bpf-local: - $(MAKE) -C ./bpf BPF_TARGET_ARCH=$(BPF_TARGET_ARCH) -j$(JOBS) + $(MAKE) -C ./bpf BPF_TARGET_ARCH=$(BPF_TARGET_ARCH) -j$(JOBS) $(__BPF_DEBUG_FLAGS) tetragon-bpf-container: $(CONTAINER_ENGINE) rm tetragon-clang || true - $(CONTAINER_ENGINE) run -v $(CURDIR):/tetragon:Z -u $$(id -u) -e BPF_TARGET_ARCH=$(BPF_TARGET_ARCH) --name tetragon-clang $(CLANG_IMAGE) $(MAKE) -C /tetragon/bpf -j$(JOBS) + $(CONTAINER_ENGINE) run -v $(CURDIR):/tetragon:Z -u $$(id -u) -e BPF_TARGET_ARCH=$(BPF_TARGET_ARCH) --name tetragon-clang $(CLANG_IMAGE) $(MAKE) -C /tetragon/bpf -j$(JOBS) $(__BPF_DEBUG_FLAGS) $(CONTAINER_ENGINE) rm tetragon-clang .PHONY: verify diff --git a/bpf/Makefile b/bpf/Makefile index e976ea4131d..334eff475c0 100644 --- a/bpf/Makefile +++ b/bpf/Makefile @@ -48,7 +48,12 @@ FLAGS := -I. \ -Wno-address-of-packed-member -Wno-compare-distinct-pointer-types -Wno-unknown-warning-option \ -O2 -CLANG_FLAGS += $(FLAGS) -I $(LIBBPF) -I $(IDIR) -I $(LDIR) -target bpf -emit-llvm -g -D__TARGET_ARCH_$(BPF_TARGET_ARCH) -fdebug-default-version=4 +DEBUG ?= 0 +ifeq ($(DEBUG),1) + __DEBUG_FLAGS = -DTETRAGON_BPF_DEBUG +endif + +CLANG_FLAGS += $(FLAGS) -I $(LIBBPF) -I $(IDIR) -I $(LDIR) -target bpf -emit-llvm -g -D__TARGET_ARCH_$(BPF_TARGET_ARCH) -fdebug-default-version=4 $(__DEBUG_FLAGS) LLC_FLAGS := -march=bpf -mcpu=v2 -mattr=dwarfris LLC_FLAGS_ALU32 := -march=bpf -mcpu=v3 -mattr=dwarfris diff --git a/bpf/lib/common.h b/bpf/lib/common.h index 09652e61824..88bef6d9149 100644 --- a/bpf/lib/common.h +++ b/bpf/lib/common.h @@ -49,4 +49,11 @@ struct bpf_map_def { #define BIT(nr) (1 << (nr)) #define BIT_ULL(nr) (1ULL << (nr)) +#ifdef TETRAGON_BPF_DEBUG +#include +#define DEBUG(__fmt, ...) bpf_printk(__fmt, ##__VA_ARGS__) +#else +#define DEBUG(__fmt, ...) +#endif + #endif // _MSG_COMMON__