raspberrypi / pico-sdk

BSD 3-Clause "New" or "Revised" License
3.26k stars 838 forks source link

Fix PICO_DEOPTIMIZED_DEBUG not updating compiler flags #1620

Closed recursivenomad closed 2 weeks ago

recursivenomad commented 5 months ago

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

recursivenomad commented 5 months ago

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 commented 5 months ago

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.

recursivenomad commented 5 months ago

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