Skip to content

Conversation

@recursivenomad
Copy link
Contributor

Setting CMAKE_${LANG}_FLAGS_DEBUG_INIT specifically only sets the flags for the Debug config the first time it is configured by CMake, pulling the initially-configured flags from CMakeCache.txt on subsequent configurations. This causes PICO_DEOPTIMIZED_DEBUG to not have any effect after the initial configuration, causing breakpoint issues when debugging certain functions.

Changing the CMake variable to CMAKE_${LANG}_FLAGS_DEBUG enables the flags to be updated every configuration, no longer depending on the cache. We also must append the debug flags which were set prior to this file to maintain functional parity with the behaviour of CMAKE_${LANG}_FLAGS_DEBUG_INIT.

See Issue #1618 for further details.

Fixes #1618

Setting CMAKE_${LANG}_FLAGS_DEBUG_INIT specifically only sets the flags for the Debug config the first time it is configured by CMake, pulling the initially-configured flags from CMakeCache.txt on subsequent configurations.  This causes PICO_DEOPTIMIZED_DEBUG to not have any effect after the initial configuration, causing breakpoint issues when debugging certain functions.

Changing the CMake variable to CMAKE_${LANG}_FLAGS_DEBUG enables the flags to be updated every configuration, no longer depending on the cache.  We also must append the debug flags which were set prior to this file to maintain functional parity with the behaviour of CMAKE_${LANG}_FLAGS_DEBUG_INIT.

See Issue raspberrypi#1618 in the primary repository for further details.

Fixes raspberrypi#1618
@recursivenomad recursivenomad marked this pull request as draft January 30, 2024 16:15
@recursivenomad
Copy link
Contributor Author

Setting to draft as I've identified a bug where the initial configuring produces -Og -Og instead of -Og -g, as visible in compile_commands.json. Subsequent configurings behave as expected. This bug was is not present in develop. Working on it...

@recursivenomad
Copy link
Contributor Author

Okay, I understand the problem. It appears that when CMake is provided -DCMAKE_BUILD_TYPE:STRING=Debug, it sets:

  string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -g")

This gets appended after calling:

project(project-name)

Since set_flags.cmake is called before creating the project, CMAKE_${lang}_FLAGS_DEBUG_INIT has not been set in the cache yet during first configuring.

Looks like unsetting CMAKE_${LANG}_FLAGS_DEBUG from the cache right before setting CMAKE_${LANG}_FLAGS_DEBUG_INIT (disregarding the first proposed changes) solves the problem and is truly at parity with the initial (and intended) behaviour of PICO_DEOPTIMIZED_DEBUG.

Setting CMAKE_${LANG}_FLAGS_DEBUG_INIT specifically only sets the flags for the Debug config the first time it is configured by CMake, pulling the initially-configured flags from CMakeCache.txt on subsequent configurations. This causes PICO_DEOPTIMIZED_DEBUG to not have any effect after the initial configuration, causing breakpoint issues when debugging certain functions.

Clearing the cache of the debug flags allows the flags to be updated every configuration, and appended to appropriately (such as with "-g").

See Issue raspberrypi#1618 and the comments of Pull Request raspberrypi#1620 for further details.

Fixes raspberrypi#1618
@recursivenomad recursivenomad marked this pull request as ready for review January 30, 2024 18:26
@recursivenomad
Copy link
Contributor Author

If accepted, I'd recommend squashing before merge as the first commit contains bugs.

recursivenomad added a commit to recursivenomad/pico-sdk that referenced this pull request Jan 30, 2024
Optimizing a debug build with PICO_DEOPTIMIZED DEBUG disabled (the current default) results in breakpoints not being possible in certain functions.  This change makes the default behaviour of PICO_DEOPTIMIZED_DEBUG to be enabled, so that debug builds will fully work as expected when no explicit value for the option is passed.

Since the cache stores the default value of PICO_DEOPTIMIZED DEBUG, you will need to delete the CMakeCache.txt previously generated in your project directory for this change to default behaviour to take effect in existing projects.

This commit is related to pull request raspberrypi#1620 in the primary repository.

See Issue raspberrpi#1618 in the primary repository for additional context.
@kilograham kilograham added this to the 1.6.0 milestone May 18, 2024
@kilograham kilograham modified the milestones: 1.6.1, 1.6.0 May 19, 2024
@kilograham kilograham merged commit 2de70c7 into raspberrypi:develop Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants