From 6e1ce52d146fe8197c1b58e2e3b0ebcf9ccda349 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 5 Jul 2016 10:19:36 +0100 Subject: [debug] Allow debug messages to be initially disabled at runtime Extend the DEBUG=... syntax to allow debug messages to be compiled in but disabled by default. For example: make bin/undionly.kpxe DEBUG=netdevice:3:1 would compile in the messages as for DEBUG=netdevice:3, but would set the debug level mask so that only the DEBUG=netdevice:1 messages would be displayed. This allows for external code to selectively enable the additional debug messages at runtime, without being overwhelmed by unwanted initial noise. For example, a developer of a new protocol may want to temporarily enable tracing of all packets received: this can be done by building with DEBUG=netdevice:3:1 and using // temporarily enable per-packet messages DBG_ENABLE_OBJECT ( netdevice, DBGLVL_EXTRA ); ... // disable per-packet messages DBG_DISABLE_OBJECT ( netdevice, DBGLVL_EXTRA ); Note that unlike the usual DBG_ENABLE() and DBG_DISABLE() macros, DBG_ENABLE_OBJECT() and DBG_DISABLE_OBJECT() will not be removed via dead code elimination if debugging is disabled in the specified object. In particular, this means that using either of these macros will always result in a symbol reference to the specified object. Signed-off-by: Michael Brown --- src/include/compiler.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/include') diff --git a/src/include/compiler.h b/src/include/compiler.h index eae62c518..4924c7ef5 100644 --- a/src/include/compiler.h +++ b/src/include/compiler.h @@ -270,6 +270,10 @@ PROVIDE_SYMBOL ( OBJECT_SYMBOL ); #define DBGLVL_MAX 0 #endif +#ifndef DBGLVL_DFLT +#define DBGLVL_DFLT DBGLVL_MAX +#endif + #ifndef ASSEMBLY /** printf() for debugging */ @@ -286,7 +290,7 @@ 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); +char __debug_disable(OBJECT) = ( DBGLVL_MAX & ~DBGLVL_DFLT ); #define DBG_DISABLE_OBJECT( object, level ) do { \ extern char __debug_disable(object); \ __debug_disable(object) |= (level); \ -- cgit v1.2.3-55-g7522