@samitouri / QOSamiQemu / commits / 25e28a7fa1

cpus: Introduce SysemuCPUOps::monitor_get_register() hook

Allow targets to register their legacy target_get_monitor_def() in SysemuCPUOps; check it first in get_monitor_def() otherwise fall back to previous per-target helper. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20260427080738.77138-20-philmd@linaro.org>

Philippe Mathieu-Daudé committed Mar 20, 2026 at 14:17 UTC 25e28a7fa1d447e62db4d8c13f6b880aa117f069
2 files changed +16 -3
include/hw/core/sysemu-cpu-ops.h
+8
@@ -85,6 +85,14 @@ typedef struct SysemuCPUOps {
85 */
86 bool (*internal_is_big_endian)(CPUState *cpu);
87
88 + /**
89 + * @monitor_get_register: Callback to fill @pval with register @name value.
90 + * This field is legacy, use @gdb_core_xml_file
91 + * to dump registers instead.
92 + * Returns: 0 on success or negative errno on failure.
93 + */
94 + int (*monitor_get_register)(CPUState *cs, const char *name, int64_t *pval);
95 +
96 /**
97 * @legacy_vmsd: Legacy state for migration.
98 * Do not use in new targets, use #DeviceClass::vmsd instead.
monitor/hmp-target.c
+8 -3
@@ -35,6 +35,7 @@
35 #include "qapi/qapi-commands-control.h"
36 #include "qapi/qapi-commands-misc.h"
37 #include "qapi/qapi-commands-machine.h"
38 +#include "hw/core/sysemu-cpu-ops.h"
39
40 /* Make devices configuration available for use in hmp-commands*.hx templates */
41 #include CONFIG_DEVICES
@@ -85,9 +86,13 @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
86 }
87 }
88
88 - ret = target_get_monitor_def(cs, name, &tmp);
89 - if (!ret) {
90 - *pval = (target_long) tmp;
89 + if (cs->cc->sysemu_ops->monitor_get_register) {
90 + ret = cs->cc->sysemu_ops->monitor_get_register(cs, name, pval);
91 + } else {
92 + ret = target_get_monitor_def(cs, name, &tmp);
93 + if (!ret) {
94 + *pval = (target_long) tmp;
95 + }
96 }
97
98 return ret;