malloc: Add malloc dump command to walk the heap
Add a new 'malloc dump' command that walks the dlmalloc heap from start
to end, printing each chunk's address, size (in hex), and status
(used/free/top). This is useful for debugging memory allocation issues.
When CONFIG_MCHECK_HEAP_PROTECTION is enabled, the caller string is
also shown if available.
Example output:
Heap dump: 18a1d000 - 1ea1f000
Address Size Status
----------------------------------
18a1d000 10 (chunk header)
18a1d010 90 used
18adfc30 60 <free>
18adff90 5f3f030 top
1ea1f000 end
----------------------------------
Used: c2ef0 bytes in 931 chunks
Free: 5f3f0c0 bytes in 2 chunks + top
Expand the console-record size to handle this command.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
This commit is contained in:
14
cmd/malloc.c
14
cmd/malloc.c
@@ -30,8 +30,18 @@ static int do_malloc_info(struct cmd_tbl *cmdtp, int flag, int argc,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int do_malloc_dump(struct cmd_tbl *cmdtp, int flag, int argc,
|
||||
char *const argv[])
|
||||
{
|
||||
malloc_dump();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
U_BOOT_LONGHELP(malloc,
|
||||
"info - display malloc statistics\n");
|
||||
"info - display malloc statistics\n"
|
||||
"malloc dump - dump heap chunks (address, size, status)\n");
|
||||
|
||||
U_BOOT_CMD_WITH_SUBCMDS(malloc, "malloc information", malloc_help_text,
|
||||
U_BOOT_SUBCMD_MKENT(info, 1, 1, do_malloc_info));
|
||||
U_BOOT_SUBCMD_MKENT(info, 1, 1, do_malloc_info),
|
||||
U_BOOT_SUBCMD_MKENT(dump, 1, 1, do_malloc_dump));
|
||||
|
||||
Reference in New Issue
Block a user