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"
28 #include "monitor/qdev.h"
30 #include "hw/pci/pci.h"
31 #include "sysemu/watchdog.h"
32 #include "hw/loader.h"
33 #include "exec/gdbstub.h"
35 #include "net/slirp.h"
36 #include "ui/qemu-spice.h"
37 #include "qemu/config-file.h"
38 #include "qemu/ctype.h"
39 #include "ui/console.h"
41 #include "audio/audio.h"
42 #include "disas/disas.h"
43 #include "sysemu/balloon.h"
44 #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/tcg.h"
52 #include "sysemu/tpm.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-trace.h"
75 #include "qapi/qapi-init-commands.h"
76 #include "qapi/error.h"
77 #include "qapi/qmp-event.h"
78 #include "sysemu/cpus.h"
79 #include "qemu/cutils.h"
81 #if defined(TARGET_S390X)
82 #include "hw/s390x/storage-keys.h"
83 #include "hw/s390x/storage-attributes.h"
86 /* file descriptors passed via SCM_RIGHTS */
87 typedef struct mon_fd_t mon_fd_t
;
91 QLIST_ENTRY(mon_fd_t
) next
;
94 /* file descriptor associated with a file descriptor set */
95 typedef struct MonFdsetFd MonFdsetFd
;
100 QLIST_ENTRY(MonFdsetFd
) next
;
103 /* file descriptor set containing fds passed via SCM_RIGHTS */
104 typedef struct MonFdset MonFdset
;
107 QLIST_HEAD(, MonFdsetFd
) fds
;
108 QLIST_HEAD(, MonFdsetFd
) dup_fds
;
109 QLIST_ENTRY(MonFdset
) next
;
112 /* Protects mon_fdsets */
113 static QemuMutex mon_fdsets_lock
;
114 static QLIST_HEAD(, MonFdset
) mon_fdsets
;
116 static HMPCommand hmp_info_cmds
[];
118 char *qmp_human_monitor_command(const char *command_line
, bool has_cpu_index
,
119 int64_t cpu_index
, Error
**errp
)
124 monitor_data_init(&hmp
.common
, false, true, false);
127 int ret
= monitor_set_cpu(&hmp
.common
, cpu_index
);
129 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "cpu-index",
135 handle_hmp_command(&hmp
, command_line
);
137 WITH_QEMU_LOCK_GUARD(&hmp
.common
.mon_lock
) {
138 output
= g_strdup(hmp
.common
.outbuf
->str
);
142 monitor_data_destroy(&hmp
.common
);
147 * Is @name in the '|' separated list of names @list?
149 int hmp_compare_cmd(const char *name
, const char *list
)
151 const char *p
, *pstart
;
157 p
= qemu_strchrnul(p
, '|');
158 if ((p
- pstart
) == len
&& !memcmp(pstart
, name
, len
)) {
169 static void do_help_cmd(Monitor
*mon
, const QDict
*qdict
)
171 help_cmd(mon
, qdict_get_try_str(qdict
, "name"));
174 static void hmp_trace_event(Monitor
*mon
, const QDict
*qdict
)
176 const char *tp_name
= qdict_get_str(qdict
, "name");
177 bool new_state
= qdict_get_bool(qdict
, "option");
178 bool has_vcpu
= qdict_haskey(qdict
, "vcpu");
179 int vcpu
= qdict_get_try_int(qdict
, "vcpu", 0);
180 Error
*local_err
= NULL
;
183 monitor_printf(mon
, "argument vcpu must be positive");
187 qmp_trace_event_set_state(tp_name
, new_state
, true, true, has_vcpu
, vcpu
, &local_err
);
189 error_report_err(local_err
);
193 #ifdef CONFIG_TRACE_SIMPLE
194 static void hmp_trace_file(Monitor
*mon
, const QDict
*qdict
)
196 const char *op
= qdict_get_try_str(qdict
, "op");
197 const char *arg
= qdict_get_try_str(qdict
, "arg");
200 st_print_trace_file_status();
201 } else if (!strcmp(op
, "on")) {
202 st_set_trace_file_enabled(true);
203 } else if (!strcmp(op
, "off")) {
204 st_set_trace_file_enabled(false);
205 } else if (!strcmp(op
, "flush")) {
206 st_flush_trace_buffer();
207 } else if (!strcmp(op
, "set")) {
209 st_set_trace_file(arg
);
212 monitor_printf(mon
, "unexpected argument \"%s\"\n", op
);
213 help_cmd(mon
, "trace-file");
218 static void hmp_info_help(Monitor
*mon
, const QDict
*qdict
)
220 help_cmd(mon
, "info");
223 static void monitor_init_qmp_commands(void)
227 * - qmp_commands contains all QMP commands
228 * - qmp_cap_negotiation_commands contains just
229 * "qmp_capabilities", to enforce capability negotiation
232 qmp_init_marshal(&qmp_commands
);
234 qmp_register_command(&qmp_commands
, "query-qmp-schema",
235 qmp_query_qmp_schema
, QCO_ALLOW_PRECONFIG
);
236 qmp_register_command(&qmp_commands
, "device_add", qmp_device_add
,
238 qmp_register_command(&qmp_commands
, "object-add", qmp_object_add
,
241 QTAILQ_INIT(&qmp_cap_negotiation_commands
);
242 qmp_register_command(&qmp_cap_negotiation_commands
, "qmp_capabilities",
243 qmp_marshal_qmp_capabilities
, QCO_ALLOW_PRECONFIG
);
246 /* Set the current CPU defined by the user. Callers must hold BQL. */
247 int monitor_set_cpu(Monitor
*mon
, int cpu_index
)
251 cpu
= qemu_get_cpu(cpu_index
);
255 g_free(mon
->mon_cpu_path
);
256 mon
->mon_cpu_path
= object_get_canonical_path(OBJECT(cpu
));
260 /* Callers must hold BQL. */
261 static CPUState
*mon_get_cpu_sync(Monitor
*mon
, bool synchronize
)
263 CPUState
*cpu
= NULL
;
265 if (mon
->mon_cpu_path
) {
266 cpu
= (CPUState
*) object_resolve_path_type(mon
->mon_cpu_path
,
269 g_free(mon
->mon_cpu_path
);
270 mon
->mon_cpu_path
= NULL
;
273 if (!mon
->mon_cpu_path
) {
277 monitor_set_cpu(mon
, first_cpu
->cpu_index
);
282 cpu_synchronize_state(cpu
);
287 CPUState
*mon_get_cpu(Monitor
*mon
)
289 return mon_get_cpu_sync(mon
, true);
292 CPUArchState
*mon_get_cpu_env(Monitor
*mon
)
294 CPUState
*cs
= mon_get_cpu(mon
);
296 return cs
? cs
->env_ptr
: NULL
;
299 int monitor_get_cpu_index(Monitor
*mon
)
301 CPUState
*cs
= mon_get_cpu_sync(mon
, false);
303 return cs
? cs
->cpu_index
: UNASSIGNED_CPU_INDEX
;
306 static void hmp_info_registers(Monitor
*mon
, const QDict
*qdict
)
308 bool all_cpus
= qdict_get_try_bool(qdict
, "cpustate_all", false);
313 monitor_printf(mon
, "\nCPU#%d\n", cs
->cpu_index
);
314 cpu_dump_state(cs
, NULL
, CPU_DUMP_FPU
);
317 cs
= mon_get_cpu(mon
);
320 monitor_printf(mon
, "No CPU available\n");
324 cpu_dump_state(cs
, NULL
, CPU_DUMP_FPU
);
329 static void hmp_info_jit(Monitor
*mon
, const QDict
*qdict
)
331 if (!tcg_enabled()) {
332 error_report("JIT information is only available with accel=tcg");
340 static void hmp_info_opcount(Monitor
*mon
, const QDict
*qdict
)
346 static void hmp_info_sync_profile(Monitor
*mon
, const QDict
*qdict
)
348 int64_t max
= qdict_get_try_int(qdict
, "max", 10);
349 bool mean
= qdict_get_try_bool(qdict
, "mean", false);
350 bool coalesce
= !qdict_get_try_bool(qdict
, "no_coalesce", false);
351 enum QSPSortBy sort_by
;
353 sort_by
= mean
? QSP_SORT_BY_AVG_WAIT_TIME
: QSP_SORT_BY_TOTAL_WAIT_TIME
;
354 qsp_report(max
, sort_by
, coalesce
);
357 static void hmp_info_history(Monitor
*mon
, const QDict
*qdict
)
359 MonitorHMP
*hmp_mon
= container_of(mon
, MonitorHMP
, common
);
368 str
= readline_get_history(hmp_mon
->rs
, i
);
372 monitor_printf(mon
, "%d: '%s'\n", i
, str
);
377 static void hmp_info_cpustats(Monitor
*mon
, const QDict
*qdict
)
379 CPUState
*cs
= mon_get_cpu(mon
);
382 monitor_printf(mon
, "No CPU available\n");
385 cpu_dump_statistics(cs
, 0);
388 static void hmp_info_trace_events(Monitor
*mon
, const QDict
*qdict
)
390 const char *name
= qdict_get_try_str(qdict
, "name");
391 bool has_vcpu
= qdict_haskey(qdict
, "vcpu");
392 int vcpu
= qdict_get_try_int(qdict
, "vcpu", 0);
393 TraceEventInfoList
*events
;
394 TraceEventInfoList
*elem
;
395 Error
*local_err
= NULL
;
401 monitor_printf(mon
, "argument vcpu must be positive");
405 events
= qmp_trace_event_get_state(name
, has_vcpu
, vcpu
, &local_err
);
407 error_report_err(local_err
);
411 for (elem
= events
; elem
!= NULL
; elem
= elem
->next
) {
412 monitor_printf(mon
, "%s : state %u\n",
414 elem
->value
->state
== TRACE_EVENT_STATE_ENABLED
? 1 : 0);
416 qapi_free_TraceEventInfoList(events
);
419 void qmp_client_migrate_info(const char *protocol
, const char *hostname
,
420 bool has_port
, int64_t port
,
421 bool has_tls_port
, int64_t tls_port
,
422 bool has_cert_subject
, const char *cert_subject
,
425 if (strcmp(protocol
, "spice") == 0) {
426 if (!qemu_using_spice(errp
)) {
430 if (!has_port
&& !has_tls_port
) {
431 error_setg(errp
, QERR_MISSING_PARAMETER
, "port/tls-port");
435 if (qemu_spice
.migrate_info(hostname
,
436 has_port
? port
: -1,
437 has_tls_port
? tls_port
: -1,
439 error_setg(errp
, "Could not set up display for migration");
445 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "protocol", "'spice'");
448 static void hmp_logfile(Monitor
*mon
, const QDict
*qdict
)
452 qemu_set_log_filename(qdict_get_str(qdict
, "filename"), &err
);
454 error_report_err(err
);
458 static void hmp_log(Monitor
*mon
, const QDict
*qdict
)
461 const char *items
= qdict_get_str(qdict
, "items");
463 if (!strcmp(items
, "none")) {
466 mask
= qemu_str_to_log_mask(items
);
468 help_cmd(mon
, "log");
475 static void hmp_singlestep(Monitor
*mon
, const QDict
*qdict
)
477 const char *option
= qdict_get_try_str(qdict
, "option");
478 if (!option
|| !strcmp(option
, "on")) {
480 } else if (!strcmp(option
, "off")) {
483 monitor_printf(mon
, "unexpected option %s\n", option
);
487 static void hmp_gdbserver(Monitor
*mon
, const QDict
*qdict
)
489 const char *device
= qdict_get_try_str(qdict
, "device");
491 device
= "tcp::" DEFAULT_GDBSTUB_PORT
;
494 if (gdbserver_start(device
) < 0) {
495 monitor_printf(mon
, "Could not open gdbserver on device '%s'\n",
497 } else if (strcmp(device
, "none") == 0) {
498 monitor_printf(mon
, "Disabled gdbserver\n");
500 monitor_printf(mon
, "Waiting for gdb connection on device '%s'\n",
505 static void hmp_watchdog_action(Monitor
*mon
, const QDict
*qdict
)
507 const char *action
= qdict_get_str(qdict
, "action");
508 if (select_watchdog_action(action
) == -1) {
509 monitor_printf(mon
, "Unknown watchdog action '%s'\n", action
);
513 static void monitor_printc(Monitor
*mon
, int c
)
515 monitor_printf(mon
, "'");
518 monitor_printf(mon
, "\\'");
521 monitor_printf(mon
, "\\\\");
524 monitor_printf(mon
, "\\n");
527 monitor_printf(mon
, "\\r");
530 if (c
>= 32 && c
<= 126) {
531 monitor_printf(mon
, "%c", c
);
533 monitor_printf(mon
, "\\x%02x", c
);
537 monitor_printf(mon
, "'");
540 static void memory_dump(Monitor
*mon
, int count
, int format
, int wsize
,
541 hwaddr addr
, int is_physical
)
543 int l
, line_size
, i
, max_digits
, len
;
546 CPUState
*cs
= mon_get_cpu(mon
);
548 if (!cs
&& (format
== 'i' || !is_physical
)) {
549 monitor_printf(mon
, "Can not dump without CPU\n");
554 monitor_disas(mon
, cs
, addr
, count
, is_physical
);
568 max_digits
= DIV_ROUND_UP(wsize
* 8, 3);
572 max_digits
= (wsize
* 8) / 4;
576 max_digits
= DIV_ROUND_UP(wsize
* 8 * 10, 33);
585 monitor_printf(mon
, TARGET_FMT_plx
":", addr
);
587 monitor_printf(mon
, TARGET_FMT_lx
":", (target_ulong
)addr
);
593 AddressSpace
*as
= cs
? cs
->as
: &address_space_memory
;
594 MemTxResult r
= address_space_read(as
, addr
,
595 MEMTXATTRS_UNSPECIFIED
, buf
, l
);
597 monitor_printf(mon
, " Cannot access memory\n");
601 if (cpu_memory_rw_debug(cs
, addr
, buf
, l
, 0) < 0) {
602 monitor_printf(mon
, " Cannot access memory\n");
617 v
= (uint32_t)ldl_p(buf
+ i
);
623 monitor_printf(mon
, " ");
626 monitor_printf(mon
, "%#*" PRIo64
, max_digits
, v
);
629 monitor_printf(mon
, "0x%0*" PRIx64
, max_digits
, v
);
632 monitor_printf(mon
, "%*" PRIu64
, max_digits
, v
);
635 monitor_printf(mon
, "%*" PRId64
, max_digits
, v
);
638 monitor_printc(mon
, v
);
643 monitor_printf(mon
, "\n");
649 static void hmp_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 target_long addr
= qdict_get_int(qdict
, "addr");
656 memory_dump(mon
, count
, format
, size
, addr
, 0);
659 static void hmp_physical_memory_dump(Monitor
*mon
, const QDict
*qdict
)
661 int count
= qdict_get_int(qdict
, "count");
662 int format
= qdict_get_int(qdict
, "format");
663 int size
= qdict_get_int(qdict
, "size");
664 hwaddr addr
= qdict_get_int(qdict
, "addr");
666 memory_dump(mon
, count
, format
, size
, addr
, 1);
669 void *gpa2hva(MemoryRegion
**p_mr
, hwaddr addr
, uint64_t size
, Error
**errp
)
671 Int128 gpa_region_size
;
672 MemoryRegionSection mrs
= memory_region_find(get_system_memory(),
676 error_setg(errp
, "No memory is mapped at address 0x%" HWADDR_PRIx
, addr
);
680 if (!memory_region_is_ram(mrs
.mr
) && !memory_region_is_romd(mrs
.mr
)) {
681 error_setg(errp
, "Memory at address 0x%" HWADDR_PRIx
"is not RAM", addr
);
682 memory_region_unref(mrs
.mr
);
686 gpa_region_size
= int128_make64(size
);
687 if (int128_lt(mrs
.size
, gpa_region_size
)) {
688 error_setg(errp
, "Size of memory region at 0x%" HWADDR_PRIx
690 memory_region_unref(mrs
.mr
);
695 return qemu_map_ram_ptr(mrs
.mr
->ram_block
, mrs
.offset_within_region
);
698 static void hmp_gpa2hva(Monitor
*mon
, const QDict
*qdict
)
700 hwaddr addr
= qdict_get_int(qdict
, "addr");
701 Error
*local_err
= NULL
;
702 MemoryRegion
*mr
= NULL
;
705 ptr
= gpa2hva(&mr
, addr
, 1, &local_err
);
707 error_report_err(local_err
);
711 monitor_printf(mon
, "Host virtual address for 0x%" HWADDR_PRIx
713 addr
, mr
->name
, ptr
);
715 memory_region_unref(mr
);
718 static void hmp_gva2gpa(Monitor
*mon
, const QDict
*qdict
)
720 target_ulong addr
= qdict_get_int(qdict
, "addr");
722 CPUState
*cs
= mon_get_cpu(mon
);
726 monitor_printf(mon
, "No cpu\n");
730 gpa
= cpu_get_phys_page_attrs_debug(cs
, addr
& TARGET_PAGE_MASK
, &attrs
);
732 monitor_printf(mon
, "Unmapped\n");
734 monitor_printf(mon
, "gpa: %#" HWADDR_PRIx
"\n",
735 gpa
+ (addr
& ~TARGET_PAGE_MASK
));
740 static uint64_t vtop(void *ptr
, Error
**errp
)
744 uintptr_t addr
= (uintptr_t) ptr
;
745 uintptr_t pagesize
= qemu_real_host_page_size
;
746 off_t offset
= addr
/ pagesize
* sizeof(pinfo
);
749 fd
= open("/proc/self/pagemap", O_RDONLY
);
751 error_setg_errno(errp
, errno
, "Cannot open /proc/self/pagemap");
755 /* Force copy-on-write if necessary. */
756 qatomic_add((uint8_t *)ptr
, 0);
758 if (pread(fd
, &pinfo
, sizeof(pinfo
), offset
) != sizeof(pinfo
)) {
759 error_setg_errno(errp
, errno
, "Cannot read pagemap");
762 if ((pinfo
& (1ull << 63)) == 0) {
763 error_setg(errp
, "Page not present");
766 ret
= ((pinfo
& 0x007fffffffffffffull
) * pagesize
) | (addr
& (pagesize
- 1));
773 static void hmp_gpa2hpa(Monitor
*mon
, const QDict
*qdict
)
775 hwaddr addr
= qdict_get_int(qdict
, "addr");
776 Error
*local_err
= NULL
;
777 MemoryRegion
*mr
= NULL
;
781 ptr
= gpa2hva(&mr
, addr
, 1, &local_err
);
783 error_report_err(local_err
);
787 physaddr
= vtop(ptr
, &local_err
);
789 error_report_err(local_err
);
791 monitor_printf(mon
, "Host physical address for 0x%" HWADDR_PRIx
792 " (%s) is 0x%" PRIx64
"\n",
793 addr
, mr
->name
, (uint64_t) physaddr
);
796 memory_region_unref(mr
);
800 static void do_print(Monitor
*mon
, const QDict
*qdict
)
802 int format
= qdict_get_int(qdict
, "format");
803 hwaddr val
= qdict_get_int(qdict
, "val");
807 monitor_printf(mon
, "%#" HWADDR_PRIo
, val
);
810 monitor_printf(mon
, "%#" HWADDR_PRIx
, val
);
813 monitor_printf(mon
, "%" HWADDR_PRIu
, val
);
817 monitor_printf(mon
, "%" HWADDR_PRId
, val
);
820 monitor_printc(mon
, val
);
823 monitor_printf(mon
, "\n");
826 static void hmp_sum(Monitor
*mon
, const QDict
*qdict
)
830 uint32_t start
= qdict_get_int(qdict
, "start");
831 uint32_t size
= qdict_get_int(qdict
, "size");
834 for(addr
= start
; addr
< (start
+ size
); addr
++) {
835 uint8_t val
= address_space_ldub(&address_space_memory
, addr
,
836 MEMTXATTRS_UNSPECIFIED
, NULL
);
837 /* BSD sum algorithm ('sum' Unix command) */
838 sum
= (sum
>> 1) | (sum
<< 15);
841 monitor_printf(mon
, "%05d\n", sum
);
844 static int mouse_button_state
;
846 static void hmp_mouse_move(Monitor
*mon
, const QDict
*qdict
)
848 int dx
, dy
, dz
, button
;
849 const char *dx_str
= qdict_get_str(qdict
, "dx_str");
850 const char *dy_str
= qdict_get_str(qdict
, "dy_str");
851 const char *dz_str
= qdict_get_try_str(qdict
, "dz_str");
853 dx
= strtol(dx_str
, NULL
, 0);
854 dy
= strtol(dy_str
, NULL
, 0);
855 qemu_input_queue_rel(NULL
, INPUT_AXIS_X
, dx
);
856 qemu_input_queue_rel(NULL
, INPUT_AXIS_Y
, dy
);
859 dz
= strtol(dz_str
, NULL
, 0);
861 button
= (dz
> 0) ? INPUT_BUTTON_WHEEL_UP
: INPUT_BUTTON_WHEEL_DOWN
;
862 qemu_input_queue_btn(NULL
, button
, true);
863 qemu_input_event_sync();
864 qemu_input_queue_btn(NULL
, button
, false);
867 qemu_input_event_sync();
870 static void hmp_mouse_button(Monitor
*mon
, const QDict
*qdict
)
872 static uint32_t bmap
[INPUT_BUTTON__MAX
] = {
873 [INPUT_BUTTON_LEFT
] = MOUSE_EVENT_LBUTTON
,
874 [INPUT_BUTTON_MIDDLE
] = MOUSE_EVENT_MBUTTON
,
875 [INPUT_BUTTON_RIGHT
] = MOUSE_EVENT_RBUTTON
,
877 int button_state
= qdict_get_int(qdict
, "button_state");
879 if (mouse_button_state
== button_state
) {
882 qemu_input_update_buttons(NULL
, bmap
, mouse_button_state
, button_state
);
883 qemu_input_event_sync();
884 mouse_button_state
= button_state
;
887 static void hmp_ioport_read(Monitor
*mon
, const QDict
*qdict
)
889 int size
= qdict_get_int(qdict
, "size");
890 int addr
= qdict_get_int(qdict
, "addr");
891 int has_index
= qdict_haskey(qdict
, "index");
896 int index
= qdict_get_int(qdict
, "index");
897 cpu_outb(addr
& IOPORTS_MASK
, index
& 0xff);
917 monitor_printf(mon
, "port%c[0x%04x] = 0x%0*x\n",
918 suffix
, addr
, size
* 2, val
);
921 static void hmp_ioport_write(Monitor
*mon
, const QDict
*qdict
)
923 int size
= qdict_get_int(qdict
, "size");
924 int addr
= qdict_get_int(qdict
, "addr");
925 int val
= qdict_get_int(qdict
, "val");
927 addr
&= IOPORTS_MASK
;
943 static void hmp_boot_set(Monitor
*mon
, const QDict
*qdict
)
945 Error
*local_err
= NULL
;
946 const char *bootdevice
= qdict_get_str(qdict
, "bootdevice");
948 qemu_boot_set(bootdevice
, &local_err
);
950 error_report_err(local_err
);
952 monitor_printf(mon
, "boot device list now set to %s\n", bootdevice
);
956 static void hmp_info_mtree(Monitor
*mon
, const QDict
*qdict
)
958 bool flatview
= qdict_get_try_bool(qdict
, "flatview", false);
959 bool dispatch_tree
= qdict_get_try_bool(qdict
, "dispatch_tree", false);
960 bool owner
= qdict_get_try_bool(qdict
, "owner", false);
961 bool disabled
= qdict_get_try_bool(qdict
, "disabled", false);
963 mtree_info(flatview
, dispatch_tree
, owner
, disabled
);
966 #ifdef CONFIG_PROFILER
970 static void hmp_info_profile(Monitor
*mon
, const QDict
*qdict
)
972 static int64_t last_cpu_exec_time
;
973 int64_t cpu_exec_time
;
976 cpu_exec_time
= tcg_cpu_exec_time();
977 delta
= cpu_exec_time
- last_cpu_exec_time
;
979 monitor_printf(mon
, "async time %" PRId64
" (%0.3f)\n",
980 dev_time
, dev_time
/ (double)NANOSECONDS_PER_SECOND
);
981 monitor_printf(mon
, "qemu time %" PRId64
" (%0.3f)\n",
982 delta
, delta
/ (double)NANOSECONDS_PER_SECOND
);
983 last_cpu_exec_time
= cpu_exec_time
;
987 static void hmp_info_profile(Monitor
*mon
, const QDict
*qdict
)
989 monitor_printf(mon
, "Internal profiler not compiled\n");
993 /* Capture support */
994 static QLIST_HEAD (capture_list_head
, CaptureState
) capture_head
;
996 static void hmp_info_capture(Monitor
*mon
, const QDict
*qdict
)
1001 for (s
= capture_head
.lh_first
, i
= 0; s
; s
= s
->entries
.le_next
, ++i
) {
1002 monitor_printf(mon
, "[%d]: ", i
);
1003 s
->ops
.info (s
->opaque
);
1007 static void hmp_stopcapture(Monitor
*mon
, const QDict
*qdict
)
1010 int n
= qdict_get_int(qdict
, "n");
1013 for (s
= capture_head
.lh_first
, i
= 0; s
; s
= s
->entries
.le_next
, ++i
) {
1015 s
->ops
.destroy (s
->opaque
);
1016 QLIST_REMOVE (s
, entries
);
1023 static void hmp_wavcapture(Monitor
*mon
, const QDict
*qdict
)
1025 const char *path
= qdict_get_str(qdict
, "path");
1026 int freq
= qdict_get_try_int(qdict
, "freq", 44100);
1027 int bits
= qdict_get_try_int(qdict
, "bits", 16);
1028 int nchannels
= qdict_get_try_int(qdict
, "nchannels", 2);
1029 const char *audiodev
= qdict_get_str(qdict
, "audiodev");
1031 AudioState
*as
= audio_state_by_name(audiodev
);
1034 monitor_printf(mon
, "Audiodev '%s' not found\n", audiodev
);
1038 s
= g_malloc0 (sizeof (*s
));
1040 if (wav_start_capture(as
, s
, path
, freq
, bits
, nchannels
)) {
1041 monitor_printf(mon
, "Failed to add wave capture\n");
1045 QLIST_INSERT_HEAD (&capture_head
, s
, entries
);
1048 void qmp_getfd(const char *fdname
, Error
**errp
)
1050 Monitor
*cur_mon
= monitor_cur();
1054 fd
= qemu_chr_fe_get_msgfd(&cur_mon
->chr
);
1056 error_setg(errp
, "No file descriptor supplied via SCM_RIGHTS");
1060 if (qemu_isdigit(fdname
[0])) {
1062 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "fdname",
1063 "a name not starting with a digit");
1067 QEMU_LOCK_GUARD(&cur_mon
->mon_lock
);
1068 QLIST_FOREACH(monfd
, &cur_mon
->fds
, next
) {
1069 if (strcmp(monfd
->name
, fdname
) != 0) {
1075 /* Make sure close() is outside critical section */
1080 monfd
= g_malloc0(sizeof(mon_fd_t
));
1081 monfd
->name
= g_strdup(fdname
);
1084 QLIST_INSERT_HEAD(&cur_mon
->fds
, monfd
, next
);
1087 void qmp_closefd(const char *fdname
, Error
**errp
)
1089 Monitor
*cur_mon
= monitor_cur();
1093 qemu_mutex_lock(&cur_mon
->mon_lock
);
1094 QLIST_FOREACH(monfd
, &cur_mon
->fds
, next
) {
1095 if (strcmp(monfd
->name
, fdname
) != 0) {
1099 QLIST_REMOVE(monfd
, next
);
1101 g_free(monfd
->name
);
1103 qemu_mutex_unlock(&cur_mon
->mon_lock
);
1104 /* Make sure close() is outside critical section */
1109 qemu_mutex_unlock(&cur_mon
->mon_lock
);
1110 error_setg(errp
, "File descriptor named '%s' not found", fdname
);
1113 int monitor_get_fd(Monitor
*mon
, const char *fdname
, Error
**errp
)
1117 QEMU_LOCK_GUARD(&mon
->mon_lock
);
1118 QLIST_FOREACH(monfd
, &mon
->fds
, next
) {
1121 if (strcmp(monfd
->name
, fdname
) != 0) {
1127 /* caller takes ownership of fd */
1128 QLIST_REMOVE(monfd
, next
);
1129 g_free(monfd
->name
);
1135 error_setg(errp
, "File descriptor named '%s' has not been found", fdname
);
1139 static void monitor_fdset_cleanup(MonFdset
*mon_fdset
)
1141 MonFdsetFd
*mon_fdset_fd
;
1142 MonFdsetFd
*mon_fdset_fd_next
;
1144 QLIST_FOREACH_SAFE(mon_fdset_fd
, &mon_fdset
->fds
, next
, mon_fdset_fd_next
) {
1145 if ((mon_fdset_fd
->removed
||
1146 (QLIST_EMPTY(&mon_fdset
->dup_fds
) && mon_refcount
== 0)) &&
1147 runstate_is_running()) {
1148 close(mon_fdset_fd
->fd
);
1149 g_free(mon_fdset_fd
->opaque
);
1150 QLIST_REMOVE(mon_fdset_fd
, next
);
1151 g_free(mon_fdset_fd
);
1155 if (QLIST_EMPTY(&mon_fdset
->fds
) && QLIST_EMPTY(&mon_fdset
->dup_fds
)) {
1156 QLIST_REMOVE(mon_fdset
, next
);
1161 void monitor_fdsets_cleanup(void)
1163 MonFdset
*mon_fdset
;
1164 MonFdset
*mon_fdset_next
;
1166 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1167 QLIST_FOREACH_SAFE(mon_fdset
, &mon_fdsets
, next
, mon_fdset_next
) {
1168 monitor_fdset_cleanup(mon_fdset
);
1172 AddfdInfo
*qmp_add_fd(bool has_fdset_id
, int64_t fdset_id
, bool has_opaque
,
1173 const char *opaque
, Error
**errp
)
1176 Monitor
*mon
= monitor_cur();
1179 fd
= qemu_chr_fe_get_msgfd(&mon
->chr
);
1181 error_setg(errp
, "No file descriptor supplied via SCM_RIGHTS");
1185 fdinfo
= monitor_fdset_add_fd(fd
, has_fdset_id
, fdset_id
,
1186 has_opaque
, opaque
, errp
);
1198 void qmp_remove_fd(int64_t fdset_id
, bool has_fd
, int64_t fd
, Error
**errp
)
1200 MonFdset
*mon_fdset
;
1201 MonFdsetFd
*mon_fdset_fd
;
1204 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1205 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1206 if (mon_fdset
->id
!= fdset_id
) {
1209 QLIST_FOREACH(mon_fdset_fd
, &mon_fdset
->fds
, next
) {
1211 if (mon_fdset_fd
->fd
!= fd
) {
1214 mon_fdset_fd
->removed
= true;
1217 mon_fdset_fd
->removed
= true;
1220 if (has_fd
&& !mon_fdset_fd
) {
1223 monitor_fdset_cleanup(mon_fdset
);
1229 snprintf(fd_str
, sizeof(fd_str
), "fdset-id:%" PRId64
", fd:%" PRId64
,
1232 snprintf(fd_str
, sizeof(fd_str
), "fdset-id:%" PRId64
, fdset_id
);
1234 error_setg(errp
, "File descriptor named '%s' not found", fd_str
);
1237 FdsetInfoList
*qmp_query_fdsets(Error
**errp
)
1239 MonFdset
*mon_fdset
;
1240 MonFdsetFd
*mon_fdset_fd
;
1241 FdsetInfoList
*fdset_list
= NULL
;
1243 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1244 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1245 FdsetInfo
*fdset_info
= g_malloc0(sizeof(*fdset_info
));
1247 fdset_info
->fdset_id
= mon_fdset
->id
;
1249 QLIST_FOREACH(mon_fdset_fd
, &mon_fdset
->fds
, next
) {
1250 FdsetFdInfo
*fdsetfd_info
;
1252 fdsetfd_info
= g_malloc0(sizeof(*fdsetfd_info
));
1253 fdsetfd_info
->fd
= mon_fdset_fd
->fd
;
1254 if (mon_fdset_fd
->opaque
) {
1255 fdsetfd_info
->has_opaque
= true;
1256 fdsetfd_info
->opaque
= g_strdup(mon_fdset_fd
->opaque
);
1258 fdsetfd_info
->has_opaque
= false;
1261 QAPI_LIST_PREPEND(fdset_info
->fds
, fdsetfd_info
);
1264 QAPI_LIST_PREPEND(fdset_list
, fdset_info
);
1270 AddfdInfo
*monitor_fdset_add_fd(int fd
, bool has_fdset_id
, int64_t fdset_id
,
1271 bool has_opaque
, const char *opaque
,
1274 MonFdset
*mon_fdset
= NULL
;
1275 MonFdsetFd
*mon_fdset_fd
;
1278 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1280 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1281 /* Break if match found or match impossible due to ordering by ID */
1282 if (fdset_id
<= mon_fdset
->id
) {
1283 if (fdset_id
< mon_fdset
->id
) {
1291 if (mon_fdset
== NULL
) {
1292 int64_t fdset_id_prev
= -1;
1293 MonFdset
*mon_fdset_cur
= QLIST_FIRST(&mon_fdsets
);
1297 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "fdset-id",
1298 "a non-negative value");
1301 /* Use specified fdset ID */
1302 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1303 mon_fdset_cur
= mon_fdset
;
1304 if (fdset_id
< mon_fdset_cur
->id
) {
1309 /* Use first available fdset ID */
1310 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1311 mon_fdset_cur
= mon_fdset
;
1312 if (fdset_id_prev
== mon_fdset_cur
->id
- 1) {
1313 fdset_id_prev
= mon_fdset_cur
->id
;
1320 mon_fdset
= g_malloc0(sizeof(*mon_fdset
));
1322 mon_fdset
->id
= fdset_id
;
1324 mon_fdset
->id
= fdset_id_prev
+ 1;
1327 /* The fdset list is ordered by fdset ID */
1328 if (!mon_fdset_cur
) {
1329 QLIST_INSERT_HEAD(&mon_fdsets
, mon_fdset
, next
);
1330 } else if (mon_fdset
->id
< mon_fdset_cur
->id
) {
1331 QLIST_INSERT_BEFORE(mon_fdset_cur
, mon_fdset
, next
);
1333 QLIST_INSERT_AFTER(mon_fdset_cur
, mon_fdset
, next
);
1337 mon_fdset_fd
= g_malloc0(sizeof(*mon_fdset_fd
));
1338 mon_fdset_fd
->fd
= fd
;
1339 mon_fdset_fd
->removed
= false;
1341 mon_fdset_fd
->opaque
= g_strdup(opaque
);
1343 QLIST_INSERT_HEAD(&mon_fdset
->fds
, mon_fdset_fd
, next
);
1345 fdinfo
= g_malloc0(sizeof(*fdinfo
));
1346 fdinfo
->fdset_id
= mon_fdset
->id
;
1347 fdinfo
->fd
= mon_fdset_fd
->fd
;
1352 int monitor_fdset_dup_fd_add(int64_t fdset_id
, int flags
)
1357 MonFdset
*mon_fdset
;
1359 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1360 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1361 MonFdsetFd
*mon_fdset_fd
;
1362 MonFdsetFd
*mon_fdset_fd_dup
;
1367 if (mon_fdset
->id
!= fdset_id
) {
1371 QLIST_FOREACH(mon_fdset_fd
, &mon_fdset
->fds
, next
) {
1372 mon_fd_flags
= fcntl(mon_fdset_fd
->fd
, F_GETFL
);
1373 if (mon_fd_flags
== -1) {
1377 if ((flags
& O_ACCMODE
) == (mon_fd_flags
& O_ACCMODE
)) {
1378 fd
= mon_fdset_fd
->fd
;
1388 dup_fd
= qemu_dup_flags(fd
, flags
);
1393 mon_fdset_fd_dup
= g_malloc0(sizeof(*mon_fdset_fd_dup
));
1394 mon_fdset_fd_dup
->fd
= dup_fd
;
1395 QLIST_INSERT_HEAD(&mon_fdset
->dup_fds
, mon_fdset_fd_dup
, next
);
1404 static int64_t monitor_fdset_dup_fd_find_remove(int dup_fd
, bool remove
)
1406 MonFdset
*mon_fdset
;
1407 MonFdsetFd
*mon_fdset_fd_dup
;
1409 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1410 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1411 QLIST_FOREACH(mon_fdset_fd_dup
, &mon_fdset
->dup_fds
, next
) {
1412 if (mon_fdset_fd_dup
->fd
== dup_fd
) {
1414 QLIST_REMOVE(mon_fdset_fd_dup
, next
);
1415 g_free(mon_fdset_fd_dup
);
1416 if (QLIST_EMPTY(&mon_fdset
->dup_fds
)) {
1417 monitor_fdset_cleanup(mon_fdset
);
1421 return mon_fdset
->id
;
1430 int64_t monitor_fdset_dup_fd_find(int dup_fd
)
1432 return monitor_fdset_dup_fd_find_remove(dup_fd
, false);
1435 void monitor_fdset_dup_fd_remove(int dup_fd
)
1437 monitor_fdset_dup_fd_find_remove(dup_fd
, true);
1440 int monitor_fd_param(Monitor
*mon
, const char *fdname
, Error
**errp
)
1443 Error
*local_err
= NULL
;
1445 if (!qemu_isdigit(fdname
[0]) && mon
) {
1446 fd
= monitor_get_fd(mon
, fdname
, &local_err
);
1448 fd
= qemu_parse_fd(fdname
);
1450 error_setg(&local_err
, "Invalid file descriptor number '%s'",
1455 error_propagate(errp
, local_err
);
1464 /* Please update hmp-commands.hx when adding or changing commands */
1465 static HMPCommand hmp_info_cmds
[] = {
1466 #include "hmp-commands-info.h"
1470 /* hmp_cmds and hmp_info_cmds would be sorted at runtime */
1471 HMPCommand hmp_cmds
[] = {
1472 #include "hmp-commands.h"
1477 * Set @pval to the value in the register identified by @name.
1478 * return 0 if OK, -1 if not found
1480 int get_monitor_def(Monitor
*mon
, int64_t *pval
, const char *name
)
1482 const MonitorDef
*md
= target_monitor_defs();
1483 CPUState
*cs
= mon_get_cpu(mon
);
1488 if (cs
== NULL
|| md
== NULL
) {
1492 for(; md
->name
!= NULL
; md
++) {
1493 if (hmp_compare_cmd(name
, md
->name
)) {
1494 if (md
->get_value
) {
1495 *pval
= md
->get_value(mon
, md
, md
->offset
);
1497 CPUArchState
*env
= mon_get_cpu_env(mon
);
1498 ptr
= (uint8_t *)env
+ md
->offset
;
1501 *pval
= *(int32_t *)ptr
;
1504 *pval
= *(target_long
*)ptr
;
1515 ret
= target_get_monitor_def(cs
, name
, &tmp
);
1517 *pval
= (target_long
) tmp
;
1523 static void add_completion_option(ReadLineState
*rs
, const char *str
,
1526 if (!str
|| !option
) {
1529 if (!strncmp(option
, str
, strlen(str
))) {
1530 readline_add_completion(rs
, option
);
1534 void chardev_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1537 ChardevBackendInfoList
*list
, *start
;
1543 readline_set_completion_index(rs
, len
);
1545 start
= list
= qmp_query_chardev_backends(NULL
);
1547 const char *chr_name
= list
->value
->name
;
1549 if (!strncmp(chr_name
, str
, len
)) {
1550 readline_add_completion(rs
, chr_name
);
1554 qapi_free_ChardevBackendInfoList(start
);
1557 void netdev_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1566 readline_set_completion_index(rs
, len
);
1567 for (i
= 0; i
< NET_CLIENT_DRIVER__MAX
; i
++) {
1568 add_completion_option(rs
, str
, NetClientDriver_str(i
));
1572 void device_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1582 readline_set_completion_index(rs
, len
);
1583 list
= elt
= object_class_get_list(TYPE_DEVICE
, false);
1586 DeviceClass
*dc
= OBJECT_CLASS_CHECK(DeviceClass
, elt
->data
,
1588 name
= object_class_get_name(OBJECT_CLASS(dc
));
1590 if (dc
->user_creatable
1591 && !strncmp(name
, str
, len
)) {
1592 readline_add_completion(rs
, name
);
1599 void object_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1609 readline_set_completion_index(rs
, len
);
1610 list
= elt
= object_class_get_list(TYPE_USER_CREATABLE
, false);
1614 name
= object_class_get_name(OBJECT_CLASS(elt
->data
));
1615 if (!strncmp(name
, str
, len
) && strcmp(name
, TYPE_USER_CREATABLE
)) {
1616 readline_add_completion(rs
, name
);
1623 static int qdev_add_hotpluggable_device(Object
*obj
, void *opaque
)
1625 GSList
**list
= opaque
;
1626 DeviceState
*dev
= (DeviceState
*)object_dynamic_cast(obj
, TYPE_DEVICE
);
1632 if (dev
->realized
&& object_property_get_bool(obj
, "hotpluggable", NULL
)) {
1633 *list
= g_slist_append(*list
, dev
);
1639 static GSList
*qdev_build_hotpluggable_device_list(Object
*peripheral
)
1641 GSList
*list
= NULL
;
1643 object_child_foreach(peripheral
, qdev_add_hotpluggable_device
, &list
);
1648 static void peripheral_device_del_completion(ReadLineState
*rs
,
1649 const char *str
, size_t len
)
1651 Object
*peripheral
= container_get(qdev_get_machine(), "/peripheral");
1652 GSList
*list
, *item
;
1654 list
= qdev_build_hotpluggable_device_list(peripheral
);
1659 for (item
= list
; item
; item
= g_slist_next(item
)) {
1660 DeviceState
*dev
= item
->data
;
1662 if (dev
->id
&& !strncmp(str
, dev
->id
, len
)) {
1663 readline_add_completion(rs
, dev
->id
);
1670 void chardev_remove_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1673 ChardevInfoList
*list
, *start
;
1679 readline_set_completion_index(rs
, len
);
1681 start
= list
= qmp_query_chardev(NULL
);
1683 ChardevInfo
*chr
= list
->value
;
1685 if (!strncmp(chr
->label
, str
, len
)) {
1686 readline_add_completion(rs
, chr
->label
);
1690 qapi_free_ChardevInfoList(start
);
1693 static void ringbuf_completion(ReadLineState
*rs
, const char *str
)
1696 ChardevInfoList
*list
, *start
;
1699 readline_set_completion_index(rs
, len
);
1701 start
= list
= qmp_query_chardev(NULL
);
1703 ChardevInfo
*chr_info
= list
->value
;
1705 if (!strncmp(chr_info
->label
, str
, len
)) {
1706 Chardev
*chr
= qemu_chr_find(chr_info
->label
);
1707 if (chr
&& CHARDEV_IS_RINGBUF(chr
)) {
1708 readline_add_completion(rs
, chr_info
->label
);
1713 qapi_free_ChardevInfoList(start
);
1716 void ringbuf_write_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1721 ringbuf_completion(rs
, str
);
1724 void device_del_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1733 readline_set_completion_index(rs
, len
);
1734 peripheral_device_del_completion(rs
, str
, len
);
1737 void object_del_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1739 ObjectPropertyInfoList
*list
, *start
;
1746 readline_set_completion_index(rs
, len
);
1748 start
= list
= qmp_qom_list("/objects", NULL
);
1750 ObjectPropertyInfo
*info
= list
->value
;
1752 if (!strncmp(info
->type
, "child<", 5)
1753 && !strncmp(info
->name
, str
, len
)) {
1754 readline_add_completion(rs
, info
->name
);
1758 qapi_free_ObjectPropertyInfoList(start
);
1761 void sendkey_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1770 sep
= strrchr(str
, '-');
1775 readline_set_completion_index(rs
, len
);
1776 for (i
= 0; i
< Q_KEY_CODE__MAX
; i
++) {
1777 if (!strncmp(str
, QKeyCode_str(i
), len
)) {
1778 readline_add_completion(rs
, QKeyCode_str(i
));
1783 void set_link_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1788 readline_set_completion_index(rs
, len
);
1790 NetClientState
*ncs
[MAX_QUEUE_NUM
];
1792 count
= qemu_find_net_clients_except(NULL
, ncs
,
1793 NET_CLIENT_DRIVER_NONE
,
1795 for (i
= 0; i
< MIN(count
, MAX_QUEUE_NUM
); i
++) {
1796 const char *name
= ncs
[i
]->name
;
1797 if (!strncmp(str
, name
, len
)) {
1798 readline_add_completion(rs
, name
);
1801 } else if (nb_args
== 3) {
1802 add_completion_option(rs
, str
, "on");
1803 add_completion_option(rs
, str
, "off");
1807 void netdev_del_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1810 NetClientState
*ncs
[MAX_QUEUE_NUM
];
1817 readline_set_completion_index(rs
, len
);
1818 count
= qemu_find_net_clients_except(NULL
, ncs
, NET_CLIENT_DRIVER_NIC
,
1820 for (i
= 0; i
< MIN(count
, MAX_QUEUE_NUM
); i
++) {
1821 const char *name
= ncs
[i
]->name
;
1822 if (strncmp(str
, name
, len
)) {
1825 if (ncs
[i
]->is_netdev
) {
1826 readline_add_completion(rs
, name
);
1831 void info_trace_events_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1836 readline_set_completion_index(rs
, len
);
1838 TraceEventIter iter
;
1840 char *pattern
= g_strdup_printf("%s*", str
);
1841 trace_event_iter_init(&iter
, pattern
);
1842 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
1843 readline_add_completion(rs
, trace_event_get_name(ev
));
1849 void trace_event_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1854 readline_set_completion_index(rs
, len
);
1856 TraceEventIter iter
;
1858 char *pattern
= g_strdup_printf("%s*", str
);
1859 trace_event_iter_init(&iter
, pattern
);
1860 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
1861 readline_add_completion(rs
, trace_event_get_name(ev
));
1864 } else if (nb_args
== 3) {
1865 add_completion_option(rs
, str
, "on");
1866 add_completion_option(rs
, str
, "off");
1870 void watchdog_action_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1877 readline_set_completion_index(rs
, strlen(str
));
1878 for (i
= 0; i
< WATCHDOG_ACTION__MAX
; i
++) {
1879 add_completion_option(rs
, str
, WatchdogAction_str(i
));
1883 void migrate_set_capability_completion(ReadLineState
*rs
, int nb_args
,
1889 readline_set_completion_index(rs
, len
);
1892 for (i
= 0; i
< MIGRATION_CAPABILITY__MAX
; i
++) {
1893 const char *name
= MigrationCapability_str(i
);
1894 if (!strncmp(str
, name
, len
)) {
1895 readline_add_completion(rs
, name
);
1898 } else if (nb_args
== 3) {
1899 add_completion_option(rs
, str
, "on");
1900 add_completion_option(rs
, str
, "off");
1904 void migrate_set_parameter_completion(ReadLineState
*rs
, int nb_args
,
1910 readline_set_completion_index(rs
, len
);
1913 for (i
= 0; i
< MIGRATION_PARAMETER__MAX
; i
++) {
1914 const char *name
= MigrationParameter_str(i
);
1915 if (!strncmp(str
, name
, len
)) {
1916 readline_add_completion(rs
, name
);
1922 static void vm_completion(ReadLineState
*rs
, const char *str
)
1925 BlockDriverState
*bs
;
1926 BdrvNextIterator it
;
1929 readline_set_completion_index(rs
, len
);
1931 for (bs
= bdrv_first(&it
); bs
; bs
= bdrv_next(&it
)) {
1932 SnapshotInfoList
*snapshots
, *snapshot
;
1933 AioContext
*ctx
= bdrv_get_aio_context(bs
);
1936 aio_context_acquire(ctx
);
1937 if (bdrv_can_snapshot(bs
)) {
1938 ok
= bdrv_query_snapshot_info_list(bs
, &snapshots
, NULL
) == 0;
1940 aio_context_release(ctx
);
1945 snapshot
= snapshots
;
1947 char *completion
= snapshot
->value
->name
;
1948 if (!strncmp(str
, completion
, len
)) {
1949 readline_add_completion(rs
, completion
);
1951 completion
= snapshot
->value
->id
;
1952 if (!strncmp(str
, completion
, len
)) {
1953 readline_add_completion(rs
, completion
);
1955 snapshot
= snapshot
->next
;
1957 qapi_free_SnapshotInfoList(snapshots
);
1962 void delvm_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1965 vm_completion(rs
, str
);
1969 void loadvm_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1972 vm_completion(rs
, str
);
1977 compare_mon_cmd(const void *a
, const void *b
)
1979 return strcmp(((const HMPCommand
*)a
)->name
,
1980 ((const HMPCommand
*)b
)->name
);
1983 static void sortcmdlist(void)
1985 qsort(hmp_cmds
, ARRAY_SIZE(hmp_cmds
) - 1,
1988 qsort(hmp_info_cmds
, ARRAY_SIZE(hmp_info_cmds
) - 1,
1989 sizeof(*hmp_info_cmds
),
1993 void monitor_init_globals(void)
1995 monitor_init_globals_core();
1996 monitor_init_qmp_commands();
1998 qemu_mutex_init(&mon_fdsets_lock
);