Browse Source

[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>
tags/v1.20.1
Michael Brown 8 years ago
parent
commit
e2c0a20d60
1 changed files with 13 additions and 4 deletions
  1. 13
    4
      src/include/compiler.h

+ 13
- 4
src/include/compiler.h View File

@@ -285,14 +285,23 @@ extern void dbg_pause ( void );
285 285
 extern void dbg_more ( void );
286 286
 
287 287
 /* Allow for selective disabling of enabled debug levels */
288
+#define __debug_disable( object ) _C2 ( __debug_disable_, object )
289
+char __debug_disable(OBJECT);
290
+#define DBG_DISABLE_OBJECT( object, level ) do {		\
291
+	extern char __debug_disable(object);			\
292
+	__debug_disable(object) |= (level);			\
293
+	} while ( 0 )
294
+#define DBG_ENABLE_OBJECT( object, level ) do {			\
295
+	extern char __debug_disable(object);			\
296
+	__debug_disable(object) &= ~(level);			\
297
+	} while ( 0 )
288 298
 #if DBGLVL_MAX
289
-int __debug_disable;
290
-#define DBGLVL ( DBGLVL_MAX & ~__debug_disable )
299
+#define DBGLVL ( DBGLVL_MAX & ~__debug_disable(OBJECT) )
291 300
 #define DBG_DISABLE( level ) do {				\
292
-	__debug_disable |= (level);				\
301
+	__debug_disable(OBJECT) |= ( (level) & DBGLVL_MAX );	\
293 302
 	} while ( 0 )
294 303
 #define DBG_ENABLE( level ) do {				\
295
-	__debug_disable &= ~(level);				\
304
+	__debug_disable(OBJECT) &= ~( (level) & DBGLVL_MAX );	\
296 305
 	} while ( 0 )
297 306
 #else
298 307
 #define DBGLVL 0

Loading…
Cancel
Save