-
Notifications
You must be signed in to change notification settings - Fork 3k
Use O0 for a better debug experience #14562
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
Conversation
@rotu, thank you for your changes. |
Hi @rotu , what problems you have with O1 optimizations? https://developer.arm.com/documentation/dui0472/k/Compiler-Coding-Practices/Compiler-optimization-levels-and-the-debug-view - worth reading about good practices. Is it this one that this PR is addressing:
There are implications of switching to O0. The size increase is one of them. How does your experience change if you add --debug for debug profile ? As suggested for O1:
Edit: we define -g there |
In my experience the debuggability of But the "debug" profile was changed to Here was a previous PR wanting to change it by adding a new profile: #12165. Check discussion there. And also discussion on the docs change: ARMmbed/mbed-os-5-docs#1195 |
The issue I regularly come up against is variables being optimized out. But all of these caveats negatively impact the debuggability of code:
When using the debugger, the Maybe there's some hidden optimization level that provides a better middle ground? |
I would rather focus on documentation and custom profiles to edit compiler/linker options. There is always a flag to change. The best customization is achieved by a custom profile. mbed-cli 1 provides custom profiles. mbed-cli 2 require more work for handling toolchain file that should take care of this. The current CMake has predefined profiles that you can edit until we get toolchain file support. |
It's not mutually exclusive. In the linked discussions it seems the general consensus is that O0 is more useful. That said, it's not obvious to the user that they should RTFM in the first place - it is rather unexpected behavior that a profile called "Debug" will hide information from the "Debugger". My experience with GCC is that the current profile is good enough; although -Og applies some optimization, it doesn't obstruct debugging in the way that O1 does on ARMC6. |
Based on the feedback, we should rather create an issue to change this in the next major version. As there are consequences (mainly about the final size), I believe this would be a breaking change and it should be in the next major version. |
@0xc0170 With the CMake work, would it be possible to select certain level of optimization for specific libraries ? |
I remember typing the reply yesterday. Yes it should be. A library can add options via compile options/compiler features, etc. To just keep it for a library, use |
@donatieng Please review |
This pull request has automatically been marked as stale because it has had no recent activity. @donatieng, @ARMmbed/mbed-os-maintainers, please complete review of the changes to move the PR forward. Thank you for your contributions. |
Hi folks, I agree about the sentiment - in practice I've often had to switch to
Seems the ideal solution, let's look at how this could be achieved in the next major release. |
I'll close this as it can't be accepted currently due to the breaking change. Please use custom profile meanwhile. @rotu Please create a tracking issue for this change I'll close this pull request now. |
Summary of changes
Make Debug profile use optimization level
-O0
instead of-O1
.Impact of changes
Previously variables in scope could have been optimized out in Mbed Studio when building with the Debug profile.
Now their values should remain visible.
Migration actions required
Documentation
None
Pull request type
Test results
Reviewers