mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/4] sandbox: add support for --loglevel option
@ 2024-12-16 11:36 Ahmad Fatoum
  2024-12-16 11:36 ` [PATCH 2/4] sandbox: add support for architecture-specific debug options Ahmad Fatoum
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2024-12-16 11:36 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

To simplify debugging, let's allow the user to override the default log
level from the command line.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/sandbox/os/common.c | 37 ++++++++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index d8bb345614ac..7067c94d9b45 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -20,6 +20,7 @@
  * files here...
  */
 #define _GNU_SOURCE
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
@@ -46,6 +47,12 @@
 #include <mach/linux.h>
 #include <mach/hostfile.h>
 
+#ifdef CONFIG_CONSOLE_NONE
+int __attribute__((unused)) barebox_loglevel;
+#else
+extern int barebox_loglevel;
+#endif
+
 #define DELETED_OFFSET (sizeof(" (deleted)") - 1)
 
 void __sanitizer_set_death_callback(void (*callback)(void));
@@ -506,6 +513,8 @@ const char *barebox_cmdline_get(void)
 
 static void print_usage(const char*);
 
+#define OPT_LOGLEVEL		(CHAR_MAX + 1)
+
 static struct option long_options[] = {
 	{"help",     0, 0, 'h'},
 	{"malloc",   1, 0, 'm'},
@@ -518,6 +527,9 @@ static struct option long_options[] = {
 	{"stdinout", 1, 0, 'B'},
 	{"xres",     1, 0, 'x'},
 	{"yres",     1, 0, 'y'},
+#ifndef CONFIG_CONSOLE_NONE
+	{"loglevel", 1, 0, OPT_LOGLEVEL},
+#endif
 	{0, 0, 0, 0},
 };
 
@@ -528,7 +540,7 @@ int main(int argc, char *argv[])
 	void *ram;
 	int opt, ret, fd, fd2;
 	int malloc_size = CONFIG_MALLOC_SIZE;
-	int fdno = 0, envno = 0, option_index = 0;
+	int loglevel = -1, fdno = 0, envno = 0, option_index = 0;
 	char *new_cmdline;
 	char *aux;
 
@@ -551,6 +563,9 @@ int main(int argc, char *argv[])
 		case 'm':
 			malloc_size = strtoul(optarg, NULL, 0);
 			break;
+		case OPT_LOGLEVEL:
+			loglevel = strtoul(optarg, NULL, 0);
+			break;
 		case 'i':
 			break;
 		case 'c':
@@ -665,6 +680,10 @@ int main(int argc, char *argv[])
 	barebox_register_console(fileno(stdin), fileno(stdout));
 
 	rawmode();
+
+	if (loglevel >= 0)
+		barebox_loglevel = loglevel;
+
 	start_barebox();
 
 	/* never reached */
@@ -705,7 +724,19 @@ static void print_usage(const char *prgname)
 "                       stdin and stdout. <filein> and <fileout> can be regular\n"
 "                       files or FIFOs.\n"
 "  -x, --xres=<res>     SDL width.\n"
-"  -y, --yres=<res>     SDL height.\n",
-	prgname
+"  -y, --yres=<res>     SDL height.\n"
+#ifndef CONFIG_CONSOLE_NONE
+"      --loglevel=<num> Default log level to use, where <num> is one of:\n"
+"			  0    system is unusable (emerg)\n"
+"			  1    action must be taken immediately (alert)\n"
+"			  2    critical conditions (crit)\n"
+"			  3    error conditions (err)\n"
+"			  4    warning conditions (warn)\n"
+"			  5    normal but significant condition (notice)\n"
+"			  6    informational (info)\n"
+"			  7    debug-level messages (debug)\n"
+"			  8    verbose debug messages (vdebug)\n"
+#endif
+	, prgname
 	);
 }
-- 
2.39.5




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

* [PATCH 2/4] sandbox: add support for architecture-specific debug options
  2024-12-16 11:36 [PATCH 1/4] sandbox: add support for --loglevel option Ahmad Fatoum
@ 2024-12-16 11:36 ` Ahmad Fatoum
  2024-12-16 11:36 ` [PATCH 3/4] sandbox: move CONFIG_ASAN to architecture Kconfig Ahmad Fatoum
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2024-12-16 11:36 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

There is work under way for better debugging facilities in sandbox,
including libfuzzer and code coverage support.

Let's provide a home for the new config options in the form of an
architecture specific Kconfig.debug file like Linux already has.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/Kconfig.debug      | 2 ++
 arch/kvx/Kconfig.debug      | 2 ++
 arch/mips/Kconfig.debug     | 2 ++
 arch/openrisc/Kconfig.debug | 2 ++
 arch/powerpc/Kconfig.debug  | 2 ++
 arch/riscv/Kconfig.debug    | 2 ++
 arch/sandbox/Kconfig.debug  | 2 ++
 arch/x86/Kconfig.debug      | 2 ++
 common/Kconfig.debug        | 6 ++++++
 9 files changed, 22 insertions(+)
 create mode 100644 arch/arm/Kconfig.debug
 create mode 100644 arch/kvx/Kconfig.debug
 create mode 100644 arch/mips/Kconfig.debug
 create mode 100644 arch/openrisc/Kconfig.debug
 create mode 100644 arch/powerpc/Kconfig.debug
 create mode 100644 arch/riscv/Kconfig.debug
 create mode 100644 arch/sandbox/Kconfig.debug
 create mode 100644 arch/x86/Kconfig.debug

diff --git a/arch/arm/Kconfig.debug b/arch/arm/Kconfig.debug
new file mode 100644
index 000000000000..295942fe3fd5
--- /dev/null
+++ b/arch/arm/Kconfig.debug
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# dummy file, do not delete
diff --git a/arch/kvx/Kconfig.debug b/arch/kvx/Kconfig.debug
new file mode 100644
index 000000000000..295942fe3fd5
--- /dev/null
+++ b/arch/kvx/Kconfig.debug
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# dummy file, do not delete
diff --git a/arch/mips/Kconfig.debug b/arch/mips/Kconfig.debug
new file mode 100644
index 000000000000..295942fe3fd5
--- /dev/null
+++ b/arch/mips/Kconfig.debug
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# dummy file, do not delete
diff --git a/arch/openrisc/Kconfig.debug b/arch/openrisc/Kconfig.debug
new file mode 100644
index 000000000000..295942fe3fd5
--- /dev/null
+++ b/arch/openrisc/Kconfig.debug
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# dummy file, do not delete
diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug
new file mode 100644
index 000000000000..295942fe3fd5
--- /dev/null
+++ b/arch/powerpc/Kconfig.debug
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# dummy file, do not delete
diff --git a/arch/riscv/Kconfig.debug b/arch/riscv/Kconfig.debug
new file mode 100644
index 000000000000..295942fe3fd5
--- /dev/null
+++ b/arch/riscv/Kconfig.debug
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# dummy file, do not delete
diff --git a/arch/sandbox/Kconfig.debug b/arch/sandbox/Kconfig.debug
new file mode 100644
index 000000000000..295942fe3fd5
--- /dev/null
+++ b/arch/sandbox/Kconfig.debug
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# dummy file, do not delete
diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
new file mode 100644
index 000000000000..295942fe3fd5
--- /dev/null
+++ b/arch/x86/Kconfig.debug
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# dummy file, do not delete
diff --git a/common/Kconfig.debug b/common/Kconfig.debug
index ea6864ac4d91..c4d1313ef866 100644
--- a/common/Kconfig.debug
+++ b/common/Kconfig.debug
@@ -161,4 +161,10 @@ config WERROR
 
 	  If in doubt, say Y.
 
+menu "$(SRCARCH) Debugging"
+
+source "arch/$(SRCARCH)/Kconfig.debug"
+
+endmenu
+
 endmenu
-- 
2.39.5




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

* [PATCH 3/4] sandbox: move CONFIG_ASAN to architecture Kconfig
  2024-12-16 11:36 [PATCH 1/4] sandbox: add support for --loglevel option Ahmad Fatoum
  2024-12-16 11:36 ` [PATCH 2/4] sandbox: add support for architecture-specific debug options Ahmad Fatoum
