Browse Source

[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 7 years ago
parent
commit
46719f2264
2 changed files with 29 additions and 0 deletions
  1. 27
    0
      src/Makefile.housekeeping
  2. 2
    0
      src/include/assert.h

+ 27
- 0
src/Makefile.housekeeping View File

@@ -720,6 +720,33 @@ config/named.h : $(CONFIG_LIST)
720 720
 
721 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 750
 # These files use .incbin inline assembly to include a binary file.
724 751
 # Unfortunately ccache does not detect this dependency and caches
725 752
 # builds even when the binary file has changed.

+ 2
- 0
src/include/assert.h View File

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

Loading…
Cancel
Save