PROPOSAL: Disable DEBUG compilation per-object
Wuerfel_21
Posts: 5,105
We posting spin language proposals now?
There's already a number of DEBUG_
constants that can be defined to modify DEBUG behaviour.
Can we add one that disables compilation of debug statements on a per-object basis? Maybe DEBUG_DISABLE
? This way, debug code could be left in a library object without clogging up the main application's output. Especially relevant to the USB code, since in some cases there are timing issues caused by the DEBUG output.
So basically:
- If the debugger is not enabled, no debug statements are built, full stop.
- If the debugger is enabled and
DEBUG_DISABLE
is set in an object, debug statements in that object are not built. - If the debugger is enabled and the special constant is not set, build debug statements as normal.
@cgracey
@ersmith
Comments
I like it.
Seems like it should be straightforward to implement in flexspin (you could probably do it, but I'm happy to as well). Let's see what @cgracey and @macca think.
It would be handy, especially if you need to focus on just one thing at a time and you use other objects written with existing DEBUG statements in them.
I have implemented it so it works also with object parameters:
Actually any value disable debug it just checks if defined.
Well that was the intent. Though I'd say it's slightly better to check for a non-zero value, so it can be disabled by default and then overriden to being enabled.
Should the constant be
DEBUG_DISABLE
(as in the original post) orDEBUG_DISABLED
(as in the example @macca posted)? I lean towards the first, but obviously it's easy to do either way.Oh, didn't even notice the discrepancy. Idk it doesn't matter.
Ah... I hadn't noticed it either... doesn't matter to me, maybe DEBUG_DISABLE is more syntactically correct given the actual effect depends on the expression evaluation.
We all seem to slightly prefer DEBUG_DISABLE, so that it is.
I consider this feature a blocker for non-beta release of the usbnew driver, btw (so you can debug your application without getting spammed with USB-related stuff or having to edit the driver file)