qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 5/5] monitor: rewrite 'info registers' in terms of 'x-query-regis


From: Daniel P . Berrangé
Subject: [PATCH 5/5] monitor: rewrite 'info registers' in terms of 'x-query-registers'
Date: Wed, 8 Sep 2021 11:37:11 +0100

Now that we have a QMP command 'x-query-registers', the HMP counterpart
'info registers' can be refactored to call the former.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 monitor/misc.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/monitor/misc.c b/monitor/misc.c
index ffe7966870..f0b94c3084 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -67,6 +67,7 @@
 #include "block/block-hmp-cmds.h"
 #include "qapi/qapi-commands-char.h"
 #include "qapi/qapi-commands-control.h"
+#include "qapi/qapi-commands-machine.h"
 #include "qapi/qapi-commands-migration.h"
 #include "qapi/qapi-commands-misc.h"
 #include "qapi/qapi-commands-qom.h"
@@ -301,23 +302,29 @@ int monitor_get_cpu_index(Monitor *mon)
 static void hmp_info_registers(Monitor *mon, const QDict *qdict)
 {
     bool all_cpus = qdict_get_try_bool(qdict, "cpustate_all", false);
-    CPUState *cs;
+    bool has_cpu = !all_cpus;
+    int64_t cpu = 0;
+    Error *local_err = NULL;
+    g_autoptr(RegisterInfo) info = NULL;
 
-    if (all_cpus) {
-        CPU_FOREACH(cs) {
-            monitor_printf(mon, "\nCPU#%d\n", cs->cpu_index);
-            cpu_dump_state(cs, NULL, CPU_DUMP_FPU);
-        }
-    } else {
-        cs = mon_get_cpu(mon);
+    if (has_cpu) {
+        CPUState *cs = mon_get_cpu(mon);
 
         if (!cs) {
             monitor_printf(mon, "No CPU available\n");
             return;
         }
 
-        cpu_dump_state(cs, NULL, CPU_DUMP_FPU);
+        cpu = cs->cpu_index;
+    }
+
+    info = qmp_x_query_registers(has_cpu, cpu, &local_err);
+    if (!info) {
+        error_report_err(local_err);
+        return;
     }
+
+    monitor_printf(mon, "%s", info->state);
 }
 
 static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
-- 
2.31.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]