monitor: move HMP-specific to monitor-hmp-internal.h
Move HMP-specific declarations to its own CONFIG_HMP guarded header. Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Reviewed-by: Dr. David Alan Gilbert <dave@treblig.org> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260828-qemu-no-hmp-v5-48-9227de146347@redhat.com>
Marc-André Lureau committed
Aug 28, 2026 at 16:04 UTC
b818e58ac419a41735d480da5c1de8a104e7f59c
12 files changed
+121
-109
include/monitor/hmp.h
+6
-2
@@ -21,6 +21,10 @@
21
#define TYPE_MONITOR_HMP "monitor-hmp"
22
OBJECT_DECLARE_TYPE(MonitorHMP, MonitorHMPClass, MONITOR_HMP);
23
24
+MonitorHMP *monitor_cur_hmp(void);
25
+
26
+#ifdef CONFIG_HMP
27
+
28
#define HMP_STUB(cmd) \
29
void hmp_##cmd(MonitorHMP *hmp, const QDict *qdict) \
30
{ \
@@ -36,8 +40,6 @@ struct MonitorDef {
40
void monitor_new_hmp(const char *id, const char *chardev_id,
41
bool use_readline, Error **errp);
42
39
-MonitorHMP *monitor_cur_hmp(void);
40
-
43
int monitor_hmp_vprintf(MonitorHMP *mon, const char *fmt, va_list ap)
44
G_GNUC_PRINTF(2, 0);
45
int monitor_hmp_printf(MonitorHMP *mon, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
@@ -218,4 +220,6 @@ void hmp_info_skeys(MonitorHMP *hmp, const QDict *qdict);
220
void hmp_info_cmma(MonitorHMP *hmp, const QDict *qdict);
221
void hmp_migrationmode(MonitorHMP *hmp, const QDict *qdict);
222
223
+#endif /* CONFIG_HMP */
224
+
225
#endif
migration/migration-hmp-cmds.c
+1
@@ -21,6 +21,7 @@
21
#include "monitor/hmp-completion.h"
22
#include "monitor/monitor.h"
23
#include "monitor/monitor-internal.h"
24
+#include "monitor/monitor-hmp-internal.h"
25
#include "qapi/error.h"
26
#include "qapi/qapi-commands-migration.h"
27
#include "qapi/qapi-visit-migration.h"
monitor/hmp-cmds.c
+1
@@ -25,6 +25,7 @@
25
#include "monitor/hmp.h"
26
#include "monitor/hmp-completion.h"
27
#include "monitor/monitor-internal.h"
28
+#include "monitor/monitor-hmp-internal.h"
29
#include "monitor/qdev.h"
30
#include "qapi/error.h"
31
#include "qapi/qapi-commands-control.h"
monitor/hmp.c
+1
@@ -27,6 +27,7 @@
27
#include "hw/core/qdev.h"
28
#include "hw/core/sysemu-cpu-ops.h"
29
#include "monitor-internal.h"
30
+#include "monitor-hmp-internal.h"
31
#include "monitor/hmp.h"
32
#include "qobject/qdict.h"
33
#include "qobject/qnum.h"
monitor/monitor-hmp-internal.h
new
+106
@@ -0,0 +1,106 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
2
+
3
+#ifndef MONITOR_HMP_INTERNAL_H
4
+#define MONITOR_HMP_INTERNAL_H
5
+
6
+#ifdef CONFIG_HMP
7
+#include "monitor/hmp.h"
8
+/*
9
+ * Supported types:
10
+ *
11
+ * 'F' filename
12
+ * 'B' block device name
13
+ * 's' string (accept optional quote)
14
+ * 'S' it just appends the rest of the string (accept optional quote)
15
+ * 'O' option string of the form NAME=VALUE,...
16
+ * parsed according to QemuOptsList given by its name
17
+ * Example: 'device:O' uses qemu_device_opts.
18
+ * Restriction: only lists with empty desc are supported
19
+ * TODO lift the restriction
20
+ * 'i' 32 bit integer
21
+ * 'l' target long (32 or 64 bit)
22
+ * 'M' Non-negative target long (32 or 64 bit), in user mode the
23
+ * value is multiplied by 2^20 (think Mebibyte)
24
+ * 'o' octets (aka bytes)
25
+ * user mode accepts an optional E, e, P, p, T, t, G, g, M, m,
26
+ * K, k suffix, which multiplies the value by 2^60 for suffixes E
27
+ * and e, 2^50 for suffixes P and p, 2^40 for suffixes T and t,
28
+ * 2^30 for suffixes G and g, 2^20 for M and m, 2^10 for K and k
29
+ * 'T' double
30
+ * user mode accepts an optional ms, us, ns suffix,
31
+ * which divides the value by 1e3, 1e6, 1e9, respectively
32
+ * '/' optional gdb-like print format (like "/10x")
33
+ *
34
+ * '?' optional type (for all types, except '/')
35
+ * '.' other form of optional type (for 'i' and 'l')
36
+ * 'b' boolean
37
+ * user mode accepts "on" or "off"
38
+ * '-' optional parameter (eg. '-f'); if followed by a 's', it
39
+ * specifies an optional string param (e.g. '-fs' allows '-f foo')
40
+ *
41
+ */
42
+
43
+typedef struct HMPCommand {
44
+ const char *name;
45
+ const char *args_type;
46
+ const char *params;
47
+ const char *help;
48
+ const char *flags; /* p=preconfig */
49
+ void (*cmd)(MonitorHMP *hmp, const QDict *qdict);
50
+ /*
51
+ * If implementing a command that takes no arguments and simply
52
+ * prints formatted data, then leave @cmd NULL, and then set
53
+ * @cmd_info_hrt to the corresponding QMP handler that returns
54
+ * the formatted text.
55
+ */
56
+ HumanReadableText *(*cmd_info_hrt)(Error **errp);
57
+ /*
58
+ * @sub_table is a list of 2nd level of commands. If it does not exist,
59
+ * cmd should be used. If it exists, sub_table[?].cmd should be
60
+ * used, and cmd of 1st level plays the role of help function.
61
+ */
62
+ struct HMPCommand *sub_table;
63
+ void (*command_completion)(ReadLineState *rs, int nb_args, const char *str);
64
+
65
+ /* Keep non-pointer data at the end to minimize holes. */
66
+
67
+ /**
68
+ * @arch_bitmask: bitmask of QEMU_ARCH_* constants
69
+ * Allow to restrict the command for a particular set of
70
+ * target architectures.
71
+ */
72
+ uint32_t arch_bitmask;
73
+ bool coroutine;
74
+} HMPCommand;
75
+
76
+struct MonitorHMPClass {
77
+ MonitorClass parent_class;
78
+};
79
+
80
+struct MonitorHMP {
81
+ Monitor parent_obj;
82
+ bool use_readline;
83
+ /*
84
+ * State used only in the thread "owning" the monitor.
85
+ * This is currently always the main thread, since
86
+ * HMP does not allow use of the I/O thread at this time.
87
+ * These members can be safely accessed without locks.
88
+ */
89
+ ReadLineState *rs;
90
+ char *mon_cpu_path;
91
+ int reset_seen;
92
+};
93
+
94
+int monitor_hmp_set_cpu(MonitorHMP *hmp, int cpu_index);
95
+void handle_hmp_command(MonitorHMP *hmp, const char *cmdline);
96
+int hmp_compare_cmd(const char *name, const char *list);
97
+
98
+/*
99
+ * hmp_cmds_for_target: Return array of HMPCommand entries
100
+ *
101
+ * If @info_command is true, return the particular 'info foo' commands array.
102
+ */
103
+HMPCommand *hmp_cmds_for_target(bool info_command);
104
+
105
+#endif /* CONFIG_HMP */
106
+#endif
monitor/monitor-internal.h
-99
@@ -27,7 +27,6 @@
27
28
#include "chardev/char-fe.h"
29
#include "monitor/monitor.h"
30
-#include "monitor/hmp.h"
30
#include "qapi/qapi-emit-events.h"
31
#include "qapi/qapi-types-control.h"
32
#include "qapi/qapi-types-qom.h"
@@ -36,75 +35,6 @@
35
#include "qemu/readline.h"
36
#include "system/iothread.h"
37
39
-/*
40
- * Supported types:
41
- *
42
- * 'F' filename
43
- * 'B' block device name
44
- * 's' string (accept optional quote)
45
- * 'S' it just appends the rest of the string (accept optional quote)
46
- * 'O' option string of the form NAME=VALUE,...
47
- * parsed according to QemuOptsList given by its name
48
- * Example: 'device:O' uses qemu_device_opts.
49
- * Restriction: only lists with empty desc are supported
50
- * TODO lift the restriction
51
- * 'i' 32 bit integer
52
- * 'l' target long (32 or 64 bit)
53
- * 'M' Non-negative target long (32 or 64 bit), in user mode the
54
- * value is multiplied by 2^20 (think Mebibyte)
55
- * 'o' octets (aka bytes)
56
- * user mode accepts an optional E, e, P, p, T, t, G, g, M, m,
57
- * K, k suffix, which multiplies the value by 2^60 for suffixes E
58
- * and e, 2^50 for suffixes P and p, 2^40 for suffixes T and t,
59
- * 2^30 for suffixes G and g, 2^20 for M and m, 2^10 for K and k
60
- * 'T' double
61
- * user mode accepts an optional ms, us, ns suffix,
62
- * which divides the value by 1e3, 1e6, 1e9, respectively
63
- * '/' optional gdb-like print format (like "/10x")
64
- *
65
- * '?' optional type (for all types, except '/')
66
- * '.' other form of optional type (for 'i' and 'l')
67
- * 'b' boolean
68
- * user mode accepts "on" or "off"
69
- * '-' optional parameter (eg. '-f'); if followed by a 's', it
70
- * specifies an optional string param (e.g. '-fs' allows '-f foo')
71
- *
72
- */
73
-
74
-typedef struct HMPCommand {
75
- const char *name;
76
- const char *args_type;
77
- const char *params;
78
- const char *help;
79
- const char *flags; /* p=preconfig */
80
- void (*cmd)(MonitorHMP *mon, const QDict *qdict);
81
- /*
82
- * If implementing a command that takes no arguments and simply
83
- * prints formatted data, then leave @cmd NULL, and then set
84
- * @cmd_info_hrt to the corresponding QMP handler that returns
85
- * the formatted text.
86
- */
87
- HumanReadableText *(*cmd_info_hrt)(Error **errp);
88
- /*
89
- * @sub_table is a list of 2nd level of commands. If it does not exist,
90
- * cmd should be used. If it exists, sub_table[?].cmd should be
91
- * used, and cmd of 1st level plays the role of help function.
92
- */
93
- struct HMPCommand *sub_table;
94
- void (*command_completion)(ReadLineState *rs, int nb_args, const char *str);
95
-
96
- /* Keep non-pointer data at the end to minimize holes. */
97
-
98
- /**
99
- * @arch_bitmask: bitmask of QEMU_ARCH_* constants
100
- * Allow to restrict the command for a particular set of
101
- * target architectures.
102
- */
103
- uint32_t arch_bitmask;
104
- bool coroutine;
105
-} HMPCommand;
106
-
107
-
38
struct MonitorClass {
39
ObjectClass parent_class;
40
@@ -149,24 +79,6 @@ struct Monitor {
79
int mux_out;
80
};
81
152
-struct MonitorHMPClass {
153
- MonitorClass parent_class;
154
-};
155
-
156
-struct MonitorHMP {
157
- Monitor parent_obj;
158
- bool use_readline;
159
- /*
160
- * State used only in the thread "owning" the monitor.
161
- * This is currently always the main thread, since
162
- * HMP does not allow use of the I/O thread at this time.
163
- * These members can be safely accessed without locks.
164
- */
165
- ReadLineState *rs;
166
- char *mon_cpu_path;
167
- int reset_seen;
168
-};
169
-
82
struct MonitorQMPClass {
83
MonitorClass parent_class;
84
};
@@ -209,21 +121,10 @@ int monitor_can_read(void *opaque);
121
void monitor_cancel_out_watch(Monitor *mon);
122
void monitor_list_append(Monitor *mon);
123
void monitor_fdsets_cleanup(void);
212
-int monitor_hmp_set_cpu(MonitorHMP *mon, int cpu_index);
124
125
void qmp_send_response(MonitorQMP *mon, const QDict *rsp);
126
void monitor_data_destroy_qmp(MonitorQMP *mon);
127
void coroutine_fn monitor_qmp_dispatcher_co(void *data);
128
void qmp_dispatcher_co_wake(void);
129
219
-void handle_hmp_command(MonitorHMP *hmp, const char *cmdline);
220
-int hmp_compare_cmd(const char *name, const char *list);
221
-
222
-/*
223
- * hmp_cmds_for_target: Return array of HMPCommand entries
224
- *
225
- * If @info_command is true, return the particular 'info foo' commands array.
226
- */
227
-HMPCommand *hmp_cmds_for_target(bool info_command);
228
-
130
#endif
monitor/monitor.c
+1
@@ -24,6 +24,7 @@
24
25
#include "qemu/osdep.h"
26
#include "monitor-internal.h"
27
+#include "monitor-hmp-internal.h"
28
#include "qapi/error.h"
29
#include "qapi/opts-visitor.h"
30
#include "qapi/qapi-emit-events.h"
monitor/qmp-cmds.c
+1
@@ -16,6 +16,7 @@
16
#include "qemu/osdep.h"
17
#include "qemu/sockets.h"
18
#include "monitor-internal.h"
19
+#include "monitor-hmp-internal.h"
20
#include "monitor/qdev.h"
21
#include "monitor/qmp-helpers.h"
22
#include "system/system.h"
stubs/monitor-core.c
+2
@@ -1,6 +1,7 @@
1
#include "qemu/osdep.h"
2
#include "monitor/hmp.h"
3
4
+#ifdef CONFIG_HMP
5
int monitor_hmp_vprintf(MonitorHMP *mon, const char *fmt, va_list ap)
6
{
7
/*
@@ -17,3 +18,4 @@ int monitor_hmp_vprintf(MonitorHMP *mon, const char *fmt, va_list ap)
18
}
19
return -1;
20
}
21
+#endif
stubs/monitor-internal.c
+2
@@ -8,8 +8,10 @@ int monitor_get_fd(Monitor *mon, const char *name, Error **errp)
8
return -1;
9
}
10
11
+#ifdef CONFIG_HMP
12
void monitor_new_hmp(const char *id, const char *chardev_id,
13
bool use_readline, Error **errp)
14
{
15
g_assert_not_reached();
16
}
17
+#endif
tests/unit/test-util-sockets.c
-2
@@ -24,7 +24,6 @@
24
#include "qapi/error.h"
25
#include "socket-helpers.h"
26
#include "monitor/monitor.h"
27
-#include "monitor/hmp.h"
27
28
static void test_fd_is_socket_bad(void)
29
{
@@ -75,7 +74,6 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp)
74
*/
75
Monitor *monitor_cur(void) { return cur_mon; }
76
Monitor *monitor_set_cur(Coroutine *co, Monitor *mon) { abort(); }
78
-int monitor_hmp_vprintf(MonitorHMP *mon, const char *fmt, va_list ap) { abort(); }
77
78
#ifndef _WIN32
79
static void test_socket_fd_pass_name_good(void)
tools/qemu-vnc/stubs.c
-6
@@ -9,7 +9,6 @@
9
#include "system/runstate.h"
10
#include "hw/core/qdev.h"
11
#include "monitor/monitor.h"
12
-#include "monitor/hmp.h"
12
#include "migration/vmstate.h"
13
14
bool runstate_is_running(void)
@@ -42,11 +41,6 @@ Monitor *monitor_set_cur(Coroutine *co, Monitor *mon)
41
return NULL;
42
}
43
45
-int monitor_hmp_vprintf(MonitorHMP *mon, const char *fmt, va_list ap)
46
-{
47
- return -1;
48
-}
49
-
44
/*
45
* Link-time stubs for VMState symbols referenced by VNC code.
46
* The standalone binary never performs migration, so these are