Skip to content

Commit

Permalink
ports: Always include debug information in the ELF.
Browse files Browse the repository at this point in the history
For bare metal ARM & xtensa targets, passing -g will make the ELF file
larger but doesn't change the binary size.  However, this means tools like
gdb, addr2line, etc can extract source-level information from the ELF.

Also standardise -ggdb to -g, these produce the exact same ELF file on
arm-none-eabi-gcc and will use DWARF format for all these ports.
  • Loading branch information
projectgus authored and dpgeorge committed Jul 29, 2022
1 parent 3c32ca6 commit fdfe4ec
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ports/esp8266/Makefile
Expand Up @@ -68,8 +68,8 @@ LIBGCC_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
LIBS += -L$(dir $(LIBGCC_FILE_NAME)) -lgcc

# Debugging/Optimization
CFLAGS += -g # always include debug info in the ELF
ifeq ($(DEBUG), 1)
CFLAGS += -g
COPT = -O0
else
CFLAGS += -fdata-sections -ffunction-sections
Expand Down
3 changes: 2 additions & 1 deletion ports/mimxrt/Makefile
Expand Up @@ -297,8 +297,9 @@ SRC_QSTR += \
# Compiler Flags
# =============================================================================

CFLAGS += -g # always include debug info in the ELF
ifeq ($(DEBUG),1)
CFLAGS += -Og -ggdb
CFLAGS += -Og
else
CFLAGS += -Os -DNDEBUG
endif
Expand Down
3 changes: 2 additions & 1 deletion ports/minimal/Makefile
Expand Up @@ -34,8 +34,9 @@ endif
CSUPEROPT = -Os # save some code space

# Tune for Debugging or Optimization
CFLAGS += -g # always include debug info in the ELF
ifeq ($(DEBUG), 1)
CFLAGS += -O0 -ggdb
CFLAGS += -O0
else
CFLAGS += -Os -DNDEBUG
CFLAGS += -fdata-sections -ffunction-sections
Expand Down
5 changes: 3 additions & 2 deletions ports/nrf/Makefile
Expand Up @@ -124,7 +124,7 @@ endif


CFLAGS += $(CFLAGS_MCU_$(MCU_SERIES))
CFLAGS += $(INC) -Wall -Werror -g -ansi -std=c11 -nostdlib $(COPT) $(NRF_DEFINES) $(CFLAGS_MOD) $(CFLAGS_EXTRA)
CFLAGS += $(INC) -Wall -Werror -ansi -std=c11 -nostdlib $(COPT) $(NRF_DEFINES) $(CFLAGS_MOD) $(CFLAGS_EXTRA)
CFLAGS += -fno-strict-aliasing
CFLAGS += -Iboards/$(BOARD)
CFLAGS += -DNRF5_HAL_H='<$(MCU_VARIANT)_hal.h>'
Expand All @@ -138,9 +138,10 @@ LDFLAGS += -Wl,'--defsym=_fs_size=$(FS_SIZE)'
endif

#Debugging/Optimization
CFLAGS += -g # always include debug info in the ELF
ifeq ($(DEBUG), 1)
#ASMFLAGS += -g -gtabs+
CFLAGS += -O0 -ggdb
CFLAGS += -O0
LDFLAGS += -O0
else
CFLAGS += -Os -DNDEBUG
Expand Down
3 changes: 2 additions & 1 deletion ports/renesas-ra/Makefile
Expand Up @@ -148,8 +148,9 @@ CFLAGS += -fdata-sections -ffunction-sections
LDFLAGS += --gc-sections

# Debugging/Optimization
CFLAGS += -g # always include debug info in the ELF
ifeq ($(DEBUG), 1)
CFLAGS += -g -DPENDSV_DEBUG
CFLAGS += -DPENDSV_DEBUG
#COPT = -Og
COPT = -Os
# Disable text compression in debug builds
Expand Down
3 changes: 2 additions & 1 deletion ports/samd/Makefile
Expand Up @@ -57,8 +57,9 @@ LDFLAGS += $(LDFLAGS_MOD)
LIBS = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)

# Tune for Debugging or Optimization
CFLAGS += -g # always include debug info in the ELF
ifeq ($(DEBUG),1)
CFLAGS += -O0 -ggdb
CFLAGS += -O0
else
CFLAGS += -Os -DNDEBUG
LDFLAGS += --gc-sections
Expand Down
3 changes: 2 additions & 1 deletion ports/stm32/Makefile
Expand Up @@ -114,8 +114,9 @@ $(BUILD)/stm32_it.o $(BUILD)/pendsv.o: CFLAGS += -fno-lto
endif

# Debugging/Optimization
CFLAGS += -g # always include debug info in the ELF
ifeq ($(DEBUG), 1)
CFLAGS += -g -DPENDSV_DEBUG
CFLAGS += -DPENDSV_DEBUG
COPT ?= -Og
# Disable text compression in debug builds
MICROPY_ROM_TEXT_COMPRESSION = 0
Expand Down
3 changes: 2 additions & 1 deletion ports/teensy/Makefile
Expand Up @@ -105,8 +105,9 @@ LIBS += -L $(dir $(LIBC_FILE_NAME)) -lc
LIBS += -L $(dir $(LIBGCC_FILE_NAME)) -lgcc

#Debugging/Optimization
CFLAGS += -g # always include debug info in the ELF
ifdef DEBUG
CFLAGS += -Og -ggdb
CFLAGS += -Og
else
CFLAGS += -Os #-DNDEBUG
endif
Expand Down

0 comments on commit fdfe4ec

Please sign in to comment.