Skip to content

Commit c83ac80

Browse files
authored
Makefile: add DEBUG flag to enable symbols (#2164)
"-ldflags= -w" turns off DWARF debugging information, so removing it one can have a debuggable binary. Usage: DEBUG=1 make ... It sets GO_DEBUG_FLAG accordingly. Docs updated.
1 parent 999e44f commit c83ac80

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

Makefile

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,16 @@ VERSION ?= $(if $(RELEASE_TAG),$(RELEASE_TAG),$(LAST_GIT_TAG))
112112
# environment
113113
#
114114

115+
DEBUG ?= 0
115116
UNAME_M := $(shell uname -m)
116117
UNAME_R := $(shell uname -r)
117118

119+
ifeq ($(DEBUG),1)
120+
GO_DEBUG_FLAG =
121+
else
122+
GO_DEBUG_FLAG = -w
123+
endif
124+
118125
ifeq ($(UNAME_M),x86_64)
119126
ARCH = x86_64
120127
LINUX_ARCH = x86
@@ -178,6 +185,9 @@ env:
178185
@echo "GO_TAGS_EBPF $(GO_TAGS_EBPF)"
179186
@echo "GO_TAGS_RULES $(GO_TAGS_RULES)"
180187
@echo ---------------------------------------
188+
@echo "DEBUG $(DEBUG)"
189+
@echo "GO_DEBUG_FLAG $(GO_DEBUG_FLAG)"
190+
@echo ---------------------------------------
181191
@echo "CUSTOM_CGO_CFLAGS $(CUSTOM_CGO_CFLAGS)"
182192
@echo "CUSTOM_CGO_LDFLAGS $(CUSTOM_CGO_LDFLAGS)"
183193
@echo "CGO_EXT_LDFLAGS_EBPF $(CGO_EXT_LDFLAGS_EBPF)"
@@ -246,6 +256,7 @@ help:
246256
@echo ""
247257
@echo " $$ STATIC=1 make ... # build static binaries"
248258
@echo " $$ BTFHUB=1 STATIC=1 make ... # build static binaries, embed BTF"
259+
@echo " $$ DEBUG=1 make ... # build binaries with debug symbols"
249260
@echo ""
250261

251262
#
@@ -465,7 +476,7 @@ $(OUTPUT_DIR)/tracee-ebpf: \
465476
$(MAKE) btfhub
466477
$(GO_ENV_EBPF) $(CMD_GO) build \
467478
-tags $(GO_TAGS_EBPF) \
468-
-ldflags="-w \
479+
-ldflags="$(GO_DEBUG_FLAG) \
469480
-extldflags \"$(CGO_EXT_LDFLAGS_EBPF)\" \
470481
-X main.version=\"$(VERSION)\" \
471482
" \
@@ -535,7 +546,7 @@ $(OUTPUT_DIR)/tracee-rules: \
535546
#
536547
$(GO_ENV_RULES) $(CMD_GO) build \
537548
-tags $(GO_TAGS_RULES) \
538-
-ldflags="-w \
549+
-ldflags="$(GO_DEBUG_FLAG) \
539550
-extldflags \"$(CGO_EXT_LDFLAGS_RULES)\" \
540551
" \
541552
-v -o $@ \
@@ -629,7 +640,7 @@ test-integration: \
629640
$(GO_ENV_EBPF) \
630641
$(CMD_GO) test \
631642
-tags $(GO_TAGS_EBPF) \
632-
-ldflags="-w \
643+
-ldflags="$(GO_DEBUG_FLAG) \
633644
-extldflags \"$(CGO_EXT_LDFLAGS_EBPF)\" \
634645
-X main.version=\"$(VERSION)\" \
635646
" \

docs/building/building.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
7272
$ STATIC=1 make ... # build static binaries
7373
$ BTFHUB=1 STATIC=1 make ... # build static binaries, embed BTF
74+
$ DEBUG=1 make ... # build binaries with debug symbols
7475
```
7576
7677
4. Build **all** targets at once (but bpf-nocore)
@@ -134,3 +135,18 @@
134135
>2021/12/13 13:27:21 error opening plugin /tracee/dist/rules/builtin.so:
135136
>plugin.Open("/tracee/dist/rules/builtin.so"): Dynamic loading not supported
136137
>```
138+
139+
7. Build a **debuggable binary** with DWARF generation by setting `DEBUG=1`
140+
141+
```text
142+
$ DEBUG=1 make
143+
...
144+
GOOS=linux CC=clang GOARCH=amd64 CGO_CFLAGS="-I/home/gg/code/tracee/dist/libbpf" CGO_LDFLAGS="-lelf -lz /home/gg/code/tracee/dist/libbpf/libbpf.a" go build \
145+
-tags core,ebpf \
146+
-ldflags=" \
147+
-extldflags \"\" \
148+
-X main.version=\"v0.8.0-107-g121efeb\" \
149+
" \
150+
-v -o dist/tracee-ebpf \
151+
./cmd/tracee-ebpf
152+
```

0 commit comments

Comments
 (0)