Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AliveGh0st opened this issue Oct 24, 2024 · 1 comment
Open

Comments

@AliveGh0st
Copy link

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.

@AliveGh0st
Copy link
Author

I strongly suggest that in PlatformIO's platformio.ini, the compiler (gcc), linker (ld), and assembler (as) have their own independent flags options. The parameters among these three are not compatible, and applying build_flags to all components is unwise, resulting in a significant loss of flexibility and introducing many issues. Additionally, options like debug_build_flags are not a wise choice; they take effect during the compilation process before debugging, yet these compilation options also apply to gcc and as, which creates confusion and chaos for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant