-
Notifications
You must be signed in to change notification settings - Fork 976
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
Print and debug improvements #1750
Print and debug improvements #1750
Conversation
Static functions are private to the compilation unit they are emitted in, so they cannot be shared between compilation units. This means that any source file that uses `core_debug()` where the compiler does not inline (all) calls, will have its own private copy of this function emitted. In practice, gcc seems to never inline this function (even with -O3), leading to one copy of the function for each compilation unit it is used in. This fixes this by removing the `static` keyword from the function. However, this prevents the function from being emitted completely in C compilation units (C++ is different and emits multiple copies, discarding all but one later). This means that if the function is only used from C compilation units and not inlined everywhere, you get a linker error. Thet `static` keyword was probably added to work around this, without realizing the overhead. The proper way to prevent this linker error is to add an `extern` definition for the function in a single source file, so this adds a `core_debug.c` with exactly that. In practice, this means that this commit saves 40 bytes of space for each compilation unit where `core_debug()` is used (beyond the first).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR.
You have to move this include outside the #if !defined(NDEBUG)
#include <stdarg.h> |
else it does not built properly when Core logs are not enabled 😉
And please fix astyle issue.
This does the same as core_debug, but (like printf vs vprintf) accepts an already processed va_list to allow other vararg functions to forward their argument lists to this function.
4667777
to
47c8d9f
Compare
This does the same as printf, but (like the vprintf libc function) accepts an already processed va_list to allow other vararg functions to forward their argument lists to this function.
47c8d9f
to
b014a94
Compare
Good call, should have tested that. Fixed (and tested ;-p) now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @matthijskooijman for this PR, it LGTM.
About the failed CI, it is not linked to this PR but to an update of the arduino-lint which raised new error/warning. This is fixed thanks #1754.
Thanks! |
Summary
This PR makes some changes to the printing/printf code, both in the Print class and in
core_debug
.The main change that I needed is to add a "v" version of the
core_debug()
function. Likevprintf
vsprintf
, thevcore_debug
function does not accept individual arguments to interpolate into format string, but ava_list
instance. This allows it to be called from another function that is itself a varargs function and forwards its variable arguments.I originally thought I needed this for
Print::printf
, so I implementedPrint::vprintf
too. I ended up usingcore_debug()
instead, but thevprintf()
implementation might be useful for others (and adds zero code space if unused), so I just added it.Finally, when looking at the
core_debug()
code, I noticed the function wasstatic
and declared in a header file, which causes it to potentially take up a lot more flash space than needed, so I fixed that as well. See the commit message for details.