Files
u-boot/lib/backtrace.c
Simon Glass cdde93a9e3 backtrace: Add a library to access the backtrace
Provide an API to access the backtrace, in an arch-neutral way.

The backtrace can be retrieved, examined and printed.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-01 15:42:04 +00:00

41 lines
696 B
C

// SPDX-License-Identifier: GPL-2.0+
/*
* Stack-backtrace support
*
* Copyright 2025 Canonical Ltd
* Written by Simon Glass <simon.glass@canonical.com>
*/
#include <backtrace.h>
#include <stdio.h>
int backtrace_show(void)
{
char buf[BACKTRACE_BUFSZ];
struct backtrace_ctx ctx;
uint i;
int ret;
ret = backtrace_init(&ctx, 1);
if (ret < 0)
return ret;
ret = backtrace_get_syms(&ctx, buf, sizeof(buf));
if (ret) {
backtrace_uninit(&ctx);
return ret;
}
printf("backtrace: %d addresses\n", ctx.count);
for (i = 0; i < ctx.count; i++) {
if (ctx.syms[i])
printf(" %s\n", ctx.syms[i]);
else
printf(" %p\n", ctx.addrs[i]);
}
backtrace_uninit(&ctx);
return 0;
}