On 30.04.25 06:02, Chao Liu wrote:
Make the hierarchical relationship between nodes clearer by adding characters
You should probably move most of your cover letter, including the example, in
here.
Signed-off-by: Chao Liu <lc00...@tecorigin.com>
---
system/memory.c | 34 +++++++++++++++++++++++++++-------
1 file changed, 27 insertions(+), 7 deletions(-)
diff --git a/system/memory.c b/system/memory.c
index 71434e7ad0..e723928068 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -3296,6 +3296,22 @@ typedef QTAILQ_HEAD(, MemoryRegionList)
MemoryRegionListHead;
int128_sub((size), int128_one())) : 0)
#define MTREE_INDENT " "
+#define PRINT_MTREE_COL(level) do { \
+ if (level == 0) { \
+ qemu_printf("│ "); \
+ } else { \
+ qemu_printf("│ "); \
+ } \
+} while (0)
+
+#define PRINT_MTREE_NODE(is_tail) do { \
+ if (is_tail) { \
+ qemu_printf("└── "); \
+ } else { \
+ qemu_printf("├── "); \
+ } \
+} while (0)
Just make these static inline functions.
+
static void mtree_expand_owner(const char *label, Object *obj)
{
DeviceState *dev = (DeviceState *) object_dynamic_cast(obj, TYPE_DEVICE);
@@ -3335,9 +3351,9 @@ static void mtree_print_mr_owner(const MemoryRegion *mr)
static void mtree_print_mr(const MemoryRegion *mr, unsigned int level,
hwaddr base,
MemoryRegionListHead *alias_print_queue,
- bool owner, bool display_disabled)
+ bool owner, bool display_disabled, bool is_tail)
The growing number of input booleans is a bit suboptimal, and the hard-coded
"false" in the caller doesn't necessarily make the code easier to read.
We could consider switching to a single flags variable, or maybe convert the
"bool is_tail" into an enum like.
enum mtree_node_type {
MTREE_NODE_T_INNER,
MTREE_NODE_T_TAIL,
}
e.g.
mtree_print_mr(mr, 1, 0, asi->ml_head, asi->owner, asi->disabled,
MTREE_NODE_T_INNER);
and
enum mtree_node_type mtree_node_type = MTREE_NODE_T_INNER;
...
if (ml == QTAILQ_LAST(&submr_print_queue)) {
mtree_node_type = MTREE_NODE_T_TAIL;
}
--
Cheers,
David / dhildenb