Chris_B
Chris_B

Reputation: 489

Code inside #ifdef SYMBOL [...] #endif is omitted, but SYMBOL is defined - STM32CubeIDE

the Story

I use Symbols to control if a specific piece of Code should be included in the build or not - as most probably everyone working with C/C++ (and others) does. In this particular case I use two symbols, to control if the code running on the Microcontroller is in "Setup"-Mode, or in "EEPROM-Init Mode".

For Both Modes I use Symbols, the Setup Mode Symbol is "SWCONFIG_SETUP" and the EEPROM-Init Symbol is "SWCONFIG_EEPINIT".

The Symbols are defined in the Project Properties of CubeIDE:

Project Properties

The issue is: both marked lines are skipped in debugging. I'd expect that I could step over/into them when I debug in single step moded, but the debugger just jumps over them, just as if they were disabled and the Symbol SWCONFIG_EEPINIT would not be defined.

skipped code

I can control that e.g. the code is not executed, because i can not jump into the function with the debugger, and additionaly I can see the Files in the EEPROM were not erased, what would be the purpose of EEP_erase_files();

In the Code both sections are enabled, indicating that the Symbol is defined, otherwise that sections would be greyed out. In an other Code Section, using the #ifdef ... #else ... #endif syntax, the debugger jumps in the greyed out section, indication that it ignores the Symbol.

What I tried to resolve this:

I tried to rebuild/refresh the Index I deleted the code and re-wrote it. I deleted the Build Configuration and created it new I deleted the Symbol in the Project Properties and created it new (using Copy & Paste from the code, to avoid typos)

The Question:

What the heck is going on here? Why is the IDE showing the code section as active, but the Debugger ignores it?

The strange thing is: this workflow allready did it's job!

Upvotes: 0

Views: 935

Answers (1)

Chris_B
Chris_B

Reputation: 489

Solved:

The issue was: i was starting the "Setup" Configuration, not the "SetupEEP" configuration, because for some reason i don't really understand, STM32CubeIDE does not automatically create a Debug configuration, when you create a Build configuration.

I had to create a new Debug Configuration, pointing to the executable in the SetupEEP directory. I just built the "SetupEEP" executable and pressed the debug button, but was not aware, that I started the Debug session with the executable from the "Setup" Build, because i had not created a Debug Configuration for "SetupEEP". This is why the code was omitted: because it was not included in the Build I was running ...

Debug Configurations

BTW: nice Pitfall, STM!

Upvotes: 1

Related Questions