platformio/platformio-core

Debug Mode Adds Unsupported `-g2` Flag to Assembler, Causing Fatal Error

Open

#5005 aperta il 24 ott 2024

Vedi su GitHub
 (1 commento) (0 reazioni) (0 assegnatari)Python (791 fork)batch import
debugginghelp wanted

Metriche repository

Star
 (7329 star)
Metriche merge PR
 (Merge medio 109g 16h) (5 PR mergiate in 30 g)

Descrizione

Description:

When attempting to debug a project created with STM32Cube in PlatformIO, the assembler (arm-none-eabi-as) receives the -g2 flag, which it does not recognize, resulting in a fatal error. This issue prevents successful debugging even though the project compiles without errors in normal build mode.

Environment:

  • PlatformIO Version: 6.1.16
  • Platform: ST STM32
  • Board: genericSTM32F103ZE
  • Toolchain: arm-none-eabi-gcc (version 12.3.1)
  • Operating System: Windows 11

Build Configuration (platformio.ini):

[env:genericSTM32F103ZE]
platform = ststm32
board = genericSTM32F103ZE
build_flags =
  -g

Problem:

When initiating a debug session using pio debug -v, PlatformIO automatically adds the -g2 and -ggdb2 flags to both the GCC compiler and the assembler. While the compiler accepts these flags, the assembler (arm-none-eabi-as) does not recognize -g2, leading to the following fatal error:

Assembler messages:
Fatal error: unknown option `-g2'
*** [path_to_output.o] Error 1

Even though I forced the -g option in build_flags, it did not take effect.I added the following content to the configuration file, and the debug debugging can be used normally.

debug_build_flags =
    -g

Steps to Reproduce:

Create a new STM32Cube project using PlatformIO with the genericSTM32F103ZE board. In platformio.ini, set -g as the debug flag. Include an assembly startup file (e.g., startup_stm32f103zetx.s) in the project. Build the project to confirm that it compiles without issues. Start a debug session using pio debug -v. Observe the assembler error related to the -g2 flag.

Log Output:

CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/genericSTM32F103ZE.html
PLATFORM: ST STM32 (17.6.0) > STM32F103ZE (64k RAM. 512k Flash)
HARDWARE: STM32F103ZET6 72MHz, 64KB RAM, 512KB Flash
DEBUG: Current (stlink) External (blackmagic, cmsis-dap, jlink, stlink)
PACKAGES:
 - toolchain-gccarmnoneeabi @ 1.120301.0 (12.3.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 11 compatible libraries
Scanning dependencies...
[Dependency graph information]
Building in debug mode
arm-none-eabi-as -mthumb -mcpu=cortex-m3 -g2 -ggdb2 -o .pio\build\genericSTM32F103ZE\src\N1OS\Startup\startup_stm32f103zetx.o Startup\startup_stm32f103zetx.s
arm-none-eabi-gcc -o .pio\build\genericSTM32F103ZE\src\N1OS\Users\App\User\Program\app.o -c [additional flags including -g2 -ggdb2]
Assembler messages:
Fatal error: unknown option `-g2'
*** [.pio\build\genericSTM32F103ZE\src\N1OS\Startup\startup_stm32f103zetx.o] Error 1

Expected Behavior:

PlatformIO should respect the build_flags specified in the platformio.ini file and avoid adding unsupported flags like -g2 to the assembler. The debugger should initiate successfully without modifying the assembler flags in an incompatible way.

Actual Behavior:

During the debug build process, PlatformIO adds -g2 and -ggdb2 flags to both the GCC compiler and the assembler. While GCC handles these flags gracefully, the assembler does not recognize -g2, resulting in a fatal error and preventing the debug session from starting.

Guida contributor