4 * Copyright (c) 2003-2004 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
26 #include "monitor-internal.h"
27 #include "monitor/qdev.h"
29 #include "hw/pci/pci.h"
30 #include "sysemu/watchdog.h"
31 #include "hw/loader.h"
32 #include "exec/gdbstub.h"
34 #include "net/slirp.h"
35 #include "ui/qemu-spice.h"
36 #include "qemu/config-file.h"
37 #include "qemu/ctype.h"
38 #include "ui/console.h"
40 #include "audio/audio.h"
41 #include "disas/disas.h"
42 #include "sysemu/balloon.h"
43 #include "qemu/timer.h"
45 #include "sysemu/hw_accel.h"
46 #include "sysemu/runstate.h"
47 #include "authz/list.h"
48 #include "qapi/util.h"
49 #include "sysemu/blockdev.h"
50 #include "sysemu/sysemu.h"
51 #include "sysemu/tpm.h"
52 #include "sysemu/device_tree.h"
53 #include "qapi/qmp/qdict.h"
54 #include "qapi/qmp/qerror.h"
55 #include "qapi/qmp/qstring.h"
56 #include "qom/object_interfaces.h"
57 #include "trace/control.h"
58 #include "monitor/hmp-target.h"
59 #include "monitor/hmp.h"
60 #ifdef CONFIG_TRACE_SIMPLE
61 #include "trace/simple.h"
63 #include "exec/memory.h"
64 #include "exec/exec-all.h"
65 #include "qemu/option.h"
66 #include "qemu/thread.h"
67 #include "block/qapi.h"
68 #include "block/block-hmp-cmds.h"
69 #include "qapi/qapi-commands-char.h"
70 #include "qapi/qapi-commands-control.h"
71 #include "qapi/qapi-commands-migration.h"
72 #include "qapi/qapi-commands-misc.h"
73 #include "qapi/qapi-commands-qom.h"
74 #include "qapi/qapi-commands-run-state.h"
75 #include "qapi/qapi-commands-trace.h"
76 #include "qapi/qapi-commands-machine.h"
77 #include "qapi/qapi-init-commands.h"
78 #include "qapi/error.h"
79 #include "qapi/qmp-event.h"
80 #include "sysemu/cpus.h"
81 #include "qemu/cutils.h"
83 #if defined(TARGET_S390X)
84 #include "hw/s390x/storage-keys.h"
85 #include "hw/s390x/storage-attributes.h"
88 /* Make devices configuration available for use in hmp-commands*.hx templates */
89 #include CONFIG_DEVICES
91 /* file descriptors passed via SCM_RIGHTS */
92 typedef struct mon_fd_t mon_fd_t
;
96 QLIST_ENTRY(mon_fd_t
) next
;
99 /* file descriptor associated with a file descriptor set */
100 typedef struct MonFdsetFd MonFdsetFd
;
105 QLIST_ENTRY(MonFdsetFd
) next
;
108 /* file descriptor set containing fds passed via SCM_RIGHTS */
109 typedef struct MonFdset MonFdset
;
112 QLIST_HEAD(, MonFdsetFd
) fds
;
113 QLIST_HEAD(, MonFdsetFd
) dup_fds
;
114 QLIST_ENTRY(MonFdset
) next
;
117 /* Protects mon_fdsets */
118 static QemuMutex mon_fdsets_lock
;
119 static QLIST_HEAD(, MonFdset
) mon_fdsets
;
121 static HMPCommand hmp_info_cmds
[];
123 char *qmp_human_monitor_command(const char *command_line
, bool has_cpu_index
,
124 int64_t cpu_index
, Error
**errp
)
129 monitor_data_init(&hmp
.common
, false, true, false);
132 int ret
= monitor_set_cpu(&hmp
.common
, cpu_index
);
134 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "cpu-index",
140 handle_hmp_command(&hmp
, command_line
);
142 WITH_QEMU_LOCK_GUARD(&hmp
.common
.mon_lock
) {
143 output
= g_strdup(hmp
.common
.outbuf
->str
);
147 monitor_data_destroy(&hmp
.common
);
152 * Is @name in the '|' separated list of names @list?
154 int hmp_compare_cmd(const char *name
, const char *list
)
156 const char *p
, *pstart
;
162 p
= qemu_strchrnul(p
, '|');
163 if ((p
- pstart
) == len
&& !memcmp(pstart
, name
, len
)) {
174 static void do_help_cmd(Monitor
*mon
, const QDict
*qdict
)
176 help_cmd(mon
, qdict_get_try_str(qdict
, "name"));
179 static void hmp_trace_event(Monitor
*mon
, const QDict
*qdict
)
181 const char *tp_name
= qdict_get_str(qdict
, "name");
182 bool new_state
= qdict_get_bool(qdict
, "option");
183 bool has_vcpu
= qdict_haskey(qdict
, "vcpu");
184 int vcpu
= qdict_get_try_int(qdict
, "vcpu", 0);
185 Error
*local_err
= NULL
;
188 monitor_printf(mon
, "argument vcpu must be positive");
192 qmp_trace_event_set_state(tp_name
, new_state
, true, true, has_vcpu
, vcpu
, &local_err
);
194 error_report_err(local_err
);
198 #ifdef CONFIG_TRACE_SIMPLE
199 static void hmp_trace_file(Monitor
*mon
, const QDict
*qdict
)
201 const char *op
= qdict_get_try_str(qdict
, "op");
202 const char *arg
= qdict_get_try_str(qdict
, "arg");
205 st_print_trace_file_status();
206 } else if (!strcmp(op
, "on")) {
207 st_set_trace_file_enabled(true);
208 } else if (!strcmp(op
, "off")) {
209 st_set_trace_file_enabled(false);
210 } else if (!strcmp(op
, "flush")) {
211 st_flush_trace_buffer();
212 } else if (!strcmp(op
, "set")) {
214 st_set_trace_file(arg
);
217 monitor_printf(mon
, "unexpected argument \"%s\"\n", op
);
218 help_cmd(mon
, "trace-file");
223 static void hmp_info_help(Monitor
*mon
, const QDict
*qdict
)
225 help_cmd(mon
, "info");
228 static void monitor_init_qmp_commands(void)
232 * - qmp_commands contains all QMP commands
233 * - qmp_cap_negotiation_commands contains just
234 * "qmp_capabilities", to enforce capability negotiation
237 qmp_init_marshal(&qmp_commands
);
239 qmp_register_command(&qmp_commands
, "device_add",
240 qmp_device_add
, 0, 0);
242 QTAILQ_INIT(&qmp_cap_negotiation_commands
);
243 qmp_register_command(&qmp_cap_negotiation_commands
, "qmp_capabilities",
244 qmp_marshal_qmp_capabilities
,
245 QCO_ALLOW_PRECONFIG
, 0);
248 /* Set the current CPU defined by the user. Callers must hold BQL. */
249 int monitor_set_cpu(Monitor
*mon
, int cpu_index
)
253 cpu
= qemu_get_cpu(cpu_index
);
257 g_free(mon
->mon_cpu_path
);
258 mon
->mon_cpu_path
= object_get_canonical_path(OBJECT(cpu
));
262 /* Callers must hold BQL. */
263 static CPUState
*mon_get_cpu_sync(Monitor
*mon
, bool synchronize
)
265 CPUState
*cpu
= NULL
;
267 if (mon
->mon_cpu_path
) {
268 cpu
= (CPUState
*) object_resolve_path_type(mon
->mon_cpu_path
,
271 g_free(mon
->mon_cpu_path
);
272 mon
->mon_cpu_path
= NULL
;
275 if (!mon
->mon_cpu_path
) {
279 monitor_set_cpu(mon
, first_cpu
->cpu_index
);
284 cpu_synchronize_state(cpu
);
289 CPUState
*mon_get_cpu(Monitor
*mon
)
291 return mon_get_cpu_sync(mon
, true);
294 CPUArchState
*mon_get_cpu_env(Monitor
*mon
)
296 CPUState
*cs
= mon_get_cpu(mon
);
298 return cs
? cs
->env_ptr
: NULL
;
301 int monitor_get_cpu_index(Monitor
*mon
)
303 CPUState
*cs
= mon_get_cpu_sync(mon
, false);
305 return cs
? cs
->cpu_index
: UNASSIGNED_CPU_INDEX
;
308 static void hmp_info_registers(Monitor
*mon
, const QDict
*qdict
)
310 bool all_cpus
= qdict_get_try_bool(qdict
, "cpustate_all", false);
311 int vcpu
= qdict_get_try_int(qdict
, "vcpu", -1);
316 monitor_printf(mon
, "\nCPU#%d\n", cs
->cpu_index
);
317 cpu_dump_state(cs
, NULL
, CPU_DUMP_FPU
);
320 cs
= vcpu
>= 0 ? qemu_get_cpu(vcpu
) : mon_get_cpu(mon
);
324 monitor_printf(mon
, "CPU#%d not available\n", vcpu
);
326 monitor_printf(mon
, "No CPU available\n");
331 monitor_printf(mon
, "\nCPU#%d\n", cs
->cpu_index
);
332 cpu_dump_state(cs
, NULL
, CPU_DUMP_FPU
);
336 static void hmp_info_sync_profile(Monitor
*mon
, const QDict
*qdict
)
338 int64_t max
= qdict_get_try_int(qdict
, "max", 10);
339 bool mean
= qdict_get_try_bool(qdict
, "mean", false);
340 bool coalesce
= !qdict_get_try_bool(qdict
, "no_coalesce", false);
341 enum QSPSortBy sort_by
;
343 sort_by
= mean
? QSP_SORT_BY_AVG_WAIT_TIME
: QSP_SORT_BY_TOTAL_WAIT_TIME
;
344 qsp_report(max
, sort_by
, coalesce
);
347 static void hmp_info_history(Monitor
*mon
, const QDict
*qdict
)
349 MonitorHMP
*hmp_mon
= container_of(mon
, MonitorHMP
, common
);
358 str
= readline_get_history(hmp_mon
->rs
, i
);
362 monitor_printf(mon
, "%d: '%s'\n", i
, str
);
367 static void hmp_info_trace_events(Monitor
*mon
, const QDict
*qdict
)
369 const char *name
= qdict_get_try_str(qdict
, "name");
370 bool has_vcpu
= qdict_haskey(qdict
, "vcpu");
371 int vcpu
= qdict_get_try_int(qdict
, "vcpu", 0);
372 TraceEventInfoList
*events
;
373 TraceEventInfoList
*elem
;
374 Error
*local_err
= NULL
;
380 monitor_printf(mon
, "argument vcpu must be positive");
384 events
= qmp_trace_event_get_state(name
, has_vcpu
, vcpu
, &local_err
);
386 error_report_err(local_err
);
390 for (elem
= events
; elem
!= NULL
; elem
= elem
->next
) {
391 monitor_printf(mon
, "%s : state %u\n",
393 elem
->value
->state
== TRACE_EVENT_STATE_ENABLED
? 1 : 0);
395 qapi_free_TraceEventInfoList(events
);
398 void qmp_client_migrate_info(const char *protocol
, const char *hostname
,
399 bool has_port
, int64_t port
,
400 bool has_tls_port
, int64_t tls_port
,
401 bool has_cert_subject
, const char *cert_subject
,
404 if (strcmp(protocol
, "spice") == 0) {
405 if (!qemu_using_spice(errp
)) {
409 if (!has_port
&& !has_tls_port
) {
410 error_setg(errp
, QERR_MISSING_PARAMETER
, "port/tls-port");
414 if (qemu_spice
.migrate_info(hostname
,
415 has_port
? port
: -1,
416 has_tls_port
? tls_port
: -1,
418 error_setg(errp
, "Could not set up display for migration");
424 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "protocol", "'spice'");
427 static void hmp_logfile(Monitor
*mon
, const QDict
*qdict
)
431 if (!qemu_set_log_filename(qdict_get_str(qdict
, "filename"), &err
)) {
432 error_report_err(err
);
436 static void hmp_log(Monitor
*mon
, const QDict
*qdict
)
439 const char *items
= qdict_get_str(qdict
, "items");
442 if (!strcmp(items
, "none")) {
445 mask
= qemu_str_to_log_mask(items
);
447 help_cmd(mon
, "log");
452 if (!qemu_set_log(mask
, &err
)) {
453 error_report_err(err
);
457 static void hmp_singlestep(Monitor
*mon
, const QDict
*qdict
)
459 const char *option
= qdict_get_try_str(qdict
, "option");
460 if (!option
|| !strcmp(option
, "on")) {
462 } else if (!strcmp(option
, "off")) {
465 monitor_printf(mon
, "unexpected option %s\n", option
);
469 static void hmp_gdbserver(Monitor
*mon
, const QDict
*qdict
)
471 const char *device
= qdict_get_try_str(qdict
, "device");
473 device
= "tcp::" DEFAULT_GDBSTUB_PORT
;
476 if (gdbserver_start(device
) < 0) {
477 monitor_printf(mon
, "Could not open gdbserver on device '%s'\n",
479 } else if (strcmp(device
, "none") == 0) {
480 monitor_printf(mon
, "Disabled gdbserver\n");
482 monitor_printf(mon
, "Waiting for gdb connection on device '%s'\n",
487 static void hmp_watchdog_action(Monitor
*mon
, const QDict
*qdict
)
490 WatchdogAction action
;
493 qapi_value
= g_ascii_strdown(qdict_get_str(qdict
, "action"), -1);
494 action
= qapi_enum_parse(&WatchdogAction_lookup
, qapi_value
, -1, &err
);
497 hmp_handle_error(mon
, err
);
500 qmp_watchdog_set_action(action
, &error_abort
);
503 static void monitor_printc(Monitor
*mon
, int c
)
505 monitor_printf(mon
, "'");
508 monitor_printf(mon
, "\\'");
511 monitor_printf(mon
, "\\\\");
514 monitor_printf(mon
, "\\n");
517 monitor_printf(mon
, "\\r");
520 if (c
>= 32 && c
<= 126) {
521 monitor_printf(mon
, "%c", c
);
523 monitor_printf(mon
, "\\x%02x", c
);
527 monitor_printf(mon
, "'");
530 static void memory_dump(Monitor
*mon
, int count
, int format
, int wsize
,
531 hwaddr addr
, int is_physical
)
533 int l
, line_size
, i
, max_digits
, len
;
536 CPUState
*cs
= mon_get_cpu(mon
);
538 if (!cs
&& (format
== 'i' || !is_physical
)) {
539 monitor_printf(mon
, "Can not dump without CPU\n");
544 monitor_disas(mon
, cs
, addr
, count
, is_physical
);
558 max_digits
= DIV_ROUND_UP(wsize
* 8, 3);
562 max_digits
= (wsize
* 8) / 4;
566 max_digits
= DIV_ROUND_UP(wsize
* 8 * 10, 33);
575 monitor_printf(mon
, TARGET_FMT_plx
":", addr
);
577 monitor_printf(mon
, TARGET_FMT_lx
":", (target_ulong
)addr
);
583 AddressSpace
*as
= cs
? cs
->as
: &address_space_memory
;
584 MemTxResult r
= address_space_read(as
, addr
,
585 MEMTXATTRS_UNSPECIFIED
, buf
, l
);
587 monitor_printf(mon
, " Cannot access memory\n");
591 if (cpu_memory_rw_debug(cs
, addr
, buf
, l
, 0) < 0) {
592 monitor_printf(mon
, " Cannot access memory\n");
607 v
= (uint32_t)ldl_p(buf
+ i
);
613 monitor_printf(mon
, " ");
616 monitor_printf(mon
, "%#*" PRIo64
, max_digits
, v
);
619 monitor_printf(mon
, "0x%0*" PRIx64
, max_digits
, v
);
622 monitor_printf(mon
, "%*" PRIu64
, max_digits
, v
);
625 monitor_printf(mon
, "%*" PRId64
, max_digits
, v
);
628 monitor_printc(mon
, v
);
633 monitor_printf(mon
, "\n");
639 static void hmp_memory_dump(Monitor
*mon
, const QDict
*qdict
)
641 int count
= qdict_get_int(qdict
, "count");
642 int format
= qdict_get_int(qdict
, "format");
643 int size
= qdict_get_int(qdict
, "size");
644 target_long addr
= qdict_get_int(qdict
, "addr");
646 memory_dump(mon
, count
, format
, size
, addr
, 0);
649 static void hmp_physical_memory_dump(Monitor
*mon
, const QDict
*qdict
)
651 int count
= qdict_get_int(qdict
, "count");
652 int format
= qdict_get_int(qdict
, "format");
653 int size
= qdict_get_int(qdict
, "size");
654 hwaddr addr
= qdict_get_int(qdict
, "addr");
656 memory_dump(mon
, count
, format
, size
, addr
, 1);
659 void *gpa2hva(MemoryRegion
**p_mr
, hwaddr addr
, uint64_t size
, Error
**errp
)
661 Int128 gpa_region_size
;
662 MemoryRegionSection mrs
= memory_region_find(get_system_memory(),
666 error_setg(errp
, "No memory is mapped at address 0x%" HWADDR_PRIx
, addr
);
670 if (!memory_region_is_ram(mrs
.mr
) && !memory_region_is_romd(mrs
.mr
)) {
671 error_setg(errp
, "Memory at address 0x%" HWADDR_PRIx
"is not RAM", addr
);
672 memory_region_unref(mrs
.mr
);
676 gpa_region_size
= int128_make64(size
);
677 if (int128_lt(mrs
.size
, gpa_region_size
)) {
678 error_setg(errp
, "Size of memory region at 0x%" HWADDR_PRIx
680 memory_region_unref(mrs
.mr
);
685 return qemu_map_ram_ptr(mrs
.mr
->ram_block
, mrs
.offset_within_region
);
688 static void hmp_gpa2hva(Monitor
*mon
, const QDict
*qdict
)
690 hwaddr addr
= qdict_get_int(qdict
, "addr");
691 Error
*local_err
= NULL
;
692 MemoryRegion
*mr
= NULL
;
695 ptr
= gpa2hva(&mr
, addr
, 1, &local_err
);
697 error_report_err(local_err
);
701 monitor_printf(mon
, "Host virtual address for 0x%" HWADDR_PRIx
703 addr
, mr
->name
, ptr
);
705 memory_region_unref(mr
);
708 static void hmp_gva2gpa(Monitor
*mon
, const QDict
*qdict
)
710 target_ulong addr
= qdict_get_int(qdict
, "addr");
712 CPUState
*cs
= mon_get_cpu(mon
);
716 monitor_printf(mon
, "No cpu\n");
720 gpa
= cpu_get_phys_page_attrs_debug(cs
, addr
& TARGET_PAGE_MASK
, &attrs
);
722 monitor_printf(mon
, "Unmapped\n");
724 monitor_printf(mon
, "gpa: %#" HWADDR_PRIx
"\n",
725 gpa
+ (addr
& ~TARGET_PAGE_MASK
));
730 static uint64_t vtop(void *ptr
, Error
**errp
)
734 uintptr_t addr
= (uintptr_t) ptr
;
735 uintptr_t pagesize
= qemu_real_host_page_size();
736 off_t offset
= addr
/ pagesize
* sizeof(pinfo
);
739 fd
= open("/proc/self/pagemap", O_RDONLY
);
741 error_setg_errno(errp
, errno
, "Cannot open /proc/self/pagemap");
745 /* Force copy-on-write if necessary. */
746 qatomic_add((uint8_t *)ptr
, 0);
748 if (pread(fd
, &pinfo
, sizeof(pinfo
), offset
) != sizeof(pinfo
)) {
749 error_setg_errno(errp
, errno
, "Cannot read pagemap");
752 if ((pinfo
& (1ull << 63)) == 0) {
753 error_setg(errp
, "Page not present");
756 ret
= ((pinfo
& 0x007fffffffffffffull
) * pagesize
) | (addr
& (pagesize
- 1));
763 static void hmp_gpa2hpa(Monitor
*mon
, const QDict
*qdict
)
765 hwaddr addr
= qdict_get_int(qdict
, "addr");
766 Error
*local_err
= NULL
;
767 MemoryRegion
*mr
= NULL
;
771 ptr
= gpa2hva(&mr
, addr
, 1, &local_err
);
773 error_report_err(local_err
);
777 physaddr
= vtop(ptr
, &local_err
);
779 error_report_err(local_err
);
781 monitor_printf(mon
, "Host physical address for 0x%" HWADDR_PRIx
782 " (%s) is 0x%" PRIx64
"\n",
783 addr
, mr
->name
, (uint64_t) physaddr
);
786 memory_region_unref(mr
);
790 static void do_print(Monitor
*mon
, const QDict
*qdict
)
792 int format
= qdict_get_int(qdict
, "format");
793 hwaddr val
= qdict_get_int(qdict
, "val");
797 monitor_printf(mon
, "%#" HWADDR_PRIo
, val
);
800 monitor_printf(mon
, "%#" HWADDR_PRIx
, val
);
803 monitor_printf(mon
, "%" HWADDR_PRIu
, val
);
807 monitor_printf(mon
, "%" HWADDR_PRId
, val
);
810 monitor_printc(mon
, val
);
813 monitor_printf(mon
, "\n");
816 static void hmp_sum(Monitor
*mon
, const QDict
*qdict
)
820 uint32_t start
= qdict_get_int(qdict
, "start");
821 uint32_t size
= qdict_get_int(qdict
, "size");
824 for(addr
= start
; addr
< (start
+ size
); addr
++) {
825 uint8_t val
= address_space_ldub(&address_space_memory
, addr
,
826 MEMTXATTRS_UNSPECIFIED
, NULL
);
827 /* BSD sum algorithm ('sum' Unix command) */
828 sum
= (sum
>> 1) | (sum
<< 15);
831 monitor_printf(mon
, "%05d\n", sum
);
834 static int mouse_button_state
;
836 static void hmp_mouse_move(Monitor
*mon
, const QDict
*qdict
)
838 int dx
, dy
, dz
, button
;
839 const char *dx_str
= qdict_get_str(qdict
, "dx_str");
840 const char *dy_str
= qdict_get_str(qdict
, "dy_str");
841 const char *dz_str
= qdict_get_try_str(qdict
, "dz_str");
843 dx
= strtol(dx_str
, NULL
, 0);
844 dy
= strtol(dy_str
, NULL
, 0);
845 qemu_input_queue_rel(NULL
, INPUT_AXIS_X
, dx
);
846 qemu_input_queue_rel(NULL
, INPUT_AXIS_Y
, dy
);
849 dz
= strtol(dz_str
, NULL
, 0);
851 button
= (dz
> 0) ? INPUT_BUTTON_WHEEL_UP
: INPUT_BUTTON_WHEEL_DOWN
;
852 qemu_input_queue_btn(NULL
, button
, true);
853 qemu_input_event_sync();
854 qemu_input_queue_btn(NULL
, button
, false);
857 qemu_input_event_sync();
860 static void hmp_mouse_button(Monitor
*mon
, const QDict
*qdict
)
862 static uint32_t bmap
[INPUT_BUTTON__MAX
] = {
863 [INPUT_BUTTON_LEFT
] = MOUSE_EVENT_LBUTTON
,
864 [INPUT_BUTTON_MIDDLE
] = MOUSE_EVENT_MBUTTON
,
865 [INPUT_BUTTON_RIGHT
] = MOUSE_EVENT_RBUTTON
,
867 int button_state
= qdict_get_int(qdict
, "button_state");
869 if (mouse_button_state
== button_state
) {
872 qemu_input_update_buttons(NULL
, bmap
, mouse_button_state
, button_state
);
873 qemu_input_event_sync();
874 mouse_button_state
= button_state
;
877 static void hmp_ioport_read(Monitor
*mon
, const QDict
*qdict
)
879 int size
= qdict_get_int(qdict
, "size");
880 int addr
= qdict_get_int(qdict
, "addr");
881 int has_index
= qdict_haskey(qdict
, "index");
886 int index
= qdict_get_int(qdict
, "index");
887 cpu_outb(addr
& IOPORTS_MASK
, index
& 0xff);
907 monitor_printf(mon
, "port%c[0x%04x] = 0x%0*x\n",
908 suffix
, addr
, size
* 2, val
);
911 static void hmp_ioport_write(Monitor
*mon
, const QDict
*qdict
)
913 int size
= qdict_get_int(qdict
, "size");
914 int addr
= qdict_get_int(qdict
, "addr");
915 int val
= qdict_get_int(qdict
, "val");
917 addr
&= IOPORTS_MASK
;
933 static void hmp_boot_set(Monitor
*mon
, const QDict
*qdict
)
935 Error
*local_err
= NULL
;
936 const char *bootdevice
= qdict_get_str(qdict
, "bootdevice");
938 qemu_boot_set(bootdevice
, &local_err
);
940 error_report_err(local_err
);
942 monitor_printf(mon
, "boot device list now set to %s\n", bootdevice
);
946 static void hmp_info_mtree(Monitor
*mon
, const QDict
*qdict
)
948 bool flatview
= qdict_get_try_bool(qdict
, "flatview", false);
949 bool dispatch_tree
= qdict_get_try_bool(qdict
, "dispatch_tree", false);
950 bool owner
= qdict_get_try_bool(qdict
, "owner", false);
951 bool disabled
= qdict_get_try_bool(qdict
, "disabled", false);
953 mtree_info(flatview
, dispatch_tree
, owner
, disabled
);
956 /* Capture support */
957 static QLIST_HEAD (capture_list_head
, CaptureState
) capture_head
;
959 static void hmp_info_capture(Monitor
*mon
, const QDict
*qdict
)
964 for (s
= capture_head
.lh_first
, i
= 0; s
; s
= s
->entries
.le_next
, ++i
) {
965 monitor_printf(mon
, "[%d]: ", i
);
966 s
->ops
.info (s
->opaque
);
970 static void hmp_stopcapture(Monitor
*mon
, const QDict
*qdict
)
973 int n
= qdict_get_int(qdict
, "n");
976 for (s
= capture_head
.lh_first
, i
= 0; s
; s
= s
->entries
.le_next
, ++i
) {
978 s
->ops
.destroy (s
->opaque
);
979 QLIST_REMOVE (s
, entries
);
986 static void hmp_wavcapture(Monitor
*mon
, const QDict
*qdict
)
988 const char *path
= qdict_get_str(qdict
, "path");
989 int freq
= qdict_get_try_int(qdict
, "freq", 44100);
990 int bits
= qdict_get_try_int(qdict
, "bits", 16);
991 int nchannels
= qdict_get_try_int(qdict
, "nchannels", 2);
992 const char *audiodev
= qdict_get_str(qdict
, "audiodev");
994 AudioState
*as
= audio_state_by_name(audiodev
);
997 monitor_printf(mon
, "Audiodev '%s' not found\n", audiodev
);
1001 s
= g_malloc0 (sizeof (*s
));
1003 if (wav_start_capture(as
, s
, path
, freq
, bits
, nchannels
)) {
1004 monitor_printf(mon
, "Failed to add wave capture\n");
1008 QLIST_INSERT_HEAD (&capture_head
, s
, entries
);
1011 void qmp_getfd(const char *fdname
, Error
**errp
)
1013 Monitor
*cur_mon
= monitor_cur();
1017 fd
= qemu_chr_fe_get_msgfd(&cur_mon
->chr
);
1019 error_setg(errp
, "No file descriptor supplied via SCM_RIGHTS");
1023 if (qemu_isdigit(fdname
[0])) {
1025 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "fdname",
1026 "a name not starting with a digit");
1030 QEMU_LOCK_GUARD(&cur_mon
->mon_lock
);
1031 QLIST_FOREACH(monfd
, &cur_mon
->fds
, next
) {
1032 if (strcmp(monfd
->name
, fdname
) != 0) {
1038 /* Make sure close() is outside critical section */
1043 monfd
= g_new0(mon_fd_t
, 1);
1044 monfd
->name
= g_strdup(fdname
);
1047 QLIST_INSERT_HEAD(&cur_mon
->fds
, monfd
, next
);
1050 void qmp_closefd(const char *fdname
, Error
**errp
)
1052 Monitor
*cur_mon
= monitor_cur();
1056 qemu_mutex_lock(&cur_mon
->mon_lock
);
1057 QLIST_FOREACH(monfd
, &cur_mon
->fds
, next
) {
1058 if (strcmp(monfd
->name
, fdname
) != 0) {
1062 QLIST_REMOVE(monfd
, next
);
1064 g_free(monfd
->name
);
1066 qemu_mutex_unlock(&cur_mon
->mon_lock
);
1067 /* Make sure close() is outside critical section */
1072 qemu_mutex_unlock(&cur_mon
->mon_lock
);
1073 error_setg(errp
, "File descriptor named '%s' not found", fdname
);
1076 int monitor_get_fd(Monitor
*mon
, const char *fdname
, Error
**errp
)
1080 QEMU_LOCK_GUARD(&mon
->mon_lock
);
1081 QLIST_FOREACH(monfd
, &mon
->fds
, next
) {
1084 if (strcmp(monfd
->name
, fdname
) != 0) {
1090 /* caller takes ownership of fd */
1091 QLIST_REMOVE(monfd
, next
);
1092 g_free(monfd
->name
);
1098 error_setg(errp
, "File descriptor named '%s' has not been found", fdname
);
1102 static void monitor_fdset_cleanup(MonFdset
*mon_fdset
)
1104 MonFdsetFd
*mon_fdset_fd
;
1105 MonFdsetFd
*mon_fdset_fd_next
;
1107 QLIST_FOREACH_SAFE(mon_fdset_fd
, &mon_fdset
->fds
, next
, mon_fdset_fd_next
) {
1108 if ((mon_fdset_fd
->removed
||
1109 (QLIST_EMPTY(&mon_fdset
->dup_fds
) && mon_refcount
== 0)) &&
1110 runstate_is_running()) {
1111 close(mon_fdset_fd
->fd
);
1112 g_free(mon_fdset_fd
->opaque
);
1113 QLIST_REMOVE(mon_fdset_fd
, next
);
1114 g_free(mon_fdset_fd
);
1118 if (QLIST_EMPTY(&mon_fdset
->fds
) && QLIST_EMPTY(&mon_fdset
->dup_fds
)) {
1119 QLIST_REMOVE(mon_fdset
, next
);
1124 void monitor_fdsets_cleanup(void)
1126 MonFdset
*mon_fdset
;
1127 MonFdset
*mon_fdset_next
;
1129 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1130 QLIST_FOREACH_SAFE(mon_fdset
, &mon_fdsets
, next
, mon_fdset_next
) {
1131 monitor_fdset_cleanup(mon_fdset
);
1135 AddfdInfo
*qmp_add_fd(bool has_fdset_id
, int64_t fdset_id
, bool has_opaque
,
1136 const char *opaque
, Error
**errp
)
1139 Monitor
*mon
= monitor_cur();
1142 fd
= qemu_chr_fe_get_msgfd(&mon
->chr
);
1144 error_setg(errp
, "No file descriptor supplied via SCM_RIGHTS");
1148 fdinfo
= monitor_fdset_add_fd(fd
, has_fdset_id
, fdset_id
,
1149 has_opaque
, opaque
, errp
);
1161 void qmp_remove_fd(int64_t fdset_id
, bool has_fd
, int64_t fd
, Error
**errp
)
1163 MonFdset
*mon_fdset
;
1164 MonFdsetFd
*mon_fdset_fd
;
1167 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1168 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1169 if (mon_fdset
->id
!= fdset_id
) {
1172 QLIST_FOREACH(mon_fdset_fd
, &mon_fdset
->fds
, next
) {
1174 if (mon_fdset_fd
->fd
!= fd
) {
1177 mon_fdset_fd
->removed
= true;
1180 mon_fdset_fd
->removed
= true;
1183 if (has_fd
&& !mon_fdset_fd
) {
1186 monitor_fdset_cleanup(mon_fdset
);
1192 snprintf(fd_str
, sizeof(fd_str
), "fdset-id:%" PRId64
", fd:%" PRId64
,
1195 snprintf(fd_str
, sizeof(fd_str
), "fdset-id:%" PRId64
, fdset_id
);
1197 error_setg(errp
, "File descriptor named '%s' not found", fd_str
);
1200 FdsetInfoList
*qmp_query_fdsets(Error
**errp
)
1202 MonFdset
*mon_fdset
;
1203 MonFdsetFd
*mon_fdset_fd
;
1204 FdsetInfoList
*fdset_list
= NULL
;
1206 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1207 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1208 FdsetInfo
*fdset_info
= g_malloc0(sizeof(*fdset_info
));
1210 fdset_info
->fdset_id
= mon_fdset
->id
;
1212 QLIST_FOREACH(mon_fdset_fd
, &mon_fdset
->fds
, next
) {
1213 FdsetFdInfo
*fdsetfd_info
;
1215 fdsetfd_info
= g_malloc0(sizeof(*fdsetfd_info
));
1216 fdsetfd_info
->fd
= mon_fdset_fd
->fd
;
1217 if (mon_fdset_fd
->opaque
) {
1218 fdsetfd_info
->has_opaque
= true;
1219 fdsetfd_info
->opaque
= g_strdup(mon_fdset_fd
->opaque
);
1221 fdsetfd_info
->has_opaque
= false;
1224 QAPI_LIST_PREPEND(fdset_info
->fds
, fdsetfd_info
);
1227 QAPI_LIST_PREPEND(fdset_list
, fdset_info
);
1233 AddfdInfo
*monitor_fdset_add_fd(int fd
, bool has_fdset_id
, int64_t fdset_id
,
1234 bool has_opaque
, const char *opaque
,
1237 MonFdset
*mon_fdset
= NULL
;
1238 MonFdsetFd
*mon_fdset_fd
;
1241 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1243 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1244 /* Break if match found or match impossible due to ordering by ID */
1245 if (fdset_id
<= mon_fdset
->id
) {
1246 if (fdset_id
< mon_fdset
->id
) {
1254 if (mon_fdset
== NULL
) {
1255 int64_t fdset_id_prev
= -1;
1256 MonFdset
*mon_fdset_cur
= QLIST_FIRST(&mon_fdsets
);
1260 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "fdset-id",
1261 "a non-negative value");
1264 /* Use specified fdset ID */
1265 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1266 mon_fdset_cur
= mon_fdset
;
1267 if (fdset_id
< mon_fdset_cur
->id
) {
1272 /* Use first available fdset ID */
1273 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1274 mon_fdset_cur
= mon_fdset
;
1275 if (fdset_id_prev
== mon_fdset_cur
->id
- 1) {
1276 fdset_id_prev
= mon_fdset_cur
->id
;
1283 mon_fdset
= g_malloc0(sizeof(*mon_fdset
));
1285 mon_fdset
->id
= fdset_id
;
1287 mon_fdset
->id
= fdset_id_prev
+ 1;
1290 /* The fdset list is ordered by fdset ID */
1291 if (!mon_fdset_cur
) {
1292 QLIST_INSERT_HEAD(&mon_fdsets
, mon_fdset
, next
);
1293 } else if (mon_fdset
->id
< mon_fdset_cur
->id
) {
1294 QLIST_INSERT_BEFORE(mon_fdset_cur
, mon_fdset
, next
);
1296 QLIST_INSERT_AFTER(mon_fdset_cur
, mon_fdset
, next
);
1300 mon_fdset_fd
= g_malloc0(sizeof(*mon_fdset_fd
));
1301 mon_fdset_fd
->fd
= fd
;
1302 mon_fdset_fd
->removed
= false;
1304 mon_fdset_fd
->opaque
= g_strdup(opaque
);
1306 QLIST_INSERT_HEAD(&mon_fdset
->fds
, mon_fdset_fd
, next
);
1308 fdinfo
= g_malloc0(sizeof(*fdinfo
));
1309 fdinfo
->fdset_id
= mon_fdset
->id
;
1310 fdinfo
->fd
= mon_fdset_fd
->fd
;
1315 int monitor_fdset_dup_fd_add(int64_t fdset_id
, int flags
)
1320 MonFdset
*mon_fdset
;
1322 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1323 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1324 MonFdsetFd
*mon_fdset_fd
;
1325 MonFdsetFd
*mon_fdset_fd_dup
;
1330 if (mon_fdset
->id
!= fdset_id
) {
1334 QLIST_FOREACH(mon_fdset_fd
, &mon_fdset
->fds
, next
) {
1335 mon_fd_flags
= fcntl(mon_fdset_fd
->fd
, F_GETFL
);
1336 if (mon_fd_flags
== -1) {
1340 if ((flags
& O_ACCMODE
) == (mon_fd_flags
& O_ACCMODE
)) {
1341 fd
= mon_fdset_fd
->fd
;
1351 dup_fd
= qemu_dup_flags(fd
, flags
);
1356 mon_fdset_fd_dup
= g_malloc0(sizeof(*mon_fdset_fd_dup
));
1357 mon_fdset_fd_dup
->fd
= dup_fd
;
1358 QLIST_INSERT_HEAD(&mon_fdset
->dup_fds
, mon_fdset_fd_dup
, next
);
1367 static int64_t monitor_fdset_dup_fd_find_remove(int dup_fd
, bool remove
)
1369 MonFdset
*mon_fdset
;
1370 MonFdsetFd
*mon_fdset_fd_dup
;
1372 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1373 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1374 QLIST_FOREACH(mon_fdset_fd_dup
, &mon_fdset
->dup_fds
, next
) {
1375 if (mon_fdset_fd_dup
->fd
== dup_fd
) {
1377 QLIST_REMOVE(mon_fdset_fd_dup
, next
);
1378 g_free(mon_fdset_fd_dup
);
1379 if (QLIST_EMPTY(&mon_fdset
->dup_fds
)) {
1380 monitor_fdset_cleanup(mon_fdset
);
1384 return mon_fdset
->id
;
1393 int64_t monitor_fdset_dup_fd_find(int dup_fd
)
1395 return monitor_fdset_dup_fd_find_remove(dup_fd
, false);
1398 void monitor_fdset_dup_fd_remove(int dup_fd
)
1400 monitor_fdset_dup_fd_find_remove(dup_fd
, true);
1403 int monitor_fd_param(Monitor
*mon
, const char *fdname
, Error
**errp
)
1406 Error
*local_err
= NULL
;
1408 if (!qemu_isdigit(fdname
[0]) && mon
) {
1409 fd
= monitor_get_fd(mon
, fdname
, &local_err
);
1411 fd
= qemu_parse_fd(fdname
);
1413 error_setg(&local_err
, "Invalid file descriptor number '%s'",
1418 error_propagate(errp
, local_err
);
1427 /* Please update hmp-commands.hx when adding or changing commands */
1428 static HMPCommand hmp_info_cmds
[] = {
1429 #include "hmp-commands-info.h"
1433 /* hmp_cmds and hmp_info_cmds would be sorted at runtime */
1434 HMPCommand hmp_cmds
[] = {
1435 #include "hmp-commands.h"
1440 * Set @pval to the value in the register identified by @name.
1441 * return 0 if OK, -1 if not found
1443 int get_monitor_def(Monitor
*mon
, int64_t *pval
, const char *name
)
1445 const MonitorDef
*md
= target_monitor_defs();
1446 CPUState
*cs
= mon_get_cpu(mon
);
1451 if (cs
== NULL
|| md
== NULL
) {
1455 for(; md
->name
!= NULL
; md
++) {
1456 if (hmp_compare_cmd(name
, md
->name
)) {
1457 if (md
->get_value
) {
1458 *pval
= md
->get_value(mon
, md
, md
->offset
);
1460 CPUArchState
*env
= mon_get_cpu_env(mon
);
1461 ptr
= (uint8_t *)env
+ md
->offset
;
1464 *pval
= *(int32_t *)ptr
;
1467 *pval
= *(target_long
*)ptr
;
1478 ret
= target_get_monitor_def(cs
, name
, &tmp
);
1480 *pval
= (target_long
) tmp
;
1486 static void add_completion_option(ReadLineState
*rs
, const char *str
,
1489 if (!str
|| !option
) {
1492 if (!strncmp(option
, str
, strlen(str
))) {
1493 readline_add_completion(rs
, option
);
1497 void chardev_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1500 ChardevBackendInfoList
*list
, *start
;
1506 readline_set_completion_index(rs
, len
);
1508 start
= list
= qmp_query_chardev_backends(NULL
);
1510 const char *chr_name
= list
->value
->name
;
1512 if (!strncmp(chr_name
, str
, len
)) {
1513 readline_add_completion(rs
, chr_name
);
1517 qapi_free_ChardevBackendInfoList(start
);
1520 void netdev_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1529 readline_set_completion_index(rs
, len
);
1530 for (i
= 0; i
< NET_CLIENT_DRIVER__MAX
; i
++) {
1531 add_completion_option(rs
, str
, NetClientDriver_str(i
));
1535 void device_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1545 readline_set_completion_index(rs
, len
);
1546 list
= elt
= object_class_get_list(TYPE_DEVICE
, false);
1549 DeviceClass
*dc
= OBJECT_CLASS_CHECK(DeviceClass
, elt
->data
,
1551 name
= object_class_get_name(OBJECT_CLASS(dc
));
1553 if (dc
->user_creatable
1554 && !strncmp(name
, str
, len
)) {
1555 readline_add_completion(rs
, name
);
1562 void object_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1572 readline_set_completion_index(rs
, len
);
1573 list
= elt
= object_class_get_list(TYPE_USER_CREATABLE
, false);
1577 name
= object_class_get_name(OBJECT_CLASS(elt
->data
));
1578 if (!strncmp(name
, str
, len
) && strcmp(name
, TYPE_USER_CREATABLE
)) {
1579 readline_add_completion(rs
, name
);
1586 static int qdev_add_hotpluggable_device(Object
*obj
, void *opaque
)
1588 GSList
**list
= opaque
;
1589 DeviceState
*dev
= (DeviceState
*)object_dynamic_cast(obj
, TYPE_DEVICE
);
1595 if (dev
->realized
&& object_property_get_bool(obj
, "hotpluggable", NULL
)) {
1596 *list
= g_slist_append(*list
, dev
);
1602 static GSList
*qdev_build_hotpluggable_device_list(Object
*peripheral
)
1604 GSList
*list
= NULL
;
1606 object_child_foreach(peripheral
, qdev_add_hotpluggable_device
, &list
);
1611 static void peripheral_device_del_completion(ReadLineState
*rs
,
1612 const char *str
, size_t len
)
1614 Object
*peripheral
= container_get(qdev_get_machine(), "/peripheral");
1615 GSList
*list
, *item
;
1617 list
= qdev_build_hotpluggable_device_list(peripheral
);
1622 for (item
= list
; item
; item
= g_slist_next(item
)) {
1623 DeviceState
*dev
= item
->data
;
1625 if (dev
->id
&& !strncmp(str
, dev
->id
, len
)) {
1626 readline_add_completion(rs
, dev
->id
);
1633 void chardev_remove_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1636 ChardevInfoList
*list
, *start
;
1642 readline_set_completion_index(rs
, len
);
1644 start
= list
= qmp_query_chardev(NULL
);
1646 ChardevInfo
*chr
= list
->value
;
1648 if (!strncmp(chr
->label
, str
, len
)) {
1649 readline_add_completion(rs
, chr
->label
);
1653 qapi_free_ChardevInfoList(start
);
1656 static void ringbuf_completion(ReadLineState
*rs
, const char *str
)
1659 ChardevInfoList
*list
, *start
;
1662 readline_set_completion_index(rs
, len
);
1664 start
= list
= qmp_query_chardev(NULL
);
1666 ChardevInfo
*chr_info
= list
->value
;
1668 if (!strncmp(chr_info
->label
, str
, len
)) {
1669 Chardev
*chr
= qemu_chr_find(chr_info
->label
);
1670 if (chr
&& CHARDEV_IS_RINGBUF(chr
)) {
1671 readline_add_completion(rs
, chr_info
->label
);
1676 qapi_free_ChardevInfoList(start
);
1679 void ringbuf_write_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1684 ringbuf_completion(rs
, str
);
1687 void device_del_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1696 readline_set_completion_index(rs
, len
);
1697 peripheral_device_del_completion(rs
, str
, len
);
1700 void object_del_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1702 ObjectPropertyInfoList
*list
, *start
;
1709 readline_set_completion_index(rs
, len
);
1711 start
= list
= qmp_qom_list("/objects", NULL
);
1713 ObjectPropertyInfo
*info
= list
->value
;
1715 if (!strncmp(info
->type
, "child<", 5)
1716 && !strncmp(info
->name
, str
, len
)) {
1717 readline_add_completion(rs
, info
->name
);
1721 qapi_free_ObjectPropertyInfoList(start
);
1724 void sendkey_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1733 sep
= strrchr(str
, '-');
1738 readline_set_completion_index(rs
, len
);
1739 for (i
= 0; i
< Q_KEY_CODE__MAX
; i
++) {
1740 if (!strncmp(str
, QKeyCode_str(i
), len
)) {
1741 readline_add_completion(rs
, QKeyCode_str(i
));
1746 void set_link_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1751 readline_set_completion_index(rs
, len
);
1753 NetClientState
*ncs
[MAX_QUEUE_NUM
];
1755 count
= qemu_find_net_clients_except(NULL
, ncs
,
1756 NET_CLIENT_DRIVER_NONE
,
1758 for (i
= 0; i
< MIN(count
, MAX_QUEUE_NUM
); i
++) {
1759 const char *name
= ncs
[i
]->name
;
1760 if (!strncmp(str
, name
, len
)) {
1761 readline_add_completion(rs
, name
);
1764 } else if (nb_args
== 3) {
1765 add_completion_option(rs
, str
, "on");
1766 add_completion_option(rs
, str
, "off");
1770 void netdev_del_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1773 NetClientState
*ncs
[MAX_QUEUE_NUM
];
1780 readline_set_completion_index(rs
, len
);
1781 count
= qemu_find_net_clients_except(NULL
, ncs
, NET_CLIENT_DRIVER_NIC
,
1783 for (i
= 0; i
< MIN(count
, MAX_QUEUE_NUM
); i
++) {
1784 const char *name
= ncs
[i
]->name
;
1785 if (strncmp(str
, name
, len
)) {
1788 if (ncs
[i
]->is_netdev
) {
1789 readline_add_completion(rs
, name
);
1794 void info_trace_events_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1799 readline_set_completion_index(rs
, len
);
1801 TraceEventIter iter
;
1803 char *pattern
= g_strdup_printf("%s*", str
);
1804 trace_event_iter_init_pattern(&iter
, pattern
);
1805 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
1806 readline_add_completion(rs
, trace_event_get_name(ev
));
1812 void trace_event_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1817 readline_set_completion_index(rs
, len
);
1819 TraceEventIter iter
;
1821 char *pattern
= g_strdup_printf("%s*", str
);
1822 trace_event_iter_init_pattern(&iter
, pattern
);
1823 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
1824 readline_add_completion(rs
, trace_event_get_name(ev
));
1827 } else if (nb_args
== 3) {
1828 add_completion_option(rs
, str
, "on");
1829 add_completion_option(rs
, str
, "off");
1833 void watchdog_action_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1840 readline_set_completion_index(rs
, strlen(str
));
1841 for (i
= 0; i
< WATCHDOG_ACTION__MAX
; i
++) {
1842 add_completion_option(rs
, str
, WatchdogAction_str(i
));
1846 void migrate_set_capability_completion(ReadLineState
*rs
, int nb_args
,
1852 readline_set_completion_index(rs
, len
);
1855 for (i
= 0; i
< MIGRATION_CAPABILITY__MAX
; i
++) {
1856 const char *name
= MigrationCapability_str(i
);
1857 if (!strncmp(str
, name
, len
)) {
1858 readline_add_completion(rs
, name
);
1861 } else if (nb_args
== 3) {
1862 add_completion_option(rs
, str
, "on");
1863 add_completion_option(rs
, str
, "off");
1867 void migrate_set_parameter_completion(ReadLineState
*rs
, int nb_args
,
1873 readline_set_completion_index(rs
, len
);
1876 for (i
= 0; i
< MIGRATION_PARAMETER__MAX
; i
++) {
1877 const char *name
= MigrationParameter_str(i
);
1878 if (!strncmp(str
, name
, len
)) {
1879 readline_add_completion(rs
, name
);
1885 static void vm_completion(ReadLineState
*rs
, const char *str
)
1888 BlockDriverState
*bs
;
1889 BdrvNextIterator it
;
1892 readline_set_completion_index(rs
, len
);
1894 for (bs
= bdrv_first(&it
); bs
; bs
= bdrv_next(&it
)) {
1895 SnapshotInfoList
*snapshots
, *snapshot
;
1896 AioContext
*ctx
= bdrv_get_aio_context(bs
);
1899 aio_context_acquire(ctx
);
1900 if (bdrv_can_snapshot(bs
)) {
1901 ok
= bdrv_query_snapshot_info_list(bs
, &snapshots
, NULL
) == 0;
1903 aio_context_release(ctx
);
1908 snapshot
= snapshots
;
1910 char *completion
= snapshot
->value
->name
;
1911 if (!strncmp(str
, completion
, len
)) {
1912 readline_add_completion(rs
, completion
);
1914 completion
= snapshot
->value
->id
;
1915 if (!strncmp(str
, completion
, len
)) {
1916 readline_add_completion(rs
, completion
);
1918 snapshot
= snapshot
->next
;
1920 qapi_free_SnapshotInfoList(snapshots
);
1925 void delvm_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1928 vm_completion(rs
, str
);
1932 void loadvm_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1935 vm_completion(rs
, str
);
1940 compare_mon_cmd(const void *a
, const void *b
)
1942 return strcmp(((const HMPCommand
*)a
)->name
,
1943 ((const HMPCommand
*)b
)->name
);
1946 static void sortcmdlist(void)
1948 qsort(hmp_cmds
, ARRAY_SIZE(hmp_cmds
) - 1,
1951 qsort(hmp_info_cmds
, ARRAY_SIZE(hmp_info_cmds
) - 1,
1952 sizeof(*hmp_info_cmds
),
1956 void monitor_register_hmp(const char *name
, bool info
,
1957 void (*cmd
)(Monitor
*mon
, const QDict
*qdict
))
1959 HMPCommand
*table
= info
? hmp_info_cmds
: hmp_cmds
;
1961 while (table
->name
!= NULL
) {
1962 if (strcmp(table
->name
, name
) == 0) {
1963 g_assert(table
->cmd
== NULL
&& table
->cmd_info_hrt
== NULL
);
1969 g_assert_not_reached();
1972 void monitor_register_hmp_info_hrt(const char *name
,
1973 HumanReadableText
*(*handler
)(Error
**errp
))
1975 HMPCommand
*table
= hmp_info_cmds
;
1977 while (table
->name
!= NULL
) {
1978 if (strcmp(table
->name
, name
) == 0) {
1979 g_assert(table
->cmd
== NULL
&& table
->cmd_info_hrt
== NULL
);
1980 table
->cmd_info_hrt
= handler
;
1985 g_assert_not_reached();
1988 void monitor_init_globals(void)
1990 monitor_init_globals_core();
1991 monitor_init_qmp_commands();
1993 qemu_mutex_init(&mon_fdsets_lock
);