backtrace: Add backtrace_str() for condensed backtrace output

Add a new function backtrace_str() that returns a condensed backtrace
string containing function names and line numbers separated by " <-".

For example: "func_a:123 <-func_b:456 <-func_c:789"

This is useful for logging and debugging where a compact representation
of the call stack is needed. The depth is controlled by the new
CONFIG_BACKTRACE_DEPTH option (default 3).

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
This commit is contained in:
Simon Glass
2025-12-02 04:57:41 +00:00
parent e1e95b2887
commit 0cf38dc8c8
4 changed files with 203 additions and 0 deletions

View File

@@ -36,6 +36,15 @@ config BACKTRACE
stack. This is currently only available on sandbox. The backtrace
command can be used to print the backtrace.
config BACKTRACE_SUMMARY_FRAMES
int "Number of frames in condensed backtrace"
depends on BACKTRACE
default 3
help
Number of stack frames to include in the condensed backtrace
string returned by backtrace_str(). This affects BSS usage
since space must be allocated for the string.
config LIB_FORMAT_SIZE
bool
default y