@ 2024-12-16 11:36 ` Ahmad Fatoum
  2024-12-16 11:36 ` [PATCH 4/4] startup: set barebox_main in data section Ahmad Fatoum
  2024-12-20  9:04 ` [PATCH 1/4] sandbox: add support for --loglevel option Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2024-12-16 11:36 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

KASAN is the bare-metal AddressSanitizer, which we currently only
support on ARM. The hosted variant ASAN will only be supported for
sandbox, so it makes sense to move it out of common/Kconfig.debug
into the sandbox-specific Kconfig.debug.

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

diff --git a/arch/sandbox/Kconfig.debug b/arch/sandbox/Kconfig.debug
index 295942fe3fd5..4a754e389964 100644
--- a/arch/sandbox/Kconfig.debug
+++ b/arch/sandbox/Kconfig.debug
@@ -1,2 +1,10 @@
 # SPDX-License-Identifier: GPL-2.0-only
-# dummy file, do not delete
+
+config ASAN
+	bool "ASAN: runtime memory debugger"
+	help
+	  Enables ASAN (AddressSANitizer) - runtime memory debugger,
+	  designed to find out-of-bounds accesses and use-after-free bugs.
+
+	  This is the hosted implementation for sandbox as opposed to
+	  KASAN, which is the bare-metal implementation.
diff --git a/common/Kconfig.debug b/common/Kconfig.debug
index c4d1313ef866..9c70555eb83c 100644
--- a/common/Kconfig.debug
+++ b/common/Kconfig.debug
@@ -124,16 +124,6 @@ config PRINTF_FULL
 source "lib/Kconfig.ubsan"
 source "lib/kasan/Kconfig"
 
-config ASAN
-	bool "ASAN: runtime memory debugger"
-	depends on SANDBOX
-	help
-	  Enables ASAN (AddressSANitizer) - runtime memory debugger,
-	  designed to find out-of-bounds accesses and use-after-free bugs.
-
-	  This is the hosted implementation for sandbox as opposed to
-	  KASAN, which is the bare-metal implementation.
-
 config COMPILE_TEST
 	bool "compile-test drivers of other platforms"
 	default n
-- 
2.39.5




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

* [PATCH 4/4] startup: set barebox_main in data section
  2024-12-16 11:36 [PATCH 1/4] sandbox: add support for --loglevel option Ahmad Fatoum
  2024-12-16 11:36 ` [PATCH 2/4] sandbox: add support for architecture-specific debug options Ahmad Fatoum
  2024-12-16 11:36 ` [PATCH 3/4] sandbox: move CONFIG_ASAN to architecture Kconfig Ahmad Fatoum
@ 2024-12-16 11:36 ` Ahmad Fatoum
  2024-12-20  9:04 ` [PATCH 1/4] sandbox: add support for --loglevel option Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2024-12-16 11:36 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

By initializing barebox_main in start_barebox(), we preclude changing
barebox_main before start_barebox() is called.

This can be useful, at least in sandbox. Therefore, let's initialize
barebox_main statically.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/startup.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/common/startup.c b/common/startup.c
index 4cb9cfcdaa49..898bef6d22e4 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -355,16 +355,15 @@ static void do_ctors(void)
 #endif
 }
 
-int (*barebox_main)(void);
+int (*barebox_main)(void)
+	= !IS_ENABLED(CONFIG_SHELL_NONE) &&
+           IS_ENABLED(CONFIG_COMMAND_SUPPORT) ? run_init : NULL;
 
 void __noreturn start_barebox(void)
 {
 	initcall_t *initcall;
 	int result;
 
-	if (!IS_ENABLED(CONFIG_SHELL_NONE) && IS_ENABLED(CONFIG_COMMAND_SUPPORT))
-		barebox_main = run_init;
-
 	do_ctors();
 
 	for (initcall = __barebox_initcalls_start;
-- 
2.39.5




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

* Re: [PATCH 1/4] sandbox: add support for --loglevel option
  2024-12-16 11:36 [PATCH 1/4] sandbox: add support for --loglevel option Ahmad Fatoum
                   ` (2 preceding siblings ...)
  2024-12-16 11:36 ` [PATCH 4/4] startup: set barebox_main in data section Ahmad Fatoum
@ 2024-12-20  9:04 ` Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2024-12-20  9:04 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Mon, 16 Dec 2024 12:36:37 +0100, Ahmad Fatoum wrote:
> To simplify debugging, let's allow the user to override the default log
> level from the command line.
> 
> 

