From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/4] bug: add support for CONFIG_DEBUG_BUGVERBOSE
Date: Fri, 28 Nov 2025 13:50:03 +0100 [thread overview]
Message-ID: <20251128125616.136559-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20251128125616.136559-1-a.fatoum@pengutronix.de>
From: Ahmad Fatoum <a.fatoum@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@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
next prev parent reply other threads:[~2025-11-28 12:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-28 12:50 [PATCH 1/4] printf: define printk/no_printk in terms of prints Ahmad Fatoum
2025-11-28 12:50 ` Ahmad Fatoum [this message]
2025-11-28 12:50 ` [PATCH 3/4] include: move sprintf prototypes to new linux/sprintf.h Ahmad Fatoum
2025-11-28 12:50 ` [PATCH 4/4] console: move non-stdio elements to console.h Ahmad Fatoum
2025-12-01 10:22 ` [PATCH 1/4] printf: define printk/no_printk in terms of prints Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251128125616.136559-2-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox