mirror of
https://github.com/qmk/qmk_firmware
synced 2024-12-22 08:26:21 +00:00
[Maintenance] builddefs: common_rules: overhaul debug information generation (#24352)
builddefs: common_rules: overhaul debug information generation Debug information is always generated while compiling a binary, but debugging is not the main use-case for the majority of users. Thus the new default is to explicitly require them with `DEBUG_ENABLE=yes`. The same is true for linker map files which are gated by the same flag. As we target the gcc compiler and debug with the gdb debugger we can specify the ggdb3 flag in the most verbose to get macro expansion. Signed-off-by: Stefan Kerkmann <karlk90@pm.me>
This commit is contained in:
parent
07535aa2c0
commit
d210590d4d
@ -43,6 +43,18 @@ ifneq ($(USE_CCACHE),no)
|
|||||||
CC_PREFIX ?= ccache
|
CC_PREFIX ?= ccache
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
#---------------- Debug Options ----------------
|
||||||
|
|
||||||
|
DEBUG_ENABLE ?= no
|
||||||
|
ifeq ($(strip $(DEBUG_ENABLE)),yes)
|
||||||
|
CFLAGS += -ggdb3
|
||||||
|
CXXFLAGS += -ggdb3
|
||||||
|
ASFLAGS += -ggdb3
|
||||||
|
# Create a map file when debugging
|
||||||
|
LDFLAGS += -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
#---------------- C Compiler Options ----------------
|
#---------------- C Compiler Options ----------------
|
||||||
|
|
||||||
ifeq ($(strip $(LTO_ENABLE)), yes)
|
ifeq ($(strip $(LTO_ENABLE)), yes)
|
||||||
@ -54,14 +66,6 @@ ifeq ($(strip $(LTO_ENABLE)), yes)
|
|||||||
CDEFS += -DLTO_ENABLE
|
CDEFS += -DLTO_ENABLE
|
||||||
endif
|
endif
|
||||||
|
|
||||||
DEBUG_ENABLE ?= yes
|
|
||||||
ifeq ($(strip $(SKIP_DEBUG_INFO)),yes)
|
|
||||||
DEBUG_ENABLE=no
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(strip $(DEBUG_ENABLE)),yes)
|
|
||||||
CFLAGS += -g$(DEBUG)
|
|
||||||
endif
|
|
||||||
CFLAGS += $(CDEFS)
|
CFLAGS += $(CDEFS)
|
||||||
CFLAGS += -O$(OPT)
|
CFLAGS += -O$(OPT)
|
||||||
# add color
|
# add color
|
||||||
@ -83,9 +87,6 @@ CFLAGS += -fcommon
|
|||||||
|
|
||||||
#---------------- C++ Compiler Options ----------------
|
#---------------- C++ Compiler Options ----------------
|
||||||
|
|
||||||
ifeq ($(strip $(DEBUG_ENABLE)),yes)
|
|
||||||
CXXFLAGS += -g$(DEBUG)
|
|
||||||
endif
|
|
||||||
CXXFLAGS += $(CXXDEFS)
|
CXXFLAGS += $(CXXDEFS)
|
||||||
CXXFLAGS += -O$(OPT)
|
CXXFLAGS += -O$(OPT)
|
||||||
# to suppress "warning: only initialized variables can be placed into program memory area"
|
# to suppress "warning: only initialized variables can be placed into program memory area"
|
||||||
@ -106,14 +107,10 @@ endif
|
|||||||
|
|
||||||
#---------------- Linker Options ----------------
|
#---------------- Linker Options ----------------
|
||||||
|
|
||||||
CREATE_MAP ?= yes
|
|
||||||
ifeq ($(CREATE_MAP),yes)
|
|
||||||
LDFLAGS += -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref
|
|
||||||
endif
|
|
||||||
ifeq ($(VERBOSE_LD_CMD),yes)
|
ifeq ($(VERBOSE_LD_CMD),yes)
|
||||||
LDFLAGS += -v
|
LDFLAGS += -v
|
||||||
endif
|
endif
|
||||||
#LDFLAGS += -Wl,--relax
|
|
||||||
LDFLAGS += $(EXTMEMOPTS)
|
LDFLAGS += $(EXTMEMOPTS)
|
||||||
LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
|
LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
|
||||||
LDFLAGS += -lm
|
LDFLAGS += -lm
|
||||||
@ -126,15 +123,11 @@ ADHLNS_ENABLE ?= no
|
|||||||
ifeq ($(ADHLNS_ENABLE),yes)
|
ifeq ($(ADHLNS_ENABLE),yes)
|
||||||
# Avoid "Options to '-Xassembler' do not match" - only specify assembler options at LTO link time
|
# Avoid "Options to '-Xassembler' do not match" - only specify assembler options at LTO link time
|
||||||
ifeq ($(strip $(LTO_ENABLE)), yes)
|
ifeq ($(strip $(LTO_ENABLE)), yes)
|
||||||
LDFLAGS += -Wa,-adhlns=$(BUILD_DIR)/$(TARGET).lst
|
LDFLAGS += -Wa,-adhlns=$(BUILD_DIR)/$(TARGET).lst
|
||||||
else
|
else
|
||||||
CFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
|
CFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
|
||||||
CXXFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
|
CXXFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
|
||||||
ifeq ($(strip $(DEBUG_ENABLE)),yes)
|
ASFLAGS += -Wa,-adhlns=$(@:%.o=%.lst),--listing-cont-lines=100
|
||||||
ASFLAGS = -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100
|
|
||||||
else
|
|
||||||
ASFLAGS = -Wa,-adhlns=$(@:%.o=%.lst),--listing-cont-lines=100
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -177,12 +177,13 @@ You'll need to perform some modifications to the file above in order to target y
|
|||||||
Windows builds of QMK Firmware are generally compiled using QMK MSYS, and the path to gdb's location (`C:\\QMK_MSYS\\mingw64\\bin`) needs to be specified under `armToolchainPath` for it to be detected. You may also need to change the GDB path to point at `C:\\QMK_MSYS\\mingw64\\bin\\gdb-multiarch.exe` in the VSCode Cortex-Debug user settings: ![VSCode Settings](https://i.imgur.com/EGrPM1L.png)
|
Windows builds of QMK Firmware are generally compiled using QMK MSYS, and the path to gdb's location (`C:\\QMK_MSYS\\mingw64\\bin`) needs to be specified under `armToolchainPath` for it to be detected. You may also need to change the GDB path to point at `C:\\QMK_MSYS\\mingw64\\bin\\gdb-multiarch.exe` in the VSCode Cortex-Debug user settings: ![VSCode Settings](https://i.imgur.com/EGrPM1L.png)
|
||||||
:::
|
:::
|
||||||
|
|
||||||
Optionally, the following modifications should also be made to the keyboard's `rules.mk` file to disable optimisations -- not strictly required but will ensure breakpoints and variable viewing works correctly:
|
The following modifications must be made to the keyboard's `rules.mk` file to enable debug information and disable optimisations -- this will ensure breakpoints and variable viewing works correctly:
|
||||||
```makefile
|
```makefile
|
||||||
|
# Enable debug information in the final binaries
|
||||||
|
DEBUG_ENABLE = yes
|
||||||
# Disable optimisations for debugging purposes
|
# Disable optimisations for debugging purposes
|
||||||
LTO_ENABLE = no
|
LTO_ENABLE = no
|
||||||
OPT = g
|
OPT = g
|
||||||
DEBUG = 3
|
|
||||||
```
|
```
|
||||||
|
|
||||||
At this point, you should build and flash your firmware through normal methods (`qmk compile ...` and `qmk flash ...`).
|
At this point, you should build and flash your firmware through normal methods (`qmk compile ...` and `qmk flash ...`).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user