mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] common: panic: add new CONFIG_PANIC_TRAP option
@ 2025-08-21 21:00 Ahmad Fatoum
  2025-08-25  8:45 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2025-08-21 21:00 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

When running under libfuzzer for example, it's better to trap, so
libfuzzer generates a crash input file than to just print an error
message and exit gracefully.

The same can apply when running under a hardware debugger, so make
this option available generally.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/Kconfig | 9 +++++++++
 common/misc.c  | 2 ++
 2 files changed, 11 insertions(+)

diff --git a/common/Kconfig b/common/Kconfig
index ad211d1fa519..0664ffcb43a5 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -376,6 +376,7 @@ config RELOCATABLE
 
 choice
 	prompt "Configure action on fatal error"
+	default PANIC_TRAP if SANDBOX
 	default PANIC_RESET
 
 	config PANIC_POWEROFF
@@ -407,6 +408,14 @@ choice
 		  fatal error, so you don't have to reset it manually.
 		  This is the recommended configuration in production.
 
+	config PANIC_TRAP
+		bool "invoke a trap instruction"
+		help
+		  This option triggers the trap instruction emitted by
+		  __builtin_trap() on fatal errors.
+		  This is mainly useful when running under a debugger
+		  or debugging instrumentation.
+
 endchoice
 
 config PROMPT
diff --git a/common/misc.c b/common/misc.c
index f2c084a0df4b..67f88af1a3df 100644
--- a/common/misc.c
+++ b/common/misc.c
@@ -305,6 +305,8 @@ static void __noreturn do_panic(bool stacktrace, const char *fmt, va_list ap)
 
 	if (IS_ENABLED(CONFIG_PANIC_POWEROFF))
 		poweroff_machine(0);
+	else if (IS_ENABLED(CONFIG_PANIC_TRAP))
+		__builtin_trap();
 	else
 		restart_machine(0);
 }
-- 
2.39.5




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] common: panic: add new CONFIG_PANIC_TRAP option
  2025-08-21 21:00 [PATCH] common: panic: add new CONFIG_PANIC_TRAP option Ahmad Fatoum
@ 2025-08-25  8:45 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2025-08-25  8:45 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Thu, 21 Aug 2025 23:00:10 +0200, Ahmad Fatoum wrote:
> When running under libfuzzer for example, it's better to trap, so
> libfuzzer generates a crash input file than to just print an error
> message and exit gracefully.
> 
> The same can apply when running under a hardware debugger, so make
> this option available generally.
> 
> [...]

Applied, thanks!

[1/1] common: panic: add new CONFIG_PANIC_TRAP option
      https://git.pengutronix.de/cgit/barebox/commit/?id=e7491c070adc (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-08-25  9:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-21 21:00 [PATCH] common: panic: add new CONFIG_PANIC_TRAP option Ahmad Fatoum
2025-08-25  8:45 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox