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"
44 #include "sysemu/hw_accel.h"
45 #include "sysemu/runstate.h"
46 #include "authz/list.h"
47 #include "qapi/util.h"
48 #include "sysemu/blockdev.h"
49 #include "sysemu/sysemu.h"
50 #include "sysemu/tcg.h"
51 #include "sysemu/tpm.h"
52 #include "qapi/qmp/qdict.h"
53 #include "qapi/qmp/qerror.h"
54 #include "qapi/qmp/qstring.h"
55 #include "qom/object_interfaces.h"
56 #include "trace/control.h"
57 #include "monitor/hmp-target.h"
58 #include "monitor/hmp.h"
59 #ifdef CONFIG_TRACE_SIMPLE
60 #include "trace/simple.h"
62 #include "exec/memory.h"
63 #include "exec/exec-all.h"
64 #include "qemu/option.h"
65 #include "qemu/thread.h"
66 #include "block/qapi.h"
67 #include "block/block-hmp-cmds.h"
68 #include "qapi/qapi-commands-char.h"
69 #include "qapi/qapi-commands-control.h"
70 #include "qapi/qapi-commands-migration.h"
71 #include "qapi/qapi-commands-misc.h"
72 #include "qapi/qapi-commands-qom.h"
73 #include "qapi/qapi-commands-trace.h"
74 #include "qapi/qapi-init-commands.h"
75 #include "qapi/error.h"
76 #include "qapi/qmp-event.h"
77 #include "sysemu/cpus.h"
78 #include "qemu/cutils.h"
80 #if defined(TARGET_S390X)
81 #include "hw/s390x/storage-keys.h"
82 #include "hw/s390x/storage-attributes.h"
85 /* file descriptors passed via SCM_RIGHTS */
86 typedef struct mon_fd_t mon_fd_t
;
90 QLIST_ENTRY(mon_fd_t
) next
;
93 /* file descriptor associated with a file descriptor set */
94 typedef struct MonFdsetFd MonFdsetFd
;
99 QLIST_ENTRY(MonFdsetFd
) next
;
102 /* file descriptor set containing fds passed via SCM_RIGHTS */
103 typedef struct MonFdset MonFdset
;
106 QLIST_HEAD(, MonFdsetFd
) fds
;
107 QLIST_HEAD(, MonFdsetFd
) dup_fds
;
108 QLIST_ENTRY(MonFdset
) next
;
111 /* Protects mon_fdsets */
112 static QemuMutex mon_fdsets_lock
;
113 static QLIST_HEAD(, MonFdset
) mon_fdsets
;
115 static HMPCommand hmp_info_cmds
[];
117 char *qmp_human_monitor_command(const char *command_line
, bool has_cpu_index
,
118 int64_t cpu_index
, Error
**errp
)
123 monitor_data_init(&hmp
.common
, false, true, false);
126 int ret
= monitor_set_cpu(&hmp
.common
, cpu_index
);
128 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "cpu-index",
134 handle_hmp_command(&hmp
, command_line
);
136 WITH_QEMU_LOCK_GUARD(&hmp
.common
.mon_lock
) {
137 output
= g_strdup(hmp
.common
.outbuf
->str
);
141 monitor_data_destroy(&hmp
.common
);
146 * Is @name in the '|' separated list of names @list?
148 int hmp_compare_cmd(const char *name
, const char *list
)
150 const char *p
, *pstart
;
156 p
= qemu_strchrnul(p
, '|');
157 if ((p
- pstart
) == len
&& !memcmp(pstart
, name
, len
)) {
168 static void do_help_cmd(Monitor
*mon
, const QDict
*qdict
)
170 help_cmd(mon
, qdict_get_try_str(qdict
, "name"));
173 static void hmp_trace_event(Monitor
*mon
, const QDict
*qdict
)
175 const char *tp_name
= qdict_get_str(qdict
, "name");
176 bool new_state
= qdict_get_bool(qdict
, "option");
177 bool has_vcpu
= qdict_haskey(qdict
, "vcpu");
178 int vcpu
= qdict_get_try_int(qdict
, "vcpu", 0);
179 Error
*local_err
= NULL
;
182 monitor_printf(mon
, "argument vcpu must be positive");
186 qmp_trace_event_set_state(tp_name
, new_state
, true, true, has_vcpu
, vcpu
, &local_err
);
188 error_report_err(local_err
);
192 #ifdef CONFIG_TRACE_SIMPLE
193 static void hmp_trace_file(Monitor
*mon
, const QDict
*qdict
)
195 const char *op
= qdict_get_try_str(qdict
, "op");
196 const char *arg
= qdict_get_try_str(qdict
, "arg");
199 st_print_trace_file_status();
200 } else if (!strcmp(op
, "on")) {
201 st_set_trace_file_enabled(true);
202 } else if (!strcmp(op
, "off")) {
203 st_set_trace_file_enabled(false);
204 } else if (!strcmp(op
, "flush")) {
205 st_flush_trace_buffer();
206 } else if (!strcmp(op
, "set")) {
208 st_set_trace_file(arg
);
211 monitor_printf(mon
, "unexpected argument \"%s\"\n", op
);
212 help_cmd(mon
, "trace-file");
217 static void hmp_info_help(Monitor
*mon
, const QDict
*qdict
)
219 help_cmd(mon
, "info");
222 static void monitor_init_qmp_commands(void)
226 * - qmp_commands contains all QMP commands
227 * - qmp_cap_negotiation_commands contains just
228 * "qmp_capabilities", to enforce capability negotiation
231 qmp_init_marshal(&qmp_commands
);
233 qmp_register_command(&qmp_commands
, "device_add", qmp_device_add
,
236 QTAILQ_INIT(&qmp_cap_negotiation_commands
);
237 qmp_register_command(&qmp_cap_negotiation_commands
, "qmp_capabilities",
238 qmp_marshal_qmp_capabilities
, QCO_ALLOW_PRECONFIG
);
241 /* Set the current CPU defined by the user. Callers must hold BQL. */
242 int monitor_set_cpu(Monitor
*mon
, int cpu_index
)
246 cpu
= qemu_get_cpu(cpu_index
);
250 g_free(mon
->mon_cpu_path
);
251 mon
->mon_cpu_path
= object_get_canonical_path(OBJECT(cpu
));
255 /* Callers must hold BQL. */
256 static CPUState
*mon_get_cpu_sync(Monitor
*mon
, bool synchronize
)
258 CPUState
*cpu
= NULL
;
260 if (mon
->mon_cpu_path
) {
261 cpu
= (CPUState
*) object_resolve_path_type(mon
->mon_cpu_path
,
264 g_free(mon
->mon_cpu_path
);
265 mon
->mon_cpu_path
= NULL
;
268 if (!mon
->mon_cpu_path
) {
272 monitor_set_cpu(mon
, first_cpu
->cpu_index
);
277 cpu_synchronize_state(cpu
);
282 CPUState
*mon_get_cpu(Monitor
*mon
)
284 return mon_get_cpu_sync(mon
, true);
287 CPUArchState
*mon_get_cpu_env(Monitor
*mon
)
289 CPUState
*cs
= mon_get_cpu(mon
);
291 return cs
? cs
->env_ptr
: NULL
;
294 int monitor_get_cpu_index(Monitor
*mon
)
296 CPUState
*cs
= mon_get_cpu_sync(mon
, false);
298 return cs
? cs
->cpu_index
: UNASSIGNED_CPU_INDEX
;
301 static void hmp_info_registers(Monitor
*mon
, const QDict
*qdict
)
303 bool all_cpus
= qdict_get_try_bool(qdict
, "cpustate_all", false);
308 monitor_printf(mon
, "\nCPU#%d\n", cs
->cpu_index
);
309 cpu_dump_state(cs
, NULL
, CPU_DUMP_FPU
);
312 cs
= mon_get_cpu(mon
);
315 monitor_printf(mon
, "No CPU available\n");
319 cpu_dump_state(cs
, NULL
, CPU_DUMP_FPU
);
323 static void hmp_info_sync_profile(Monitor
*mon
, const QDict
*qdict
)
325 int64_t max
= qdict_get_try_int(qdict
, "max", 10);
326 bool mean
= qdict_get_try_bool(qdict
, "mean", false);
327 bool coalesce
= !qdict_get_try_bool(qdict
, "no_coalesce", false);
328 enum QSPSortBy sort_by
;
330 sort_by
= mean
? QSP_SORT_BY_AVG_WAIT_TIME
: QSP_SORT_BY_TOTAL_WAIT_TIME
;
331 qsp_report(max
, sort_by
, coalesce
);
334 static void hmp_info_history(Monitor
*mon
, const QDict
*qdict
)
336 MonitorHMP
*hmp_mon
= container_of(mon
, MonitorHMP
, common
);
345 str
= readline_get_history(hmp_mon
->rs
, i
);
349 monitor_printf(mon
, "%d: '%s'\n", i
, str
);
354 static void hmp_info_trace_events(Monitor
*mon
, const QDict
*qdict
)
356 const char *name
= qdict_get_try_str(qdict
, "name");
357 bool has_vcpu
= qdict_haskey(qdict
, "vcpu");
358 int vcpu
= qdict_get_try_int(qdict
, "vcpu", 0);
359 TraceEventInfoList
*events
;
360 TraceEventInfoList
*elem
;
361 Error
*local_err
= NULL
;
367 monitor_printf(mon
, "argument vcpu must be positive");
371 events
= qmp_trace_event_get_state(name
, has_vcpu
, vcpu
, &local_err
);
373 error_report_err(local_err
);
377 for (elem
= events
; elem
!= NULL
; elem
= elem
->next
) {
378 monitor_printf(mon
, "%s : state %u\n",
380 elem
->value
->state
== TRACE_EVENT_STATE_ENABLED
? 1 : 0);
382 qapi_free_TraceEventInfoList(events
);
385 void qmp_client_migrate_info(const char *protocol
, const char *hostname
,
386 bool has_port
, int64_t port
,
387 bool has_tls_port
, int64_t tls_port
,
388 bool has_cert_subject
, const char *cert_subject
,
391 if (strcmp(protocol
, "spice") == 0) {
392 if (!qemu_using_spice(errp
)) {
396 if (!has_port
&& !has_tls_port
) {
397 error_setg(errp
, QERR_MISSING_PARAMETER
, "port/tls-port");
401 if (qemu_spice
.migrate_info(hostname
,
402 has_port
? port
: -1,
403 has_tls_port
? tls_port
: -1,
405 error_setg(errp
, "Could not set up display for migration");
411 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "protocol", "'spice'");
414 static void hmp_logfile(Monitor
*mon
, const QDict
*qdict
)
418 qemu_set_log_filename(qdict_get_str(qdict
, "filename"), &err
);
420 error_report_err(err
);
424 static void hmp_log(Monitor
*mon
, const QDict
*qdict
)
427 const char *items
= qdict_get_str(qdict
, "items");
429 if (!strcmp(items
, "none")) {
432 mask
= qemu_str_to_log_mask(items
);
434 help_cmd(mon
, "log");
441 static void hmp_singlestep(Monitor
*mon
, const QDict
*qdict
)
443 const char *option
= qdict_get_try_str(qdict
, "option");
444 if (!option
|| !strcmp(option
, "on")) {
446 } else if (!strcmp(option
, "off")) {
449 monitor_printf(mon
, "unexpected option %s\n", option
);
453 static void hmp_gdbserver(Monitor
*mon
, const QDict
*qdict
)
455 const char *device
= qdict_get_try_str(qdict
, "device");
457 device
= "tcp::" DEFAULT_GDBSTUB_PORT
;
460 if (gdbserver_start(device
) < 0) {
461 monitor_printf(mon
, "Could not open gdbserver on device '%s'\n",
463 } else if (strcmp(device
, "none") == 0) {
464 monitor_printf(mon
, "Disabled gdbserver\n");
466 monitor_printf(mon
, "Waiting for gdb connection on device '%s'\n",
471 static void hmp_watchdog_action(Monitor
*mon
, const QDict
*qdict
)
473 const char *action
= qdict_get_str(qdict
, "action");
474 if (select_watchdog_action(action
) == -1) {
475 monitor_printf(mon
, "Unknown watchdog action '%s'\n", action
);
479 static void monitor_printc(Monitor
*mon
, int c
)
481 monitor_printf(mon
, "'");
484 monitor_printf(mon
, "\\'");
487 monitor_printf(mon
, "\\\\");
490 monitor_printf(mon
, "\\n");
493 monitor_printf(mon
, "\\r");
496 if (c
>= 32 && c
<= 126) {
497 monitor_printf(mon
, "%c", c
);
499 monitor_printf(mon
, "\\x%02x", c
);
503 monitor_printf(mon
, "'");
506 static void memory_dump(Monitor
*mon
, int count
, int format
, int wsize
,
507 hwaddr addr
, int is_physical
)
509 int l
, line_size
, i
, max_digits
, len
;
512 CPUState
*cs
= mon_get_cpu(mon
);
514 if (!cs
&& (format
== 'i' || !is_physical
)) {
515 monitor_printf(mon
, "Can not dump without CPU\n");
520 monitor_disas(mon
, cs
, addr
, count
, is_physical
);
534 max_digits
= DIV_ROUND_UP(wsize
* 8, 3);
538 max_digits
= (wsize
* 8) / 4;
542 max_digits
= DIV_ROUND_UP(wsize
* 8 * 10, 33);
551 monitor_printf(mon
, TARGET_FMT_plx
":", addr
);
553 monitor_printf(mon
, TARGET_FMT_lx
":", (target_ulong
)addr
);
559 AddressSpace
*as
= cs
? cs
->as
: &address_space_memory
;
560 MemTxResult r
= address_space_read(as
, addr
,
561 MEMTXATTRS_UNSPECIFIED
, buf
, l
);
563 monitor_printf(mon
, " Cannot access memory\n");
567 if (cpu_memory_rw_debug(cs
, addr
, buf
, l
, 0) < 0) {
568 monitor_printf(mon
, " Cannot access memory\n");
583 v
= (uint32_t)ldl_p(buf
+ i
);
589 monitor_printf(mon
, " ");
592 monitor_printf(mon
, "%#*" PRIo64
, max_digits
, v
);
595 monitor_printf(mon
, "0x%0*" PRIx64
, max_digits
, v
);
598 monitor_printf(mon
, "%*" PRIu64
, max_digits
, v
);
601 monitor_printf(mon
, "%*" PRId64
, max_digits
, v
);
604 monitor_printc(mon
, v
);
609 monitor_printf(mon
, "\n");
615 static void hmp_memory_dump(Monitor
*mon
, const QDict
*qdict
)
617 int count
= qdict_get_int(qdict
, "count");
618 int format
= qdict_get_int(qdict
, "format");
619 int size
= qdict_get_int(qdict
, "size");
620 target_long addr
= qdict_get_int(qdict
, "addr");
622 memory_dump(mon
, count
, format
, size
, addr
, 0);
625 static void hmp_physical_memory_dump(Monitor
*mon
, const QDict
*qdict
)
627 int count
= qdict_get_int(qdict
, "count");
628 int format
= qdict_get_int(qdict
, "format");
629 int size
= qdict_get_int(qdict
, "size");
630 hwaddr addr
= qdict_get_int(qdict
, "addr");
632 memory_dump(mon
, count
, format
, size
, addr
, 1);
635 void *gpa2hva(MemoryRegion
**p_mr
, hwaddr addr
, uint64_t size
, Error
**errp
)
637 Int128 gpa_region_size
;
638 MemoryRegionSection mrs
= memory_region_find(get_system_memory(),
642 error_setg(errp
, "No memory is mapped at address 0x%" HWADDR_PRIx
, addr
);
646 if (!memory_region_is_ram(mrs
.mr
) && !memory_region_is_romd(mrs
.mr
)) {
647 error_setg(errp
, "Memory at address 0x%" HWADDR_PRIx
"is not RAM", addr
);
648 memory_region_unref(mrs
.mr
);
652 gpa_region_size
= int128_make64(size
);
653 if (int128_lt(mrs
.size
, gpa_region_size
)) {
654 error_setg(errp
, "Size of memory region at 0x%" HWADDR_PRIx
656 memory_region_unref(mrs
.mr
);
661 return qemu_map_ram_ptr(mrs
.mr
->ram_block
, mrs
.offset_within_region
);
664 static void hmp_gpa2hva(Monitor
*mon
, const QDict
*qdict
)
666 hwaddr addr
= qdict_get_int(qdict
, "addr");
667 Error
*local_err
= NULL
;
668 MemoryRegion
*mr
= NULL
;
671 ptr
= gpa2hva(&mr
, addr
, 1, &local_err
);
673 error_report_err(local_err
);
677 monitor_printf(mon
, "Host virtual address for 0x%" HWADDR_PRIx
679 addr
, mr
->name
, ptr
);
681 memory_region_unref(mr
);
684 static void hmp_gva2gpa(Monitor
*mon
, const QDict
*qdict
)
686 target_ulong addr
= qdict_get_int(qdict
, "addr");
688 CPUState
*cs
= mon_get_cpu(mon
);
692 monitor_printf(mon
, "No cpu\n");
696 gpa
= cpu_get_phys_page_attrs_debug(cs
, addr
& TARGET_PAGE_MASK
, &attrs
);
698 monitor_printf(mon
, "Unmapped\n");
700 monitor_printf(mon
, "gpa: %#" HWADDR_PRIx
"\n",
701 gpa
+ (addr
& ~TARGET_PAGE_MASK
));
706 static uint64_t vtop(void *ptr
, Error
**errp
)
710 uintptr_t addr
= (uintptr_t) ptr
;
711 uintptr_t pagesize
= qemu_real_host_page_size
;
712 off_t offset
= addr
/ pagesize
* sizeof(pinfo
);
715 fd
= open("/proc/self/pagemap", O_RDONLY
);
717 error_setg_errno(errp
, errno
, "Cannot open /proc/self/pagemap");
721 /* Force copy-on-write if necessary. */
722 qatomic_add((uint8_t *)ptr
, 0);
724 if (pread(fd
, &pinfo
, sizeof(pinfo
), offset
) != sizeof(pinfo
)) {
725 error_setg_errno(errp
, errno
, "Cannot read pagemap");
728 if ((pinfo
& (1ull << 63)) == 0) {
729 error_setg(errp
, "Page not present");
732 ret
= ((pinfo
& 0x007fffffffffffffull
) * pagesize
) | (addr
& (pagesize
- 1));
739 static void hmp_gpa2hpa(Monitor
*mon
, const QDict
*qdict
)
741 hwaddr addr
= qdict_get_int(qdict
, "addr");
742 Error
*local_err
= NULL
;
743 MemoryRegion
*mr
= NULL
;
747 ptr
= gpa2hva(&mr
, addr
, 1, &local_err
);
749 error_report_err(local_err
);
753 physaddr
= vtop(ptr
, &local_err
);
755 error_report_err(local_err
);
757 monitor_printf(mon
, "Host physical address for 0x%" HWADDR_PRIx
758 " (%s) is 0x%" PRIx64
"\n",
759 addr
, mr
->name
, (uint64_t) physaddr
);
762 memory_region_unref(mr
);
766 static void do_print(Monitor
*mon
, const QDict
*qdict
)
768 int format
= qdict_get_int(qdict
, "format");
769 hwaddr val
= qdict_get_int(qdict
, "val");
773 monitor_printf(mon
, "%#" HWADDR_PRIo
, val
);
776 monitor_printf(mon
, "%#" HWADDR_PRIx
, val
);
779 monitor_printf(mon
, "%" HWADDR_PRIu
, val
);
783 monitor_printf(mon
, "%" HWADDR_PRId
, val
);
786 monitor_printc(mon
, val
);
789 monitor_printf(mon
, "\n");
792 static void hmp_sum(Monitor
*mon
, const QDict
*qdict
)
796 uint32_t start
= qdict_get_int(qdict
, "start");
797 uint32_t size
= qdict_get_int(qdict
, "size");
800 for(addr
= start
; addr
< (start
+ size
); addr
++) {
801 uint8_t val
= address_space_ldub(&address_space_memory
, addr
,
802 MEMTXATTRS_UNSPECIFIED
, NULL
);
803 /* BSD sum algorithm ('sum' Unix command) */
804 sum
= (sum
>> 1) | (sum
<< 15);
807 monitor_printf(mon
, "%05d\n", sum
);
810 static int mouse_button_state
;
812 static void hmp_mouse_move(Monitor
*mon
, const QDict
*qdict
)
814 int dx
, dy
, dz
, button
;
815 const char *dx_str
= qdict_get_str(qdict
, "dx_str");
816 const char *dy_str
= qdict_get_str(qdict
, "dy_str");
817 const char *dz_str
= qdict_get_try_str(qdict
, "dz_str");
819 dx
= strtol(dx_str
, NULL
, 0);
820 dy
= strtol(dy_str
, NULL
, 0);
821 qemu_input_queue_rel(NULL
, INPUT_AXIS_X
, dx
);
822 qemu_input_queue_rel(NULL
, INPUT_AXIS_Y
, dy
);
825 dz
= strtol(dz_str
, NULL
, 0);
827 button
= (dz
> 0) ? INPUT_BUTTON_WHEEL_UP
: INPUT_BUTTON_WHEEL_DOWN
;
828 qemu_input_queue_btn(NULL
, button
, true);
829 qemu_input_event_sync();
830 qemu_input_queue_btn(NULL
, button
, false);
833 qemu_input_event_sync();
836 static void hmp_mouse_button(Monitor
*mon
, const QDict
*qdict
)
838 static uint32_t bmap
[INPUT_BUTTON__MAX
] = {
839 [INPUT_BUTTON_LEFT
] = MOUSE_EVENT_LBUTTON
,
840 [INPUT_BUTTON_MIDDLE
] = MOUSE_EVENT_MBUTTON
,
841 [INPUT_BUTTON_RIGHT
] = MOUSE_EVENT_RBUTTON
,
843 int button_state
= qdict_get_int(qdict
, "button_state");
845 if (mouse_button_state
== button_state
) {
848 qemu_input_update_buttons(NULL
, bmap
, mouse_button_state
, button_state
);
849 qemu_input_event_sync();
850 mouse_button_state
= button_state
;
853 static void hmp_ioport_read(Monitor
*mon
, const QDict
*qdict
)
855 int size
= qdict_get_int(qdict
, "size");
856 int addr
= qdict_get_int(qdict
, "addr");
857 int has_index
= qdict_haskey(qdict
, "index");
862 int index
= qdict_get_int(qdict
, "index");
863 cpu_outb(addr
& IOPORTS_MASK
, index
& 0xff);
883 monitor_printf(mon
, "port%c[0x%04x] = 0x%0*x\n",
884 suffix
, addr
, size
* 2, val
);
887 static void hmp_ioport_write(Monitor
*mon
, const QDict
*qdict
)
889 int size
= qdict_get_int(qdict
, "size");
890 int addr
= qdict_get_int(qdict
, "addr");
891 int val
= qdict_get_int(qdict
, "val");
893 addr
&= IOPORTS_MASK
;
909 static void hmp_boot_set(Monitor
*mon
, const QDict
*qdict
)
911 Error
*local_err
= NULL
;
912 const char *bootdevice
= qdict_get_str(qdict
, "bootdevice");
914 qemu_boot_set(bootdevice
, &local_err
);
916 error_report_err(local_err
);
918 monitor_printf(mon
, "boot device list now set to %s\n", bootdevice
);
922 static void hmp_info_mtree(Monitor
*mon
, const QDict
*qdict
)
924 bool flatview
= qdict_get_try_bool(qdict
, "flatview", false);
925 bool dispatch_tree
= qdict_get_try_bool(qdict
, "dispatch_tree", false);
926 bool owner
= qdict_get_try_bool(qdict
, "owner", false);
927 bool disabled
= qdict_get_try_bool(qdict
, "disabled", false);
929 mtree_info(flatview
, dispatch_tree
, owner
, disabled
);
932 #ifdef CONFIG_PROFILER
936 static void hmp_info_profile(Monitor
*mon
, const QDict
*qdict
)
938 static int64_t last_cpu_exec_time
;
939 int64_t cpu_exec_time
;
942 cpu_exec_time
= tcg_cpu_exec_time();
943 delta
= cpu_exec_time
- last_cpu_exec_time
;
945 monitor_printf(mon
, "async time %" PRId64
" (%0.3f)\n",
946 dev_time
, dev_time
/ (double)NANOSECONDS_PER_SECOND
);
947 monitor_printf(mon
, "qemu time %" PRId64
" (%0.3f)\n",
948 delta
, delta
/ (double)NANOSECONDS_PER_SECOND
);
949 last_cpu_exec_time
= cpu_exec_time
;
953 static void hmp_info_profile(Monitor
*mon
, const QDict
*qdict
)
955 monitor_printf(mon
, "Internal profiler not compiled\n");
959 /* Capture support */
960 static QLIST_HEAD (capture_list_head
, CaptureState
) capture_head
;
962 static void hmp_info_capture(Monitor
*mon
, const QDict
*qdict
)
967 for (s
= capture_head
.lh_first
, i
= 0; s
; s
= s
->entries
.le_next
, ++i
) {
968 monitor_printf(mon
, "[%d]: ", i
);
969 s
->ops
.info (s
->opaque
);
973 static void hmp_stopcapture(Monitor
*mon
, const QDict
*qdict
)
976 int n
= qdict_get_int(qdict
, "n");
979 for (s
= capture_head
.lh_first
, i
= 0; s
; s
= s
->entries
.le_next
, ++i
) {
981 s
->ops
.destroy (s
->opaque
);
982 QLIST_REMOVE (s
, entries
);
989 static void hmp_wavcapture(Monitor
*mon
, const QDict
*qdict
)
991 const char *path
= qdict_get_str(qdict
, "path");
992 int freq
= qdict_get_try_int(qdict
, "freq", 44100);
993 int bits
= qdict_get_try_int(qdict
, "bits", 16);
994 int nchannels
= qdict_get_try_int(qdict
, "nchannels", 2);
995 const char *audiodev
= qdict_get_str(qdict
, "audiodev");
997 AudioState
*as
= audio_state_by_name(audiodev
);
1000 monitor_printf(mon
, "Audiodev '%s' not found\n", audiodev
);
1004 s
= g_malloc0 (sizeof (*s
));
1006 if (wav_start_capture(as
, s
, path
, freq
, bits
, nchannels
)) {
1007 monitor_printf(mon
, "Failed to add wave capture\n");
1011 QLIST_INSERT_HEAD (&capture_head
, s
, entries
);
1014 void qmp_getfd(const char *fdname
, Error
**errp
)
1016 Monitor
*cur_mon
= monitor_cur();
1020 fd
= qemu_chr_fe_get_msgfd(&cur_mon
->chr
);
1022 error_setg(errp
, "No file descriptor supplied via SCM_RIGHTS");
1026 if (qemu_isdigit(fdname
[0])) {
1028 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "fdname",
1029 "a name not starting with a digit");
1033 QEMU_LOCK_GUARD(&cur_mon
->mon_lock
);
1034 QLIST_FOREACH(monfd
, &cur_mon
->fds
, next
) {
1035 if (strcmp(monfd
->name
, fdname
) != 0) {
1041 /* Make sure close() is outside critical section */
1046 monfd
= g_malloc0(sizeof(mon_fd_t
));
1047 monfd
->name
= g_strdup(fdname
);
1050 QLIST_INSERT_HEAD(&cur_mon
->fds
, monfd
, next
);
1053 void qmp_closefd(const char *fdname
, Error
**errp
)
1055 Monitor
*cur_mon
= monitor_cur();
1059 qemu_mutex_lock(&cur_mon
->mon_lock
);
1060 QLIST_FOREACH(monfd
, &cur_mon
->fds
, next
) {
1061 if (strcmp(monfd
->name
, fdname
) != 0) {
1065 QLIST_REMOVE(monfd
, next
);
1067 g_free(monfd
->name
);
1069 qemu_mutex_unlock(&cur_mon
->mon_lock
);
1070 /* Make sure close() is outside critical section */
1075 qemu_mutex_unlock(&cur_mon
->mon_lock
);
1076 error_setg(errp
, "File descriptor named '%s' not found", fdname
);
1079 int monitor_get_fd(Monitor
*mon
, const char *fdname
, Error
**errp
)
1083 QEMU_LOCK_GUARD(&mon
->mon_lock
);
1084 QLIST_FOREACH(monfd
, &mon
->fds
, next
) {
1087 if (strcmp(monfd
->name
, fdname
) != 0) {
1093 /* caller takes ownership of fd */
1094 QLIST_REMOVE(monfd
, next
);
1095 g_free(monfd
->name
);
1101 error_setg(errp
, "File descriptor named '%s' has not been found", fdname
);
1105 static void monitor_fdset_cleanup(MonFdset
*mon_fdset
)
1107 MonFdsetFd
*mon_fdset_fd
;
1108 MonFdsetFd
*mon_fdset_fd_next
;
1110 QLIST_FOREACH_SAFE(mon_fdset_fd
, &mon_fdset
->fds
, next
, mon_fdset_fd_next
) {
1111 if ((mon_fdset_fd
->removed
||
1112 (QLIST_EMPTY(&mon_fdset
->dup_fds
) && mon_refcount
== 0)) &&
1113 runstate_is_running()) {
1114 close(mon_fdset_fd
->fd
);
1115 g_free(mon_fdset_fd
->opaque
);
1116 QLIST_REMOVE(mon_fdset_fd
, next
);
1117 g_free(mon_fdset_fd
);
1121 if (QLIST_EMPTY(&mon_fdset
->fds
) && QLIST_EMPTY(&mon_fdset
->dup_fds
)) {
1122 QLIST_REMOVE(mon_fdset
, next
);
1127 void monitor_fdsets_cleanup(void)
1129 MonFdset
*mon_fdset
;
1130 MonFdset
*mon_fdset_next
;
1132 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1133 QLIST_FOREACH_SAFE(mon_fdset
, &mon_fdsets
, next
, mon_fdset_next
) {
1134 monitor_fdset_cleanup(mon_fdset
);
1138 AddfdInfo
*qmp_add_fd(bool has_fdset_id
, int64_t fdset_id
, bool has_opaque
,
1139 const char *opaque
, Error
**errp
)
1142 Monitor
*mon
= monitor_cur();
1145 fd
= qemu_chr_fe_get_msgfd(&mon
->chr
);
1147 error_setg(errp
, "No file descriptor supplied via SCM_RIGHTS");
1151 fdinfo
= monitor_fdset_add_fd(fd
, has_fdset_id
, fdset_id
,
1152 has_opaque
, opaque
, errp
);
1164 void qmp_remove_fd(int64_t fdset_id
, bool has_fd
, int64_t fd
, Error
**errp
)
1166 MonFdset
*mon_fdset
;
1167 MonFdsetFd
*mon_fdset_fd
;
1170 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1171 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1172 if (mon_fdset
->id
!= fdset_id
) {
1175 QLIST_FOREACH(mon_fdset_fd
, &mon_fdset
->fds
, next
) {
1177 if (mon_fdset_fd
->fd
!= fd
) {
1180 mon_fdset_fd
->removed
= true;
1183 mon_fdset_fd
->removed
= true;
1186 if (has_fd
&& !mon_fdset_fd
) {
1189 monitor_fdset_cleanup(mon_fdset
);
1195 snprintf(fd_str
, sizeof(fd_str
), "fdset-id:%" PRId64
", fd:%" PRId64
,
1198 snprintf(fd_str
, sizeof(fd_str
), "fdset-id:%" PRId64
, fdset_id
);
1200 error_setg(errp
, "File descriptor named '%s' not found", fd_str
);
1203 FdsetInfoList
*qmp_query_fdsets(Error
**errp
)
1205 MonFdset
*mon_fdset
;
1206 MonFdsetFd
*mon_fdset_fd
;
1207 FdsetInfoList
*fdset_list
= NULL
;
1209 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1210 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1211 FdsetInfo
*fdset_info
= g_malloc0(sizeof(*fdset_info
));
1213 fdset_info
->fdset_id
= mon_fdset
->id
;
1215 QLIST_FOREACH(mon_fdset_fd
, &mon_fdset
->fds
, next
) {
1216 FdsetFdInfo
*fdsetfd_info
;
1218 fdsetfd_info
= g_malloc0(sizeof(*fdsetfd_info
));
1219 fdsetfd_info
->fd
= mon_fdset_fd
->fd
;
1220 if (mon_fdset_fd
->opaque
) {
1221 fdsetfd_info
->has_opaque
= true;
1222 fdsetfd_info
->opaque
= g_strdup(mon_fdset_fd
->opaque
);
1224 fdsetfd_info
->has_opaque
= false;
1227 QAPI_LIST_PREPEND(fdset_info
->fds
, fdsetfd_info
);
1230 QAPI_LIST_PREPEND(fdset_list
, fdset_info
);
1236 AddfdInfo
*monitor_fdset_add_fd(int fd
, bool has_fdset_id
, int64_t fdset_id
,
1237 bool has_opaque
, const char *opaque
,
1240 MonFdset
*mon_fdset
= NULL
;
1241 MonFdsetFd
*mon_fdset_fd
;
1244 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1246 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1247 /* Break if match found or match impossible due to ordering by ID */
1248 if (fdset_id
<= mon_fdset
->id
) {
1249 if (fdset_id
< mon_fdset
->id
) {
1257 if (mon_fdset
== NULL
) {
1258 int64_t fdset_id_prev
= -1;
1259 MonFdset
*mon_fdset_cur
= QLIST_FIRST(&mon_fdsets
);
1263 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "fdset-id",
1264 "a non-negative value");
1267 /* Use specified fdset ID */
1268 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1269 mon_fdset_cur
= mon_fdset
;
1270 if (fdset_id
< mon_fdset_cur
->id
) {
1275 /* Use first available fdset ID */
1276 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1277 mon_fdset_cur
= mon_fdset
;
1278 if (fdset_id_prev
== mon_fdset_cur
->id
- 1) {
1279 fdset_id_prev
= mon_fdset_cur
->id
;
1286 mon_fdset
= g_malloc0(sizeof(*mon_fdset
));
1288 mon_fdset
->id
= fdset_id
;
1290 mon_fdset
->id
= fdset_id_prev
+ 1;
1293 /* The fdset list is ordered by fdset ID */
1294 if (!mon_fdset_cur
) {
1295 QLIST_INSERT_HEAD(&mon_fdsets
, mon_fdset
, next
);
1296 } else if (mon_fdset
->id
< mon_fdset_cur
->id
) {
1297 QLIST_INSERT_BEFORE(mon_fdset_cur
, mon_fdset
, next
);
1299 QLIST_INSERT_AFTER(mon_fdset_cur
, mon_fdset
, next
);
1303 mon_fdset_fd
= g_malloc0(sizeof(*mon_fdset_fd
));
1304 mon_fdset_fd
->fd
= fd
;
1305 mon_fdset_fd
->removed
= false;
1307 mon_fdset_fd
->opaque
= g_strdup(opaque
);
1309 QLIST_INSERT_HEAD(&mon_fdset
->fds
, mon_fdset_fd
, next
);
1311 fdinfo
= g_malloc0(sizeof(*fdinfo
));
1312 fdinfo
->fdset_id
= mon_fdset
->id
;
1313 fdinfo
->fd
= mon_fdset_fd
->fd
;
1318 int monitor_fdset_dup_fd_add(int64_t fdset_id
, int flags
)
1323 MonFdset
*mon_fdset
;
1325 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1326 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1327 MonFdsetFd
*mon_fdset_fd
;
1328 MonFdsetFd
*mon_fdset_fd_dup
;
1333 if (mon_fdset
->id
!= fdset_id
) {
1337 QLIST_FOREACH(mon_fdset_fd
, &mon_fdset
->fds
, next
) {
1338 mon_fd_flags
= fcntl(mon_fdset_fd
->fd
, F_GETFL
);
1339 if (mon_fd_flags
== -1) {
1343 if ((flags
& O_ACCMODE
) == (mon_fd_flags
& O_ACCMODE
)) {
1344 fd
= mon_fdset_fd
->fd
;
1354 dup_fd
= qemu_dup_flags(fd
, flags
);
1359 mon_fdset_fd_dup
= g_malloc0(sizeof(*mon_fdset_fd_dup
));
1360 mon_fdset_fd_dup
->fd
= dup_fd
;
1361 QLIST_INSERT_HEAD(&mon_fdset
->dup_fds
, mon_fdset_fd_dup
, next
);
1370 static int64_t monitor_fdset_dup_fd_find_remove(int dup_fd
, bool remove
)
1372 MonFdset
*mon_fdset
;
1373 MonFdsetFd
*mon_fdset_fd_dup
;
1375 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1376 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1377 QLIST_FOREACH(mon_fdset_fd_dup
, &mon_fdset
->dup_fds
, next
) {
1378 if (mon_fdset_fd_dup
->fd
== dup_fd
) {
1380 QLIST_REMOVE(mon_fdset_fd_dup
, next
);
1381 g_free(mon_fdset_fd_dup
);
1382 if (QLIST_EMPTY(&mon_fdset
->dup_fds
)) {
1383 monitor_fdset_cleanup(mon_fdset
);
1387 return mon_fdset
->id
;
1396 int64_t monitor_fdset_dup_fd_find(int dup_fd
)
1398 return monitor_fdset_dup_fd_find_remove(dup_fd
, false);
1401 void monitor_fdset_dup_fd_remove(int dup_fd
)
1403 monitor_fdset_dup_fd_find_remove(dup_fd
, true);
1406 int monitor_fd_param(Monitor
*mon
, const char *fdname
, Error
**errp
)
1409 Error
*local_err
= NULL
;
1411 if (!qemu_isdigit(fdname
[0]) && mon
) {
1412 fd
= monitor_get_fd(mon
, fdname
, &local_err
);
1414 fd
= qemu_parse_fd(fdname
);
1416 error_setg(&local_err
, "Invalid file descriptor number '%s'",
1421 error_propagate(errp
, local_err
);
1430 /* Please update hmp-commands.hx when adding or changing commands */
1431 static HMPCommand hmp_info_cmds
[] = {
1432 #include "hmp-commands-info.h"
1436 /* hmp_cmds and hmp_info_cmds would be sorted at runtime */
1437 HMPCommand hmp_cmds
[] = {
1438 #include "hmp-commands.h"
1443 * Set @pval to the value in the register identified by @name.
1444 * return 0 if OK, -1 if not found
1446 int get_monitor_def(Monitor
*mon
, int64_t *pval
, const char *name
)
1448 const MonitorDef
*md
= target_monitor_defs();
1449 CPUState
*cs
= mon_get_cpu(mon
);
1454 if (cs
== NULL
|| md
== NULL
) {
1458 for(; md
->name
!= NULL
; md
++) {
1459 if (hmp_compare_cmd(name
, md
->name
)) {
1460 if (md
->get_value
) {
1461 *pval
= md
->get_value(mon
, md
, md
->offset
);
1463 CPUArchState
*env
= mon_get_cpu_env(mon
);
1464 ptr
= (uint8_t *)env
+ md
->offset
;
1467 *pval
= *(int32_t *)ptr
;
1470 *pval
= *(target_long
*)ptr
;
1481 ret
= target_get_monitor_def(cs
, name
, &tmp
);
1483 *pval
= (target_long
) tmp
;
1489 static void add_completion_option(ReadLineState
*rs
, const char *str
,
1492 if (!str
|| !option
) {
1495 if (!strncmp(option
, str
, strlen(str
))) {
1496 readline_add_completion(rs
, option
);
1500 void chardev_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1503 ChardevBackendInfoList
*list
, *start
;
1509 readline_set_completion_index(rs
, len
);
1511 start
= list
= qmp_query_chardev_backends(NULL
);
1513 const char *chr_name
= list
->value
->name
;
1515 if (!strncmp(chr_name
, str
, len
)) {
1516 readline_add_completion(rs
, chr_name
);
1520 qapi_free_ChardevBackendInfoList(start
);
1523 void netdev_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1532 readline_set_completion_index(rs
, len
);
1533 for (i
= 0; i
< NET_CLIENT_DRIVER__MAX
; i
++) {
1534 add_completion_option(rs
, str
, NetClientDriver_str(i
));
1538 void device_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1548 readline_set_completion_index(rs
, len
);
1549 list
= elt
= object_class_get_list(TYPE_DEVICE
, false);
1552 DeviceClass
*dc
= OBJECT_CLASS_CHECK(DeviceClass
, elt
->data
,
1554 name
= object_class_get_name(OBJECT_CLASS(dc
));
1556 if (dc
->user_creatable
1557 && !strncmp(name
, str
, len
)) {
1558 readline_add_completion(rs
, name
);
1565 void object_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1575 readline_set_completion_index(rs
, len
);
1576 list
= elt
= object_class_get_list(TYPE_USER_CREATABLE
, false);
1580 name
= object_class_get_name(OBJECT_CLASS(elt
->data
));
1581 if (!strncmp(name
, str
, len
) && strcmp(name
, TYPE_USER_CREATABLE
)) {
1582 readline_add_completion(rs
, name
);
1589 static int qdev_add_hotpluggable_device(Object
*obj
, void *opaque
)
1591 GSList
**list
= opaque
;
1592 DeviceState
*dev
= (DeviceState
*)object_dynamic_cast(obj
, TYPE_DEVICE
);
1598 if (dev
->realized
&& object_property_get_bool(obj
, "hotpluggable", NULL
)) {
1599 *list
= g_slist_append(*list
, dev
);
1605 static GSList
*qdev_build_hotpluggable_device_list(Object
*peripheral
)
1607 GSList
*list
= NULL
;
1609 object_child_foreach(peripheral
, qdev_add_hotpluggable_device
, &list
);
1614 static void peripheral_device_del_completion(ReadLineState
*rs
,
1615 const char *str
, size_t len
)
1617 Object
*peripheral
= container_get(qdev_get_machine(), "/peripheral");
1618 GSList
*list
, *item
;
1620 list
= qdev_build_hotpluggable_device_list(peripheral
);
1625 for (item
= list
; item
; item
= g_slist_next(item
)) {
1626 DeviceState
*dev
= item
->data
;
1628 if (dev
->id
&& !strncmp(str
, dev
->id
, len
)) {
1629 readline_add_completion(rs
, dev
->id
);
1636 void chardev_remove_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1639 ChardevInfoList
*list
, *start
;
1645 readline_set_completion_index(rs
, len
);
1647 start
= list
= qmp_query_chardev(NULL
);
1649 ChardevInfo
*chr
= list
->value
;
1651 if (!strncmp(chr
->label
, str
, len
)) {
1652 readline_add_completion(rs
, chr
->label
);
1656 qapi_free_ChardevInfoList(start
);
1659 static void ringbuf_completion(ReadLineState
*rs
, const char *str
)
1662 ChardevInfoList
*list
, *start
;
1665 readline_set_completion_index(rs
, len
);
1667 start
= list
= qmp_query_chardev(NULL
);
1669 ChardevInfo
*chr_info
= list
->value
;
1671 if (!strncmp(chr_info
->label
, str
, len
)) {
1672 Chardev
*chr
= qemu_chr_find(chr_info
->label
);
1673 if (chr
&& CHARDEV_IS_RINGBUF(chr
)) {
1674 readline_add_completion(rs
, chr_info
->label
);
1679 qapi_free_ChardevInfoList(start
);
1682 void ringbuf_write_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1687 ringbuf_completion(rs
, str
);
1690 void device_del_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1699 readline_set_completion_index(rs
, len
);
1700 peripheral_device_del_completion(rs
, str
, len
);
1703 void object_del_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1705 ObjectPropertyInfoList
*list
, *start
;
1712 readline_set_completion_index(rs
, len
);
1714 start
= list
= qmp_qom_list("/objects", NULL
);
1716 ObjectPropertyInfo
*info
= list
->value
;
1718 if (!strncmp(info
->type
, "child<", 5)
1719 && !strncmp(info
->name
, str
, len
)) {
1720 readline_add_completion(rs
, info
->name
);
1724 qapi_free_ObjectPropertyInfoList(start
);
1727 void sendkey_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1736 sep
= strrchr(str
, '-');
1741 readline_set_completion_index(rs
, len
);
1742 for (i
= 0; i
< Q_KEY_CODE__MAX
; i
++) {
1743 if (!strncmp(str
, QKeyCode_str(i
), len
)) {
1744 readline_add_completion(rs
, QKeyCode_str(i
));
1749 void set_link_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1754 readline_set_completion_index(rs
, len
);
1756 NetClientState
*ncs
[MAX_QUEUE_NUM
];
1758 count
= qemu_find_net_clients_except(NULL
, ncs
,
1759 NET_CLIENT_DRIVER_NONE
,
1761 for (i
= 0; i
< MIN(count
, MAX_QUEUE_NUM
); i
++) {
1762 const char *name
= ncs
[i
]->name
;
1763 if (!strncmp(str
, name
, len
)) {
1764 readline_add_completion(rs
, name
);
1767 } else if (nb_args
== 3) {
1768 add_completion_option(rs
, str
, "on");
1769 add_completion_option(rs
, str
, "off");
1773 void netdev_del_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1776 NetClientState
*ncs
[MAX_QUEUE_NUM
];
1783 readline_set_completion_index(rs
, len
);
1784 count
= qemu_find_net_clients_except(NULL
, ncs
, NET_CLIENT_DRIVER_NIC
,
1786 for (i
= 0; i
< MIN(count
, MAX_QUEUE_NUM
); i
++) {
1787 const char *name
= ncs
[i
]->name
;
1788 if (strncmp(str
, name
, len
)) {
1791 if (ncs
[i
]->is_netdev
) {
1792 readline_add_completion(rs
, name
);
1797 void info_trace_events_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1802 readline_set_completion_index(rs
, len
);
1804 TraceEventIter iter
;
1806 char *pattern
= g_strdup_printf("%s*", str
);
1807 trace_event_iter_init_pattern(&iter
, pattern
);
1808 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
1809 readline_add_completion(rs
, trace_event_get_name(ev
));
1815 void trace_event_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1820 readline_set_completion_index(rs
, len
);
1822 TraceEventIter iter
;
1824 char *pattern
= g_strdup_printf("%s*", str
);
1825 trace_event_iter_init_pattern(&iter
, pattern
);
1826 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
1827 readline_add_completion(rs
, trace_event_get_name(ev
));
1830 } else if (nb_args
== 3) {
1831 add_completion_option(rs
, str
, "on");
1832 add_completion_option(rs
, str
, "off");
1836 void watchdog_action_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1843 readline_set_completion_index(rs
, strlen(str
));
1844 for (i
= 0; i
< WATCHDOG_ACTION__MAX
; i
++) {
1845 add_completion_option(rs
, str
, WatchdogAction_str(i
));
1849 void migrate_set_capability_completion(ReadLineState
*rs
, int nb_args
,
1855 readline_set_completion_index(rs
, len
);
1858 for (i
= 0; i
< MIGRATION_CAPABILITY__MAX
; i
++) {
1859 const char *name
= MigrationCapability_str(i
);
1860 if (!strncmp(str
, name
, len
)) {
1861 readline_add_completion(rs
, name
);
1864 } else if (nb_args
== 3) {
1865 add_completion_option(rs
, str
, "on");
1866 add_completion_option(rs
, str
, "off");
1870 void migrate_set_parameter_completion(ReadLineState
*rs
, int nb_args
,
1876 readline_set_completion_index(rs
, len
);
1879 for (i
= 0; i
< MIGRATION_PARAMETER__MAX
; i
++) {
1880 const char *name
= MigrationParameter_str(i
);
1881 if (!strncmp(str
, name
, len
)) {
1882 readline_add_completion(rs
, name
);
1888 static void vm_completion(ReadLineState
*rs
, const char *str
)
1891 BlockDriverState
*bs
;
1892 BdrvNextIterator it
;
1895 readline_set_completion_index(rs
, len
);
1897 for (bs
= bdrv_first(&it
); bs
; bs
= bdrv_next(&it
)) {
1898 SnapshotInfoList
*snapshots
, *snapshot
;
1899 AioContext
*ctx
= bdrv_get_aio_context(bs
);
1902 aio_context_acquire(ctx
);
1903 if (bdrv_can_snapshot(bs
)) {
1904 ok
= bdrv_query_snapshot_info_list(bs
, &snapshots
, NULL
) == 0;
1906 aio_context_release(ctx
);
1911 snapshot
= snapshots
;
1913 char *completion
= snapshot
->value
->name
;
1914 if (!strncmp(str
, completion
, len
)) {
1915 readline_add_completion(rs
, completion
);
1917 completion
= snapshot
->value
->id
;
1918 if (!strncmp(str
, completion
, len
)) {
1919 readline_add_completion(rs
, completion
);
1921 snapshot
= snapshot
->next
;
1923 qapi_free_SnapshotInfoList(snapshots
);
1928 void delvm_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1931 vm_completion(rs
, str
);
1935 void loadvm_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1938 vm_completion(rs
, str
);
1943 compare_mon_cmd(const void *a
, const void *b
)
1945 return strcmp(((const HMPCommand
*)a
)->name
,
1946 ((const HMPCommand
*)b
)->name
);
1949 static void sortcmdlist(void)
1951 qsort(hmp_cmds
, ARRAY_SIZE(hmp_cmds
) - 1,
1954 qsort(hmp_info_cmds
, ARRAY_SIZE(hmp_info_cmds
) - 1,
1955 sizeof(*hmp_info_cmds
),
1959 void monitor_register_hmp(const char *name
, bool info
,
1960 void (*cmd
)(Monitor
*mon
, const QDict
*qdict
))
1962 HMPCommand
*table
= info
? hmp_info_cmds
: hmp_cmds
;
1964 while (table
->name
!= NULL
) {
1965 if (strcmp(table
->name
, name
) == 0) {
1966 g_assert(table
->cmd
== NULL
);
1972 g_assert_not_reached();
1975 void monitor_init_globals(void)
1977 monitor_init_globals_core();
1978 monitor_init_qmp_commands();
1980 qemu_mutex_init(&mon_fdsets_lock
);