@samitouri / QOSamiQemu / commits / 1a618b2ddd

monitor: add 'readline' property to HMP Monitor class

This determines whether a human monitor runs with readline for interactive use, or without readline for non-interactive use by the GDB stub. Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Tested-by: Peter Krempa <pkrempa@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-ID: <20260706135824.2623960-9-berrange@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Daniel P. Berrangé committed Jul 6, 2026 at 14:57 UTC 1a618b2dddb9bd4819cf6f019c19deb25b1038a8
1 file changed +26 -1
monitor/hmp.c
+26 -1
@@ -50,12 +50,37 @@ static void monitor_hmp_finalize(Object *obj)
50 {
51 }
52
53 +static bool monitor_hmp_get_readline(Object *obj, Error **errp)
54 +{
55 + MonitorHMP *mon = MONITOR_HMP(obj);
56 +
57 + return mon->use_readline;
58 +}
59 +
60 +static void monitor_hmp_set_readline(Object *obj, bool val, Error **errp)
61 +{
62 + MonitorHMP *mon = MONITOR_HMP(obj);
63 +
64 + mon->use_readline = val;
65 +}
66 +
67 static void monitor_hmp_class_init(ObjectClass *cls, const void *data)
68 {
69 + object_class_property_add_bool(cls, "readline",
70 + monitor_hmp_get_readline,
71 + monitor_hmp_set_readline);
72 }
73
74 static void monitor_hmp_init(Object *obj)
75 {
76 + MonitorHMP *hmp = MONITOR_HMP(obj);
77 +
78 + /*
79 + * Default to common case for external HMP use,
80 + * as opposed to non-interactive internal use
81 + * from gdbstub
82 + */
83 + hmp->use_readline = true;
84 }
85
86 static void monitor_command_cb(void *opaque, const char *cmdline,
@@ -1550,6 +1575,7 @@ void monitor_new_hmp(const char *id, const char *chardev_id,
1575 id ? id : autoid,
1576 errp,
1577 "chardev", chardev_id,
1578 + "readline", use_readline ? "yes" : "no",
1579 NULL);
1580
1581 if (!obj) {
@@ -1566,7 +1592,6 @@ void monitor_new_hmp(const char *id, const char *chardev_id,
1592
1593 monitor_data_init(&mon->parent_obj, false, false, false);
1594
1569 - mon->use_readline = use_readline;
1595 if (mon->use_readline) {
1596 mon->rs = readline_init(monitor_readline_printf,
1597 monitor_readline_flush,