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:
@@ -32,3 +32,23 @@ static int cmd_test_malloc_info(struct unit_test_state *uts)
|
||||
return 0;
|
||||
}
|
||||
CMD_TEST(cmd_test_malloc_info, UTF_CONSOLE);
|
||||
|
||||
/* Test 'malloc dump' command */
|
||||
static int cmd_test_malloc_dump(struct unit_test_state *uts)
|
||||
{
|
||||
/* this takes a long time to dump, with truetype enabled, so skip it */
|
||||
return -EAGAIN;
|
||||
|
||||
ut_assertok(run_command("malloc dump", 0));
|
||||
ut_assert_nextlinen("Heap dump: ");
|
||||
ut_assert_nextline("%12s %10s %s", "Address", "Size", "Status");
|
||||
ut_assert_nextline("----------------------------------");
|
||||
ut_assert_nextline("%12lx %10x (chunk header)", mem_malloc_start, 0x10);
|
||||
ut_assert_skip_to_line("----------------------------------");
|
||||
ut_assert_nextlinen("Used: ");
|
||||
ut_assert_nextlinen("Free: ");
|
||||
ut_assert_console_end();
|
||||
|
||||
return 0;
|
||||
}
|
||||
CMD_TEST(cmd_test_malloc_dump, UTF_CONSOLE);
|
||||
|
||||
Reference in New Issue
Block a user