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

@@ -0,0 +1,51 @@
.. SPDX-License-Identifier: GPL-2.0+
.. index::
single: backtrace (command)
backtrace command
=================
Synopsis
--------
::
backtrace
Description
-----------
The *backtrace* command prints a backtrace of the current call stack. This can
be useful for debugging to see how a particular code path was reached.
The output shows each stack frame with the function name, source file, and line
number (when debug information is available). This includes static functions.
Example
-------
::
=> backtrace
backtrace: 14 addresses
backtrace_show() at /home/user/u-boot/lib/backtrace.c:17
do_backtrace() at /home/user/u-boot/cmd/backtrace.c:18
cmd_process() at /home/user/u-boot/common/command.c:637
run_list_real() at /home/user/u-boot/common/cli_hush.c:1868
parse_stream_outer() at /home/user/u-boot/common/cli_hush.c:3207
parse_string_outer() at /home/user/u-boot/common/cli_hush.c:3257
run_command_list() at /home/user/u-boot/common/cli.c:168
sandbox_main_loop_init() at /home/user/u-boot/arch/sandbox/cpu/start.c:153
board_init_r() at /home/user/u-boot/common/board_r.c:774
...
Configuration
-------------
The backtrace command is enabled by CONFIG_CMD_BACKTRACE which depends on
CONFIG_BACKTRACE. Currently this is only available on sandbox.
The sandbox implementation uses libbacktrace (bundled with GCC) to provide
detailed symbol information including function names, source files, and line
numbers.

View File

@@ -31,6 +31,7 @@ Shell commands
cmd/addrmap
cmd/armffa
cmd/askenv
cmd/backtrace
cmd/base
cmd/bdinfo
cmd/bind