Skip to content

Allow the trace output by mbed error to be conditional of NDEBUG. #2715

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

Merged
merged 1 commit into from
Sep 24, 2016

Conversation

pan-
Copy link
Member

@pan- pan- commented Sep 15, 2016

This change disable any trace output by error when the application is compiled with NDEBUG.

Unlike assert, error will still crash/halt the execution of the application even if NDEBUG is enabled.
In that regard, its core behavior is preserved.

This change avoid the inclusion of printf and friends code in a binary when it is compiled with the macro NDEBUG enabled because a lot of driver code use error rather than assert.

The memory gain is non negligible: This is the differences with and without this change when mbed-os-example-blinky is compilef with NDEBUG enabled.

  • Without the patch:
GCC ARMCC IAR
RAM 11832 10152 7970
ROM 37008 26868 21266
  • With the patch:
GCC ARMCC IAR
RAM 11808 10152 7834
ROM 19852 20239 14600
  • Difference
GCC ARMCC IAR
RAM -24 bytes (-0.2%) 0 bytes (0%) -136 bytes (-1.70%)
ROM -17156 bytes (-46.3%) -6629 bytes (-24.7%) ROM: -6666 bytes (-31.3%)

This change avoid inclusion of printf and friends code in a binary when it
is compiled with the macro NDEBUG enabled (this macro is usually enabled
for production builds).

Unlike assert, the error function will still crash/halt the execution of the
application even if NDEBUG is enabled; the traces are just not outputed.
@pan-
Copy link
Member Author

pan- commented Sep 15, 2016

@0xc0170 @sg- Waiting for your comments.
I would like to know where the documentation around NDEBUG should be located.
For example, MBED_ASSERT use it but it is not documented.

@sg-
Copy link
Contributor

sg- commented Sep 16, 2016

I would like to know where the documentation around NDEBUG should be located.

I'd suggest we have 2, maybe 3 max build profiles that compliment this patch and have specific objectives and flags / macros used based on that. The never ending list of -o options should be wrapped into build profiles and documented. Something like -o size, speed, debug.

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 20, 2016

The never ending list of -o options should be wrapped into build profiles and documented

+1 for having profiles

This change-set looks good to me. We will discuss connection between NDEBUG and profiles once profiles get into the codebase, or?

@pan- 👍 for this

@sg- sg- merged commit bd3d6ab into ARMmbed:master Sep 24, 2016
pan- added a commit to pan-/mbed that referenced this pull request Oct 21, 2016
@pan- pan- deleted the NDEBUG_optimization branch July 3, 2018 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants