diff options
author | Matt Fleming <matt.fleming@intel.com> | 2013-06-28 20:53:30 +0100 |
---|---|---|
committer | Matt Fleming <matt.fleming@intel.com> | 2013-07-05 13:50:03 +0100 |
commit | 487f7581b4a4639d237a4a27a50252adabac62af (patch) | |
tree | 995e902be080517f3ebc745d27d36bb50a3314cb /com32/include | |
parent | bbd9262c2323c1df461f18fcfa2aed56cd2411ce (diff) | |
download | syslinux-487f7581b4a4639d237a4a27a50252adabac62af.tar.gz syslinux-487f7581b4a4639d237a4a27a50252adabac62af.tar.xz syslinux-487f7581b4a4639d237a4a27a50252adabac62af.zip |
debug.c32: Dynamically enable/disable debug code at runtime
It's useful to be able to enable (and disable) debug code at runtime,
particularly for allowing users that are unable to build their own
Syslinux releases the chance to provide useful debugging output.
For example, say a user reports trouble with their PXE stack but doesn't
have a development environment setup to turn on the debug code
themselves. With this change you can simply request that they do,
debug.c32 -e pxe_call unload_pxe open_file
to enable the debug in those functions. By only turning on code in
specific functions we reduce the chance of disrupting the buggy
behaviour and improve the signal to noise ratio for print statements.
To disable debug code use the -d flag,
debug.c32 -d pxe_call
To use this new feature simply do,
if (syslinux_debug_enabled) {
debug1();
debug2();
....
}
from within the function you wish to add debug code. Note that this
feature is not limited to print statements - you can put any code within
the conditional, such as verifying a checksum or checking for memory
leaks.
The plan is to leave the dynamic debug code built in for all prereleases
and to turn it off for final releases.
People may still want to build with all dprintf() statements enabled,
and so a new symbol, DYNAMIC_DEBUG, was introduced rather than
repurposing the old DEBUG, DEBUG_STDIO and DEBUG_PORT symbols.
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Diffstat (limited to 'com32/include')
-rw-r--r-- | com32/include/dprintf.h | 10 | ||||
-rw-r--r-- | com32/include/syslinux/debug.h | 15 |
2 files changed, 23 insertions, 2 deletions
diff --git a/com32/include/dprintf.h b/com32/include/dprintf.h index 26ca734b..51d5c61d 100644 --- a/com32/include/dprintf.h +++ b/com32/include/dprintf.h @@ -5,6 +5,8 @@ #ifndef _DPRINTF_H #define _DPRINTF_H +#include <syslinux/debug.h> + #if !defined(DEBUG_PORT) && !defined(DEBUG_STDIO) # undef DEBUG #endif @@ -23,8 +25,12 @@ void vdprintf(const char *, va_list); #else -# define dprintf(fmt, ...) ((void)(0)) -# define vdprintf(fmt, ap) ((void)(0)) +#define dprintf(...) \ + if (syslinux_debug_enabled) \ + printf(__VA_ARGS__) +#define vdprintf(fmt, ap) \ + if (syslinux_debug_enabled) \ + vprintf(fmt, ap) #endif /* DEBUG */ diff --git a/com32/include/syslinux/debug.h b/com32/include/syslinux/debug.h new file mode 100644 index 00000000..aee6fdbb --- /dev/null +++ b/com32/include/syslinux/debug.h @@ -0,0 +1,15 @@ +#ifndef DEBUG_H +#define DEBUG_H + +#include <stdbool.h> + +#ifdef DYNAMIC_DEBUG +#define syslinux_debug_enabled __syslinux_debug_enabled(__func__) +extern bool __syslinux_debug_enabled(const char *func); +#else +#define syslinux_debug_enabled (0) +#endif /* DYNAMIC_DEBUG */ + +extern int syslinux_debug(const char *str, bool enable); + +#endif /* DEBUG_H */ |