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
Add debug symbols to release builds (all toolchains) #2139
Conversation
Could you enable it for all toolchains? We can test if you don't have all toolchains. |
@0xc0170: Made the change for armcc and iar toolchains as well. |
LGTM |
cc @screamerbg @sg- |
@andresag01 Sorry, but could you update PR description and e.g. write why this change is happening? |
@PrzemekWirkus: Updated PR description. |
Sorry, we are adding debug information to release build ? |
@PrzemekWirkus: Well, we are adding debug information to the elf file generated by the compilers, but this should not much affect the .bin that is actually flashed into the target boards. |
This will be really nice to have. Good work @andresag01! |
Sorry but |
@0xc0170 I would really discuss this change with Bogdan or Marcus before applying it. Better be safe than sorry! |
Agree with @PrzemekWirkus. ARM Compiler 5 adds HUGE debug payload. For a single target the full compiled OS is 280MB with every object file between 1 and 2 MB. Can you please try the PR locally before submitting it? E.g. running |
I think that release build should not be compiled with debugs because that change binary context a bit and increase valuable size. Of cource we could provide also release builds with debugs but that should be separate build. cc: @kjbracey-arm @SeppoTakalo |
Not sure what you mean. This change will only add debug symbols to the .elf file, not to the actual binary that is flashed, as @0xc0170 already explained. |
cc @mjs-arm
That would be nice to have (explanation below) @PrzemekWirkus made some valid points, this change requires more information to be provided (toolchains behavior with debug symbols, how much it affects the build sizes), plus some consideration for this type of a change. Do we want to enable debug info for all builds, or provide a new extension as "debug info" was added. I many times when was catching a bug, had to do this change manually. Question for us: if we consider having extra debug symbols is useful (not in the form as its in this patch at the moment), how we could enable it? Or "debug-info" and default build is sufficient? Please could you provide an alternative if you express negative opinion about a patch? that would be helpful |
I'm also a bit doubtful that -g and optimisation level are totally independent on all 3 toolchains. Certainly this was never historically the case with armcc. A whole bunch of optimisations were inhibited by -g. However, the current armcc manual does explicitly say that -g does not affect code generation. IAR and GCC manuals don't explicitly say, but suggest it. Can you definitely experimentally confirm that "should not have an impact in the binary" is "currently does not"? Also, saying "debug symbols" is a bit misleading. Symbols (ie variable and function locations) should always be available, regardless of compiler -g. -g is adding extra debug information, like variable types and line numbers. |
Personally I think that
Where did you get that information from? At least for GCC, the manual doesn't say anything about that:
|
Also, as @0xc0170's comments highlight - with this change as proposed, "-o debug-info" becomes a total misnomer (as opposed the partial one it is now), as it's not actually adding debug info, but only changing optimisation level. That would need adjusting in some way. |
@bogdanm Bogdan, thank you for the insights ! :)
I read somewhere I guess. My reasoning was based on assumption that compiler may remove some optimizations like inlining to make debug bearable. I had some time and I have read GCC manual. And yes, AFAIK there is no impact on binary size and only extra symbols are added to ELF. It is actually easier to find this information for ARMCC, see Using --debug does not affect optimization settings.. Building for debug purposesI was thinking the whole point of having virtual And yes, like Kevin said. With this change whole Some testsI've also ran test case build for ARMCC, IAR and GCC with Build size impactThere is a valid point for size of vanilla/release build. This option increases dramatically size of build like @screamerbg said. Basically there should be an option to have vanilla and debug builds on demand with e.g. vanilla/release as default. May I assume that most of the build systems work like this and there will be no confusion for developers where to find and how to enable " For Jenkins/CI build is an artifact. It can weigh ~50MB but not 250MB by default! |
@adbridge @mazimkhan FYI |
It definiteley does. But this is a common and relatively well understood problem. Having ocasionally dodgy debug information is better than not having any debug information at all.
I didn't do any benchmarks in this area personally. Does anyone have some numbers to support this claim?
Ouch! Are those real life numbers? |
I would think standard approach for debugging is to build fully for debug so that each line of code can actually be stepped through. Trying to step through optimised code that just happens to have debug symbols could actually be quite a confusing experience and lead to unexpected values present in registers etc. They way I have seen this approached in the past is to have some kind of post crash processor dump that can be extracted, which includes current memory state and values of all global data and registers (including stack backtrace) . This can then be analysed offline. Just a thought... |
For GCC the switching from -g -O0 to -g -Og would make more sense. I can see no reason to force the compiler down to -O0. From the gcc manual: """-Og |
I did try that a few months ago. I wasn't entirely convinced. It was certainly a lot better to debug than -O2, but still had some oddities that -O0 didn't. |
This also raises the question of why (at least for gcc) we are using -O2 instead of -Os in a footprint constrained environment. I wonder is their is a particular historical reason for this choice, if not then we should look towards switching. |
This just came up here - we want to switch to -Os to squeeze something in to 512K. There is a comment in the Python about using -O2 instead of -Os to avoid a compiler bug, but that bug appears to have been long since fixed. |
This is already open issue on mbed - #664 please discuss it there why O2, not Og or Os. Look at Adam's response, not certain if there was any improvement in gcc since 2014, if yes, add a comment there. Thanks |
Yes, avoiding that bug was the original reason for using -O2: https://github.com/mbedmicro/mbed/blob/master/tools/toolchains/gcc.py#L79 At this point, I fully agree that we should switch to -Os. |
After a quick look, it appear that the GCC documentation explicitly state that the generation of debugging information has no impact to the generated binary (here).
This PR raise another question for me: Why NDEBUG is not defined for release builds ? |
@PrzemekWirkus If the artifacts size is an issue in the CI infrastructure, we could have a build option that disables the build symbols for that specific case (basically the opposite of what we have now, I agree with @bogdanm though that in all other cases debug symbols should be present by default, as they do not affect the final code size and performance. Debug builds (where optimizations are disabled) should have a more explicit build option, like |
At this point, the only thing that would prevent me from merging this PR is this:
If this impacts our infrastructure, we need to find a better way to handle it. But I don't know how much of a problem this really is. Maybe @bridadan or someone else can comment? In any case, we can use @AlessandroA's suggestion:
|
I don't have a problem with adding flags to CI builds that prevent the build size from blowing up. But if we're changing the compiler flags and adding new Until there is an option to disable the build symbols, I'd say we'd need to hold off on merging this PR. |
cc @meriac |
Update: By default ARMCC produces debug macros that increase the output files. Some numbers: The size of the output folder for mbed-os-blinky with ARMCC: If we are happy with |
That looks like a good compromise to me, but we still need to assess the impact of the increased size on our CIs. @bridadan |
@0xc0170 Thanks a lot for running the numbers! Can you please update the pull request accordingly so we can get it merged? @screamerbg @bogdanm |
@0xc0170 Might be worth trying |
Demo has now 13mb output folder, that means increase only 2x. I'll try to fetch this PR, and update it to the current code base. |
I am going to send a new pull request , rebased on top of master, and applied new flags for ARMCC, will reference it here. |
…..4a19dc4 4a19dc4 Import new thread files f6a021d Removed test files b9e842a Merge branch 'release_internal' into release_external 7d5d869 Merge pull request ARMmbed#2167 from ARMmbed/release_internal_merge 26e2d43 Merge branch 'master' into release_internal f43620f Add support for India band (ARMmbed#2166) 122f158 Merge pull request ARMmbed#2165 from ARMmbed/release_internal_merge 0e65ee5 Added disabling of NA for Thread BR PPP backbone 4c50e52 Added disabling of NA for Wi-SUN BR PPP backbone d2ea325 Moved DAD enabled check to Ipv6 SLAAC handler 49994fc Added PPP interface to nanostack 3383e91 Merge pull request ARMmbed#2163 from ARMmbed/IOTTHD-3558 81f7511 MAC: print RF configs 397240a MAC: Implemented CCA threshold and TX power setting 5907042 Added check for allocation failures in EAPOL 9ed97c9 ETX update: b489415 Add own certificate handling APIS (ARMmbed#2149) 888a0fb fhss_ws: check if 0 used as divider 586f2f2 Merge pull request ARMmbed#2160 from hugueskamba/hk-iotcore-1299-remove-fp-usage-ns_monitor f1d03b1 Remove floating-point usage in Nanostack heap monitor ef88f64 Removed rank comprae and also probe 5 best on the list. a2887d6 Clean PAN id compare trace print. f37dcf2 Wi-SUN NS NUD & Probe send update f7133f8 Merge pull request ARMmbed#2158 from ARMmbed/remove_temp_debug_traces 2dc1a8e fhss_ws: removed temporary debug traces 96f962a Reduce wi-sun NS Probe 0a1beb2 GTK update trigger fix a1d172e Limit Pan config sol timeout after 5 solication. 9d7414b Limit PAE supplikant GTK re-use for authentication from 2->1. 662df08 Fixed Key request address set issue if GTK mismatch is detected. a56b908 Merge pull request ARMmbed#2153 from ARMmbed/IOTTHD-3650 9b33e98 Fixed mac_pd_sap CCA_PREPARE active ACK handler. 035af9a Enhanced ACK GEN and TX update b1beb5d fhss_ws: typecast drift to int32_t f786fc9 Merge pull request ARMmbed#2152 from ARMmbed/fhss_coverity_fix 6efff35 fhss_ws: Coverity fixes d743e91 WS LLC brodacst shedule fix 6a6fb0c Removed old configuration options from Border router API a051865 Merge pull request ARMmbed#2135 from ARMmbed/IOTTHD-3232 ff771b1 Added empty interface function for network name set e94da3c Merge pull request ARMmbed#2146 from ARMmbed/IOTTHD-3571_2 234e649 added network name change function to public API 1770465 fhss_ws: Added temporary debug traces (IOTTHD-3571) d400859 Fix Thread 1.1 unitests (ARMmbed#2145) 38978f3 wi-sun ETX update: 4a71b04 Adjust Thread functions defined for Thread 1.2 (ARMmbed#2139) 4d8dc0d remove border router from pan size calculation fb3363e Merge pull request ARMmbed#2141 from ARMmbed/IOTTHD-3571 f01c5f2 fhss_ws: conversion macros/functions to support int64 a7b0027 Suprress dio sending whenRPL is not yet ready f8c9d54 Adjust tracing (ARMmbed#2138) 678eaf8 Moved Thread 1.2 code to to correct place f39d07e Merge pull request ARMmbed#2136 from ARMmbed/IOTTHD-3571 ab23116 FHSS: temporary debug traces (IOTTHD-3571) 09d4b06 MAC: Implemented PHY statistics git-subtree-dir: features/nanostack/sal-stack-nanostack git-subtree-split: 4a19dc4
Add debug symbols to release builds in all toolchains. Including symbols in the builds significantly improves the debugging experience for all users because they can now relate the program execution to lines of source code rather than just plain assembly while using debugging tools such as GDB. This makes it significantly easier to identify bugs and issues in applications.
Note: Adding debug symbols will increase the size of the resulting elf file produced by the compiler, but should not have an impact in the binary that is flashed onto the target device.