From baf3bac6d818e0ea96b6cefdf6088e22315fff5a Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Wed, 24 Sep 2014 11:46:24 +0800 Subject: [PATCH] ryu: Use brief assertion failure message Currently, when an assertion fails, the error message is like: ASSERTION FAILURE '1 + 1 == 3' in command_apreset() at common/chipset.c:24 To save flash space, let's add an option to remove the failed expression and function name. The error message becomes: ASSERTION FAILURE at common/chipset.c:24 BUG=chrome-os-partner:32203 TEST=make buildall TEST=Add an assertion and triggers it. Check error message. BRANCH=None Change-Id: Ie323d5b43cbff2cd8f6cd5bb46c1f34ecd16bd5e Signed-off-by: Vic Yang Reviewed-on: https://chromium-review.googlesource.com/219670 Reviewed-by: Randall Spangler --- board/ryu/board.h | 1 + common/panic_output.c | 9 +++++++++ include/config.h | 9 +++++++++ include/panic.h | 4 ++++ include/util.h | 8 ++++++++ 5 files changed, 31 insertions(+) diff --git a/board/ryu/board.h b/board/ryu/board.h index 04bf5e4d94..9f14ef1d1d 100644 --- a/board/ryu/board.h +++ b/board/ryu/board.h @@ -36,6 +36,7 @@ #undef CONFIG_CONSOLE_CMDHELP #define CONFIG_INDUCTIVE_CHARGING #undef CONFIG_HIBERNATE +#define CONFIG_DEBUG_ASSERT_BRIEF /* Disable unused console command to save flash space */ #undef CONFIG_CMD_POWERINDEBUG diff --git a/common/panic_output.c b/common/panic_output.c index f77277ab33..4f0f22d00d 100644 --- a/common/panic_output.c +++ b/common/panic_output.c @@ -78,6 +78,14 @@ void panic_reboot(void) } #ifdef CONFIG_DEBUG_ASSERT_REBOOTS +#ifdef CONFIG_DEBUG_ASSERT_BRIEF +void panic_assert_fail(const char *fname, int linenum) +{ + panic_printf("\nASSERTION FAILURE at %s:%d\n", fname, linenum); + + panic_reboot(); +} +#else void panic_assert_fail(const char *msg, const char *func, const char *fname, int linenum) { @@ -87,6 +95,7 @@ void panic_assert_fail(const char *msg, const char *func, const char *fname, panic_reboot(); } #endif +#endif void panic(const char *msg) { diff --git a/include/config.h b/include/config.h index cfd7a5f97d..b119823601 100644 --- a/include/config.h +++ b/include/config.h @@ -413,6 +413,15 @@ */ #define CONFIG_DEBUG_ASSERT_REBOOTS +/* + * On assertion failure, prints only the file name and the line number. + * + * Ignored if CONFIG_DEBUG_ASSERT_REBOOTS is not defined. + * + * Boards may define this to reduce image size. + */ +#undef CONFIG_DEBUG_ASSERT_BRIEF + /* * Disable the write buffer used for default memory map accesses. * This turns "Imprecise data bus errors" into "Precise" errors diff --git a/include/panic.h b/include/panic.h index 40bab2487e..74376554b6 100644 --- a/include/panic.h +++ b/include/panic.h @@ -101,8 +101,12 @@ void panic_data_print(const struct panic_data *pdata); * @param fname File name where assertion happened * @param linenum Line number where assertion happened */ +#ifdef CONFIG_DEBUG_ASSERT_BRIEF +void panic_assert_fail(const char *fname, int linenum); +#else void panic_assert_fail(const char *msg, const char *func, const char *fname, int linenum); +#endif /** * Display a custom panic message and reset diff --git a/include/util.h b/include/util.h index 8b1e51e2c5..e83e2fe05e 100644 --- a/include/util.h +++ b/include/util.h @@ -18,11 +18,19 @@ */ #ifdef CONFIG_DEBUG_ASSERT #ifdef CONFIG_DEBUG_ASSERT_REBOOTS + +#ifdef CONFIG_DEBUG_ASSERT_BRIEF +#define ASSERT(cond) do { \ + if (!(cond)) \ + panic_assert_fail(__FILE__, __LINE__); \ + } while (0) +#else #define ASSERT(cond) do { \ if (!(cond)) \ panic_assert_fail(#cond, __func__, __FILE__, \ __LINE__); \ } while (0) +#endif #else #define ASSERT(cond) do { \ if (!(cond)) \