From 94d331b2eb53acbaf304413ff8f3d7ead47402c3 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Mon, 9 Dec 2019 14:07:10 +0100 Subject: [PATCH] assert: Add option to disable condition from assertion message Add Kconfig option to disable the conditional expression in the assert that failed. This would save code space, and file and line provides better information than the conditional expression in case where the same expression would be asserted upon. For example __ASSERT_NO_MSG(buf) wouldn't make much sense in configuration where CONFIG_ASSERT_NO_FILE_INFO was enabled. 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 40565d5ad20..918b4ca8a21 100644 --- a/include/sys/__assert.h +++ b/include/sys/__assert.h @@ -26,6 +26,12 @@ #define __ASSERT_FILE_INFO __FILE__ #endif /* CONFIG_ASSERT_NO_FILE_INFO */ +#ifdef CONFIG_ASSERT_NO_COND_INFO +#define __ASSERT_COND_INFO(test) "" +#else /* CONFIG_ASSERT_NO_COND_INFO */ +#define __ASSERT_COND_INFO(test) Z_STRINGIFY(test) +#endif /* CONFIG_ASSERT_NO_COND_INFO */ + #ifdef __ASSERT_ON #if (__ASSERT_ON < 0) || (__ASSERT_ON > 2) #error "Invalid __ASSERT() level: must be between 0 and 2" @@ -47,7 +53,7 @@ void assert_post_action(const char *file, unsigned int line); #define __ASSERT_LOC(test) \ printk("ASSERTION FAIL [%s] @ %s:%d\n", \ - Z_STRINGIFY(test), \ + __ASSERT_COND_INFO(test), \ __ASSERT_FILE_INFO, \ __LINE__) \ diff --git a/subsys/debug/Kconfig b/subsys/debug/Kconfig index 86b6251c5b0..57d74e48c9d 100644 --- a/subsys/debug/Kconfig +++ b/subsys/debug/Kconfig @@ -188,6 +188,15 @@ config ASSERT_NO_FILE_INFO in which the assertion occurred. Enabling this will save target code space, and thus may be necessary for tiny targets. +config ASSERT_NO_COND_INFO + bool "Disable condition info for asserts" + help + This option removes the assert condition from the printed assert + message. Enabling this will save target code space, and thus may be + necessary for tiny targets. It is recommended to disable condition + info before disabling file info since the condition can be found in + the source using file info. + config OBJECT_TRACING bool "Kernel object tracing" help