Chao Liu <lc00...@tecorigin.com> writes:

> Make the hierarchical relationship between nodes clearer by adding characters
>
> e.g.
>
> qemu-system-riscv64 -M virt -monitor stdio -display none
>
> ```
> (qemu) info mtree
> ...
> memory-region: system
> │  ├── 0000000000000000-ffffffffffffffff (prio 0, i/o): system
> │  │   ├── 0000000003000000-000000000300ffff (prio 0, i/o): gpex_ioport_window
> │  │   │   └── 0000000003000000-000000000300ffff (prio 0, i/o): gpex_ioport
> ...
> │  │   └── 0000000400000000-00000007ffffffff (prio 0, i/o): alias ...
> ```

info qtree and info qom-tree could perhaps use similar treatment.

> Signed-off-by: Chao Liu <lc00...@tecorigin.com>
> Reviewed-by: Qingze Zhao <zqz00...@tecorigin.com>
> Reviewed-by: Tingjian Zhang <zhan...@tecorigin.com>
> ---
>  system/memory.c | 42 ++++++++++++++++++++++++++++++++++++------
>  1 file changed, 36 insertions(+), 6 deletions(-)
>
> diff --git a/system/memory.c b/system/memory.c
> index 71434e7ad0..3a7faeb533 100644
> --- a/system/memory.c
> +++ b/system/memory.c
> @@ -3296,6 +3296,27 @@ typedef QTAILQ_HEAD(, MemoryRegionList) 
> MemoryRegionListHead;
>                             int128_sub((size), int128_one())) : 0)
>  #define MTREE_INDENT "  "
>  
> +enum mtree_node_type {
> +    MTREE_NODE_T_INNER,
> +    MTREE_NODE_T_TAIL,
> +};
> +
> +#define PRINT_MTREE_NODE(node_type) do {  \
> +    if (node_type == MTREE_NODE_T_TAIL) { \
> +        qemu_printf("└── ");              \
> +    } else {                              \
> +        qemu_printf("├── ");              \
> +    }                                     \
> +} while (0)
> +
> +#define PRINT_MTREE_COL(level) do { \
> +    if (level == 0) {               \
> +        qemu_printf("│  ");         \
> +    } else {                        \
> +        qemu_printf("│   ");        \
> +    }                               \
> +} while (0)

Printing non-ASCII Unicode characters encoded in UTF-8 assumes the
monitor / stdout uses UTF-8.  Are we happy with such an assumption?

For what it's worth, such characters are exceedingly rare in C strings
so far.  I found:

    contrib/plugins/lockstep.c:        g_string_printf(out, "Δ too high, we 
have diverged, previous insns\n");

Intentional.  This is a "plugin for debugging TCG changes" (commit
c81950a2f19).

    hw/uefi/var-service-policy.c:    fprintf(stderr, "    name ´");

This looks like a typo to me.

    tests/tcg/plugins/insn.c:                               " Δ+%"PRId64 " 
since last match,"

Intentional.  Seems to be a plugin used for testing.

    ui/sdl2.c:            status = " - Press ⌃⌥⇧G to exit grab";
    ui/sdl2.c:            status = " - Press ⌃⌥G to exit grab";

These are #ifndef CONFIG_DARWIN.

None found in QEMU proper.

The common ASCII equivalent to

    │
    ├──

is

    |
    +--

Not as pretty, but quite readable.

[...]


Reply via email to