[PATCH 2/6] monitor/hmp: Use plain uint64_t @addr argument in memory_dump()

Philippe Mathieu-Daudé posted 6 patches 1 month, 2 weeks ago
Maintainers: "Dr. David Alan Gilbert" <dave@treblig.org>
There is a newer version of this series
[PATCH 2/6] monitor/hmp: Use plain uint64_t @addr argument in memory_dump()
Posted by Philippe Mathieu-Daudé 1 month, 2 weeks ago
memory_dump() takes either hwaddr or vaddr type, depending
on the @is_physical argument. Simply use uint64_t type which
is common to both.
Pad address using field width formatting, removing the need
for the target_ulong type.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 monitor/hmp-cmds-target.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/monitor/hmp-cmds-target.c b/monitor/hmp-cmds-target.c
index 2976f986d35..c00f75eab3c 100644
--- a/monitor/hmp-cmds-target.c
+++ b/monitor/hmp-cmds-target.c
@@ -122,12 +122,13 @@ void hmp_info_registers(Monitor *mon, const QDict *qdict)
 }
 
 static void memory_dump(Monitor *mon, int count, int format, int wsize,
-                        hwaddr addr, int is_physical)
+                        uint64_t addr, int is_physical)
 {
     int l, line_size, i, max_digits, len;
     uint8_t buf[16];
     uint64_t v;
     CPUState *cs = mon_get_cpu(mon);
+    const unsigned int addr_width = is_physical ? 8 : (target_long_bits() * 2);
 
     if (!cs && (format == 'i' || !is_physical)) {
         monitor_printf(mon, "Can not dump without CPU\n");
@@ -165,11 +166,7 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize,
     }
 
     while (len > 0) {
-        if (is_physical) {
-            monitor_printf(mon, HWADDR_FMT_plx ":", addr);
-        } else {
-            monitor_printf(mon, TARGET_FMT_lx ":", (target_ulong)addr);
-        }
+        monitor_printf(mon, "%0*" PRIx64 ":", addr_width, addr);
         l = len;
         if (l > line_size)
             l = line_size;
-- 
2.52.0


Re: [PATCH 2/6] monitor/hmp: Use plain uint64_t @addr argument in memory_dump()
Posted by Dr. David Alan Gilbert 1 month, 2 weeks ago
* Philippe Mathieu-Daudé (philmd@linaro.org) wrote:
> memory_dump() takes either hwaddr or vaddr type, depending
> on the @is_physical argument. Simply use uint64_t type which
> is common to both.
> Pad address using field width formatting, removing the need
> for the target_ulong type.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  monitor/hmp-cmds-target.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/monitor/hmp-cmds-target.c b/monitor/hmp-cmds-target.c
> index 2976f986d35..c00f75eab3c 100644
> --- a/monitor/hmp-cmds-target.c
> +++ b/monitor/hmp-cmds-target.c
> @@ -122,12 +122,13 @@ void hmp_info_registers(Monitor *mon, const QDict *qdict)
>  }
>  
>  static void memory_dump(Monitor *mon, int count, int format, int wsize,
> -                        hwaddr addr, int is_physical)
> +                        uint64_t addr, int is_physical)

(It would be nice sometime for that to be a bool is_physical)
>  {

>      int l, line_size, i, max_digits, len;
>      uint8_t buf[16];
>      uint64_t v;
>      CPUState *cs = mon_get_cpu(mon);
> +    const unsigned int addr_width = is_physical ? 8 : (target_long_bits() * 2);

That's not obvious until you read later down to see how you're using it
and see it's characters/nybbles.


Reviewed-by: Dr. David Alan Gilbert <dave@treblig.org>

>      if (!cs && (format == 'i' || !is_physical)) {
>          monitor_printf(mon, "Can not dump without CPU\n");
> @@ -165,11 +166,7 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize,
>      }
>  
>      while (len > 0) {
> -        if (is_physical) {
> -            monitor_printf(mon, HWADDR_FMT_plx ":", addr);
> -        } else {
> -            monitor_printf(mon, TARGET_FMT_lx ":", (target_ulong)addr);
> -        }
> +        monitor_printf(mon, "%0*" PRIx64 ":", addr_width, addr);
>          l = len;
>          if (l > line_size)
>              l = line_size;
> -- 
> 2.52.0
> 
-- 
 -----Open up your eyes, open up your mind, open up your code -------   
/ Dr. David Alan Gilbert    |       Running GNU/Linux       | Happy  \ 
\        dave @ treblig.org |                               | In Hex /
 \ _________________________|_____ http://www.treblig.org   |_______/
Re: [PATCH 2/6] monitor/hmp: Use plain uint64_t @addr argument in memory_dump()
Posted by Manos Pitsidianakis 1 month, 2 weeks ago
On Wed, Dec 24, 2025 at 3:40 PM Philippe Mathieu-Daudé
<philmd@linaro.org> wrote:
>
> memory_dump() takes either hwaddr or vaddr type, depending
> on the @is_physical argument. Simply use uint64_t type which
> is common to both.
> Pad address using field width formatting, removing the need
> for the target_ulong type.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---

Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>

>  monitor/hmp-cmds-target.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/monitor/hmp-cmds-target.c b/monitor/hmp-cmds-target.c
> index 2976f986d35..c00f75eab3c 100644
> --- a/monitor/hmp-cmds-target.c
> +++ b/monitor/hmp-cmds-target.c
> @@ -122,12 +122,13 @@ void hmp_info_registers(Monitor *mon, const QDict *qdict)
>  }
>
>  static void memory_dump(Monitor *mon, int count, int format, int wsize,
> -                        hwaddr addr, int is_physical)
> +                        uint64_t addr, int is_physical)
>  {
>      int l, line_size, i, max_digits, len;
>      uint8_t buf[16];
>      uint64_t v;
>      CPUState *cs = mon_get_cpu(mon);
> +    const unsigned int addr_width = is_physical ? 8 : (target_long_bits() * 2);
>
>      if (!cs && (format == 'i' || !is_physical)) {
>          monitor_printf(mon, "Can not dump without CPU\n");
> @@ -165,11 +166,7 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize,
>      }
>
>      while (len > 0) {
> -        if (is_physical) {
> -            monitor_printf(mon, HWADDR_FMT_plx ":", addr);
> -        } else {
> -            monitor_printf(mon, TARGET_FMT_lx ":", (target_ulong)addr);
> -        }
> +        monitor_printf(mon, "%0*" PRIx64 ":", addr_width, addr);
>          l = len;
>          if (l > line_size)
>              l = line_size;
> --
> 2.52.0
>