From patchwork Sat Mar 14 23:15:54 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1976 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=1773530253; bh=t8209i1v4/yArbq9lPzKTuM/60Zid2S416JV2NT0f9E=; 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=Wj6NL8duWGRUVl7GkecrZRnVOyP/5TrEELMtQ3t06VnRkA4JHxCSHNlg19hB7HnDC 1u3bWvJq5pAlakrT3hFr4c9caHBAhjebVp5MHPcVntRp56lHkSvQ812ao4SoISCIS4 rKG5Kw2jj+Nctj6Uiu+80s115BMUr6hzmCvDzSEb6WQ8zptCH0nt4uV4MYmiPzC2bv 4XVi7t39Vqhda4TxuIGdYsfNQT7Wz4MJIYRWL8UV9fwEVH1nVj1SsZyt20EnT4anVt KsqRt8WY0X6jypNmM5grJR40bb0K5prT5WR4Qi9/XgneEAHtKDvqgtyA0auyIP74wG 4emAMUnymX//Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4778C6A042 for ; Sat, 14 Mar 2026 17:17:33 -0600 (MDT) 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 jH694yIR1xMU for ; Sat, 14 Mar 2026 17:17:33 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773530252; bh=t8209i1v4/yArbq9lPzKTuM/60Zid2S416JV2NT0f9E=; 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=D3d6PlQFhxptd1dT1KW+ipeGL24ItPBip2EpwPBZAXRiXzJEBUvvOnPShKwSoZNm6 Z/UoWBO9h86fQcln0H1ORcd8/kb3x/7qwtw2jAp+P+GPbli/Yb1MgJph7glJR9WyWC hH2epU9tYZOk2updcr4wMS3iXfiMWSWz0iHMtVePasR6DEqQK65yLeGx87rhQYF4fe +A9Pipfe+1LsT8h+D9irKSxiGekFcfzGGxVGx/FjNGwHRigQZHkbop6HJRL2IJESPb E5d75qMGuEaw1HEyg3MX+XQ+DLuCiy4PR6+Iuq4EoJI38c4kVHv6hs2a/vai+Ad4Hk nhgMfMhIEbjsw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D46716A036 for ; Sat, 14 Mar 2026 17:17:32 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773530250; bh=xHHeRURUh/kKkfxdFhY6yDkCpQTcstT94tRYzzK/Us8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IOr4tlPbJJ/0nk+O828N9+KxvHCaBDCIpWDunfu/GPruADDXjzR2uYuUqRHqJxkdv ELPnQ8YEsv5OJnc/yyx1/afFYNEYqqYyxDpgjvS2K5u84jOcSH0g6/DHYrXH9erOeK eoINQMsojEjF9aepMie3bQ9gGbQS0JABvPONquC9t6rmYQ4Wv+w2AI58yaU/Xn+pME RcBf/YY9VZbGtJ3iw8WT+lRMtvAYxya2qeFhjgvgRUYlzy5jqyDS8lCl1/YPGHvZ+N BuxfEPSqcmTzdzOuT73XbdDjrMtSeavkgF6ek7hHIQQkmd4lB4bk3h0zpBcHW2uWIy ULuMcHja2loAg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 128E869ECF; Sat, 14 Mar 2026 17:17:30 -0600 (MDT) 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 kX-xQxqZfWaJ; Sat, 14 Mar 2026 17:17:29 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773530249; bh=lHtDSCIhTNxayIm1o3gYvn37XP6NQfsUr0aJbYCKJcE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ofbE7q8EbcAIBob35L0+iiF39hwNPnW7tj4RWK8t0GogwWBvFeaTecc67IGeCaRri WFEOl2kfZAtB2jmNhnrHCp4PWDCHFwRptYpH4Cl3lSzXaKWm0nm1bzKD19bIzNExrI Ktu4YebFiVjflnlC4W+xPqBA9aqSVWjtO9RuGNUGZ6sasG5OlQy9qE/TD5yD3bp8fw YR3/z+n08e/3gNmi4EK8/IYPK/wFwpRYwsawyCCWIzbZnglUGRNhQasXwgQJKxxchi KeGq1jZL2RbYqVc2lEXDTWii7oM6q8BDbqf+IA3ggbOcIVZkIf2Wtms3Mz+JntCRCe 6o9YsuGxkuRww== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 8376B6A036; Sat, 14 Mar 2026 17:17:29 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Sat, 14 Mar 2026 17:15:54 -0600 Message-ID: <20260314231618.338113-4-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260314231618.338113-1-sjg@u-boot.org> References: <20260314231618.338113-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: DBTTNQNJ4SMPLF7GQCPZYS7LBQF6HAWZ X-Message-ID-Hash: DBTTNQNJ4SMPLF7GQCPZYS7LBQF6HAWZ 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: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 03/19] sandbox: Add a command-line option to dump malloc state 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 --malloc_dump option that writes the heap dump to a file on exit. This is useful for debugging memory leaks in test sessions. The dump is written from state_uninit() which runs on clean shutdown (poweroff, reset). The prototype for malloc_dump_to_file() comes from os.h, avoiding the asm/malloc.h conflict. Signed-off-by: Simon Glass --- arch/sandbox/cpu/start.c | 9 +++++++++ arch/sandbox/cpu/state.c | 3 +++ arch/sandbox/include/asm/state.h | 1 + 3 files changed, 13 insertions(+) diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index 7c9f0a99654..caa9b61dcd9 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -553,6 +553,15 @@ static int sandbox_cmdline_cb_pager_bypass(struct sandbox_state *state, SANDBOX_CMDLINE_OPT_SHORT(pager_bypass, 'P', 0, "Enable pager bypass mode"); +static int sandbox_cmdline_cb_malloc_dump(struct sandbox_state *state, + const char *arg) +{ + state->malloc_dump_fname = arg; + + return 0; +} +SANDBOX_CMDLINE_OPT(malloc_dump, 1, "Write malloc dump to file on exit"); + static int sandbox_cmdline_cb_bind(struct sandbox_state *state, const char *arg) { if (state->num_binds >= SB_MAX_BINDS) { diff --git a/arch/sandbox/cpu/state.c b/arch/sandbox/cpu/state.c index e492855755b..fd31d93c500 100644 --- a/arch/sandbox/cpu/state.c +++ b/arch/sandbox/cpu/state.c @@ -544,6 +544,9 @@ int state_uninit(void) if (state->jumped_fname) os_unlink(state->jumped_fname); + if (state->malloc_dump_fname) + malloc_dump_to_file(state->malloc_dump_fname); + /* Disable tracing before unmapping RAM */ if (IS_ENABLED(CONFIG_TRACE)) trace_set_enabled(0); diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h index 001d780aec8..8707d798d8d 100644 --- a/arch/sandbox/include/asm/state.h +++ b/arch/sandbox/include/asm/state.h @@ -184,6 +184,7 @@ struct sandbox_state { int video_test; /* ms to wait before next assert */ const char *video_frames_dir; /* Directory to write video frames */ int video_frame_count; /* Number of frames written */ + const char *malloc_dump_fname; /* File to write malloc dump on exit */ /* Pointer to information for each SPI bus/cs */ struct sandbox_spi_info spi[CONFIG_SANDBOX_SPI_MAX_BUS]