[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 34/48] monitor: allow register hmp commands
From: |
Paolo Bonzini |
Subject: |
[PULL 34/48] monitor: allow register hmp commands |
Date: |
Thu, 8 Jul 2021 17:17:34 +0200 |
From: Gerd Hoffmann <kraxel@redhat.com>
Allow commands having a NULL cmd pointer, add a function to set the
pointer later. Use case: allow modules implement hmp commands.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Jose R. Ziviani <jziviani@suse.de>
Message-Id: <20210624103836.2382472-31-kraxel@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
include/monitor/monitor.h | 3 +++
monitor/hmp.c | 7 +++++++
monitor/misc.c | 16 ++++++++++++++++
3 files changed, 26 insertions(+)
diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index 1211d6e6d6..1a8a369b50 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -51,4 +51,7 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags);
void monitor_fdset_dup_fd_remove(int dup_fd);
int64_t monitor_fdset_dup_fd_find(int dup_fd);
+void monitor_register_hmp(const char *name, bool info,
+ void (*cmd)(Monitor *mon, const QDict *qdict));
+
#endif /* MONITOR_H */
diff --git a/monitor/hmp.c b/monitor/hmp.c
index 6c0b33a0b1..d50c3124e1 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -1089,6 +1089,13 @@ void handle_hmp_command(MonitorHMP *mon, const char
*cmdline)
return;
}
+ if (!cmd->cmd) {
+ /* FIXME: is it useful to try autoload modules here ??? */
+ monitor_printf(&mon->common, "Command \"%.*s\" is not available.\n",
+ (int)(cmdline - cmd_start), cmd_start);
+ return;
+ }
+
qdict = monitor_parse_arguments(&mon->common, &cmdline, cmd);
if (!qdict) {
while (cmdline > cmd_start && qemu_isspace(cmdline[-1])) {
diff --git a/monitor/misc.c b/monitor/misc.c
index 1539e18557..ad476c6e51 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -1974,6 +1974,22 @@ static void sortcmdlist(void)
compare_mon_cmd);
}
+void monitor_register_hmp(const char *name, bool info,
+ void (*cmd)(Monitor *mon, const QDict *qdict))
+{
+ HMPCommand *table = info ? hmp_info_cmds : hmp_cmds;
+
+ while (table->name != NULL) {
+ if (strcmp(table->name, name) == 0) {
+ g_assert(table->cmd == NULL);
+ table->cmd = cmd;
+ return;
+ }
+ table++;
+ }
+ g_assert_not_reached();
+}
+
void monitor_init_globals(void)
{
monitor_init_globals_core();
--
2.31.1
- [PULL 21/48] modules: add tracepoints, (continued)
- [PULL 21/48] modules: add tracepoints, Paolo Bonzini, 2021/07/08
- [PULL 22/48] modules: check arch and block load on mismatch, Paolo Bonzini, 2021/07/08
- [PULL 29/48] accel: autoload modules, Paolo Bonzini, 2021/07/08
- [PULL 28/48] modules: hook up modules.h to docs build, Paolo Bonzini, 2021/07/08
- [PULL 30/48] accel: add qtest module annotations, Paolo Bonzini, 2021/07/08
- [PULL 32/48] accel: add tcg module annotations, Paolo Bonzini, 2021/07/08
- [PULL 35/48] usb: drop usb_host_dev_is_scsi_storage hook, Paolo Bonzini, 2021/07/08
- [PULL 37/48] usb: build usb-host as module, Paolo Bonzini, 2021/07/08
- [PULL 34/48] monitor: allow register hmp commands,
Paolo Bonzini <=
- [PULL 33/48] accel: build tcg modular, Paolo Bonzini, 2021/07/08
- [PULL 26/48] modules: add module_obj() note to QOM docs, Paolo Bonzini, 2021/07/08
- [PULL 39/48] target/i386: Added MSRPM and IOPM size check, Paolo Bonzini, 2021/07/08
- [PULL 40/48] target/i386: Added DR6 and DR7 consistency checks, Paolo Bonzini, 2021/07/08
- [PULL 36/48] monitor/usb: register 'info usbhost' dynamically, Paolo Bonzini, 2021/07/08
- [PULL 38/48] monitor/tcg: move tcg hmp commands to accel/tcg, register them dynamically, Paolo Bonzini, 2021/07/08
- [PULL 45/48] hw/arm: add dependency on OR_IRQ for XLNX_VERSAL, Paolo Bonzini, 2021/07/08
- [PULL 48/48] configure: allow the selection of alternate config in the build, Paolo Bonzini, 2021/07/08
- [PULL 31/48] accel: build qtest modular, Paolo Bonzini, 2021/07/08
- [PULL 41/48] target/i386: fix exceptions for MOV to DR, Paolo Bonzini, 2021/07/08