monitor: move monitor_hmp_print*() functions to hmp.c

Those functions are only used when CONFIG_HMP, compile them out, and add
conditions for the calling code.

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-47-9227de146347@redhat.com>
This commit is contained in:
Marc-André Lureau committed 2026-08-29 12:07:45 +04:00
1 parent 856b7f1768
commit ab0d33832f
4 files changed
+57 -50

No files matched your search

+49
View File
@@ -1754,3 +1754,52 @@ static int get_monitor_def(MonitorHMP *hmp, int64_t *pval, const char *name)
}
return cs->cc->sysemu_ops->monitor_get_register(cs, name, pval);
}
int monitor_hmp_vprintf(MonitorHMP *hmp, const char *fmt, va_list ap)
{
g_autofree char *buf = g_strdup_vprintf(fmt, ap);
if (!hmp) {
return -1;
}
return monitor_puts(MONITOR(hmp), buf);
}
int monitor_hmp_printf(MonitorHMP *hmp, const char *fmt, ...)
{
int ret;
va_list ap;
va_start(ap, fmt);
ret = monitor_hmp_vprintf(hmp, fmt, ap);
va_end(ap);
return ret;
}
void monitor_hmp_printc(MonitorHMP *hmp, int c)
{
monitor_hmp_printf(hmp, "'");
switch (c) {
case '\'':
monitor_hmp_printf(hmp, "\\'");
break;
case '\\':
monitor_hmp_printf(hmp, "\\\\");
break;
case '\n':
monitor_hmp_printf(hmp, "\\n");
break;
case '\r':
monitor_hmp_printf(hmp, "\\r");
break;
default:
if (c >= 32 && c <= 126) {
monitor_hmp_printf(hmp, "%c", c);
} else {
monitor_hmp_printf(hmp, "\\x%02x", c);
}
break;
}
monitor_hmp_printf(hmp, "'");
}
-49
View File
@@ -272,55 +272,6 @@ int monitor_puts(Monitor *mon, const char *str)
return monitor_puts_locked(mon, str);
}
int monitor_hmp_vprintf(MonitorHMP *mon, const char *fmt, va_list ap)
{
g_autofree char *buf = g_strdup_vprintf(fmt, ap);
if (!mon) {
return -1;
}
return monitor_puts(MONITOR(mon), buf);
}
int monitor_hmp_printf(MonitorHMP *mon, const char *fmt, ...)
{
int ret;
va_list ap;
va_start(ap, fmt);
ret = monitor_hmp_vprintf(mon, fmt, ap);
va_end(ap);
return ret;
}
void monitor_hmp_printc(MonitorHMP *mon, int c)
{
monitor_hmp_printf(mon, "'");
switch(c) {
case '\'':
monitor_hmp_printf(mon, "\\'");
break;
case '\\':
monitor_hmp_printf(mon, "\\\\");
break;
case '\n':
monitor_hmp_printf(mon, "\\n");
break;
case '\r':
monitor_hmp_printf(mon, "\\r");
break;
default:
if (c >= 32 && c <= 126) {
monitor_hmp_printf(mon, "%c", c);
} else {
monitor_hmp_printf(mon, "\\x%02x", c);
}
break;
}
monitor_hmp_printf(mon, "'");
}
static MonitorQAPIEventConf monitor_qapi_event_conf[QAPI_EVENT__MAX] = {
/* Limit guest-triggerable events to 1 per second */
[QAPI_EVENT_RTC_CHANGE] = { 1000 * SCALE_MS },
+2 -1
View File
@@ -35,10 +35,11 @@ const char *error_guest_name;
static int G_GNUC_PRINTF(2, 0)
error_vprintf_hmp(MonitorHMP *hmp, const char *fmt, va_list ap)
{
#ifdef CONFIG_HMP
if (hmp) {
return monitor_hmp_vprintf(hmp, fmt, ap);
}
#endif
return vfprintf(stderr, fmt, ap);
}
+6
View File
@@ -27,6 +27,7 @@ int qemu_vprintf(const char *fmt, va_list ap)
/* for all monitors: QMP & HMP */
if (cur_mon) {
#ifdef CONFIG_HMP
/* don't use monitor_cur_hmp(), to avoid a second lookup */
MonitorHMP *hmp = (MonitorHMP *)
object_dynamic_cast(OBJECT(cur_mon), TYPE_MONITOR_HMP);
@@ -34,6 +35,9 @@ int qemu_vprintf(const char *fmt, va_list ap)
return -1;
}
return monitor_hmp_vprintf(hmp, fmt, ap);
#else
return -1;
#endif
}
return vprintf(fmt, ap);
}
@@ -63,6 +67,7 @@ int qemu_printf(const char *fmt, ...)
*/
int qemu_vfprintf(FILE *stream, const char *fmt, va_list ap)
{
#ifdef CONFIG_HMP
if (!stream) {
MonitorHMP *hmp = monitor_cur_hmp();
if (!hmp) {
@@ -70,6 +75,7 @@ int qemu_vfprintf(FILE *stream, const char *fmt, va_list ap)
}
return monitor_hmp_vprintf(hmp, fmt, ap);
}
#endif
return vfprintf(stream, fmt, ap);
}