From 5e01e21490994a538b70ff27f1caf9e4865aeba1 Mon Sep 17 00:00:00 2001 Message-Id: From: Blue Swirl Date: Sun, 11 Sep 2011 20:22:05 +0000 Subject: [PATCH] memory: simple memory tree printer Add a monitor command 'info mtree' to show the memory hierarchy. Signed-off-by: Blue Swirl --- memory.c | 27 +++++++++++++++++++++++++++ memory.h | 2 ++ monitor.c | 7 +++++++ 3 files changed, 36 insertions(+), 0 deletions(-) diff --git a/memory.c b/memory.c index 57f0fa4..0bcef84 100644 --- a/memory.c +++ b/memory.c @@ -17,6 +17,7 @@ #include "bitops.h" #include "kvm.h" #include +#include "monitor.h" unsigned memory_region_transaction_depth = 0; @@ -1253,3 +1254,29 @@ void set_system_io_map(MemoryRegion *mr) address_space_io.root = mr; memory_region_update_topology(); } + +static void mtree_print_mr(Monitor *mon, MemoryRegion *mr, unsigned int level) +{ + MemoryRegion *submr; + unsigned int i; + + for (i = 0; i < level; i++) { + monitor_printf(mon, "-"); + } + monitor_printf(mon, "%s addr " TARGET_FMT_plx " off " TARGET_FMT_plx + " size %" PRIx64 "\n", + mr->name, mr->addr, mr->offset, mr->size); + + QTAILQ_FOREACH(submr, &mr->subregions, subregions_link) { + mtree_print_mr(mon, submr, level + 1); + } +} + +void mtree_info(Monitor *mon) +{ + monitor_printf(mon, "memory\n"); + mtree_print_mr(mon, address_space_memory.root, 0); + + monitor_printf(mon, "I/O\n"); + mtree_print_mr(mon, address_space_io.root, 0); +} diff --git a/memory.h b/memory.h index 06b83ae..09d8e29 100644 --- a/memory.h +++ b/memory.h @@ -500,6 +500,8 @@ void memory_region_transaction_begin(void); */ void memory_region_transaction_commit(void); +void mtree_info(Monitor *mon); + #endif #endif diff --git a/monitor.c b/monitor.c index 03ae997..0302446 100644 --- a/monitor.c +++ b/monitor.c @@ -2968,6 +2968,13 @@ static const mon_cmd_t info_cmds[] = { }, #endif { + .name = "mtree", + .args_type = "", + .params = "", + .help = "show memory tree", + .mhandler.info = mtree_info, + }, + { .name = "jit", .args_type = "", .params = "", -- 1.7.2.5