diff mbox

[v5,08/22] instrument: [hmp] Add library loader

Message ID 150525204093.15988.8421573656094243079.stgit@frigg.lan (mailing list archive)
State New, archived
Headers show

Commit Message

Lluís Vilanova Sept. 12, 2017, 9:34 p.m. UTC
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
 hmp-commands.hx |   32 ++++++++++++++++++++++++++++++++
 monitor.c       |   39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+)
diff mbox

Patch

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 1941e19932..2e8ebe8422 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1858,6 +1858,38 @@  ETEXI
         .sub_table  = info_cmds,
     },
 
+#ifdef CONFIG_INSTRUMENT
+    {
+        .name       = "instr-load",
+        .args_type  = "path:F,id:s?,arg:s?",
+        .params     = "path [id] [arg]",
+        .help       = "load an instrumentation library",
+        .cmd        = hmp_instr_load,
+    },
+#endif
+
+STEXI
+@item instr-load @var{path} [@var{id}] [@var{arg}]
+@findex instr-load
+Load an instrumentation library.
+ETEXI
+
+#ifdef CONFIG_INSTRUMENT
+    {
+        .name       = "instr-unload",
+        .args_type  = "id:s",
+        .params     = "id",
+        .help       = "unload an instrumentation library",
+        .cmd        = hmp_instr_unload,
+    },
+#endif
+
+STEXI
+@item instr-unload
+@findex instr-unload
+Unload an instrumentation library.
+ETEXI
+
 STEXI
 @end table
 ETEXI
diff --git a/monitor.c b/monitor.c
index e031aa2687..7b80d5351f 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2323,6 +2323,45 @@  int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp)
     return fd;
 }
 
+#ifdef CONFIG_INSTRUMENT
+static void hmp_instr_load(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    const char *path = qdict_get_str(qdict, "path");
+    const char *id = qdict_get_try_str(qdict, "id");
+    const char *str = qdict_get_try_str(qdict, "arg");
+    strList args;
+
+    args.value = (char *)str;
+    args.next = NULL;
+
+    InstrLoadResult *res = qmp_instr_load(path,
+                                          id != NULL, id,
+                                          args.value != NULL, &args,
+                                          &err);
+    if (err) {
+        error_report_err(err);
+    } else {
+        monitor_printf(mon, "Handle: %s\n", res->id);
+        monitor_printf(mon, "OK\n");
+    }
+    qapi_free_InstrLoadResult(res);
+}
+
+static void hmp_instr_unload(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    const char *id = qdict_get_str(qdict, "id");
+
+    qmp_instr_unload(id, &err);
+    if (err) {
+        error_report_err(err);
+    } else {
+        monitor_printf(mon, "OK\n");
+    }
+}
+#endif
+
 /* Please update hmp-commands.hx when adding or changing commands */
 static mon_cmd_t info_cmds[] = {
 #include "hmp-commands-info.h"