[PATCH 2/4] bug: add support for CONFIG_DEBUG_BUGVERBOSE
Ahmad Fatoum
a.fatoum at pengutronix.de
Fri Nov 28 04:50:03 PST 2025
From: Ahmad Fatoum <a.fatoum at barebox.org>
This can be used to remove panic strings from barebox, when there is no
way to look at them anyway.
Also add a CONFIG_BUG symbol as it will make it easier to port kernel
code that checks for the symbol without having to patch it.
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
common/Kconfig | 11 +++++++++++
include/asm-generic/bug.h | 26 +++++++++++++++++++-------
2 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/common/Kconfig b/common/Kconfig
index 7c9b28543ffa..7442e24026e0 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -902,6 +902,17 @@ config PBL_CONSOLE
must be running at the address it's linked at and bss must
be cleared. On ARM that would be after setup_c().
+config BUG
+ def_bool y
+
+config DEBUG_BUGVERBOSE
+ bool "Verbose BUG() reporting"
+ depends on BUG
+ default y
+ help
+ Say Y here to make WARN_ONCE() and BUG() panics output the file name
+ and line number of the BUG/WARN call as well as the EIP and oops trace.
+
source "common/ratp/Kconfig"
config PARTITION
diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
index 389327adfc5d..ca75b1c7646e 100644
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -6,15 +6,27 @@
#include <linux/compiler.h>
#include <printf.h>
-#define BUG() do { \
- printf("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
- panic("BUG!"); \
+#ifdef CONFIG_DEBUG_BUGVERBOSE
+#define __bug_printf printf
+#define __bug_panic panic
+#define __bug_dump_stack dump_stack
+#else
+#define __bug_printf no_printf
+#define __bug_panic panic_no_stacktrace
+#define __bug_dump_stack (void)0
+#endif
+
+#define BUG() do { \
+ __bug_printf("BUG: failure at %s:%d/%s()!\n", \
+ __FILE__, __LINE__, __FUNCTION__); \
+ __bug_panic("BUG!"); \
} while (0)
#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
-#define __WARN() do { \
- printf("WARNING: at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
+#define __WARN() do { \
+ __bug_printf("WARNING: at %s:%d/%s()!\n", \
+ __FILE__, __LINE__, __FUNCTION__); \
} while (0)
#ifndef WARN_ON
@@ -31,7 +43,7 @@
int __ret_warn_on = !!(condition); \
if (unlikely(__ret_warn_on)) { \
__WARN(); \
- printf("WARNING: " format); \
+ __bug_printf("WARNING: " format); \
} \
unlikely(__ret_warn_on); \
})
@@ -44,7 +56,7 @@
if (unlikely(__ret_warn_once)) { \
if (WARN(!__warned, format)) { \
__warned = 1; \
- dump_stack(); \
+ __bug_dump_stack(); \
} \
} \
unlikely(__ret_warn_once); \
--
2.47.3
More information about the barebox
mailing list