david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

[debug] Allow per-object runtime enabling/disabling of debug messages

The DBG_ENABLE() and DBG_DISABLE() macros currently affect the debug
level of all objects that were built with debugging enabled.  This is
undesirable, since it is common to use different debug levels in each
object.

Make the debug level mask a per-object variable.  DBG_ENABLE() and
DBG_DISABLE() now control only the debug level for the containing
object (which is consistent with the intended usage across the
existing codebase).  DBG_ENABLE_OBJECT() and DBG_DISABLE_OBJECT() may
be used to control the debug level for a specified object.  For
example:

  // Enable DBG() messages from tcpip.c
  DBG_ENABLE_OBJECT ( tcpip, DBGLVL_LOG );

Note that the existence of debug messages continues to be gated by the
DEBUG=... list specified on the build command line.  If an object was
built without the relevant debug level, then DBG_ENABLE_OBJECT() will
have no effect on that object at runtime (other than to explicitly
drag in the object via a symbol reference).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown 2016-07-05 10:10:35 +01:00
parent 55f7a675d6
commit e2c0a20d60
1 changed files with 13 additions and 4 deletions

View File

@ -285,14 +285,23 @@ extern void dbg_pause ( void );
extern void dbg_more ( void );
/* Allow for selective disabling of enabled debug levels */
#define __debug_disable( object ) _C2 ( __debug_disable_, object )
char __debug_disable(OBJECT);
#define DBG_DISABLE_OBJECT( object, level ) do { \
extern char __debug_disable(object); \
__debug_disable(object) |= (level); \
} while ( 0 )
#define DBG_ENABLE_OBJECT( object, level ) do { \
extern char __debug_disable(object); \
__debug_disable(object) &= ~(level); \
} while ( 0 )
#if DBGLVL_MAX
int __debug_disable;
#define DBGLVL ( DBGLVL_MAX & ~__debug_disable )
#define DBGLVL ( DBGLVL_MAX & ~__debug_disable(OBJECT) )
#define DBG_DISABLE( level ) do { \
__debug_disable |= (level); \
__debug_disable(OBJECT) |= ( (level) & DBGLVL_MAX ); \
} while ( 0 )
#define DBG_ENABLE( level ) do { \
__debug_disable &= ~(level); \
__debug_disable(OBJECT) &= ~( (level) & DBGLVL_MAX ); \
} while ( 0 )
#else
#define DBGLVL 0