Skip to content

Commit 005d538

Browse files
committed
ports/Makefile: Reinstate -O0 option on demand.
-Og introduced in for example 9ffb1ad and c5dbbf7 results in a binary with debug symbols, but essentially breaks debugging with gdb since it still allows the compiler to optimize temporaries for instance, so gdb will report 'optimized out' for a lot of variables and breakpoints will often halt at the wrong line. -O0 has none of these problems so allow it by specifying DEBUG=2, leaving the original DEBUG=1 functionality as-is. Signed-off-by: stijn <stijn@ignitron.net>
1 parent d712feb commit 005d538

File tree

7 files changed

+34
-10
lines changed

7 files changed

+34
-10
lines changed

ports/bare-arm/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ CFLAGS += -mthumb -mtune=cortex-m4 -mcpu=cortex-m4 -msoft-float
1919
CSUPEROPT = -Os # save some code space for performance-critical code
2020

2121
# Select debugging or optimisation build.
22-
ifeq ($(DEBUG), 1)
22+
ifdef DEBUG
23+
ifeq ($(DEBUG),2)
24+
CFLAGS += -O0
25+
else
2326
CFLAGS += -Og
27+
endif
2428
else
2529
CFLAGS += -Os -DNDEBUG
2630
CFLAGS += -fdata-sections -ffunction-sections

ports/mimxrt/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,12 @@ SRC_QSTR += $(SRC_C) $(SHARED_SRC_C) $(GEN_PINS_SRC)
308308
# =============================================================================
309309

310310
CFLAGS += -g # always include debug info in the ELF
311-
ifeq ($(DEBUG),1)
311+
ifdef DEBUG
312+
ifeq ($(DEBUG),2)
313+
CFLAGS += -O0
314+
else
312315
CFLAGS += -Og
316+
endif
313317
# Disable text compression in debug builds
314318
MICROPY_ROM_TEXT_COMPRESSION = 0
315319
else

ports/renesas-ra/Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,13 @@ LDFLAGS += --gc-sections
138138

139139
# Debugging/Optimization
140140
CFLAGS += -g # always include debug info in the ELF
141-
ifeq ($(DEBUG), 1)
142-
CFLAGS += -DPENDSV_DEBUG
143-
#COPT = -Og
141+
ifdef DEBUG
142+
ifeq ($(DEBUG),2)
143+
COPT = -O0
144+
else
144145
COPT = -Os
146+
endif
147+
CFLAGS += -DPENDSV_DEBUG
145148
# Disable text compression in debug builds
146149
MICROPY_ROM_TEXT_COMPRESSION = 0
147150
else

ports/stm32/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,13 @@ $(BUILD)/stm32_it.o $(BUILD)/pendsv.o: CFLAGS += -fno-lto
148148
endif
149149

150150
# Debugging/Optimization
151-
ifeq ($(DEBUG), 1)
152-
CFLAGS += -g -DPENDSV_DEBUG
151+
ifdef DEBUG
152+
ifeq ($(DEBUG),2)
153+
COPT ?= -O0
154+
else
153155
COPT ?= -Og
156+
endif
157+
CFLAGS += -g -DPENDSV_DEBUG
154158
# Disable text compression in debug builds
155159
MICROPY_ROM_TEXT_COMPRESSION = 0
156160
else

ports/stm32/mboot/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,13 @@ CFLAGS += -fdata-sections -ffunction-sections
8888
LDFLAGS += --gc-sections
8989

9090
# Debugging/Optimization
91-
ifeq ($(DEBUG), 1)
92-
CFLAGS += -g -DPENDSV_DEBUG
91+
ifdef DEBUG
92+
ifeq ($(DEBUG),2)
93+
COPT = -O0
94+
else
9395
COPT = -Og
96+
endif
97+
CFLAGS += -g -DPENDSV_DEBUG
9498
else
9599
COPT += -Os -DNDEBUG
96100
endif

ports/unix/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ CFLAGS += $(INC) $(CWARN) -std=gnu99 -DUNIX $(COPT) -I$(VARIANT_DIR) $(CFLAGS_EX
5050

5151
# Debugging/Optimization
5252
ifdef DEBUG
53+
ifeq ($(DEBUG),2)
54+
COPT ?= -O0
55+
else
5356
COPT ?= -Og
57+
endif
5458
else
5559
COPT ?= -Os
5660
COPT += -DNDEBUG

ports/unix/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ To build a debuggable version of the Unix port, there are two options
8282

8383
1. Run `make [other arguments] DEBUG=1`. Note setting `DEBUG` also reduces the
8484
optimisation level, so it's not a good option for builds that also want the
85-
best performance.
85+
best performance. When using gdb and facing 'optimized out' values or stepping
86+
through the source not halting at the correct location, use `DEBUG=2` instead.
8687
2. Run `make [other arguments] STRIP=`. Note that the value of `STRIP` is
8788
empty. This will skip the build step that strips symbols and debug
8889
information, but changes nothing else in the build configuration.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy