backtrace: Add a command

Add a new 'backtrace' command which prints the current call stack, which
is useful for debugging. The command is enabled by CONFIG_CMD_BACKTRACE

Add docs and a test.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
This commit is contained in:
Simon Glass
2025-11-28 05:27:29 -07:00
committed by Simon Glass
parent 14b0a3e2e0
commit b174084ef9
7 changed files with 114 additions and 0 deletions

View File

@@ -136,6 +136,14 @@ config CMD_ADDR_FIND
sufficiently large to hold a file. If successful, it sets the
loadaddr variable to this address.
config CMD_BACKTRACE
bool "backtrace"
depends on BACKTRACE
default y if BACKTRACE
help
This command prints a backtrace showing the current call stack.
This can be useful for debugging.
config CMD_ADDRMAP
bool "addrmap"
depends on ADDR_MAP

View File

@@ -14,6 +14,7 @@ obj-y += version.o
# command
obj-$(CONFIG_CMD_ARMFFA) += armffa.o
obj-$(CONFIG_CMD_2048) += 2048.o
obj-$(CONFIG_CMD_BACKTRACE) += backtrace.o
obj-$(CONFIG_CMD_ACPI) += acpi.o
obj-$(CONFIG_CMD_ADDR_FIND) += addr_find.o
obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o

30
cmd/backtrace.c Normal file
View File

@@ -0,0 +1,30 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Backtrace command
*
* Copyright 2025 Canonical Ltd
* Written by Simon Glass <simon.glass@canonical.com>
*/
#include <backtrace.h>
#include <command.h>
static int do_backtrace(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
int ret;
ret = backtrace_show();
if (ret) {
printf("backtrace failed: %d\n", ret);
return CMD_RET_FAILURE;
}
return 0;
}
U_BOOT_CMD(backtrace, 1, 1, do_backtrace,
"Print backtrace",
"\n"
" - Print a backtrace of the current call stack"
);