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

Better defaults for "debug project" #153

Open
infovore opened this issue Jan 13, 2025 · 5 comments
Open

Better defaults for "debug project" #153

infovore opened this issue Jan 13, 2025 · 5 comments
Labels
enhancement New feature or request

Comments

@infovore
Copy link

Not a bug, but a suggestion / feature request:

  • The default compilation flag in CMake is, I believe, Release; it'd be nice if when you chose to Debug a project, it compiled in Debug mode (which I'm not sure it does).
  • Similarly, it'd be great if in Debug mode, the compiler flags -g -O0 were added; as it is, when I debug a project, the debugger works... but all my variables are optimized out and it's very hard to track anything.

My knowledge of Cortex Debug is... thin, but I've had it working on previous RP2040 projects, and in general I'm a huge fan of making this stuff available to end users.

As it is, I have these lines in my CmakeLists.txt:

set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_C_FLAGS_DEBUG "-g -O0")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")

and I comment out the first for release building.

@infovore
Copy link
Author

That said - these issues might all be my fault in that a) I already had a CMake/Cortex Debug configuration setup and b) I'm actually using a custom board type, in a board subdirectory in my project, and I note in launchTargetPath.mts that there's a check for boardtype in there that might affect this. Previous experience of Cortex Debug have been... similarly fragile, and I know things are in beta, but perhaps there's something here.

@will-v-pi
Copy link
Collaborator

To set the de-optimised debug flags, you can use set(PICO_DEOPTIMIZED_DEBUG 1) instead of setting the CMAKE_C..._FLAGS_DEBUG directly - the default Debug build of the SDK still has some optimisations, which PICO_DEOPTIMIZED_DEBUG disables. We wouldn't add this by default, but could add a code generation option to enable it.

I think we could add the automatic switch to Debug builds when using Cortex-Debug, vs release builds when you click Run - it would just require checking the build type and possibly running a CMake Configure whenever you switch between Cortex-Debug and Run.

@will-v-pi will-v-pi added the enhancement New feature or request label Jan 14, 2025
@infovore
Copy link
Author

Good to know about that flag. I like the idea of switching to Debug builds automatically... but understand that there are good reasons to make that switch manual / use a debugger with a Release build. It's just it turns out a lot of the functionality of the debugger for me was actually specific to deoptimized code.

I'm not sure what the right answer is here, hence being discursive; I do know that the Debug Probe is an excellent thing, and helping more users use it more easily is a win for everybody, so I'll keep seeing how I get on here. Thanks for your patience with me!

@will-v-pi
Copy link
Collaborator

I've added a switchBuildType command, which allows for manual switching between build types - I'm currently thinking that automatic switching would be quite annoying for me (and probably others), so I think for now manual switching is probably best. Although we might add it as a feature that you can enable through a setting, but I think the default should be disabled.

@IvanVeloz
Copy link

I'm on the same boat here. I want Cmake to have a Debug configuration when debugging, so that I can add compile flags like -DLOGGING_LEVEL_DEBUG=1.

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

No branches or pull requests

3 participants