From 7a433325f57dd4061a027a9ff90202807e15509f Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Fri, 20 Dec 2019 16:16:12 +0100 Subject: [PATCH] assert: Add verbose option to assertion messages Add verbose option which would control if the assertion mechanism prints any information at all. With this disabled they application will have to use the stack-frame to locate the assertion location. Signed-off-by: Joakim Andersson --- include/sys/__assert.h | 8 +++++++- subsys/debug/Kconfig | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/sys/__assert.h b/include/sys/__assert.h index 1b28dcecc4f..e0ca1b296af 100644 --- a/include/sys/__assert.h +++ b/include/sys/__assert.h @@ -20,6 +20,12 @@ #define __ASSERT_ON 0 #endif +#if defined(CONFIG_ASSERT_VERBOSE) +#define __ASSERT_PRINT(fmt, ...) printk(fmt, ##__VA_ARGS__) +#else /* CONFIG_ASSERT_VERBOSE */ +#define __ASSERT_PRINT(fmt, ...) +#endif /* CONFIG_ASSERT_VERBOSE */ + #ifdef CONFIG_ASSERT_NO_FILE_INFO #define __ASSERT_FILE_INFO "" #else /* CONFIG_ASSERT_NO_FILE_INFO */ @@ -33,7 +39,7 @@ #endif /* CONFIG_ASSERT_NO_COND_INFO */ #define __ASSERT_LOC(test) \ - printk("ASSERTION FAIL [%s] @ %s:%d\n", \ + __ASSERT_PRINT("ASSERTION FAIL [%s] @ %s:%d\n", \ __ASSERT_COND_INFO(test), \ __ASSERT_FILE_INFO, \ __LINE__) \ diff --git a/subsys/debug/Kconfig b/subsys/debug/Kconfig index 57d74e48c9d..cae46f0c8dc 100644 --- a/subsys/debug/Kconfig +++ b/subsys/debug/Kconfig @@ -181,6 +181,15 @@ config FORCE_NO_ASSERT CFLAGS and not Kconfig. Added solely to be able to work around compiler bugs for specific tests. +config ASSERT_VERBOSE + bool "Enable verbose assertions" + default y + help + This option enables printing an assert message with information about + the assertion that occurred. This includes printing the location, + the conditional expression and additional message specific to the + assert. + config ASSERT_NO_FILE_INFO bool "Disable file info for asserts" help