From 3ce27961750612ca4c252668312fec60f24c0dfa Mon Sep 17 00:00:00 2001 From: chao an Date: Thu, 8 Jun 2023 22:08:23 +0800 Subject: [PATCH] assert: disable function/line print if DEBUG_ASSERTIONS_FILENAME disabled Test on sim/nsh: (CONFIG_DEBUG_ASSERTIONS=y CONFIG_DEFAULT_SMALL=y) text data bss dec hex filename 423626 27152 4128 454906 6f0fa nuttx /* before */ 417010 27152 4128 448290 6d722 nuttx /* after */ -6616 Signed-off-by: chao an --- Kconfig | 9 +++++++++ include/assert.h | 26 +++++++++++++++++--------- include/debug.h | 3 ++- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Kconfig b/Kconfig index 3641b60b93..5f1b11379b 100644 --- a/Kconfig +++ b/Kconfig @@ -665,6 +665,15 @@ config DEBUG_ASSERTIONS_EXPRESSION function when it is triggered. This option maybe will take up a lot of space. +config DEBUG_ASSERTIONS_FILENAME + bool "Enable Debug Assertions show file name" + default !DEFAULT_SMALL + depends on DEBUG_ASSERTIONS + ---help--- + This option can display the file information of the ASSERT() + function when it is enabled. This option maybe will take up a lot + of space. + comment "Subsystem Debug Options" config DEBUG_AUDIO diff --git a/include/assert.h b/include/assert.h index 96f13d0d1b..a429507dc1 100644 --- a/include/assert.h +++ b/include/assert.h @@ -42,20 +42,25 @@ #undef DEBUGASSERT /* Like ASSERT, but only if CONFIG_DEBUG_ASSERTIONS is defined */ #undef DEBUGVERIFY /* Like VERIFY, but only if CONFIG_DEBUG_ASSERTIONS is defined */ -#ifndef CONFIG_HAVE_FILENAME -# define __FILE__ 0 -# define __LINE__ 0 +#if !defined(CONFIG_HAVE_FILENAME) || !defined(CONFIG_DEBUG_ASSERTIONS_FILENAME) +# define __ASSERT_FILE__ 0 +# define __ASSERT_LINE__ 0 +#else +# define __ASSERT_FILE__ __FILE__ +# define __ASSERT_LINE__ __LINE__ #endif -#define PANIC() __assert(__FILE__, __LINE__, "panic") -#define PANIC_WITH_REGS(msg, regs) _assert(__FILE__, __LINE__, msg, regs) +#define PANIC() __assert(__ASSERT_FILE__, __ASSERT_LINE__, "panic") +#define PANIC_WITH_REGS(msg, regs) _assert(__ASSERT_FILE__, \ + __ASSERT_LINE__, msg, regs) #ifdef CONFIG_DEBUG_ASSERTIONS_EXPRESSION # define ASSERT(f) \ do \ { \ if (predict_false(!(f))) \ - __assert(__FILE__, __LINE__, #f); \ + __assert(__ASSERT_FILE__, \ + __ASSERT_LINE__, #f); \ } \ while (0) @@ -63,7 +68,8 @@ do \ { \ if (predict_false((f) < 0)) \ - __assert(__FILE__, __LINE__, #f); \ + __assert(__ASSERT_FILE__, \ + __ASSERT_LINE__, #f); \ } \ while (0) #else @@ -71,7 +77,8 @@ do \ { \ if (predict_false(!(f))) \ - __assert(__FILE__, __LINE__, 0); \ + __assert(__ASSERT_FILE__, \ + __ASSERT_LINE__, 0); \ } \ while (0) @@ -79,7 +86,8 @@ do \ { \ if (predict_false((f) < 0)) \ - __assert(__FILE__, __LINE__, 0); \ + __assert(__ASSERT_FILE__, \ + __ASSERT_LINE__, 0); \ } \ while (0) #endif diff --git a/include/debug.h b/include/debug.h index daee3a4162..659c5dd6c0 100644 --- a/include/debug.h +++ b/include/debug.h @@ -78,7 +78,8 @@ * really intended only for crash error reporting. */ -#if !defined(EXTRA_FMT) && !defined(EXTRA_ARG) && defined(CONFIG_HAVE_FUNCTIONNAME) +#if !defined(EXTRA_FMT) && !defined(EXTRA_ARG) && \ + defined(CONFIG_HAVE_FUNCTIONNAME) && !defined(CONFIG_DEFAULT_SMALL) # define EXTRA_FMT "%s: " # define EXTRA_ARG ,__FUNCTION__ #endif