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>
This commit is contained in:
Marc-André Lureau committed 2026-08-29 12:07:45 +04:00
1 parent ab0d33832f
commit b818e58ac4
12 files changed
+121 -109

No files matched your search

+6 -2
View File
@@ -21,6 +21,10 @@
#define TYPE_MONITOR_HMP "monitor-hmp"
OBJECT_DECLARE_TYPE(MonitorHMP, MonitorHMPClass, MONITOR_HMP);
MonitorHMP *monitor_cur_hmp(void);
#ifdef CONFIG_HMP
#define HMP_STUB(cmd) \
void hmp_##cmd(MonitorHMP *hmp, const QDict *qdict) \
{ \
@@ -36,8 +40,6 @@ struct MonitorDef {
void monitor_new_hmp(const char *id, const char *chardev_id,
bool use_readline, Error **errp);
MonitorHMP *monitor_cur_hmp(void);
int monitor_hmp_vprintf(MonitorHMP *mon, const char *fmt, va_list ap)
G_GNUC_PRINTF(2, 0);
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);
void hmp_info_cmma(MonitorHMP *hmp, const QDict *qdict);
void hmp_migrationmode(MonitorHMP *hmp, const QDict *qdict);
#endif /* CONFIG_HMP */
#endif
+1
View File
@@ -21,6 +21,7 @@
#include "monitor/hmp-completion.h"
#include "monitor/monitor.h"
#include "monitor/monitor-internal.h"
#include "monitor/monitor-hmp-internal.h"
#include "qapi/error.h"
#include "qapi/qapi-commands-migration.h"
#include "qapi/qapi-visit-migration.h"
+1
View File
@@ -25,6 +25,7 @@
#include "monitor/hmp.h"
#include "monitor/hmp-completion.h"
#include "monitor/monitor-internal.h"
#include "monitor/monitor-hmp-internal.h"
#include "monitor/qdev.h"
#include "qapi/error.h"
#include "qapi/qapi-commands-control.h"
+1
View File
@@ -27,6 +27,7 @@
#include "hw/core/qdev.h"
#include "hw/core/sysemu-cpu-ops.h"
#include "monitor-internal.h"
#include "monitor-hmp-internal.h"
#include "monitor/hmp.h"
#include "qobject/qdict.h"
#include "qobject/qnum.h"
+106
View File
@@ -0,0 +1,106 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#ifndef MONITOR_HMP_INTERNAL_H
#define MONITOR_HMP_INTERNAL_H
#ifdef CONFIG_HMP
#include "monitor/hmp.h"
/*
* Supported types:
*
* 'F' filename
* 'B' block device name
* 's' string (accept optional quote)
* 'S' it just appends the rest of the string (accept optional quote)
* 'O' option string of the form NAME=VALUE,...
* parsed according to QemuOptsList given by its name
* Example: 'device:O' uses qemu_device_opts.
* Restriction: only lists with empty desc are supported
* TODO lift the restriction
* 'i' 32 bit integer
* 'l' target long (32 or 64 bit)
* 'M' Non-negative target long (32 or 64 bit), in user mode the
* value is multiplied by 2^20 (think Mebibyte)
* 'o' octets (aka bytes)
* user mode accepts an optional E, e, P, p, T, t, G, g, M, m,
* K, k suffix, which multiplies the value by 2^60 for suffixes E
* and e, 2^50 for suffixes P and p, 2^40 for suffixes T and t,
* 2^30 for suffixes G and g, 2^20 for M and m, 2^10 for K and k
* 'T' double
* user mode accepts an optional ms, us, ns suffix,
* which divides the value by 1e3, 1e6, 1e9, respectively
* '/' optional gdb-like print format (like "/10x")
*
* '?' optional type (for all types, except '/')
* '.' other form of optional type (for 'i' and 'l')
* 'b' boolean
* user mode accepts "on" or "off"
* '-' optional parameter (eg. '-f'); if followed by a 's', it
* specifies an optional string param (e.g. '-fs' allows '-f foo')
*
*/
typedef struct HMPCommand {
const char *name;
const char *args_type;
const char *params;
const char *help;
const char *flags; /* p=preconfig */
void (*cmd)(MonitorHMP *hmp, const QDict *qdict);
/*
* If implementing a command that takes no arguments and simply
* prints formatted data, then leave @cmd NULL, and then set
* @cmd_info_hrt to the corresponding QMP handler that returns
* the formatted text.
*/
HumanReadableText *(*cmd_info_hrt)(Error **errp);
/*
* @sub_table is a list of 2nd level of commands. If it does not exist,
* cmd should be used. If it exists, sub_table[?].cmd should be
* used, and cmd of 1st level plays the role of help function.
*/
struct HMPCommand *sub_table;
void (*command_completion)(ReadLineState *rs, int nb_args, const char *str);
/* Keep non-pointer data at the end to minimize holes. */
/**
* @arch_bitmask: bitmask of QEMU_ARCH_* constants
* Allow to restrict the command for a particular set of
* target architectures.
*/
uint32_t arch_bitmask;
bool coroutine;
} HMPCommand;
struct MonitorHMPClass {
MonitorClass parent_class;
};
struct MonitorHMP {
Monitor parent_obj;
bool use_readline;
/*
* State used only in the thread "owning" the monitor.
* This is currently always the main thread, since
* HMP does not allow use of the I/O thread at this time.
* These members can be safely accessed without locks.
*/
ReadLineState *rs;
char *mon_cpu_path;
int reset_seen;
};
int monitor_hmp_set_cpu(MonitorHMP *hmp, int cpu_index);
void handle_hmp_command(MonitorHMP *hmp, const char *cmdline);
int hmp_compare_cmd(const char *name, const char *list);
/*
* hmp_cmds_for_target: Return array of HMPCommand entries
*
* If @info_command is true, return the particular 'info foo' commands array.
*/
HMPCommand *hmp_cmds_for_target(bool info_command);
#endif /* CONFIG_HMP */
#endif
-99
View File
@@ -27,7 +27,6 @@
#include "chardev/char-fe.h"
#include "monitor/monitor.h"
#include "monitor/hmp.h"
#include "qapi/qapi-emit-events.h"
#include "qapi/qapi-types-control.h"
#include "qapi/qapi-types-qom.h"
@@ -36,75 +35,6 @@
#include "qemu/readline.h"
#include "system/iothread.h"
/*
* Supported types:
*
* 'F' filename
* 'B' block device name
* 's' string (accept optional quote)
* 'S' it just appends the rest of the string (accept optional quote)
* 'O' option string of the form NAME=VALUE,...
* parsed according to QemuOptsList given by its name
* Example: 'device:O' uses qemu_device_opts.
* Restriction: only lists with empty desc are supported
* TODO lift the restriction
* 'i' 32 bit integer
* 'l' target long (32 or 64 bit)
* 'M' Non-negative target long (32 or 64 bit), in user mode the
* value is multiplied by 2^20 (think Mebibyte)
* 'o' octets (aka bytes)
* user mode accepts an optional E, e, P, p, T, t, G, g, M, m,
* K, k suffix, which multiplies the value by 2^60 for suffixes E
* and e, 2^50 for suffixes P and p, 2^40 for suffixes T and t,
* 2^30 for suffixes G and g, 2^20 for M and m, 2^10 for K and k
* 'T' double
* user mode accepts an optional ms, us, ns suffix,
* which divides the value by 1e3, 1e6, 1e9, respectively
* '/' optional gdb-like print format (like "/10x")
*
* '?' optional type (for all types, except '/')
* '.' other form of optional type (for 'i' and 'l')
* 'b' boolean
* user mode accepts "on" or "off"
* '-' optional parameter (eg. '-f'); if followed by a 's', it
* specifies an optional string param (e.g. '-fs' allows '-f foo')
*
*/
typedef struct HMPCommand {
const char *name;
const char *args_type;
const char *params;
const char *help;
const char *flags; /* p=preconfig */
void (*cmd)(MonitorHMP *mon, const QDict *qdict);
/*
* If implementing a command that takes no arguments and simply
* prints formatted data, then leave @cmd NULL, and then set
* @cmd_info_hrt to the corresponding QMP handler that returns
* the formatted text.
*/
HumanReadableText *(*cmd_info_hrt)(Error **errp);
/*
* @sub_table is a list of 2nd level of commands. If it does not exist,
* cmd should be used. If it exists, sub_table[?].cmd should be
* used, and cmd of 1st level plays the role of help function.
*/
struct HMPCommand *sub_table;
void (*command_completion)(ReadLineState *rs, int nb_args, const char *str);
/* Keep non-pointer data at the end to minimize holes. */
/**
* @arch_bitmask: bitmask of QEMU_ARCH_* constants
* Allow to restrict the command for a particular set of
* target architectures.
*/
uint32_t arch_bitmask;
bool coroutine;
} HMPCommand;
struct MonitorClass {
ObjectClass parent_class;
@@ -149,24 +79,6 @@ struct Monitor {
int mux_out;
};
struct MonitorHMPClass {
MonitorClass parent_class;
};
struct MonitorHMP {
Monitor parent_obj;
bool use_readline;
/*
* State used only in the thread "owning" the monitor.
* This is currently always the main thread, since
* HMP does not allow use of the I/O thread at this time.
* These members can be safely accessed without locks.
*/
ReadLineState *rs;
char *mon_cpu_path;
int reset_seen;
};
struct MonitorQMPClass {
MonitorClass parent_class;
};
@@ -209,21 +121,10 @@ int monitor_can_read(void *opaque);
void monitor_cancel_out_watch(Monitor *mon);
void monitor_list_append(Monitor *mon);
void monitor_fdsets_cleanup(void);
int monitor_hmp_set_cpu(MonitorHMP *mon, int cpu_index);
void qmp_send_response(MonitorQMP *mon, const QDict *rsp);
void monitor_data_destroy_qmp(MonitorQMP *mon);
void coroutine_fn monitor_qmp_dispatcher_co(void *data);
void qmp_dispatcher_co_wake(void);
void handle_hmp_command(MonitorHMP *hmp, const char *cmdline);
int hmp_compare_cmd(const char *name, const char *list);
/*
* hmp_cmds_for_target: Return array of HMPCommand entries
*
* If @info_command is true, return the particular 'info foo' commands array.
*/
HMPCommand *hmp_cmds_for_target(bool info_command);
#endif
+1
View File
@@ -24,6 +24,7 @@
#include "qemu/osdep.h"
#include "monitor-internal.h"
#include "monitor-hmp-internal.h"
#include "qapi/error.h"
#include "qapi/opts-visitor.h"
#include "qapi/qapi-emit-events.h"
+1
View File
@@ -16,6 +16,7 @@
#include "qemu/osdep.h"
#include "qemu/sockets.h"
#include "monitor-internal.h"
#include "monitor-hmp-internal.h"
#include "monitor/qdev.h"
#include "monitor/qmp-helpers.h"
#include "system/system.h"
+2
View File
@@ -1,6 +1,7 @@
#include "qemu/osdep.h"
#include "monitor/hmp.h"
#ifdef CONFIG_HMP
int monitor_hmp_vprintf(MonitorHMP *mon, const char *fmt, va_list ap)
{
/*
@@ -17,3 +18,4 @@ int monitor_hmp_vprintf(MonitorHMP *mon, const char *fmt, va_list ap)
}
return -1;
}
#endif
+2
View File
@@ -8,8 +8,10 @@ int monitor_get_fd(Monitor *mon, const char *name, Error **errp)
return -1;
}
#ifdef CONFIG_HMP
void monitor_new_hmp(const char *id, const char *chardev_id,
bool use_readline, Error **errp)
{
g_assert_not_reached();
}
#endif
-2
View File
@@ -24,7 +24,6 @@
#include "qapi/error.h"
#include "socket-helpers.h"
#include "monitor/monitor.h"
#include "monitor/hmp.h"
static void test_fd_is_socket_bad(void)
{
@@ -75,7 +74,6 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp)
*/
Monitor *monitor_cur(void) { return cur_mon; }
Monitor *monitor_set_cur(Coroutine *co, Monitor *mon) { abort(); }
int monitor_hmp_vprintf(MonitorHMP *mon, const char *fmt, va_list ap) { abort(); }
#ifndef _WIN32
static void test_socket_fd_pass_name_good(void)
-6
View File
@@ -9,7 +9,6 @@
#include "system/runstate.h"
#include "hw/core/qdev.h"
#include "monitor/monitor.h"
#include "monitor/hmp.h"
#include "migration/vmstate.h"
bool runstate_is_running(void)
@@ -42,11 +41,6 @@ Monitor *monitor_set_cur(Coroutine *co, Monitor *mon)
return NULL;
}
int monitor_hmp_vprintf(MonitorHMP *mon, const char *fmt, va_list ap)
{
return -1;
}
/*
* Link-time stubs for VMState symbols referenced by VNC code.
* The standalone binary never performs migration, so these are