Applied, thanks!

[1/4] sandbox: add support for --loglevel option
      https://git.pengutronix.de/cgit/barebox/commit/?id=6c1313c7debf (link may not be stable)
[2/4] sandbox: add support for architecture-specific debug options
      https://git.pengutronix.de/cgit/barebox/commit/?id=17252b36f040 (link may not be stable)
[3/4] sandbox: move CONFIG_ASAN to architecture Kconfig
      https://git.pengutronix.de/cgit/barebox/commit/?id=97b5b7d21d2d (link may not be stable)
[4/4] startup: set barebox_main in data section
      https://git.pengutronix.de/cgit/barebox/commit/?id=be892df4acc7 (link may not be stable)

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




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

end of thread, other threads:[~2024-12-20  9:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-16 11:36 [PATCH 1/4] sandbox: add support for --loglevel option Ahmad Fatoum
2024-12-16 11:36 ` [PATCH 2/4] sandbox: add support for architecture-specific debug options Ahmad Fatoum
2024-12-16 11:36 ` [PATCH 3/4] sandbox: move CONFIG_ASAN to architecture Kconfig Ahmad Fatoum
2024-12-16 11:36 ` [PATCH 4/4] startup: set barebox_main in data section Ahmad Fatoum
2024-12-20  9:04 ` [PATCH 1/4] sandbox: add support for --loglevel option Sascha Hauer

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