浏览代码

[libc] Allow assertions to be globally enabled or disabled

Assertions are enabled for objects built with any debug level
(including an explicit debug level of zero).  It is sometimes useful
to be able to enable assertions across all objects; this currently
requires manually hacking include/assert.h.

Allow assertions to be globally enabled by adding ASSERT=1 to the
build command line.  For example:

  make bin/8086100e.mrom ASSERT=1

Similarly, allow assertions to be globally disabled by adding ASSERT=0
to the build command line.  If no ASSERT=... is specified on the
build command line, then only objects mentioned in DEBUG=... will have
assertions enabled (as is currently the case).

Note than globally enabling assertions imposes a relatively heavy
runtime penalty, primarily due to the various sanity checks performed
by list_add(), list_for_each_entry(), etc.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9 年前
父节点
当前提交
46719f2264
共有 2 个文件被更改,包括 29 次插入0 次删除
  1. 27
    0
      src/Makefile.housekeeping
  2. 2
    0
      src/include/assert.h

+ 27
- 0
src/Makefile.housekeeping 查看文件

720
 
720
 
721
 .PRECIOUS : config/named.h
721
 .PRECIOUS : config/named.h
722
 
722
 
723
+# (Single-element) list of assertion configuration
724
+#
725
+ASSERT_LIST := $(BIN)/.assert.list
726
+ifeq ($(wildcard $(ASSERT_LIST)),)
727
+ASSERT_OLD := <invalid>
728
+else
729
+ASSERT_OLD := $(shell cat $(ASSERT_LIST))
730
+endif
731
+ifneq ($(ASSERT_OLD),$(ASSERT))
732
+$(shell $(ECHO) "$(ASSERT)" > $(ASSERT_LIST))
733
+endif
734
+
735
+$(ASSERT_LIST) : $(MAKEDEPS)
736
+
737
+VERYCLEANUP += $(ASSERT_LIST)
738
+
739
+# Assertion configuration
740
+#
741
+ifneq ($(ASSERT),)
742
+CFLAGS	+= -DASSERTING=$(ASSERT)
743
+endif
744
+
745
+include/assert.h : $(ASSERT_LIST)
746
+	$(Q)$(TOUCH) $@
747
+
748
+.PRECIOUS : include/assert.h
749
+
723
 # These files use .incbin inline assembly to include a binary file.
750
 # These files use .incbin inline assembly to include a binary file.
724
 # Unfortunately ccache does not detect this dependency and caches
751
 # Unfortunately ccache does not detect this dependency and caches
725
 # builds even when the binary file has changed.
752
 # builds even when the binary file has changed.

+ 2
- 0
src/include/assert.h 查看文件

12
 
12
 
13
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
13
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
14
 
14
 
15
+#ifndef ASSERTING
15
 #ifdef NDEBUG
16
 #ifdef NDEBUG
16
 #define ASSERTING 0
17
 #define ASSERTING 0
17
 #else
18
 #else
18
 #define ASSERTING 1
19
 #define ASSERTING 1
19
 #endif
20
 #endif
21
+#endif
20
 
22
 
21
 extern unsigned int assertion_failures;
23
 extern unsigned int assertion_failures;
22
 
24
 

正在加载...
取消
保存