@samitouri / QOSamiQemu / commits / 8758e250bf

monitor: Reduce target-specific methods further

get_monitor_def() doesn't use any target-specific declaration anymore, move it to hmp.c to compile it once. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Dr. David Alan Gilbert <dave@treblig.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> Message-Id: <20260427080738.77138-24-philmd@linaro.org>

Philippe Mathieu-Daudé committed Jan 16, 2026 at 14:59 UTC 8758e250bf62db3e4451e9512818ac5a4332e1eb
3 files changed +36 -34
monitor/hmp-target.c
-33
@@ -57,39 +57,6 @@ HMPCommand *hmp_cmds_for_target(bool info_command)
57 return info_command ? hmp_info_cmds : hmp_cmds;
58 }
59
60 -/*
61 - * Set @pval to the value in the register identified by @name.
62 - * return 0 if OK, -1 if not found
63 - */
64 -int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
65 -{
66 - const MonitorDef *md = target_monitor_defs();
67 - CPUState *cs = mon_get_cpu(mon);
68 - void *ptr;
69 -
70 - if (cs == NULL || md == NULL) {
71 - return -1;
72 - }
73 -
74 - for(; md->name != NULL; md++) {
75 - if (hmp_compare_cmd(name, md->name)) {
76 - if (md->get_value) {
77 - *pval = md->get_value(mon, md, md->offset);
78 - } else {
79 - CPUArchState *env = mon_get_cpu_env(mon);
80 - ptr = (uint8_t *)env + md->offset;
81 - *pval = *(int32_t *)ptr;
82 - }
83 - return 0;
84 - }
85 - }
86 -
87 - if (!cs->cc->sysemu_ops->monitor_get_register) {
88 - return -1;
89 - }
90 - return cs->cc->sysemu_ops->monitor_get_register(cs, name, pval);
91 -}
92 -
60 static int
61 compare_mon_cmd(const void *a, const void *b)
62 {
monitor/hmp.c
+36
@@ -25,6 +25,7 @@
25 #include "qemu/osdep.h"
26 #include <dirent.h>
27 #include "hw/core/qdev.h"
28 +#include "hw/core/sysemu-cpu-ops.h"
29 #include "monitor-internal.h"
30 #include "monitor/hmp.h"
31 #include "monitor/hmp-target.h"
@@ -359,6 +360,8 @@ static bool gdb_get_register(Monitor *mon, int64_t *pval, const char *name)
360 static const char *pch;
361 static sigjmp_buf expr_env;
362
363 +static int get_monitor_def(Monitor *mon, int64_t *pval, const char *name);
364 +
365 static G_NORETURN G_GNUC_PRINTF(2, 3)
366 void expr_error(Monitor *mon, const char *fmt, ...)
367 {
@@ -1599,3 +1602,36 @@ void monitor_register_hmp_info_hrt(const char *name,
1602 }
1603 g_assert_not_reached();
1604 }
1605 +
1606 +/*
1607 + * Set @pval to the value in the register identified by @name.
1608 + * return 0 if OK, -1 if not found
1609 + */
1610 +static int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
1611 +{
1612 + const MonitorDef *md = target_monitor_defs();
1613 + CPUState *cs = mon_get_cpu(mon);
1614 + void *ptr;
1615 +
1616 + if (cs == NULL || md == NULL) {
1617 + return -1;
1618 + }
1619 +
1620 + for (; md->name != NULL; md++) {
1621 + if (hmp_compare_cmd(name, md->name)) {
1622 + if (md->get_value) {
1623 + *pval = md->get_value(mon, md, md->offset);
1624 + } else {
1625 + CPUArchState *env = mon_get_cpu_env(mon);
1626 + ptr = (uint8_t *)env + md->offset;
1627 + *pval = *(int32_t *)ptr;
1628 + }
1629 + return 0;
1630 + }
1631 + }
1632 +
1633 + if (!cs->cc->sysemu_ops->monitor_get_register) {
1634 + return -1;
1635 + }
1636 + return cs->cc->sysemu_ops->monitor_get_register(cs, name, pval);
1637 +}
monitor/monitor-internal.h
-1
@@ -191,7 +191,6 @@ void monitor_data_destroy_qmp(MonitorQMP *mon);
191 void coroutine_fn monitor_qmp_dispatcher_co(void *data);
192 void qmp_dispatcher_co_wake(void);
193
194 -int get_monitor_def(Monitor *mon, int64_t *pval, const char *name);
194 void handle_hmp_command(MonitorHMP *mon, const char *cmdline);
195 int hmp_compare_cmd(const char *name, const char *list);
196