From patchwork Sat Nov 29 07:59:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 768 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403244; bh=EmJQWQ8gAIe1cRqgXU7dII5nqyMFJ46JiCWaPAnZ2OQ=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=OtxhLtSxzHgBzyFHhWYCsvnovKb/b9WvjadP7dzvMuRTz+CE61NniFkuPm+bQlfxA BdREc8SDsimKD98UXjEsKwZrTpeoGq5IicXUWhBcmo8xmkpb9OleVNlIyQiybRK5E1 5vy8sFRuT3jYJ59iOvu1cpfli5jZBTz3HFN6muAsNvDQIm6r2SCdZlyrKbdYZOpj2y gVmR/G3wt/BhhaOuRCXk4Ox6nI+3C8Sv89fV+u6b74N2gMN53ajwz7P31PFtUv2ynl /fXlWF0/WhRN07pVmm6yn3WYQkvYPg/yA6FUZDLeIUYfkPw4/2I1lHLXcV2wtU+MLB mwWG7knjRnouA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 78213687CC for ; Sat, 29 Nov 2025 01:00:44 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id N57RKy6y8TGF for ; Sat, 29 Nov 2025 01:00:44 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403244; bh=EmJQWQ8gAIe1cRqgXU7dII5nqyMFJ46JiCWaPAnZ2OQ=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=OtxhLtSxzHgBzyFHhWYCsvnovKb/b9WvjadP7dzvMuRTz+CE61NniFkuPm+bQlfxA BdREc8SDsimKD98UXjEsKwZrTpeoGq5IicXUWhBcmo8xmkpb9OleVNlIyQiybRK5E1 5vy8sFRuT3jYJ59iOvu1cpfli5jZBTz3HFN6muAsNvDQIm6r2SCdZlyrKbdYZOpj2y gVmR/G3wt/BhhaOuRCXk4Ox6nI+3C8Sv89fV+u6b74N2gMN53ajwz7P31PFtUv2ynl /fXlWF0/WhRN07pVmm6yn3WYQkvYPg/yA6FUZDLeIUYfkPw4/2I1lHLXcV2wtU+MLB mwWG7knjRnouA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6598C687BB for ; Sat, 29 Nov 2025 01:00:44 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403241; bh=7GY0/KaOOJsTZ1SoKa8J/idWTsfevJKAAylGg/H+TSg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k0kx71TMcgGGSD69AVS6FDG0oyBf2M7Mq27/FuoGr28BmmZlGN6tbaD1+jpBtLdmT s7UCMsGn59u81901BP7N6+SMtE2MpugIr3X+J8Wwfd8Wn3b8o23iZXX8aJYc+5dmK4 aasLvml0HD5ahDqpiupf8VyCvwedeOLPMZFN80S+WNycdPCaI9mNA29gqNu2tEsv7f rnhm/sALRTHOj8m9jUA2lsRsU0ZnxtddHIXale3J4/pParbD34X2AWm9XAkGuKeOI0 6Kg52ETuywCeLURO7ynZuk0Ian+w+93IeTKaOnEq94UWTls1kALOlYSLcq5LIM6lk0 DoNeOfo36voeA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E2BFF6875D; Sat, 29 Nov 2025 01:00:41 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id RKyGX-Km2WgB; Sat, 29 Nov 2025 01:00:41 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403238; bh=ndTAbf2hl0lyG7MSRW5/H3tV6mQHFEte1KV/xF9zKrM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WvkWAVrLTDi5g6Qy/oev5tHFTqi55+lYBUAvfRQ5SYM3MwPBYEe8L/OUYStcOZhoQ E37ALJA8gdANCIdf6Iront15l9nhiiBuZbaMTKbmW4avM+kbD1qDmTN2lq6xGWFIYC KXPG6ig0RvJc5jeTB8raM4E+ocaAepA5+HvGs3lnP5s3ejvIxVYVgnrnHc1SI1zlIC QSyIPAcR+bTBpmae1yWb/ztg30vPUmX+RWQXc6cIHBBoI2zQed6uC5/44bqjqWNPeh rXnFSVUnv/YWBmolZAhsVTN/DhMGPSqJD29lll9yRfQvmXoDu3tW5UP7LGiYrrerJc 9i1lYsDXAJA1g== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id D878068795; Sat, 29 Nov 2025 01:00:37 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 29 Nov 2025 00:59:46 -0700 Message-ID: <20251129080014.758001-2-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251129080014.758001-1-sjg@u-boot.org> References: <20251129080014.758001-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: LAWQ4HAI74AMZWDAGY2KZ7BSL5YK73BT X-Message-ID-Hash: LAWQ4HAI74AMZWDAGY2KZ7BSL5YK73BT X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 01/10] claude: Tell it about my crosfw script being silent List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add a note about this. At some point we should create a proper tools for IDE use in U-Boot. Signed-off-by: Simon Glass --- CLAUDE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CLAUDE.md b/CLAUDE.md index 374f24ba1f9..a13dd995b68 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -59,6 +59,7 @@ pyt - Always run `make mrproper` if you encounter build issues - The sandbox build creates a test environment for U-Boot that runs on the host system - When using `git diff`, add `--no-ext-diff` to avoid external diff tools that may not work in this environment +- crosfw shows now output if everything was ok! ## Coding Conventions From patchwork Sat Nov 29 07:59:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 769 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403247; bh=QsYecGH2r4PnNGt1EYx5mRvC7fIb06CtMpSSa7gSdUE=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=vw9TN87CTEdVp7PMNmfjlUUEuKlF/4xcaxpOnuMq0B83G1eMRlR/HA29l9gO4rSpf NUWXbw/8ijE1TDhq6TT5SPZf/Eyijk0w5UiJ2IxwHbcIo2SBba7kxNadsLpQb5OLVB RrLH80eAoFxSRx3nd/A2hKnL4Ep5O34wm203XaowsrCoZpgm0gJ+U1eRCF9CTksSP9 aBo9RP4XoSUZY8F72U/oyRg597YjvB3zs7A/SUyfyZ6oAFjADFosFTvVht8aPl+eh9 1fpCmyI2gXx8Q4vQKPGdo2xCEHunqAB3Ut6jCtscZLY0FLBLYSk7l36nFqvqdg47Pj wpfqKVn9MR2tw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E6DD3687C8 for ; Sat, 29 Nov 2025 01:00:47 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id cbnTlBtrGvHv for ; Sat, 29 Nov 2025 01:00:47 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403247; bh=QsYecGH2r4PnNGt1EYx5mRvC7fIb06CtMpSSa7gSdUE=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=vw9TN87CTEdVp7PMNmfjlUUEuKlF/4xcaxpOnuMq0B83G1eMRlR/HA29l9gO4rSpf NUWXbw/8ijE1TDhq6TT5SPZf/Eyijk0w5UiJ2IxwHbcIo2SBba7kxNadsLpQb5OLVB RrLH80eAoFxSRx3nd/A2hKnL4Ep5O34wm203XaowsrCoZpgm0gJ+U1eRCF9CTksSP9 aBo9RP4XoSUZY8F72U/oyRg597YjvB3zs7A/SUyfyZ6oAFjADFosFTvVht8aPl+eh9 1fpCmyI2gXx8Q4vQKPGdo2xCEHunqAB3Ut6jCtscZLY0FLBLYSk7l36nFqvqdg47Pj wpfqKVn9MR2tw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D5D46687BA for ; Sat, 29 Nov 2025 01:00:47 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403246; bh=OUdbJompNuGHWKUzbY8Xw1Vb+UGBA/fZjMOV9MxNusA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uP5SmPqjxxW7rfOS6H26dghz5NFTxSQI6FzlviXPTOXzMqFI9+aSN4MqFtw/0ttei oS6tfNV5Dk42RdLLIy3QKreB9wVozmYGoCyC/giE9LSS5B+cNuxET4y0ox1JfA4r6u lxmSKnHfIT94kAl+FoyYHTylhbAx2kKu2ERfuLNEf1t7bOp7vqFHNm2GnwmpfwgO1+ xnv4I7Le7E+yBU5k0v5ECQsxOgCdlcfsSMN7oXG0szaqGZPxKxjQUj0q1ZNwPMEc5m q8gZeiVgFwWMmBHF82bVG8idrJ8BRP7IBiSyW1C+QYtPVTO78AbFzZmqyg0q6ISeYL Y6U+5REJhxsAg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CF6A26875D; Sat, 29 Nov 2025 01:00:46 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id IO6ITbRRDv1q; Sat, 29 Nov 2025 01:00:46 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403242; bh=y7YQfNvGLdYHrS5YIfzMeDjglzBY5Nyr+pdjs/7Zh/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kDanbK9Dh9aDLeKXK4SaSt6o0vv/nYrJGEBzGKbKEzjiBgcO7A7971llEMvR+AYmW ul/eh7Z0OZQJUA18IgX9kuCreMpNJxtfPHP6rz2qYXCmdzc2xPphp5AP67fVPmBjNH gxEK/MDAN3kxXz1zAioFrp/UxG0gfN59uaOh7KCnMohAd3B9XOX/Antx3UeBQI2CTW JvvOrsFJmhvoaRs4BFbe/6dT6Y0KzEanSd8wRBB3+rBLKN2XVgJCEuwLnN9OiksmFi MAlwWa453d89Gw7/JvQ6BZXPN3Wwbsq7hpO+isbgPGJ9oJRQtAKq+ja1gXHSrZJH+X 7YVaKzxYXB5+Q== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 3733E6876F; Sat, 29 Nov 2025 01:00:42 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 29 Nov 2025 00:59:47 -0700 Message-ID: <20251129080014.758001-3-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251129080014.758001-1-sjg@u-boot.org> References: <20251129080014.758001-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 57B4M6TI4UJILHLHVKA3X5OYSCJJ7YH5 X-Message-ID-Hash: 57B4M6TI4UJILHLHVKA3X5OYSCJJ7YH5 X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 02/10] backtrace: Add a library to access the backtrace List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Provide an API to access the backtrace, in an arch-neutral way. The backtrace can be retrieved, examined and printed. Co-developed-by: Claude Signed-off-by: Simon Glass --- include/backtrace.h | 72 +++++++++++++++++++++++++++++++++++++++++++++ lib/Kconfig | 8 +++++ lib/Makefile | 1 + lib/backtrace.c | 40 +++++++++++++++++++++++++ 4 files changed, 121 insertions(+) create mode 100644 include/backtrace.h create mode 100644 lib/backtrace.c diff --git a/include/backtrace.h b/include/backtrace.h new file mode 100644 index 00000000000..eece61e4d9a --- /dev/null +++ b/include/backtrace.h @@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Backtrace support + * + * Copyright 2025 Canonical Ltd + * Written by Simon Glass + */ + +#ifndef __BACKTRACE_H +#define __BACKTRACE_H + +#define BACKTRACE_MAX 100 +#define BACKTRACE_SYM_SIZE 128 +#define BACKTRACE_BUFSZ (BACKTRACE_MAX * BACKTRACE_SYM_SIZE) + +/** + * struct backtrace_ctx - context for backtrace operations + * + * @addrs: array of return addresses + * @syms: array of symbol strings (NULL until backtrace_get_syms() called) + * @count: number of entries in addrs/syms arrays + */ +struct backtrace_ctx { + void *addrs[BACKTRACE_MAX]; + char *syms[BACKTRACE_MAX]; + unsigned int count; +}; + +/** + * backtrace_init() - collect a backtrace + * + * Collect backtrace addresses into the context. Call backtrace_uninit() when + * done with the context. + * + * @ctx: context to fill + * @skip: number of stack frames to skip (0 to include backtrace_init itself) + * Return: number of addresses collected, or -ve on error (e.g. -ENOSYS) + */ +int backtrace_init(struct backtrace_ctx *ctx, unsigned int skip); + +/** + * backtrace_get_syms() - get symbol strings for a backtrace + * + * Convert the addresses in the context to symbol strings. The strings are + * stored in ctx->syms[]. The caller must provide a buffer of sufficient size. + * + * @ctx: context with addresses from backtrace_init() + * @buf: buffer to use for string storage + * @size: size of buffer in bytes + * Return: 0 if OK, -ENOSPC if buffer too small + */ +int backtrace_get_syms(struct backtrace_ctx *ctx, char *buf, int size); + +/** + * backtrace_uninit() - free backtrace resources + * + * Free any memory allocated in the context. + * + * @ctx: context to free + */ +void backtrace_uninit(struct backtrace_ctx *ctx); + +/** + * backtrace_show() - print a backtrace + * + * Print a backtrace of the current call stack. + * + * Return: 0 if OK, -ve on error + */ +int backtrace_show(void); + +#endif /* __BACKTRACE_H */ diff --git a/lib/Kconfig b/lib/Kconfig index 662b1a44d45..d7f791f77f3 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -28,6 +28,14 @@ config PHYSMEM Enable this to access this basic support, which only supports clearing the memory. +config BACKTRACE + bool "Enable backtrace support" + depends on SANDBOX + help + Enables support for printing a backtrace showing the current call + stack. This is currently only available on sandbox. The backtrace + command can be used to print the backtrace. + config BCH bool "Enable Software based BCH ECC" help diff --git a/lib/Makefile b/lib/Makefile index 5cbf3071f96..b696e81c496 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -147,6 +147,7 @@ obj-$(CONFIG_TRACE) += trace.o obj-$(CONFIG_LIB_UUID) += uuid.o obj-$(CONFIG_LIB_RAND) += rand.o obj-y += panic.o +obj-$(CONFIG_BACKTRACE) += backtrace.o ifeq ($(CONFIG_XPL_BUILD),y) # SPL U-Boot may use full-printf, tiny-printf or none at all diff --git a/lib/backtrace.c b/lib/backtrace.c new file mode 100644 index 00000000000..e3d93b80b8a --- /dev/null +++ b/lib/backtrace.c @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Stack-backtrace support + * + * Copyright 2025 Canonical Ltd + * Written by Simon Glass + */ + +#include +#include + +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; +} From patchwork Sat Nov 29 07:59:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 770 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403253; bh=UA7W2fUUWKA0BcSLBtY84YIF2iBqGfbRZ1Fo+n6D4/0=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=e8T/q/TUIdLwNVa6MvNskFacxoOyef/Rq0KcfIOYRu3ZCvPUp/RTqANhpSvGPXga6 4YDkNWFX5vTnGOu57Bl8HyGUYiheS2uvbGZu/7bp5OTzXO5ByjbxLOff+w0XcQbBW2 yfw1Z2qriTg1psN6bFJ3weSmOlmaJ85+ufw5gYaOMQ+UXd5n0slmV/2kqRiwhd3ofz dZklAHvK2vS9IBlR0YF9In/CG4LaMWipiFLxo1CxslwlptCzr6yXwb/EtJqQmkm9z+ Jw/8w6kL1xXQS4Is7EpUBMDK3ktqWXqCKDXypY/ZtJ1zqEl8/0EikC325esxY1+qCE qbl5t2xqhQlcQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C1CC7687CC for ; Sat, 29 Nov 2025 01:00:53 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 5UUrzIsFdkj4 for ; Sat, 29 Nov 2025 01:00:53 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403253; bh=UA7W2fUUWKA0BcSLBtY84YIF2iBqGfbRZ1Fo+n6D4/0=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=e8T/q/TUIdLwNVa6MvNskFacxoOyef/Rq0KcfIOYRu3ZCvPUp/RTqANhpSvGPXga6 4YDkNWFX5vTnGOu57Bl8HyGUYiheS2uvbGZu/7bp5OTzXO5ByjbxLOff+w0XcQbBW2 yfw1Z2qriTg1psN6bFJ3weSmOlmaJ85+ufw5gYaOMQ+UXd5n0slmV/2kqRiwhd3ofz dZklAHvK2vS9IBlR0YF9In/CG4LaMWipiFLxo1CxslwlptCzr6yXwb/EtJqQmkm9z+ Jw/8w6kL1xXQS4Is7EpUBMDK3ktqWXqCKDXypY/ZtJ1zqEl8/0EikC325esxY1+qCE qbl5t2xqhQlcQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B15F9687C6 for ; Sat, 29 Nov 2025 01:00:53 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403251; bh=K1onuxygtdyEmTtAy6CKhyPOGftxxiOUCE7ZCB7XSz8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gkgHlBpKzrMJ/qlQxDNDRGKaKyKki4yhaKmnQU+0wTad92oLlB2sAJ6KXjZPkUGN3 uRJ/X0R+gkE905zsRHiZX3d+rF3KDz6CMC+yZEfdr4owO4taz1oJ+YCHLUIvf63iWp vJob0iXvEKLiBZDgVqQdiBhMwS9zHHTjMoJVxTj6xbgdZceKlTPgxrl5OG27Cg2t2R HL3k7UdvPF9SOi90GNRYTxI8hAoo7sIU9vVbdNKfRGvUgDvMBwg1TZIS1FopVIIhLj GJYISfp7r9vDvgZpxK19Q0mqEMHNJDet6a+7mdfnvM6FdhdPgy/q00Yw/o34v1K2+W sBVI3TX6VW4iw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 36F856875D; Sat, 29 Nov 2025 01:00:51 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id 2z59VBxl7YUi; Sat, 29 Nov 2025 01:00:51 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403247; bh=VPHzHNWXMjcz3RveFzF3JgQw0XQVT7kd80j2dru2cDs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VclZuugew+JJ1noC8FPppfFZkzmtDUAGJl8nwujSYbaFcQqbqztEeiRlMrDWmB1w0 ABQneqG5qcxYumhIJBwmPPR5N6nwyxyuxuJayJmcE2g58RIXkemL90yPXSXN/LSJpk XbVE8T8qBhLye93mXnLw6e7Jl/AZISTmcLPA988Nm8mCySDHW0VelPi66dzF/obn+/ SZNOVNWaIUI67tzy4JT8+RnYKiahCt7MidMMQsZGkvyXXiDljDsmH1iTBBsWkIakxn bVz7lEax0v0/n8oj2EGRlwULtn5yerM5YXfqtyxTSucDT7G0m5SBXkuI7Go+8To6Au oUyaA/JjTxDgw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id DF7856876F; Sat, 29 Nov 2025 01:00:46 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 29 Nov 2025 00:59:48 -0700 Message-ID: <20251129080014.758001-4-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251129080014.758001-1-sjg@u-boot.org> References: <20251129080014.758001-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: XFKXILDNZU7NITHGPOL55O5BT7COQCJX X-Message-ID-Hash: XFKXILDNZU7NITHGPOL55O5BT7COQCJX X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 03/10] CI: Disable backtrace for the trace test List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass This test expects to only sese a subset of the symbols in the executable. Disable backtrace to avoid dealing with changes in this area. Signed-off-by: Simon Glass --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 68f2534918c..0d63bd4c358 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -480,7 +480,7 @@ sandbox trace_test.py: TEST_PY_BD: "sandbox" BUILD_ENV: "FTRACE=1 NO_LTO=1" TEST_PY_TEST_SPEC: "trace" - OVERRIDE: "-a CONFIG_TRACE=y -a CONFIG_TRACE_EARLY=y -a CONFIG_TRACE_EARLY_SIZE=0x01000000 -a CONFIG_TRACE_BUFFER_SIZE=0x02000000" + OVERRIDE: "-a CONFIG_TRACE=y -a CONFIG_TRACE_EARLY=y -a CONFIG_TRACE_EARLY_SIZE=0x01000000 -a CONFIG_TRACE_BUFFER_SIZE=0x02000000 -a ~CONFIG_BACKTRACE" <<: *buildman_and_testpy_dfn evb-ast2500 test.py: From patchwork Sat Nov 29 07:59:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 771 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403258; bh=rIDH3CrK+cktultb87DcB/xM+6Fz3huodHgp1Gk+pnA=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=uan6B0GGK0qTcw9hEXm0+0Ur5R1kFeeRMf6P19LIv2pPfrzEB+nSBbXbaZFqzvvRy xVtn5mljT3+SgA7xHw2BSQ0O+GqKtwf08k6YA7g/wmyDOIZkzzFO40iXuEB962FJyu /AFsB5AhZXHEZAaFBM4y7zkdgtWtz680caQYako3hPTrRD/kIDlJb6/10gxiHn8TMA FUKhJctSCvOhxFQIWZt2CUjuqpxKP2zOXv8WQwt/ZAGvw9+Sx9g1yw1txdeVmmKp56 rwNeMTH2gBbKRVQpYKXUpHNZ+cHUhL3Fn0kv7ayNoHJPeyTBI8GLprjmbSD2yd7DOQ 1IDfYVlfsyi3Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 41F08687CC for ; Sat, 29 Nov 2025 01:00:58 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id Fxh9nrkpYAla for ; Sat, 29 Nov 2025 01:00:58 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403258; bh=rIDH3CrK+cktultb87DcB/xM+6Fz3huodHgp1Gk+pnA=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=uan6B0GGK0qTcw9hEXm0+0Ur5R1kFeeRMf6P19LIv2pPfrzEB+nSBbXbaZFqzvvRy xVtn5mljT3+SgA7xHw2BSQ0O+GqKtwf08k6YA7g/wmyDOIZkzzFO40iXuEB962FJyu /AFsB5AhZXHEZAaFBM4y7zkdgtWtz680caQYako3hPTrRD/kIDlJb6/10gxiHn8TMA FUKhJctSCvOhxFQIWZt2CUjuqpxKP2zOXv8WQwt/ZAGvw9+Sx9g1yw1txdeVmmKp56 rwNeMTH2gBbKRVQpYKXUpHNZ+cHUhL3Fn0kv7ayNoHJPeyTBI8GLprjmbSD2yd7DOQ 1IDfYVlfsyi3Q== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3103D687B5 for ; Sat, 29 Nov 2025 01:00:58 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403256; bh=mOf03Mv8EKe8cAvkkXmAYOLFh9DlQDfK4b/sZ/9w9Kk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cYPThkDLgnBcf8CoG4HQRDO5fqBmPjHsI6ZxB915AtZOmeWN733zYlduW6gdaZ2zw 5s35YHBRK1639/X2v+GvjQYFraCOD9beoa/4SHje8EVwSZ0s6mEux+13rerMrEI0YQ WC1BDzP4DpibHgFXYdPa13YpC59zzZolrQYDSrRNWqWpiIMy7LOfeDD1WdUFELgj+z duXXmKId+fNVHDONt//OVTVPbQHj8UIMbKr/6qShoHG3zzYV8t8iVl1hc5okRXLeYo 0HoNPXX/FUSz7hMBww8oqiUmcOwYqDt2SlJ/Fr+wjKFkJ+hi0oy0NVtPf8J75Hh1o9 A9mMkdAEESDfA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 27F6C6875D; Sat, 29 Nov 2025 01:00:56 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id BPPc0NZX0__r; Sat, 29 Nov 2025 01:00:56 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403251; bh=D4k14JL6O76TPumUKgpDJZHZTWKHoD5CSQEAJ0z+0jk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RHJAcT4upTdHysJV3ie9GcpGeP2Gz/zpLEx2UEwTpg8ogZaV+b2WQXeUMgS0mFc3k Z1JxQk1igk/r7YHlo9VdZNLQCyTwkd5oC5DG22z+DG4ReHtZzmT1uMtHzTEExSJBtW 0lsLyWwxRPOXUaUTioPEQ4V66lpo4FXPfl9Ywn3up46j4g7oeMazF8Vu4ArX4eMyry P1Gks2Rwy2WTIm0EFFqixbCn1FO84h9qbHChR2EsaJEpDHwXgU0Owb0d65iQ4tAAdW Pu/qNoGHb92Jb6SEwaO6KwAYHZi8ea0M/xwvxP3XhNmMUvCrNE2uhyip3+6UNBJxRH k2Q4SpY15WcqQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 7F74A6876F; Sat, 29 Nov 2025 01:00:51 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 29 Nov 2025 00:59:49 -0700 Message-ID: <20251129080014.758001-5-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251129080014.758001-1-sjg@u-boot.org> References: <20251129080014.758001-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: GHRLNRK642GMP2TLVIQNGHM27CTN6VWD X-Message-ID-Hash: GHRLNRK642GMP2TLVIQNGHM27CTN6VWD X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 04/10] backtrace: sandbox: Add support for obtaining symbols List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add backtrace functions for sandbox, including: - os_backtrace() to collect addresses into a caller-supplied buffer - os_backtrace_symbols() to convert addresses to symbol strings - os_backtrace_symbols_free() to free the symbol array The libbacktrace library (bundled with GCC) reads DWARF debug information to provide detailed symbol resolution including function names (even for static functions), source file paths, and line numbers. The sandbox backtrace implementation wraps these OS functions to implement the generic backtrace API (backtrace_init, backtrace_get_syms, etc.). Enable it for just the 'sandbox' board. Add the library for the Rust example too. Co-developed-by: Claude Signed-off-by: Simon Glass --- arch/sandbox/cpu/Makefile | 7 +- arch/sandbox/cpu/backtrace.c | 122 +++++++++++++++++++++++++++++++++++ arch/sandbox/lib/Makefile | 1 + arch/sandbox/lib/backtrace.c | 71 ++++++++++++++++++++ configs/sandbox_defconfig | 1 + examples/rust/build.rs | 3 + examples/ulib/config.mk | 2 +- include/os.h | 34 ++++++++++ 8 files changed, 239 insertions(+), 2 deletions(-) create mode 100644 arch/sandbox/cpu/backtrace.c create mode 100644 arch/sandbox/lib/backtrace.c diff --git a/arch/sandbox/cpu/Makefile b/arch/sandbox/cpu/Makefile index ef9a01c5d7c..212cf14fe37 100644 --- a/arch/sandbox/cpu/Makefile +++ b/arch/sandbox/cpu/Makefile @@ -15,9 +15,14 @@ extra-y := start.o extra-$(CONFIG_SANDBOX_SDL) += sdl.o obj-$(CONFIG_XPL_BUILD) += spl.o obj-$(CONFIG_ETH_SANDBOX_RAW) += eth-raw-os.o +obj-$(CONFIG_BACKTRACE) += backtrace.o # Compile these files with system headers -CFLAGS_USE_SYSHDRS := eth-raw-os.o fuzz.o main.o os.o sdl.o tty.o +CFLAGS_USE_SYSHDRS := backtrace.o eth-raw-os.o fuzz.o main.o os.o sdl.o tty.o + +# backtrace.c needs libbacktrace header from GCC +LIBBT_INC := $(dir $(shell $(CC) -print-file-name=include/backtrace.h)) +CFLAGS_backtrace.o += -isystem $(LIBBT_INC) # sdl.c fails to build with -fshort-wchar using musl cmd_cc_sdl.o = $(CC) $(filter-out -nostdinc -fshort-wchar, \ diff --git a/arch/sandbox/cpu/backtrace.c b/arch/sandbox/cpu/backtrace.c new file mode 100644 index 00000000000..1f5a14ed541 --- /dev/null +++ b/arch/sandbox/cpu/backtrace.c @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * OS-level backtrace support for sandbox + * + * Copyright 2025 Canonical Ltd + * Written by Simon Glass + */ + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include + +#include + +/* libbacktrace state - created once and cached */ +static struct backtrace_state *bt_state; + +/* Context for collecting symbol info */ +struct bt_sym_ctx { + char *buf; + size_t size; + int found; +}; + +uint os_backtrace(void **buffer, uint size, uint skip) +{ + void *tmp[size + skip]; + uint count; + int nptrs; + + nptrs = backtrace(tmp, size + skip); + if ((int)skip >= nptrs) + return 0; + + count = nptrs - skip; + memcpy(buffer, tmp + skip, count * sizeof(*buffer)); + + return count; +} + +static void bt_error_callback(void *data, const char *msg, int errnum) +{ + /* Silently ignore errors - we'll fall back to addresses */ +} + +static struct backtrace_state *get_bt_state(void) +{ + if (!bt_state) + bt_state = backtrace_create_state(NULL, 0, bt_error_callback, + NULL); + + return bt_state; +} + +static int bt_full_callback(void *data, uintptr_t pc, const char *fname, + int lineno, const char *func) +{ + struct bt_sym_ctx *ctx = data; + + if (func) { + if (fname && lineno) + snprintf(ctx->buf, ctx->size, "%s() at %s:%d", func, + fname, lineno); + else if (fname) + snprintf(ctx->buf, ctx->size, "%s() at %s", func, + fname); + else + snprintf(ctx->buf, ctx->size, "%s()", func); + ctx->found = 1; + } + + return 0; /* continue to get innermost frame for inlined functions */ +} + +char **os_backtrace_symbols(void *const *buffer, uint count) +{ + struct backtrace_state *state; + char *str_storage; + char **strings; + uint i; + + state = get_bt_state(); + + /* Allocate array of string pointers plus space for strings */ + strings = malloc(count * sizeof(char *) + count * 256); + if (!strings) + return NULL; + + /* String storage starts after the pointer array */ + str_storage = (char *)(strings + count); + + for (i = 0; i < count; i++) { + struct bt_sym_ctx ctx; + + strings[i] = str_storage + i * 256; + ctx.buf = strings[i]; + ctx.size = 256; + ctx.found = 0; + + if (state) { + backtrace_pcinfo(state, (uintptr_t)buffer[i], + bt_full_callback, bt_error_callback, + &ctx); + } + + /* Fall back to address if no symbol found */ + if (!ctx.found) + snprintf(strings[i], 256, "%p", buffer[i]); + } + + return strings; +} + +void os_backtrace_symbols_free(char **strings) +{ + free(strings); +} diff --git a/arch/sandbox/lib/Makefile b/arch/sandbox/lib/Makefile index edb650c48da..563a5c33156 100644 --- a/arch/sandbox/lib/Makefile +++ b/arch/sandbox/lib/Makefile @@ -5,6 +5,7 @@ # (C) Copyright 2002-2006 # Wolfgang Denk, DENX Software Engineering, wd@denx.de. +obj-$(CONFIG_BACKTRACE) += backtrace.o obj-y += fdt_fixup.o interrupts.o obj-$(CONFIG_PCI) += pci_io.o obj-$(CONFIG_BOOT) += bootm.o diff --git a/arch/sandbox/lib/backtrace.c b/arch/sandbox/lib/backtrace.c new file mode 100644 index 00000000000..073eb945622 --- /dev/null +++ b/arch/sandbox/lib/backtrace.c @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Backtrace support for sandbox + * + * Copyright 2025 Canonical Ltd + * Written by Simon Glass + */ + +#include +#include +#include +#include + +int backtrace_init(struct backtrace_ctx *ctx, uint skip) +{ + uint i; + + for (i = 0; i < BACKTRACE_MAX; i++) + ctx->syms[i] = NULL; + /* +1 to skip this function */ + ctx->count = os_backtrace(ctx->addrs, BACKTRACE_MAX, skip + 1); + + return ctx->count; +} + +int backtrace_get_syms(struct backtrace_ctx *ctx, char *buf, int size) +{ + char **raw_syms; + size_t total_len; + char *p; + uint i; + + raw_syms = os_backtrace_symbols(ctx->addrs, ctx->count); + if (!raw_syms) + return -ENOMEM; + + /* Calculate total buffer size needed */ + total_len = 0; + for (i = 0; i < ctx->count; i++) { + if (raw_syms[i]) + total_len += strlen(raw_syms[i]) + 1; + else + total_len += 1; /* empty string */ + } + + if ((size_t)size < total_len) { + os_backtrace_symbols_free(raw_syms); + return -ENOSPC; + } + + /* Copy strings into buffer */ + p = buf; + for (i = 0; i < ctx->count; i++) { + ctx->syms[i] = p; + if (raw_syms[i]) { + strcpy(p, raw_syms[i]); + p += strlen(raw_syms[i]) + 1; + } else { + *p++ = '\0'; + } + } + + os_backtrace_symbols_free(raw_syms); + + return 0; +} + +void backtrace_uninit(struct backtrace_ctx *ctx) +{ + /* Nothing to free - caller owns the buffer */ +} diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 006c6916af6..55f8ddcc952 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -368,6 +368,7 @@ CONFIG_TPM=y CONFIG_ERRNO_STR=y CONFIG_GETOPT=y CONFIG_ARGON2=y +CONFIG_BACKTRACE=y CONFIG_TEST_FDTDEC=y CONFIG_UNIT_TEST=y CONFIG_UT_TIME=y diff --git a/examples/rust/build.rs b/examples/rust/build.rs index 9c713ba574c..6be6a21d714 100644 --- a/examples/rust/build.rs +++ b/examples/rust/build.rs @@ -65,6 +65,9 @@ fn main() { // Fallback to just SDL2 if sdl2-config is not available println!("cargo:rustc-link-arg=-lSDL2"); } + + // Link with libbacktrace for backtrace support on sandbox + println!("cargo:rustc-link-arg=-lbacktrace"); } // For dynamic linking, link required system libraries normally diff --git a/examples/ulib/config.mk b/examples/ulib/config.mk index 993f0923b4f..5e2ffa5a4fe 100644 --- a/examples/ulib/config.mk +++ b/examples/ulib/config.mk @@ -44,4 +44,4 @@ SHARED_LDFLAGS := -L$(UBOOT_BUILD) -lu-boot -Wl,-rpath,$(UBOOT_BUILD) STATIC_LDFLAGS := -Wl,-T,$(LIB_STATIC_LDS) \ -Wl,--whole-archive $(UBOOT_BUILD)/libu-boot.a \ -Wl,--no-whole-archive \ - -lpthread -ldl $(PLATFORM_LIBS) -Wl,-z,noexecstack + -lpthread -ldl -lbacktrace $(PLATFORM_LIBS) -Wl,-z,noexecstack diff --git a/include/os.h b/include/os.h index 1b2243d46d4..ab4710fc265 100644 --- a/include/os.h +++ b/include/os.h @@ -576,6 +576,40 @@ int os_setup_signal_handlers(void); */ void os_signal_action(int sig, unsigned long pc); +/** + * os_backtrace() - get backtrace addresses + * + * Collect backtrace addresses into a caller-supplied buffer. + * + * @buffer: array to fill with return addresses + * @size: maximum number of entries in buffer + * @skip: number of stack frames to skip (0 to include os_backtrace itself) + * Return: number of addresses collected + */ +uint os_backtrace(void **buffer, uint size, uint skip); + +/** + * os_backtrace_symbols() - convert addresses to symbol strings + * + * Convert backtrace addresses to human-readable symbol strings. The returned + * array and strings are allocated with malloc() and must be freed with + * os_backtrace_symbols_free(). + * + * @buffer: array of addresses from os_backtrace() + * @count: number of addresses in buffer + * Return: array of symbol strings, or NULL on error + */ +char **os_backtrace_symbols(void *const *buffer, uint count); + +/** + * os_backtrace_symbols_free() - free symbol strings + * + * Free the array returned by os_backtrace_symbols(). + * + * @strings: array to free (may be NULL) + */ +void os_backtrace_symbols_free(char **strings); + /** * os_get_time_offset() - get time offset * From patchwork Sat Nov 29 07:59:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 772 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403262; bh=DBK1cdu1T2LOjhgMYuGuJf3dyPO1iqB0Jb+iS3uTQdI=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=o3NfJIYZZKDvElgDd3rHAOk2d7908kHpvr6qIVGdzcH3pcbbU5mlLkrL8xqKaJMKY h9vGLIV8XATH7hoAkHVQNPHwaBB5aF2edof2lhU4Sjr7BnR8NLBLxc9jVzbY30b6OI T8Z5Aq/l/MApKsMlEua9X5o0pA78ounHPoXTqASq8ZsD4R+IhsEgDj4Z0+ok9YXrKS 38hPTQVSFhrmC3mWvAfjfxzY3FDhpwnVhXwlqJeHrt3KvlzP5KG77ufjOnrGCy/tKj QCRn0sVNsTjUIqEKw8YfvjIjtRLPyIT9w6S4nlvfOAMfhZJBlNPgZCypondOBwhf5K /hHnDHYJYxSxw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AFE62687CD for ; Sat, 29 Nov 2025 01:01:02 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id OmUJySBxzxjI for ; Sat, 29 Nov 2025 01:01:02 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403262; bh=DBK1cdu1T2LOjhgMYuGuJf3dyPO1iqB0Jb+iS3uTQdI=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=o3NfJIYZZKDvElgDd3rHAOk2d7908kHpvr6qIVGdzcH3pcbbU5mlLkrL8xqKaJMKY h9vGLIV8XATH7hoAkHVQNPHwaBB5aF2edof2lhU4Sjr7BnR8NLBLxc9jVzbY30b6OI T8Z5Aq/l/MApKsMlEua9X5o0pA78ounHPoXTqASq8ZsD4R+IhsEgDj4Z0+ok9YXrKS 38hPTQVSFhrmC3mWvAfjfxzY3FDhpwnVhXwlqJeHrt3KvlzP5KG77ufjOnrGCy/tKj QCRn0sVNsTjUIqEKw8YfvjIjtRLPyIT9w6S4nlvfOAMfhZJBlNPgZCypondOBwhf5K /hHnDHYJYxSxw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9E8A9687C7 for ; Sat, 29 Nov 2025 01:01:02 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403260; bh=JTxv/Z4ICabj4VjnMTecKIEUgfAm5sSPZyWIQa+Y0kQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FCwg2uhjn2ygvs+D7fwJ0RfWQYhZRUaVie+KtVJ/X04TYCbDRXnFsrEOX4jNCUF08 boy34F1M9bwfDV723yCR890aNDKBDXI3Nh686w8pXEdrL21dHk9Nt+Lp2zbkBDZOOZ 0Ut7D6aJT/M8viVNXF+MKSbDdm8FQ4OxW26DhZHHlE3du2kTIJxhCH/waEzbJsWGyu 1rdwATDKJ2F35RLgWLz63uuc9BLPTIGmMOBHq6/gEvkiCGnK0Jtwsx94ryjtNyx4FS TFkhfD/4g+dpXaLTeR7vN4w6H5seCYKsEt+oMkP2rpRJazHFiR6tS84qHKUi73kiII 2NQQqrSZqaSRA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DF10F6875D; Sat, 29 Nov 2025 01:01:00 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id R_fs2deti7OB; Sat, 29 Nov 2025 01:01:00 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403256; bh=x8k3b+X/Jor9InFU83Dqi5+EkhoTWWHW1Thtnyn/cYM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jD++4Typj6FbrsT4LcWFZeYGMgbjuMIcQznTvQn8NBu7RJoYvjBARyThj+VmVFfFx bc4b4iUUcOgdn6vezbhrw1o34l9bXQubd2b1IdOK3ACFYiK/wk8iNL1pGx6oIqGcd2 E634iRS++wLSEH1V1peAYqkGFo0GfX13zPr97TpTrCxY4P1vn2Od2dx4v+H1z6a5NU 4ySDgUCTpwc1oSUlAxAkS2+yuLHonLECVaitW3xdsVH5H+6R5Uy8Loep+ey2P8zw/t SePHMuIei0lrLFLl0BF2NtiCkYDjrRFjeuNV3qIBbeCXjvtXink7iMxmvRxY5Ux6o2 8IrlC7p18C5tg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 6749A6876F; Sat, 29 Nov 2025 01:00:56 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 29 Nov 2025 00:59:50 -0700 Message-ID: <20251129080014.758001-6-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251129080014.758001-1-sjg@u-boot.org> References: <20251129080014.758001-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: VI76W7SBG6NJEOJEW7ECRLR5GFN22YNY X-Message-ID-Hash: VI76W7SBG6NJEOJEW7ECRLR5GFN22YNY X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 05/10] backtrace: sandbox: Link with libbacktraces List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Link with libbacktrace when CONFIG_BACKTRACE is enabled. This library is bundled with GCC and provides DWARF-based symbol resolution for backtraces. Co-developed-by: Claude Signed-off-by: Simon Glass --- arch/sandbox/config.mk | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk index f80e2ef369f..7039b256d81 100644 --- a/arch/sandbox/config.mk +++ b/arch/sandbox/config.mk @@ -3,7 +3,13 @@ PLATFORM_CPPFLAGS += -D__SANDBOX__ -U_FORTIFY_SOURCE PLATFORM_CPPFLAGS += -fPIC -ffunction-sections -fdata-sections + +ifeq ($(CONFIG_BACKTRACE),y) +GCC_LIB_DIR := $(shell $(CC) -print-file-name=) +PLATFORM_LIBS += -L$(GCC_LIB_DIR) -lbacktrace +endif PLATFORM_LIBS += -lrt + SDL_CONFIG ?= sdl2-config # Define this to avoid linking with SDL, which requires SDL libraries From patchwork Sat Nov 29 07:59:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 773 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403267; bh=XImdqhLAKbGwUMKJ3RV9sFFoiVOfFi1zXZckjnznVtA=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=sCxJ3vNOxLDcYTqwESuhe/9nNzlcx0ekYU9GHkpmxZXq0EY2q7w4aANqOxJYuKmzE FcyykvfKQ10AxN+LgAY+oIRs8a5ZQRUZ8TMMm8gBMeNcrKsaiEV5P3wBivtHKEFCYe AzEqSZaZvJfWG3F8iqu3fjqt4DvkBGAnsGiE57LTWpUDxxe5Q5HZcMzJi1Mfc53/lV AjeSKGYgSkN+hk8zjpdBZwFqcTcJACEWVt1LzuqMObHSyvu8Z7+wQ1X+t5l22tOrjW kCI2ONlXmaEWRLWtVDmQWlp5rZi2TxtKTCto4E3yJt6WVH1LdBRlK2SdAHV+Si6bbg lE/OK6UB8Y97g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2F33A687CC for ; Sat, 29 Nov 2025 01:01:07 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id JqLFO8QWRkNf for ; Sat, 29 Nov 2025 01:01:07 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403267; bh=XImdqhLAKbGwUMKJ3RV9sFFoiVOfFi1zXZckjnznVtA=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=sCxJ3vNOxLDcYTqwESuhe/9nNzlcx0ekYU9GHkpmxZXq0EY2q7w4aANqOxJYuKmzE FcyykvfKQ10AxN+LgAY+oIRs8a5ZQRUZ8TMMm8gBMeNcrKsaiEV5P3wBivtHKEFCYe AzEqSZaZvJfWG3F8iqu3fjqt4DvkBGAnsGiE57LTWpUDxxe5Q5HZcMzJi1Mfc53/lV AjeSKGYgSkN+hk8zjpdBZwFqcTcJACEWVt1LzuqMObHSyvu8Z7+wQ1X+t5l22tOrjW kCI2ONlXmaEWRLWtVDmQWlp5rZi2TxtKTCto4E3yJt6WVH1LdBRlK2SdAHV+Si6bbg lE/OK6UB8Y97g== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1E512687C7 for ; Sat, 29 Nov 2025 01:01:07 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403265; bh=fHNWTaSdtmcKHBLYaytKrrC9SuANMBxLUDiC3mmhW5M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D4hsTYNmYAMlBZG9jaYRFqICru6cuZP53EOJDiDks+DUaL5RJXcjPijMlKhaE8neC ZcvSePSy9t9m/4zGBL4nE8VWFlL1GY9wSktXvCXLRTSVT/sZpeciBBAr3MmXo5W5mC 1wRL8JLuWUSU2vY/x1py+JjXogMuogYihIA0Im3IISmhFWF7k3BlaKQd/eNLfJtLmF 6uyaGKTXrb7UBUh4RMCbac9CCzXs9+6ZYLKxB5LtVkM8Fq2J95gGrHWjm1GMJzfkTJ lQKC0o+g/3gU4Qm6dk4XWRUKQmi8mQiHv3zfFSJK1YBVkuevujIgG24/KmVmSEJkUv YznisGNVx6g7g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BED2A6875D; Sat, 29 Nov 2025 01:01:05 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id UzTnglF_gOs4; Sat, 29 Nov 2025 01:01:05 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403261; bh=tOGK7gomcAUZeCrVXFVg3QNjP8TF6fNgi+X5hiiLxSE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BHRKdxYvm0lS1T0QHvSRUZMApw38HQdku3lt6IRAD9u9SY0AYKLMycyk/aijWwC4l pbWDY9d5zy+pihLtrTPMN+7fouRQvcaD6G6oSFBbxVV4NkAfp7H1lRjjcxFhUS/rwH p3NydLFDxCeIzFweU33H6hNBfzVy4KbROiWvcE5tAl4WBSnzS4e4JeKzAUkDCej/tc 6MBYIM5WcLbTxON0GOz7gVkuxLujXZ47y1AMowHqIR5Kqs8y3xYJdE4VDe+t8H2wdR KwTaQKuhJA7SEmrnCXxVgri2IotDSvisHMjMHwz00z9HeF1KCpmYd5NgX2fpU0wLC/ ipwZBmhpQdgGw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 359CE6876F; Sat, 29 Nov 2025 01:01:01 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 29 Nov 2025 00:59:51 -0700 Message-ID: <20251129080014.758001-7-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251129080014.758001-1-sjg@u-boot.org> References: <20251129080014.758001-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: GRN57LMV26KR3YV6MZILDF7FJ37D2YFZ X-Message-ID-Hash: GRN57LMV26KR3YV6MZILDF7FJ37D2YFZ X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 06/10] backtrace: sandbox: Add -rdynamic to export symbols List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add the -rdynamic linker flag so that backtrace_symbols() can resolve function names. This is needed to show meaningful symbol names instead of just addresses. Only enable this CONFIG_BACKTRACE and CONFIG_CMDLINE are enabled, since it causes build failures with the tools-only build and sandbox_nocmdline Co-developed-by: Claude Signed-off-by: Simon Glass --- arch/sandbox/config.mk | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk index 7039b256d81..b92c259d2e3 100644 --- a/arch/sandbox/config.mk +++ b/arch/sandbox/config.mk @@ -28,6 +28,11 @@ SANITIZERS += -fsanitize=fuzzer endif KBUILD_CFLAGS += $(SANITIZERS) +# Avoid defeating linker's garbage collection +ifeq ($(CONFIG_BACKTRACE)$(CONFIG_CMDLINE),yy) +RDYNAMIC += -rdynamic +endif + cmd_u-boot__ = $(CC) -o $@ -Wl,-T u-boot.lds $(u-boot-init) \ $(KBUILD_LDFLAGS:%=-Wl,%) \ $(SANITIZERS) \ @@ -36,7 +41,7 @@ cmd_u-boot__ = $(CC) -o $@ -Wl,-T u-boot.lds $(u-boot-init) \ $(u-boot-main) \ $(u-boot-keep-syms-lto) \ -Wl,--no-whole-archive \ - $(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot.map -Wl,--gc-sections + $(RDYNAMIC) $(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot.map -Wl,--gc-sections cmd_u-boot-spl = (cd $(obj) && $(CC) -o $(SPL_BIN) -Wl,-T u-boot-spl.lds \ $(KBUILD_LDFLAGS:%=-Wl,%) \ From patchwork Sat Nov 29 07:59:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 774 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403272; bh=eQmJzYgm/QK5/qh6w6MHVEP3cwbuxAKkLgdnqxZ//iQ=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=WkKjxGNTdNngHhv7MhhWeuW6PBWmQ3Xjkh8kkoSwzUzruqyeAc2ga1AdpPpN5Xu9s qpImE3voDXUFHJWT/HkkMavyCCx+gulDyaTMmUfT4UQ2Hqj/Fd1V+T6peYjXiD/2WT +4cOsu6+CFQTv9QFG8UIrhY9IJ9jBZnqR2C4N+yh1nOIGxaMKnbaMOmLWcl11ntabg 9gKD1zQ44M3+PFXMB4JybL6VJX5N4EJLKrxR9I64X3W5LfeRZvULNvs4krSVa0jTZd UShTsSiwow3Fz3AL59F7PCWzruiguWJxR4l+p3AuB/Tfgj7t7Ol0HzS+PfT/dfBTdr Xds/Cz7+vpUXg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DEBC4687CC for ; Sat, 29 Nov 2025 01:01:12 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id cwGObkaSCzVd for ; Sat, 29 Nov 2025 01:01:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403272; bh=eQmJzYgm/QK5/qh6w6MHVEP3cwbuxAKkLgdnqxZ//iQ=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=WkKjxGNTdNngHhv7MhhWeuW6PBWmQ3Xjkh8kkoSwzUzruqyeAc2ga1AdpPpN5Xu9s qpImE3voDXUFHJWT/HkkMavyCCx+gulDyaTMmUfT4UQ2Hqj/Fd1V+T6peYjXiD/2WT +4cOsu6+CFQTv9QFG8UIrhY9IJ9jBZnqR2C4N+yh1nOIGxaMKnbaMOmLWcl11ntabg 9gKD1zQ44M3+PFXMB4JybL6VJX5N4EJLKrxR9I64X3W5LfeRZvULNvs4krSVa0jTZd UShTsSiwow3Fz3AL59F7PCWzruiguWJxR4l+p3AuB/Tfgj7t7Ol0HzS+PfT/dfBTdr Xds/Cz7+vpUXg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CDDF2687B5 for ; Sat, 29 Nov 2025 01:01:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403270; bh=TOjlvL0SbR/I4E38YWQEyxadoJ+Nf6ZwbWiR9Iwybd8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aQawj8Ala5C77o13iTNORFbDVhL/ZkcCt3HgeLOlNmvVxkRdpl7mWw/bQG88ag7Ac Gd7ZIAwn+unYOzr9Mm7K69rWz1rGYlXaxvLggIPJ5LQJXDQ7HpYtKHNjH3EOlH/thL 657Uy14z5tVQL31rR37nOtrjol9R7enaou8s6wDxefvY3S/i41b1eWIPJyfMWh9ekn v5IQsXh+k5wYf6Rwadhp6aGX2Zw1KF5VV3YOVS3Xr/IUj/+cGDcqd1sJMuSibtBn7T GLg3BFG11Z+Fy0TfCOyitauvDF9IC/pe61rKZYy7ixKj57nKOLQ0mDU5ATRVu/6rUO cuJnbgpnHoYTA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 71A3E6875D; Sat, 29 Nov 2025 01:01:10 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id 1dCrIR9Ts6Xs; Sat, 29 Nov 2025 01:01:10 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403266; bh=qb1Mc0kajM3W6R+kWvs50F8tYOHLURgYxRe94HlJzV4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qOw+YObPLOg0eZMUM1nDuWzTIWuzyxHVW8WPBY/WDvOyPNWrrgehcEJ4KfbAl7j0m 9JKvZo7r9f+8zMlsFY3cMoEjf5fNDMn8Yh606GH3E5wngpDAw35d/BJyxqe9WzkmiD 2Ghis3DtVEd/nE+QTNSnLMhYrmnAkoHHjf7dHcz32oXy3ukZ9JI6vGvPRmNd12wOno +k1G0ZdZXPSSLlWKlZNkcK1/QAIuWrtFxhiEKM9V9jLBsUS+Ghy+x8tm7RTHUs/kM6 flEZ0ZFo5gAik+Cs4nJDfWvsJkhZl7urWppLdA1D+AS5q9hbb1WJ+jY3fLc35V4HMY ZPidXIvMmsWUg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 0EEB56876F; Sat, 29 Nov 2025 01:01:05 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 29 Nov 2025 00:59:52 -0700 Message-ID: <20251129080014.758001-8-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251129080014.758001-1-sjg@u-boot.org> References: <20251129080014.758001-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 7F3H3EMXCJCPDLWIRPVIG6FWHODF46RL X-Message-ID-Hash: 7F3H3EMXCJCPDLWIRPVIG6FWHODF46RL X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 07/10] backtrace: Add a test List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add a simple test for the backtrace library. Co-developed-by: Claude Signed-off-by: Simon Glass --- test/lib/Makefile | 1 + test/lib/backtrace.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 test/lib/backtrace.c diff --git a/test/lib/Makefile b/test/lib/Makefile index 1d94d6604d5..8b322df3b45 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_$(PHASE_)UT_COMPRESSION) += compression.o ifeq ($(CONFIG_XPL_BUILD),) obj-y += abuf.o obj-y += alist.o +obj-$(CONFIG_BACKTRACE) += backtrace.o obj-$(CONFIG_EFI_LOADER) += efi_device_path.o obj-$(CONFIG_EFI_SECURE_BOOT) += efi_image_region.o obj-$(CONFIG_EFI_LOG) += efi_log.o diff --git a/test/lib/backtrace.c b/test/lib/backtrace.c new file mode 100644 index 00000000000..d9c36bbd495 --- /dev/null +++ b/test/lib/backtrace.c @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test for backtrace functions + * + * Copyright 2025 Canonical Ltd + * Written by Simon Glass + */ + +#include +#include +#include +#include +#include + +/* Test backtrace_init() and backtrace_get_syms() */ +static int lib_test_backtrace(struct unit_test_state *uts) +{ + char buf[BACKTRACE_BUFSZ]; + struct backtrace_ctx ctx; + bool found_self = false; + bool found_ut_run_list = false; + uint i; + + ut_assert(backtrace_init(&ctx, 0) > 2); + ut_assertok(backtrace_get_syms(&ctx, buf, sizeof(buf))); + + /* + * Check for known functions in the call stack. With libbacktrace + * we can find static functions too, so check for this test function. + */ + for (i = 0; i < ctx.count; i++) { + if (ctx.syms[i]) { + if (strstr(ctx.syms[i], "lib_test_backtrace")) + found_self = true; + if (strstr(ctx.syms[i], "ut_run_list")) + found_ut_run_list = true; + } + } + + ut_assert(found_self); + ut_assert(found_ut_run_list); + + backtrace_uninit(&ctx); + + return 0; +} +LIB_TEST(lib_test_backtrace, 0); From patchwork Sat Nov 29 07:59:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 775 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403277; bh=olPsufoIktCea1+cE/oW/1RyUhaXB8dgaveM/eX4lx4=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=ilbT63J3cQuPRCsdkPPZkXLkDBdP3XwntTQgWWYyVljppPaRjJ0x/1D/JWye4fTra 4oYXxhcxAV45+AnG5kbRBPynHvUfU+XeYHl0oC3yBLnYP4EDRPtnm8djz/ABWa2wRb ghZLvJlTKkY7VqkdEXiiBLmd2MEyrKj9OuLBtzKRjpjskAKJ7q3E3JL6IAKV4lFrBQ +ucx/aPYx/XjtucsuYvJyTaMCM2S8p6aN9qa+h7fkmDjQ5vgEXEJIqoT0KKm2YfvF4 3dSrRav3BgEZqCfHuOh/xjJNzkE7ODEyLWM6uFMtndqYI94c3BsdC0NahXD4FqkTvg tJW5zta5CterQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5A50B687CE for ; Sat, 29 Nov 2025 01:01:17 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id FJBzq7PO9GkU for ; Sat, 29 Nov 2025 01:01:17 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403277; bh=olPsufoIktCea1+cE/oW/1RyUhaXB8dgaveM/eX4lx4=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=ilbT63J3cQuPRCsdkPPZkXLkDBdP3XwntTQgWWYyVljppPaRjJ0x/1D/JWye4fTra 4oYXxhcxAV45+AnG5kbRBPynHvUfU+XeYHl0oC3yBLnYP4EDRPtnm8djz/ABWa2wRb ghZLvJlTKkY7VqkdEXiiBLmd2MEyrKj9OuLBtzKRjpjskAKJ7q3E3JL6IAKV4lFrBQ +ucx/aPYx/XjtucsuYvJyTaMCM2S8p6aN9qa+h7fkmDjQ5vgEXEJIqoT0KKm2YfvF4 3dSrRav3BgEZqCfHuOh/xjJNzkE7ODEyLWM6uFMtndqYI94c3BsdC0NahXD4FqkTvg tJW5zta5CterQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4A324687CC for ; Sat, 29 Nov 2025 01:01:17 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403275; bh=VGSpJIAsoG3EzRhJccC8mBg8tzbszl1LZwabbjeQ4BA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MRtwqn+1L7sh2MhK9ap2oaFE+YQYuN48gpu7aB1fRqNgBJR24ZuJyLgrwmSjJ896i AmecCFqS6hyTqh6tZrbS1uKA3ftr+iilhUhDkyMoWw/ngIrmVZlyr44l8Kt9aiAoyz RSZKLsTSiFFhchrcHU/mKJi7tdldHKdZgpzL8AjuBfrqqsl52V2Rr9kcvPg5mljI+q DGEoNoZQYkYvjwBj6aVkxJfUXmM56s0A4R9TJL5PnB7Dy2aKmQcEwy4sXn0Z+XDKW3 S+edVukoRnw7WlVgYeqOS+gZRTxOeS0mBKaCYJfXK6MoSBhH4FVW5qLraD9Ncz9jDQ r3girt3KqzNxQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 42ADE6875D; Sat, 29 Nov 2025 01:01:15 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id vkZNM6iQC_Uw; Sat, 29 Nov 2025 01:01:15 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403271; bh=N9hlwrY6N+rSS7zZQChnaq0/ZTRb/914fRITJJaMvrI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jgmP1BAt+wAwtSogw5O4OKWzWtH+qhaZ8Wl/KP1eJH57VNa/HUbcWSZ2xjIe8VLkX NjhStQYXiNOojNocJ3t5v63pApFV2LfRM8AcjpKvRTDBaYeFcjPMkfucqspGMuCZAq I0HdBHTeO/TnRLDyjNIeGS9MKH3HkNciEIdwli9pLXDag02pr7UD+J6gS9GR2JrvUm ts5PBy8kuxqE1JQ6iz359pzXEA6UmYZHAo6MG5gB/e2CM56Djxj+sOj7h40EGLoNwI I+UEgtYF0HANPlvwa+NWwdsf8lA9sFC6BMhgKHjFS4eDjudQOKq7Q+bUM2v57/j+fg 4ONH0NIPvUpbQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id BC9E06876F; Sat, 29 Nov 2025 01:01:10 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 29 Nov 2025 00:59:53 -0700 Message-ID: <20251129080014.758001-9-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251129080014.758001-1-sjg@u-boot.org> References: <20251129080014.758001-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: XV4AXNCJJ2QMR35FFGKNYF3JPTVAESHA X-Message-ID-Hash: XV4AXNCJJ2QMR35FFGKNYF3JPTVAESHA X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 08/10] backtrace: Add a command List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass 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 Signed-off-by: Simon Glass --- cmd/Kconfig | 8 ++++++ cmd/Makefile | 1 + cmd/backtrace.c | 30 ++++++++++++++++++++++ doc/usage/cmd/backtrace.rst | 51 +++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + test/cmd/Makefile | 1 + test/cmd/backtrace.c | 22 ++++++++++++++++ 7 files changed, 114 insertions(+) create mode 100644 cmd/backtrace.c create mode 100644 doc/usage/cmd/backtrace.rst create mode 100644 test/cmd/backtrace.c diff --git a/cmd/Kconfig b/cmd/Kconfig index a45df78c8fd..ff5f6f85144 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -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 diff --git a/cmd/Makefile b/cmd/Makefile index 2c6a16752bd..ebf66ea0d3c 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -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 diff --git a/cmd/backtrace.c b/cmd/backtrace.c new file mode 100644 index 00000000000..c54ac057f16 --- /dev/null +++ b/cmd/backtrace.c @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Backtrace command + * + * Copyright 2025 Canonical Ltd + * Written by Simon Glass + */ + +#include +#include + +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" +); diff --git a/doc/usage/cmd/backtrace.rst b/doc/usage/cmd/backtrace.rst new file mode 100644 index 00000000000..37acb0b3067 --- /dev/null +++ b/doc/usage/cmd/backtrace.rst @@ -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. diff --git a/doc/usage/index.rst b/doc/usage/index.rst index e8dbabfa9d2..8913c0a4f9b 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -31,6 +31,7 @@ Shell commands cmd/addrmap cmd/armffa cmd/askenv + cmd/backtrace cmd/base cmd/bdinfo cmd/bind diff --git a/test/cmd/Makefile b/test/cmd/Makefile index 4d8f93e2551..c43aefb4eb3 100644 --- a/test/cmd/Makefile +++ b/test/cmd/Makefile @@ -14,6 +14,7 @@ obj-y += exit.o obj-$(CONFIG_X86) += cpuid.o msr.o obj-$(CONFIG_CMD_ADDR_FIND) += addr_find.o obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o +obj-$(CONFIG_CMD_BACKTRACE) += backtrace.o obj-$(CONFIG_CMD_BDI) += bdinfo.o obj-$(CONFIG_CMD_BOOTSTAGE) += bootstage.o obj-$(CONFIG_CMD_CHID) += chid.o diff --git a/test/cmd/backtrace.c b/test/cmd/backtrace.c new file mode 100644 index 00000000000..2d999e20f31 --- /dev/null +++ b/test/cmd/backtrace.c @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test for backtrace command + * + * Copyright 2025 Canonical Ltd + * Written by Simon Glass + */ + +#include +#include +#include +#include + +/* Test 'backtrace' command */ +static int cmd_test_backtrace(struct unit_test_state *uts) +{ + /* for now, just run the command */ + ut_assertok(run_command("backtrace", 0)); + + return 0; +} +DM_TEST(cmd_test_backtrace, UTF_SCAN_FDT); From patchwork Sat Nov 29 07:59:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 776 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403277; bh=k5Fhn7S/BvbLOdlQga/R5iX6nZ5Uj4bb5t1fV32DR3o=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=B6b9KigVynQoBY/2NWHsNq2noXw+DCVwgxTiV7oR0e4+X1h9S+R1kebajWsMlnUfr CVQj3viPbTCY0G/nGns/UYvQWAUZMv+Bx0TBDGmvavO9uC4f034SVIUnhT4FzQcWbS tu99uP2Y9GUezTIPZhDcCC0BHHkzQMcE7zsW/3VBvZz5nSWRN3eObiydtFrfwOBRXn r6kNytRnlIiFNNr0k3awa1j61OzcwsH6M7h6L11ETGZQYneLS3ur+aA1B7gBe3R7qz wYiCMW5S8wik6zz4Y/6qGeZI44Fl37zner1FcK8+Y/cRYTTgqmeDeXmYim1jmiZaHf /cNepOsb/6kSw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C8F9D68835 for ; Sat, 29 Nov 2025 01:01:17 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id G8hGz510Y0s5 for ; Sat, 29 Nov 2025 01:01:17 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403277; bh=k5Fhn7S/BvbLOdlQga/R5iX6nZ5Uj4bb5t1fV32DR3o=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=B6b9KigVynQoBY/2NWHsNq2noXw+DCVwgxTiV7oR0e4+X1h9S+R1kebajWsMlnUfr CVQj3viPbTCY0G/nGns/UYvQWAUZMv+Bx0TBDGmvavO9uC4f034SVIUnhT4FzQcWbS tu99uP2Y9GUezTIPZhDcCC0BHHkzQMcE7zsW/3VBvZz5nSWRN3eObiydtFrfwOBRXn r6kNytRnlIiFNNr0k3awa1j61OzcwsH6M7h6L11ETGZQYneLS3ur+aA1B7gBe3R7qz wYiCMW5S8wik6zz4Y/6qGeZI44Fl37zner1FcK8+Y/cRYTTgqmeDeXmYim1jmiZaHf /cNepOsb/6kSw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B866B687D3 for ; Sat, 29 Nov 2025 01:01:17 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403276; bh=SN2jn9l4rZvanD7cTiIO7T4Lyo9ylcY0ihyjVF4Ug/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fiWLMRhnDtr14XdxMiuhiWyqDIjs44sstigNIy9CYggPZf99WAeFrO4ItV87RQHCs 4g3/M7lF0FfRuuoGuCoQ87b4Uy2LPl+jhzv+xpExKz2Fe0o/C0lviLsaVXnSnyhIlz MiYRNKdwGghgSESM/aEXwDyC4YN5uOckyWEWkk6fWLZyDx7XaHdmoRb5cWtt5X+VaO NCacK0hH+31/gdkd44rCW65cOq7yocRhe6sV4DhlN8I/pDQVnOeqTnl7dWk8yrYRJ6 LBmoxklc/7mzD4cDQrpDZ87pb3IjhZSfAo4Z0uWhBi7s/t1pusYgOQt663BXLdXCfa f9uVpVAwgwEgQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1415D687B5; Sat, 29 Nov 2025 01:01:16 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id G2NZAa2CSG0L; Sat, 29 Nov 2025 01:01:16 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403275; bh=9Ht7pSYJbW/mPRhyR1LV6bx9B4V/hNqI9rQFRbBWa2s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eZwnzpKQ1IZ1U8mbvbx3ocOELlVmPdGYLulv1063vyuWXlsEQL9IfwtVwoVmx0CXQ Nud7C9kR0EMDOhT+3862lTdo5YmvJ91RhGicLJtQ+OlOFIgU8lJ3jrLFNfRfAYdEzA R9kKNcnLx1gnTYqJ0STZgSTD37T/8bk4u/FaXo2fkXgU3QZ6u9RLson1HwHpC0Yjdb VfkNBnif2BXzNiAY0FYuhPKsf4C+aAP1k/iCnbHZhNjPEjhEc1d2ra8kGHpL2qvrfR rvHFiZ9du45w6Qy5+6XTISosJuNdbsjAMS73SGN2fZehGV9EWLHCyuckEqBpmZRG3Z mhxK1SXxJfEsQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 727756876F; Sat, 29 Nov 2025 01:01:15 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 29 Nov 2025 00:59:54 -0700 Message-ID: <20251129080014.758001-10-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251129080014.758001-1-sjg@u-boot.org> References: <20251129080014.758001-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: KL7R46ON7JH4ZRUHH6GK5CCBDLHXEVQB X-Message-ID-Hash: KL7R46ON7JH4ZRUHH6GK5CCBDLHXEVQB X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 09/10] backtrace: doc: Mention the feature List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add a short section about the backtrace feature to the sandbox docs. Co-developed-by: Claude Signed-off-by: Simon Glass --- doc/arch/sandbox/sandbox.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/doc/arch/sandbox/sandbox.rst b/doc/arch/sandbox/sandbox.rst index fc2b7c482f4..9e9b027be8b 100644 --- a/doc/arch/sandbox/sandbox.rst +++ b/doc/arch/sandbox/sandbox.rst @@ -616,6 +616,23 @@ Here is an example trace:: Hit any key to stop autoboot: 1 +Backtrace Support +----------------- + +Sandbox supports printing a backtrace of the current call stack, which can be +useful for debugging. The :doc:`backtrace <../../usage/cmd/backtrace>` command +prints a backtrace showing function names, source files, and line numbers. + +This uses the libbacktrace library (bundled with GCC) to provide detailed symbol +information, including for static functions. + +To use it, simply run:: + + => backtrace + +This command is enabled with ``CONFIG_CMD_BACKTRACE``. + + Debugging the init sequence --------------------------- From patchwork Sat Nov 29 07:59:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 777 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403282; bh=HTYoQq6kG4CioqXv5oPYav5TsC6Eh9CM4CxyOpQ8kQA=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=R+vJPgFd63uU6dofXTOWJXUGfLQIg25RVw2DU+61znhlEr5VgrEc/b0SW/TUaCDjG HJjmle7KYRxS+amo68N93TYf8gPdlOwCkDIkOoQ2NTlLDKu4WZ7QO+J6oiyEaB9//L R2nMRU68kdZdiMpEkyJwWE+A4w1DyqXXgTJEBsVgs3Ije3RmwveZ5NpOGAJD4O+8Kk AEDq1lhIKG+OUjrlyGGtjAwyOJYhgz+ONhn04FJClSnrFaMs+Sh6z4GWA6AfXO3eAi pQbBUWXsTkUscaQotGJDglKufyDIpS3sAfxWOWz7cBUA+HYTR0T7dMqnXBiIIK2LqZ gi8ZCrnfLCBfg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D48BF6876F for ; Sat, 29 Nov 2025 01:01:22 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id Y1I8AXI06aKV for ; Sat, 29 Nov 2025 01:01:22 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403282; bh=HTYoQq6kG4CioqXv5oPYav5TsC6Eh9CM4CxyOpQ8kQA=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=R+vJPgFd63uU6dofXTOWJXUGfLQIg25RVw2DU+61znhlEr5VgrEc/b0SW/TUaCDjG HJjmle7KYRxS+amo68N93TYf8gPdlOwCkDIkOoQ2NTlLDKu4WZ7QO+J6oiyEaB9//L R2nMRU68kdZdiMpEkyJwWE+A4w1DyqXXgTJEBsVgs3Ije3RmwveZ5NpOGAJD4O+8Kk AEDq1lhIKG+OUjrlyGGtjAwyOJYhgz+ONhn04FJClSnrFaMs+Sh6z4GWA6AfXO3eAi pQbBUWXsTkUscaQotGJDglKufyDIpS3sAfxWOWz7cBUA+HYTR0T7dMqnXBiIIK2LqZ gi8ZCrnfLCBfg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C2395687B5 for ; Sat, 29 Nov 2025 01:01:22 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403281; bh=n7AJkHg7i+a2j4gYmmdKZ6EOCjdwrGNTqJ0g2ghC8vo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TrNxLJiJ6hBs+fxMsk2svYwj+tWxrUdb6/2gvP4Ft/HngPOwfoXam4tvQ+0FxBOQT /CYFulwXE0lUj/ndQRrwcXQ7i5oTg3D2UPKsbwLkp5DNpZj8e31rBqbJugVMhirHdR E9CBDgVypay9zOpmi2y3T6j5ibwE1pph59IFYBD9cBtjestzIoOz6egl0r36P24qfy dULstZ756t3ieI7wXYfgj83yHtWEiVX7snoELBa6V/CerjVSkJm5S63/22ZeNzxWrv oFr0iNM1TnE2WYBW5qcdbCONr95dEr49iu/b/K3ESbuDPa1UvS4ysuc5xqPyU5xtlP bWRvknt1qfUfQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 22F4D6875D; Sat, 29 Nov 2025 01:01:21 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id eE8_-hXtawmU; Sat, 29 Nov 2025 01:01:21 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764403276; bh=GZwofWoY+65NTejZDvPDVOSFPByC7JJARvRq0iHG8rw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eryeVAnizTgb+93joEkdHT9tLT6mhoMJLU2ozihgPIwGbTZ5ILHugPckvDc9GSGUM c4qzzi5eG+cLtgFzg2ztoUjFeAbMBhegvu8Yv2pl+fA1Nyk/kFZnJFFZNoEy5R4mvA L2ktz+DeJM+vJrMUiu1VFwHjGz6BwoY7f/Lw8nyUX7Hzes9Pby/nTsgoC3PX2bgxys TwUvqCusn4HMBoBhdGBFGzRYJpa1P1OSPJ3lDZzdcU4YjQ4JWXVa8LT/XwIsAxLkej MoOVEIlIyJNRvXutTT/cOXSPLkzn0/wP86DEFbmmrCvp3ykdQzLlJg3Mjn6qspzBfw 8NKu3KBmPyXjw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 5B82B6876F; Sat, 29 Nov 2025 01:01:16 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 29 Nov 2025 00:59:55 -0700 Message-ID: <20251129080014.758001-11-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251129080014.758001-1-sjg@u-boot.org> References: <20251129080014.758001-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: FUCGMLVTBPMFOK5TSK5PCVUZGDLDDKFA X-Message-ID-Hash: FUCGMLVTBPMFOK5TSK5PCVUZGDLDDKFA X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 10/10] backtrace: Strip the source tree prefix from filenames List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Display relative paths instead of absolute paths in backtrace output, making the output cleaner and more portable across different build environments. This works by adding a SRCTREE define to lib/backtrace.c and stripping it from filenames when printing. Co-developed-by: Claude Signed-off-by: Simon Glass --- doc/usage/cmd/backtrace.rst | 18 +++++++++--------- lib/Makefile | 1 + lib/backtrace.c | 17 ++++++++++++++++- test/cmd/backtrace.c | 7 ++++++- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/doc/usage/cmd/backtrace.rst b/doc/usage/cmd/backtrace.rst index 37acb0b3067..edee54ccf22 100644 --- a/doc/usage/cmd/backtrace.rst +++ b/doc/usage/cmd/backtrace.rst @@ -29,15 +29,15 @@ 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 + backtrace_show() at lib/backtrace.c:18 + do_backtrace() at cmd/backtrace.c:17 + cmd_process() at common/command.c:637 + run_list_real() at common/cli_hush.c:1868 + parse_stream_outer() at common/cli_hush.c:3207 + parse_string_outer() at common/cli_hush.c:3257 + run_command_list() at common/cli.c:168 + sandbox_main_loop_init() at arch/sandbox/cpu/start.c:153 + board_init_r() at common/board_r.c:774 ... Configuration diff --git a/lib/Makefile b/lib/Makefile index b696e81c496..15a43b2cc5e 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -148,6 +148,7 @@ obj-$(CONFIG_LIB_UUID) += uuid.o obj-$(CONFIG_LIB_RAND) += rand.o obj-y += panic.o obj-$(CONFIG_BACKTRACE) += backtrace.o +CFLAGS_backtrace.o += -DSRCTREE='"$(srctree)/"' ifeq ($(CONFIG_XPL_BUILD),y) # SPL U-Boot may use full-printf, tiny-printf or none at all diff --git a/lib/backtrace.c b/lib/backtrace.c index e3d93b80b8a..715d7d1d05e 100644 --- a/lib/backtrace.c +++ b/lib/backtrace.c @@ -8,6 +8,21 @@ #include #include +#include + +static void print_sym(const char *sym) +{ + const char *p; + + /* Look for SRCTREE prefix in the string and skip it */ + p = strstr(sym, SRCTREE); + if (p) { + /* Print part before SRCTREE, then the rest after SRCTREE */ + printf(" %.*s%s\n", (int)(p - sym), sym, p + strlen(SRCTREE)); + } else { + printf(" %s\n", sym); + } +} int backtrace_show(void) { @@ -29,7 +44,7 @@ int backtrace_show(void) printf("backtrace: %d addresses\n", ctx.count); for (i = 0; i < ctx.count; i++) { if (ctx.syms[i]) - printf(" %s\n", ctx.syms[i]); + print_sym(ctx.syms[i]); else printf(" %p\n", ctx.addrs[i]); } diff --git a/test/cmd/backtrace.c b/test/cmd/backtrace.c index 2d999e20f31..9d55c74769e 100644 --- a/test/cmd/backtrace.c +++ b/test/cmd/backtrace.c @@ -14,9 +14,14 @@ /* Test 'backtrace' command */ static int cmd_test_backtrace(struct unit_test_state *uts) { - /* for now, just run the command */ ut_assertok(run_command("backtrace", 0)); + ut_assert_nextlinen("backtrace:"); + ut_assert_nextlinen(" backtrace_show() at lib/backtrace.c:"); + ut_assert_nextlinen(" do_backtrace() at cmd/backtrace.c:"); + ut_assert_nextlinen(" cmd_process() at common/command.c:"); + ut_assert_skip_to_linen(" cmd_test_backtrace() at test/cmd/backtrace.c:"); + return 0; } DM_TEST(cmd_test_backtrace, UTF_SCAN_FDT);