[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 <mcb30@ipxe.org>
This commit is contained in:
parent
e2c0a20d60
commit
6e1ce52d14
|
@ -523,19 +523,25 @@ POST_O :=
|
||||||
POST_O_DEPS :=
|
POST_O_DEPS :=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# Debug level calculations
|
||||||
|
#
|
||||||
|
DBGLVL_MAX = -DDBGLVL_MAX=$(firstword $(subst ., ,$(1)))
|
||||||
|
DBGLVL_DFLT = -DDBGLVL_DFLT=$(lastword $(subst ., ,$(1)))
|
||||||
|
DBGLVL = $(call DBGLVL_MAX,$(1)) $(call DBGLVL_DFLT,$(1))
|
||||||
|
|
||||||
# Rules for specific object types.
|
# Rules for specific object types.
|
||||||
#
|
#
|
||||||
COMPILE_c = $(CC) $(CFLAGS) $(CFLAGS_c) $(OBJ_CFLAGS)
|
COMPILE_c = $(CC) $(CFLAGS) $(CFLAGS_c) $(OBJ_CFLAGS)
|
||||||
RULE_c = $(Q)$(COMPILE_c) -c $< -o $@ $(POST_O)
|
RULE_c = $(Q)$(COMPILE_c) -c $< -o $@ $(POST_O)
|
||||||
RULE_c_to_ids.o = $(Q)$(ECHO_E) '$(OBJ_IDS_ASM_NL)' | $(ASSEMBLE_S) -o $@
|
RULE_c_to_ids.o = $(Q)$(ECHO_E) '$(OBJ_IDS_ASM_NL)' | $(ASSEMBLE_S) -o $@
|
||||||
RULE_c_to_dbg%.o = $(Q)$(COMPILE_c) -DDBGLVL_MAX=$* -c $< -o $@ $(POST_O)
|
RULE_c_to_dbg%.o= $(Q)$(COMPILE_c) $(call DBGLVL,$*) -c $< -o $@ $(POST_O)
|
||||||
RULE_c_to_c = $(Q)$(COMPILE_c) -E -c $< > $@
|
RULE_c_to_c = $(Q)$(COMPILE_c) -E -c $< > $@
|
||||||
RULE_c_to_s = $(Q)$(COMPILE_c) -S -g0 -c $< -o $@
|
RULE_c_to_s = $(Q)$(COMPILE_c) -S -g0 -c $< -o $@
|
||||||
|
|
||||||
PREPROCESS_S = $(CPP) $(CFLAGS) $(CFLAGS_S) $(OBJ_CFLAGS)
|
PREPROCESS_S = $(CPP) $(CFLAGS) $(CFLAGS_S) $(OBJ_CFLAGS)
|
||||||
ASSEMBLE_S = $(AS) $(ASFLAGS)
|
ASSEMBLE_S = $(AS) $(ASFLAGS)
|
||||||
RULE_S = $(Q)$(PREPROCESS_S) $< | $(ASSEMBLE_S) -o $@
|
RULE_S = $(Q)$(PREPROCESS_S) $< | $(ASSEMBLE_S) -o $@
|
||||||
RULE_S_to_dbg%.o = $(Q)$(PREPROCESS_S) -DDBGLVL_MAX=$* $< | $(ASSEMBLE_S) -o $@
|
RULE_S_to_dbg%.o= $(Q)$(PREPROCESS_S) $(call DBGLVL,$*) $< | $(ASSEMBLE_S) -o $@
|
||||||
RULE_S_to_s = $(Q)$(PREPROCESS_S) $< > $@
|
RULE_S_to_s = $(Q)$(PREPROCESS_S) $< > $@
|
||||||
|
|
||||||
GENERIC_TARGETS += ids.o dbg%.o c s
|
GENERIC_TARGETS += ids.o dbg%.o c s
|
||||||
|
@ -1019,10 +1025,12 @@ TGT_LD_FLAGS = $(foreach SYM,$(TGT_LD_ENTRY) $(TGT_LD_DRIVERS) \
|
||||||
# the target.
|
# the target.
|
||||||
#
|
#
|
||||||
DEBUG_LIST = $(subst $(COMMA), ,$(DEBUG))
|
DEBUG_LIST = $(subst $(COMMA), ,$(DEBUG))
|
||||||
DEBUG_OBJ_LEVEL = $(firstword $(word 2,$(subst :, ,$(1))) 1)
|
DEBUG_MAX = $(firstword $(word 2,$(subst :, ,$(1))) 1)
|
||||||
DEBUG_OBJ_BASE = $(word 1,$(subst :, ,$(1))).dbg$(call DEBUG_OBJ_LEVEL,$(1))
|
DEBUG_DFLT = $(if $(word 3,$(subst :, ,$(1))),.$(word 3,$(subst :, ,$(1))))
|
||||||
DEBUG_OBJ = $(BIN)/$(call DEBUG_OBJ_BASE,$(1)).o
|
DEBUG_LEVEL = $(call DEBUG_MAX,$(1))$(call DEBUG_DFLT,$(1))
|
||||||
DEBUG_ORIG_OBJ = $(BIN)/$(word 1,$(subst :, ,$(1))).o
|
DEBUG_BASE = $(firstword $(subst :, ,$(1))).dbg$(call DEBUG_LEVEL,$(1))
|
||||||
|
DEBUG_OBJ = $(BIN)/$(call DEBUG_BASE,$(1)).o
|
||||||
|
DEBUG_ORIG_OBJ = $(BIN)/$(firstword $(subst :, ,$(1))).o
|
||||||
DEBUG_OBJS = $(foreach D,$(DEBUG_LIST),$(call DEBUG_OBJ,$(D)))
|
DEBUG_OBJS = $(foreach D,$(DEBUG_LIST),$(call DEBUG_OBJ,$(D)))
|
||||||
DEBUG_ORIG_OBJS = $(foreach D,$(DEBUG_LIST),$(call DEBUG_ORIG_OBJ,$(D)))
|
DEBUG_ORIG_OBJS = $(foreach D,$(DEBUG_LIST),$(call DEBUG_ORIG_OBJ,$(D)))
|
||||||
BLIB_OBJS = $(DEBUG_OBJS) $(filter-out $(DEBUG_ORIG_OBJS),$(BOBJS))
|
BLIB_OBJS = $(DEBUG_OBJS) $(filter-out $(DEBUG_ORIG_OBJS),$(BOBJS))
|
||||||
|
|
|
@ -270,6 +270,10 @@ PROVIDE_SYMBOL ( OBJECT_SYMBOL );
|
||||||
#define DBGLVL_MAX 0
|
#define DBGLVL_MAX 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef DBGLVL_DFLT
|
||||||
|
#define DBGLVL_DFLT DBGLVL_MAX
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef ASSEMBLY
|
#ifndef ASSEMBLY
|
||||||
|
|
||||||
/** printf() for debugging */
|
/** printf() for debugging */
|
||||||
|
@ -286,7 +290,7 @@ extern void dbg_more ( void );
|
||||||
|
|
||||||
/* Allow for selective disabling of enabled debug levels */
|
/* Allow for selective disabling of enabled debug levels */
|
||||||
#define __debug_disable( object ) _C2 ( __debug_disable_, object )
|
#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 { \
|
#define DBG_DISABLE_OBJECT( object, level ) do { \
|
||||||
extern char __debug_disable(object); \
|
extern char __debug_disable(object); \
|
||||||
__debug_disable(object) |= (level); \
|
__debug_disable(object) |= (level); \
|
||||||
|
|
Reference in New Issue