2 * Human Monitor Interface commands
4 * Copyright IBM, Corp. 2011
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
16 #include "qemu/osdep.h"
17 #include "exec/address-spaces.h"
18 #include "exec/gdbstub.h"
19 #include "exec/ioport.h"
20 #include "monitor/hmp.h"
21 #include "qemu/help_option.h"
22 #include "monitor/monitor-internal.h"
23 #include "qapi/error.h"
24 #include "qapi/qapi-commands-control.h"
25 #include "qapi/qapi-commands-misc.h"
26 #include "qapi/qmp/qdict.h"
27 #include "qapi/qmp/qerror.h"
28 #include "qemu/cutils.h"
29 #include "hw/intc/intc.h"
31 #include "sysemu/sysemu.h"
33 bool hmp_handle_error(Monitor
*mon
, Error
*err
)
36 error_reportf_err(err
, "Error: ");
43 * Split @str at comma.
44 * A null @str defaults to "".
46 strList
*hmp_split_at_comma(const char *str
)
48 char **split
= g_strsplit(str
?: "", ",", -1);
50 strList
**tail
= &res
;
53 for (i
= 0; split
[i
]; i
++) {
54 QAPI_LIST_APPEND(tail
, split
[i
]);
61 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
65 info
= qmp_query_name(NULL
);
67 monitor_printf(mon
, "%s\n", info
->name
);
69 qapi_free_NameInfo(info
);
72 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
76 info
= qmp_query_version(NULL
);
78 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
79 info
->qemu
->major
, info
->qemu
->minor
, info
->qemu
->micro
,
82 qapi_free_VersionInfo(info
);
85 static int hmp_info_pic_foreach(Object
*obj
, void *opaque
)
87 InterruptStatsProvider
*intc
;
88 InterruptStatsProviderClass
*k
;
89 Monitor
*mon
= opaque
;
91 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
92 intc
= INTERRUPT_STATS_PROVIDER(obj
);
93 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
95 k
->print_info(intc
, mon
);
97 monitor_printf(mon
, "Interrupt controller information not available for %s.\n",
98 object_get_typename(obj
));
105 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
)
107 object_child_foreach_recursive(object_get_root(),
108 hmp_info_pic_foreach
, mon
);
111 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
113 monitor_suspend(mon
);
117 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
122 void hmp_sync_profile(Monitor
*mon
, const QDict
*qdict
)
124 const char *op
= qdict_get_try_str(qdict
, "op");
127 bool on
= qsp_is_enabled();
129 monitor_printf(mon
, "sync-profile is %s\n", on
? "on" : "off");
132 if (!strcmp(op
, "on")) {
134 } else if (!strcmp(op
, "off")) {
136 } else if (!strcmp(op
, "reset")) {
141 error_setg(&err
, QERR_INVALID_PARAMETER
, op
);
142 hmp_handle_error(mon
, err
);
146 void hmp_exit_preconfig(Monitor
*mon
, const QDict
*qdict
)
150 qmp_x_exit_preconfig(&err
);
151 hmp_handle_error(mon
, err
);
154 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
158 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
159 use it are converted to the QAPI */
160 cpu_index
= qdict_get_int(qdict
, "index");
161 if (monitor_set_cpu(mon
, cpu_index
) < 0) {
162 monitor_printf(mon
, "invalid CPU index\n");
166 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
171 hmp_handle_error(mon
, err
);
174 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
176 const char *device
= qdict_get_str(qdict
, "device");
177 const char *target
= qdict_get_str(qdict
, "target");
178 const char *arg
= qdict_get_try_str(qdict
, "arg");
179 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
180 bool force
= qdict_get_try_bool(qdict
, "force", false);
184 if (strcmp(device
, "vnc") == 0) {
185 hmp_change_vnc(mon
, device
, target
, arg
, read_only
, force
, &err
);
189 hmp_change_medium(mon
, device
, target
, arg
, read_only
, force
, &err
);
192 hmp_handle_error(mon
, err
);
196 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
198 const char *fdname
= qdict_get_str(qdict
, "fdname");
201 qmp_getfd(fdname
, &err
);
202 hmp_handle_error(mon
, err
);
206 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
208 const char *fdname
= qdict_get_str(qdict
, "fdname");
211 qmp_closefd(fdname
, &err
);
212 hmp_handle_error(mon
, err
);
215 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
217 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
218 IOThreadInfoList
*info
;
221 for (info
= info_list
; info
; info
= info
->next
) {
223 monitor_printf(mon
, "%s:\n", value
->id
);
224 monitor_printf(mon
, " thread_id=%" PRId64
"\n", value
->thread_id
);
225 monitor_printf(mon
, " poll-max-ns=%" PRId64
"\n", value
->poll_max_ns
);
226 monitor_printf(mon
, " poll-grow=%" PRId64
"\n", value
->poll_grow
);
227 monitor_printf(mon
, " poll-shrink=%" PRId64
"\n", value
->poll_shrink
);
228 monitor_printf(mon
, " aio-max-batch=%" PRId64
"\n",
229 value
->aio_max_batch
);
232 qapi_free_IOThreadInfoList(info_list
);
235 void hmp_help(Monitor
*mon
, const QDict
*qdict
)
237 hmp_help_cmd(mon
, qdict_get_try_str(qdict
, "name"));
240 void hmp_info_help(Monitor
*mon
, const QDict
*qdict
)
242 hmp_help_cmd(mon
, "info");
245 void hmp_info_sync_profile(Monitor
*mon
, const QDict
*qdict
)
247 int64_t max
= qdict_get_try_int(qdict
, "max", 10);
248 bool mean
= qdict_get_try_bool(qdict
, "mean", false);
249 bool coalesce
= !qdict_get_try_bool(qdict
, "no_coalesce", false);
250 enum QSPSortBy sort_by
;
252 sort_by
= mean
? QSP_SORT_BY_AVG_WAIT_TIME
: QSP_SORT_BY_TOTAL_WAIT_TIME
;
253 qsp_report(max
, sort_by
, coalesce
);
256 void hmp_info_history(Monitor
*mon
, const QDict
*qdict
)
258 MonitorHMP
*hmp_mon
= container_of(mon
, MonitorHMP
, common
);
267 str
= readline_get_history(hmp_mon
->rs
, i
);
271 monitor_printf(mon
, "%d: '%s'\n", i
, str
);
276 void hmp_logfile(Monitor
*mon
, const QDict
*qdict
)
280 if (!qemu_set_log_filename(qdict_get_str(qdict
, "filename"), &err
)) {
281 error_report_err(err
);
285 void hmp_log(Monitor
*mon
, const QDict
*qdict
)
288 const char *items
= qdict_get_str(qdict
, "items");
291 if (!strcmp(items
, "none")) {
294 mask
= qemu_str_to_log_mask(items
);
296 hmp_help_cmd(mon
, "log");
301 if (!qemu_set_log(mask
, &err
)) {
302 error_report_err(err
);
306 void hmp_gdbserver(Monitor
*mon
, const QDict
*qdict
)
308 const char *device
= qdict_get_try_str(qdict
, "device");
310 device
= "tcp::" DEFAULT_GDBSTUB_PORT
;
313 if (gdbserver_start(device
) < 0) {
314 monitor_printf(mon
, "Could not open gdbserver on device '%s'\n",
316 } else if (strcmp(device
, "none") == 0) {
317 monitor_printf(mon
, "Disabled gdbserver\n");
319 monitor_printf(mon
, "Waiting for gdb connection on device '%s'\n",
324 void hmp_print(Monitor
*mon
, const QDict
*qdict
)
326 int format
= qdict_get_int(qdict
, "format");
327 hwaddr val
= qdict_get_int(qdict
, "val");
331 monitor_printf(mon
, "%#" HWADDR_PRIo
, val
);
334 monitor_printf(mon
, "%#" HWADDR_PRIx
, val
);
337 monitor_printf(mon
, "%" HWADDR_PRIu
, val
);
341 monitor_printf(mon
, "%" HWADDR_PRId
, val
);
344 monitor_printc(mon
, val
);
347 monitor_printf(mon
, "\n");
350 void hmp_sum(Monitor
*mon
, const QDict
*qdict
)
354 uint32_t start
= qdict_get_int(qdict
, "start");
355 uint32_t size
= qdict_get_int(qdict
, "size");
358 for(addr
= start
; addr
< (start
+ size
); addr
++) {
359 uint8_t val
= address_space_ldub(&address_space_memory
, addr
,
360 MEMTXATTRS_UNSPECIFIED
, NULL
);
361 /* BSD sum algorithm ('sum' Unix command) */
362 sum
= (sum
>> 1) | (sum
<< 15);
365 monitor_printf(mon
, "%05d\n", sum
);
368 void hmp_ioport_read(Monitor
*mon
, const QDict
*qdict
)
370 int size
= qdict_get_int(qdict
, "size");
371 int addr
= qdict_get_int(qdict
, "addr");
372 int has_index
= qdict_haskey(qdict
, "index");
377 int index
= qdict_get_int(qdict
, "index");
378 cpu_outb(addr
& IOPORTS_MASK
, index
& 0xff);
398 monitor_printf(mon
, "port%c[0x%04x] = 0x%0*x\n",
399 suffix
, addr
, size
* 2, val
);
402 void hmp_ioport_write(Monitor
*mon
, const QDict
*qdict
)
404 int size
= qdict_get_int(qdict
, "size");
405 int addr
= qdict_get_int(qdict
, "addr");
406 int val
= qdict_get_int(qdict
, "val");
408 addr
&= IOPORTS_MASK
;
424 void hmp_boot_set(Monitor
*mon
, const QDict
*qdict
)
426 Error
*local_err
= NULL
;
427 const char *bootdevice
= qdict_get_str(qdict
, "bootdevice");
429 qemu_boot_set(bootdevice
, &local_err
);
431 error_report_err(local_err
);
433 monitor_printf(mon
, "boot device list now set to %s\n", bootdevice
);
437 void hmp_info_mtree(Monitor
*mon
, const QDict
*qdict
)
439 bool flatview
= qdict_get_try_bool(qdict
, "flatview", false);
440 bool dispatch_tree
= qdict_get_try_bool(qdict
, "dispatch_tree", false);
441 bool owner
= qdict_get_try_bool(qdict
, "owner", false);
442 bool disabled
= qdict_get_try_bool(qdict
, "disabled", false);
444 mtree_info(flatview
, dispatch_tree
, owner
, disabled
);