tests: Add option for debug symbols & no optimization

To make it easier to build the tests with debug symbols, add a check for
the "GDB_DEBUG" environment variable.  If set, build with -g and -Og to
enable the symbols and disable optimization.

Signed-off-by: Martin Roth <gaumless@gmail.com>
Change-Id: I3a644dcccb7e15473413b775da8f70617afaefce
Reviewed-on: https://review.coreboot.org/c/coreboot/+/67918
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Jakub Czapiga <jacz@semihalf.com>
diff --git a/tests/Makefile.inc b/tests/Makefile.inc
index 2c1a30b..90f01d1 100644
--- a/tests/Makefile.inc
+++ b/tests/Makefile.inc
@@ -10,7 +10,13 @@
 
 include $(top)/tests/Makefile.common
 
-# Enable code coverage if COV=1
+# Enable GDB debug build if requested
+GDB_DEBUG ?= 0
+ifneq ($(GDB_DEBUG),0)
+TEST_CFLAGS += -g -Og
+endif
+
+# Enable code coverage if requested
 ifeq ($(COV),1)
 TEST_CFLAGS += --coverage
 TEST_LDFLAGS += --coverage
@@ -175,6 +181,7 @@
 help-unit-tests help::
 	@echo  '*** coreboot unit-tests targets ***'
 	@echo  '  Use "COV=1 make [target]" to enable code coverage for unit tests'
+	@echo  '  Use "GDB_DEBUG=1 make [target]" to build with debug symbols'
 	@echo  '  unit-tests            - Run all unit-tests from tests/'
 	@echo  '  clean-unit-tests      - Remove unit-tests build artifacts'
 	@echo  '  list-unit-tests       - List all unit-tests'