Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.arch.embedded > #27071
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.arch.embedded |
| Subject | Re: Efficient debug log |
| Date | 2017-07-24 09:40 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <ol482a$b09$1@dont-email.me> (permalink) |
| References | <okpt2m$sok$1@dont-email.me> <nnd$5a9c0de5$7bdbc657@f8f0cd39675aa771> |
On 20/07/17 23:14, Stef wrote:
> On 2017-07-20 pozz wrote in comp.arch.embedded:
>> I usually prints some messages on a free UART used as a debug port.
>> They are very useful during debugging to understand the flow of execution.
>>
>> Most of the time, I don't compile the debug log facility in release build.
>>
>> I sometimes need to disable messages from some modules and enable
>> messages from other modules under debugging.
>> Moreover I sometimes need to enable/disable less important messages.
>>
>> Do you suggest some efficient implementation of debug log macros that
>> include all the features above?
>
> If I have a output stream available for this purpose, I often use the
> following (assuming you use C):
>
> #ifdef DEBUG_ENABLE
> #define DEBUG_PRINTF(level, ...) ((level) <= (DebugLevel) ? fprintf(stderr, __VA_ARGS__) : (level))
> #else
> #define DEBUG_PRINTF(level, ...)
>
> Call like a normal printf, except there is an initial parameter for the
> level of that paticular call.
>
> Lower the value of 'DebugLevel' to reduce the output.
>
Yes, something like that is the way to do it. That means in the code
itself, you avoid having any extra "#ifdef DEBUG_ENABLE" conditional
compilation that /really/ messes up the readability of the code. You
just use DEBUG_PRINTF, safe in the knowledge that it does nothing when
debugging is disabled.
The only unpleasant thing about this method is that if you have local
data that is only used for debugging, you are going to get warnings
about it when you disable debugging. Since I like to have most of my
compiler warnings enabled, and like my code to be warning-free when
compiled, this bugs me.
So I have this definition:
static inline int emptyFunctionX(int x, ...) { (void) x; return 0; }
#define emptyFunction(...) emptyFunctionX(0, ## __VA_ARGS__)
Then when disabling debugging, I have:
#define debugPrintf emptyFunction
(I don't like defining a function as an expression in the way you did,
and I hate all-caps macro names for constants or function-like macros.)
"emptyFunction" uses a gcc extension here, but that's a common compiler
for many people. It swallows any arguments without generating code, and
without requiring the arguments to be calculated at all (assuming you
have optimisation enabled), but considers the arguments "used" as far as
warnings are concerned.
Back to comp.arch.embedded | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Efficient debug log pozz <pozzugno@gmail.com> - 2017-07-20 11:31 +0200
Re: Efficient debug log Anders.Montonen@kapsi.spam.stop.fi.invalid - 2017-07-20 10:35 +0000
Re: Efficient debug log Stef <stef33d@yahooI-N-V-A-L-I-D.com.invalid> - 2017-07-20 23:14 +0200
Re: Efficient debug log David Brown <david.brown@hesbynett.no> - 2017-07-24 09:40 +0200
Re: Efficient debug log pozz <pozzugno@gmail.com> - 2017-07-26 11:15 +0200
Re: Efficient debug log David Brown <david.brown@hesbynett.no> - 2017-07-26 14:24 +0200
Re: Efficient debug log Stef <stef33d@yahooI-N-V-A-L-I-D.com.invalid> - 2017-07-27 10:23 +0200
Re: Efficient debug log David Brown <david.brown@hesbynett.no> - 2017-07-27 11:14 +0200
Re: Efficient debug log Stef <stef33d@yahooI-N-V-A-L-I-D.com.invalid> - 2017-07-27 10:06 +0200
Re: Efficient debug log David Brown <david.brown@hesbynett.no> - 2017-07-27 11:35 +0200
Re: Efficient debug log Clifford Heath <no.spam@please.net> - 2017-07-21 12:57 +1000
Re: Efficient debug log Jack <jack4747@gmail.com> - 2017-07-20 23:17 -0700
Re: Efficient debug log Chris <xxx.syseng.yyy@gfsys.co.uk> - 2017-07-29 12:47 +0000
Re: Efficient debug log pozz <pozzugno@gmail.com> - 2017-07-31 10:45 +0200
Re: Efficient debug log Chris <xxx.syseng.yyy@gfsys.co.uk> - 2017-07-31 16:44 +0000
csiph-web