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
);
324 static void hmp_info_jit(Monitor
*mon
, const QDict
*qdict
)
326 if (!tcg_enabled()) {
327 error_report("JIT information is only available with accel=tcg");
335 static void hmp_info_opcount(Monitor
*mon
, const QDict
*qdict
)
341 static void hmp_info_sync_profile(Monitor
*mon
, const QDict
*qdict
)
343 int64_t max
= qdict_get_try_int(qdict
, "max", 10);
344 bool mean
= qdict_get_try_bool(qdict
, "mean", false);
345 bool coalesce
= !qdict_get_try_bool(qdict
, "no_coalesce", false);
346 enum QSPSortBy sort_by
;
348 sort_by
= mean
? QSP_SORT_BY_AVG_WAIT_TIME
: QSP_SORT_BY_TOTAL_WAIT_TIME
;
349 qsp_report(max
, sort_by
, coalesce
);
352 static void hmp_info_history(Monitor
*mon
, const QDict
*qdict
)
354 MonitorHMP
*hmp_mon
= container_of(mon
, MonitorHMP
, common
);
363 str
= readline_get_history(hmp_mon
->rs
, i
);
367 monitor_printf(mon
, "%d: '%s'\n", i
, str
);
372 static void hmp_info_cpustats(Monitor
*mon
, const QDict
*qdict
)
374 CPUState
*cs
= mon_get_cpu(mon
);
377 monitor_printf(mon
, "No CPU available\n");
380 cpu_dump_statistics(cs
, 0);
383 static void hmp_info_trace_events(Monitor
*mon
, const QDict
*qdict
)
385 const char *name
= qdict_get_try_str(qdict
, "name");
386 bool has_vcpu
= qdict_haskey(qdict
, "vcpu");
387 int vcpu
= qdict_get_try_int(qdict
, "vcpu", 0);
388 TraceEventInfoList
*events
;
389 TraceEventInfoList
*elem
;
390 Error
*local_err
= NULL
;
396 monitor_printf(mon
, "argument vcpu must be positive");
400 events
= qmp_trace_event_get_state(name
, has_vcpu
, vcpu
, &local_err
);
402 error_report_err(local_err
);
406 for (elem
= events
; elem
!= NULL
; elem
= elem
->next
) {
407 monitor_printf(mon
, "%s : state %u\n",
409 elem
->value
->state
== TRACE_EVENT_STATE_ENABLED
? 1 : 0);
411 qapi_free_TraceEventInfoList(events
);
414 void qmp_client_migrate_info(const char *protocol
, const char *hostname
,
415 bool has_port
, int64_t port
,
416 bool has_tls_port
, int64_t tls_port
,
417 bool has_cert_subject
, const char *cert_subject
,
420 if (strcmp(protocol
, "spice") == 0) {
421 if (!qemu_using_spice(errp
)) {
425 if (!has_port
&& !has_tls_port
) {
426 error_setg(errp
, QERR_MISSING_PARAMETER
, "port/tls-port");
430 if (qemu_spice
.migrate_info(hostname
,
431 has_port
? port
: -1,
432 has_tls_port
? tls_port
: -1,
434 error_setg(errp
, "Could not set up display for migration");
440 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "protocol", "'spice'");
443 static void hmp_logfile(Monitor
*mon
, const QDict
*qdict
)
447 qemu_set_log_filename(qdict_get_str(qdict
, "filename"), &err
);
449 error_report_err(err
);
453 static void hmp_log(Monitor
*mon
, const QDict
*qdict
)
456 const char *items
= qdict_get_str(qdict
, "items");
458 if (!strcmp(items
, "none")) {
461 mask
= qemu_str_to_log_mask(items
);
463 help_cmd(mon
, "log");
470 static void hmp_singlestep(Monitor
*mon
, const QDict
*qdict
)
472 const char *option
= qdict_get_try_str(qdict
, "option");
473 if (!option
|| !strcmp(option
, "on")) {
475 } else if (!strcmp(option
, "off")) {
478 monitor_printf(mon
, "unexpected option %s\n", option
);
482 static void hmp_gdbserver(Monitor
*mon
, const QDict
*qdict
)
484 const char *device
= qdict_get_try_str(qdict
, "device");
486 device
= "tcp::" DEFAULT_GDBSTUB_PORT
;
489 if (gdbserver_start(device
) < 0) {
490 monitor_printf(mon
, "Could not open gdbserver on device '%s'\n",
492 } else if (strcmp(device
, "none") == 0) {
493 monitor_printf(mon
, "Disabled gdbserver\n");
495 monitor_printf(mon
, "Waiting for gdb connection on device '%s'\n",
500 static void hmp_watchdog_action(Monitor
*mon
, const QDict
*qdict
)
502 const char *action
= qdict_get_str(qdict
, "action");
503 if (select_watchdog_action(action
) == -1) {
504 monitor_printf(mon
, "Unknown watchdog action '%s'\n", action
);
508 static void monitor_printc(Monitor
*mon
, int c
)
510 monitor_printf(mon
, "'");
513 monitor_printf(mon
, "\\'");
516 monitor_printf(mon
, "\\\\");
519 monitor_printf(mon
, "\\n");
522 monitor_printf(mon
, "\\r");
525 if (c
>= 32 && c
<= 126) {
526 monitor_printf(mon
, "%c", c
);
528 monitor_printf(mon
, "\\x%02x", c
);
532 monitor_printf(mon
, "'");
535 static void memory_dump(Monitor
*mon
, int count
, int format
, int wsize
,
536 hwaddr addr
, int is_physical
)
538 int l
, line_size
, i
, max_digits
, len
;
541 CPUState
*cs
= mon_get_cpu(mon
);
543 if (!cs
&& (format
== 'i' || !is_physical
)) {
544 monitor_printf(mon
, "Can not dump without CPU\n");
549 monitor_disas(mon
, cs
, addr
, count
, is_physical
);
563 max_digits
= DIV_ROUND_UP(wsize
* 8, 3);
567 max_digits
= (wsize
* 8) / 4;
571 max_digits
= DIV_ROUND_UP(wsize
* 8 * 10, 33);
580 monitor_printf(mon
, TARGET_FMT_plx
":", addr
);
582 monitor_printf(mon
, TARGET_FMT_lx
":", (target_ulong
)addr
);
588 AddressSpace
*as
= cs
? cs
->as
: &address_space_memory
;
589 MemTxResult r
= address_space_read(as
, addr
,
590 MEMTXATTRS_UNSPECIFIED
, buf
, l
);
592 monitor_printf(mon
, " Cannot access memory\n");
596 if (cpu_memory_rw_debug(cs
, addr
, buf
, l
, 0) < 0) {
597 monitor_printf(mon
, " Cannot access memory\n");
612 v
= (uint32_t)ldl_p(buf
+ i
);
618 monitor_printf(mon
, " ");
621 monitor_printf(mon
, "%#*" PRIo64
, max_digits
, v
);
624 monitor_printf(mon
, "0x%0*" PRIx64
, max_digits
, v
);
627 monitor_printf(mon
, "%*" PRIu64
, max_digits
, v
);
630 monitor_printf(mon
, "%*" PRId64
, max_digits
, v
);
633 monitor_printc(mon
, v
);
638 monitor_printf(mon
, "\n");
644 static void hmp_memory_dump(Monitor
*mon
, const QDict
*qdict
)
646 int count
= qdict_get_int(qdict
, "count");
647 int format
= qdict_get_int(qdict
, "format");
648 int size
= qdict_get_int(qdict
, "size");
649 target_long addr
= qdict_get_int(qdict
, "addr");
651 memory_dump(mon
, count
, format
, size
, addr
, 0);
654 static void hmp_physical_memory_dump(Monitor
*mon
, const QDict
*qdict
)
656 int count
= qdict_get_int(qdict
, "count");
657 int format
= qdict_get_int(qdict
, "format");
658 int size
= qdict_get_int(qdict
, "size");
659 hwaddr addr
= qdict_get_int(qdict
, "addr");
661 memory_dump(mon
, count
, format
, size
, addr
, 1);
664 void *gpa2hva(MemoryRegion
**p_mr
, hwaddr addr
, uint64_t size
, Error
**errp
)
666 Int128 gpa_region_size
;
667 MemoryRegionSection mrs
= memory_region_find(get_system_memory(),
671 error_setg(errp
, "No memory is mapped at address 0x%" HWADDR_PRIx
, addr
);
675 if (!memory_region_is_ram(mrs
.mr
) && !memory_region_is_romd(mrs
.mr
)) {
676 error_setg(errp
, "Memory at address 0x%" HWADDR_PRIx
"is not RAM", addr
);
677 memory_region_unref(mrs
.mr
);
681 gpa_region_size
= int128_make64(size
);
682 if (int128_lt(mrs
.size
, gpa_region_size
)) {
683 error_setg(errp
, "Size of memory region at 0x%" HWADDR_PRIx
685 memory_region_unref(mrs
.mr
);
690 return qemu_map_ram_ptr(mrs
.mr
->ram_block
, mrs
.offset_within_region
);
693 static void hmp_gpa2hva(Monitor
*mon
, const QDict
*qdict
)
695 hwaddr addr
= qdict_get_int(qdict
, "addr");
696 Error
*local_err
= NULL
;
697 MemoryRegion
*mr
= NULL
;
700 ptr
= gpa2hva(&mr
, addr
, 1, &local_err
);
702 error_report_err(local_err
);
706 monitor_printf(mon
, "Host virtual address for 0x%" HWADDR_PRIx
708 addr
, mr
->name
, ptr
);
710 memory_region_unref(mr
);
713 static void hmp_gva2gpa(Monitor
*mon
, const QDict
*qdict
)
715 target_ulong addr
= qdict_get_int(qdict
, "addr");
717 CPUState
*cs
= mon_get_cpu(mon
);
721 monitor_printf(mon
, "No cpu\n");
725 gpa
= cpu_get_phys_page_attrs_debug(cs
, addr
& TARGET_PAGE_MASK
, &attrs
);
727 monitor_printf(mon
, "Unmapped\n");
729 monitor_printf(mon
, "gpa: %#" HWADDR_PRIx
"\n",
730 gpa
+ (addr
& ~TARGET_PAGE_MASK
));
735 static uint64_t vtop(void *ptr
, Error
**errp
)
739 uintptr_t addr
= (uintptr_t) ptr
;
740 uintptr_t pagesize
= qemu_real_host_page_size
;
741 off_t offset
= addr
/ pagesize
* sizeof(pinfo
);
744 fd
= open("/proc/self/pagemap", O_RDONLY
);
746 error_setg_errno(errp
, errno
, "Cannot open /proc/self/pagemap");
750 /* Force copy-on-write if necessary. */
751 qatomic_add((uint8_t *)ptr
, 0);
753 if (pread(fd
, &pinfo
, sizeof(pinfo
), offset
) != sizeof(pinfo
)) {
754 error_setg_errno(errp
, errno
, "Cannot read pagemap");
757 if ((pinfo
& (1ull << 63)) == 0) {
758 error_setg(errp
, "Page not present");
761 ret
= ((pinfo
& 0x007fffffffffffffull
) * pagesize
) | (addr
& (pagesize
- 1));
768 static void hmp_gpa2hpa(Monitor
*mon
, const QDict
*qdict
)
770 hwaddr addr
= qdict_get_int(qdict
, "addr");
771 Error
*local_err
= NULL
;
772 MemoryRegion
*mr
= NULL
;
776 ptr
= gpa2hva(&mr
, addr
, 1, &local_err
);
778 error_report_err(local_err
);
782 physaddr
= vtop(ptr
, &local_err
);
784 error_report_err(local_err
);
786 monitor_printf(mon
, "Host physical address for 0x%" HWADDR_PRIx
787 " (%s) is 0x%" PRIx64
"\n",
788 addr
, mr
->name
, (uint64_t) physaddr
);
791 memory_region_unref(mr
);
795 static void do_print(Monitor
*mon
, const QDict
*qdict
)
797 int format
= qdict_get_int(qdict
, "format");
798 hwaddr val
= qdict_get_int(qdict
, "val");
802 monitor_printf(mon
, "%#" HWADDR_PRIo
, val
);
805 monitor_printf(mon
, "%#" HWADDR_PRIx
, val
);
808 monitor_printf(mon
, "%" HWADDR_PRIu
, val
);
812 monitor_printf(mon
, "%" HWADDR_PRId
, val
);
815 monitor_printc(mon
, val
);
818 monitor_printf(mon
, "\n");
821 static void hmp_sum(Monitor
*mon
, const QDict
*qdict
)
825 uint32_t start
= qdict_get_int(qdict
, "start");
826 uint32_t size
= qdict_get_int(qdict
, "size");
829 for(addr
= start
; addr
< (start
+ size
); addr
++) {
830 uint8_t val
= address_space_ldub(&address_space_memory
, addr
,
831 MEMTXATTRS_UNSPECIFIED
, NULL
);
832 /* BSD sum algorithm ('sum' Unix command) */
833 sum
= (sum
>> 1) | (sum
<< 15);
836 monitor_printf(mon
, "%05d\n", sum
);
839 static int mouse_button_state
;
841 static void hmp_mouse_move(Monitor
*mon
, const QDict
*qdict
)
843 int dx
, dy
, dz
, button
;
844 const char *dx_str
= qdict_get_str(qdict
, "dx_str");
845 const char *dy_str
= qdict_get_str(qdict
, "dy_str");
846 const char *dz_str
= qdict_get_try_str(qdict
, "dz_str");
848 dx
= strtol(dx_str
, NULL
, 0);
849 dy
= strtol(dy_str
, NULL
, 0);
850 qemu_input_queue_rel(NULL
, INPUT_AXIS_X
, dx
);
851 qemu_input_queue_rel(NULL
, INPUT_AXIS_Y
, dy
);
854 dz
= strtol(dz_str
, NULL
, 0);
856 button
= (dz
> 0) ? INPUT_BUTTON_WHEEL_UP
: INPUT_BUTTON_WHEEL_DOWN
;
857 qemu_input_queue_btn(NULL
, button
, true);
858 qemu_input_event_sync();
859 qemu_input_queue_btn(NULL
, button
, false);
862 qemu_input_event_sync();
865 static void hmp_mouse_button(Monitor
*mon
, const QDict
*qdict
)
867 static uint32_t bmap
[INPUT_BUTTON__MAX
] = {
868 [INPUT_BUTTON_LEFT
] = MOUSE_EVENT_LBUTTON
,
869 [INPUT_BUTTON_MIDDLE
] = MOUSE_EVENT_MBUTTON
,
870 [INPUT_BUTTON_RIGHT
] = MOUSE_EVENT_RBUTTON
,
872 int button_state
= qdict_get_int(qdict
, "button_state");
874 if (mouse_button_state
== button_state
) {
877 qemu_input_update_buttons(NULL
, bmap
, mouse_button_state
, button_state
);
878 qemu_input_event_sync();
879 mouse_button_state
= button_state
;
882 static void hmp_ioport_read(Monitor
*mon
, const QDict
*qdict
)
884 int size
= qdict_get_int(qdict
, "size");
885 int addr
= qdict_get_int(qdict
, "addr");
886 int has_index
= qdict_haskey(qdict
, "index");
891 int index
= qdict_get_int(qdict
, "index");
892 cpu_outb(addr
& IOPORTS_MASK
, index
& 0xff);
912 monitor_printf(mon
, "port%c[0x%04x] = 0x%0*x\n",
913 suffix
, addr
, size
* 2, val
);
916 static void hmp_ioport_write(Monitor
*mon
, const QDict
*qdict
)
918 int size
= qdict_get_int(qdict
, "size");
919 int addr
= qdict_get_int(qdict
, "addr");
920 int val
= qdict_get_int(qdict
, "val");
922 addr
&= IOPORTS_MASK
;
938 static void hmp_boot_set(Monitor
*mon
, const QDict
*qdict
)
940 Error
*local_err
= NULL
;
941 const char *bootdevice
= qdict_get_str(qdict
, "bootdevice");
943 qemu_boot_set(bootdevice
, &local_err
);
945 error_report_err(local_err
);
947 monitor_printf(mon
, "boot device list now set to %s\n", bootdevice
);
951 static void hmp_info_mtree(Monitor
*mon
, const QDict
*qdict
)
953 bool flatview
= qdict_get_try_bool(qdict
, "flatview", false);
954 bool dispatch_tree
= qdict_get_try_bool(qdict
, "dispatch_tree", false);
955 bool owner
= qdict_get_try_bool(qdict
, "owner", false);
956 bool disabled
= qdict_get_try_bool(qdict
, "disabled", false);
958 mtree_info(flatview
, dispatch_tree
, owner
, disabled
);
961 #ifdef CONFIG_PROFILER
965 static void hmp_info_profile(Monitor
*mon
, const QDict
*qdict
)
967 static int64_t last_cpu_exec_time
;
968 int64_t cpu_exec_time
;
971 cpu_exec_time
= tcg_cpu_exec_time();
972 delta
= cpu_exec_time
- last_cpu_exec_time
;
974 monitor_printf(mon
, "async time %" PRId64
" (%0.3f)\n",
975 dev_time
, dev_time
/ (double)NANOSECONDS_PER_SECOND
);
976 monitor_printf(mon
, "qemu time %" PRId64
" (%0.3f)\n",
977 delta
, delta
/ (double)NANOSECONDS_PER_SECOND
);
978 last_cpu_exec_time
= cpu_exec_time
;
982 static void hmp_info_profile(Monitor
*mon
, const QDict
*qdict
)
984 monitor_printf(mon
, "Internal profiler not compiled\n");
988 /* Capture support */
989 static QLIST_HEAD (capture_list_head
, CaptureState
) capture_head
;
991 static void hmp_info_capture(Monitor
*mon
, const QDict
*qdict
)
996 for (s
= capture_head
.lh_first
, i
= 0; s
; s
= s
->entries
.le_next
, ++i
) {
997 monitor_printf(mon
, "[%d]: ", i
);
998 s
->ops
.info (s
->opaque
);
1002 static void hmp_stopcapture(Monitor
*mon
, const QDict
*qdict
)
1005 int n
= qdict_get_int(qdict
, "n");
1008 for (s
= capture_head
.lh_first
, i
= 0; s
; s
= s
->entries
.le_next
, ++i
) {
1010 s
->ops
.destroy (s
->opaque
);
1011 QLIST_REMOVE (s
, entries
);
1018 static void hmp_wavcapture(Monitor
*mon
, const QDict
*qdict
)
1020 const char *path
= qdict_get_str(qdict
, "path");
1021 int freq
= qdict_get_try_int(qdict
, "freq", 44100);
1022 int bits
= qdict_get_try_int(qdict
, "bits", 16);
1023 int nchannels
= qdict_get_try_int(qdict
, "nchannels", 2);
1024 const char *audiodev
= qdict_get_str(qdict
, "audiodev");
1026 AudioState
*as
= audio_state_by_name(audiodev
);
1029 monitor_printf(mon
, "Audiodev '%s' not found\n", audiodev
);
1033 s
= g_malloc0 (sizeof (*s
));
1035 if (wav_start_capture(as
, s
, path
, freq
, bits
, nchannels
)) {
1036 monitor_printf(mon
, "Failed to add wave capture\n");
1040 QLIST_INSERT_HEAD (&capture_head
, s
, entries
);
1043 void qmp_getfd(const char *fdname
, Error
**errp
)
1045 Monitor
*cur_mon
= monitor_cur();
1049 fd
= qemu_chr_fe_get_msgfd(&cur_mon
->chr
);
1051 error_setg(errp
, "No file descriptor supplied via SCM_RIGHTS");
1055 if (qemu_isdigit(fdname
[0])) {
1057 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "fdname",
1058 "a name not starting with a digit");
1062 QEMU_LOCK_GUARD(&cur_mon
->mon_lock
);
1063 QLIST_FOREACH(monfd
, &cur_mon
->fds
, next
) {
1064 if (strcmp(monfd
->name
, fdname
) != 0) {
1070 /* Make sure close() is outside critical section */
1075 monfd
= g_malloc0(sizeof(mon_fd_t
));
1076 monfd
->name
= g_strdup(fdname
);
1079 QLIST_INSERT_HEAD(&cur_mon
->fds
, monfd
, next
);
1082 void qmp_closefd(const char *fdname
, Error
**errp
)
1084 Monitor
*cur_mon
= monitor_cur();
1088 qemu_mutex_lock(&cur_mon
->mon_lock
);
1089 QLIST_FOREACH(monfd
, &cur_mon
->fds
, next
) {
1090 if (strcmp(monfd
->name
, fdname
) != 0) {
1094 QLIST_REMOVE(monfd
, next
);
1096 g_free(monfd
->name
);
1098 qemu_mutex_unlock(&cur_mon
->mon_lock
);
1099 /* Make sure close() is outside critical section */
1104 qemu_mutex_unlock(&cur_mon
->mon_lock
);
1105 error_setg(errp
, "File descriptor named '%s' not found", fdname
);
1108 int monitor_get_fd(Monitor
*mon
, const char *fdname
, Error
**errp
)
1112 QEMU_LOCK_GUARD(&mon
->mon_lock
);
1113 QLIST_FOREACH(monfd
, &mon
->fds
, next
) {
1116 if (strcmp(monfd
->name
, fdname
) != 0) {
1122 /* caller takes ownership of fd */
1123 QLIST_REMOVE(monfd
, next
);
1124 g_free(monfd
->name
);
1130 error_setg(errp
, "File descriptor named '%s' has not been found", fdname
);
1134 static void monitor_fdset_cleanup(MonFdset
*mon_fdset
)
1136 MonFdsetFd
*mon_fdset_fd
;
1137 MonFdsetFd
*mon_fdset_fd_next
;
1139 QLIST_FOREACH_SAFE(mon_fdset_fd
, &mon_fdset
->fds
, next
, mon_fdset_fd_next
) {
1140 if ((mon_fdset_fd
->removed
||
1141 (QLIST_EMPTY(&mon_fdset
->dup_fds
) && mon_refcount
== 0)) &&
1142 runstate_is_running()) {
1143 close(mon_fdset_fd
->fd
);
1144 g_free(mon_fdset_fd
->opaque
);
1145 QLIST_REMOVE(mon_fdset_fd
, next
);
1146 g_free(mon_fdset_fd
);
1150 if (QLIST_EMPTY(&mon_fdset
->fds
) && QLIST_EMPTY(&mon_fdset
->dup_fds
)) {
1151 QLIST_REMOVE(mon_fdset
, next
);
1156 void monitor_fdsets_cleanup(void)
1158 MonFdset
*mon_fdset
;
1159 MonFdset
*mon_fdset_next
;
1161 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1162 QLIST_FOREACH_SAFE(mon_fdset
, &mon_fdsets
, next
, mon_fdset_next
) {
1163 monitor_fdset_cleanup(mon_fdset
);
1167 AddfdInfo
*qmp_add_fd(bool has_fdset_id
, int64_t fdset_id
, bool has_opaque
,
1168 const char *opaque
, Error
**errp
)
1171 Monitor
*mon
= monitor_cur();
1174 fd
= qemu_chr_fe_get_msgfd(&mon
->chr
);
1176 error_setg(errp
, "No file descriptor supplied via SCM_RIGHTS");
1180 fdinfo
= monitor_fdset_add_fd(fd
, has_fdset_id
, fdset_id
,
1181 has_opaque
, opaque
, errp
);
1193 void qmp_remove_fd(int64_t fdset_id
, bool has_fd
, int64_t fd
, Error
**errp
)
1195 MonFdset
*mon_fdset
;
1196 MonFdsetFd
*mon_fdset_fd
;
1199 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1200 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1201 if (mon_fdset
->id
!= fdset_id
) {
1204 QLIST_FOREACH(mon_fdset_fd
, &mon_fdset
->fds
, next
) {
1206 if (mon_fdset_fd
->fd
!= fd
) {
1209 mon_fdset_fd
->removed
= true;
1212 mon_fdset_fd
->removed
= true;
1215 if (has_fd
&& !mon_fdset_fd
) {
1218 monitor_fdset_cleanup(mon_fdset
);
1224 snprintf(fd_str
, sizeof(fd_str
), "fdset-id:%" PRId64
", fd:%" PRId64
,
1227 snprintf(fd_str
, sizeof(fd_str
), "fdset-id:%" PRId64
, fdset_id
);
1229 error_setg(errp
, "File descriptor named '%s' not found", fd_str
);
1232 FdsetInfoList
*qmp_query_fdsets(Error
**errp
)
1234 MonFdset
*mon_fdset
;
1235 MonFdsetFd
*mon_fdset_fd
;
1236 FdsetInfoList
*fdset_list
= NULL
;
1238 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1239 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1240 FdsetInfo
*fdset_info
= g_malloc0(sizeof(*fdset_info
));
1242 fdset_info
->fdset_id
= mon_fdset
->id
;
1244 QLIST_FOREACH(mon_fdset_fd
, &mon_fdset
->fds
, next
) {
1245 FdsetFdInfo
*fdsetfd_info
;
1247 fdsetfd_info
= g_malloc0(sizeof(*fdsetfd_info
));
1248 fdsetfd_info
->fd
= mon_fdset_fd
->fd
;
1249 if (mon_fdset_fd
->opaque
) {
1250 fdsetfd_info
->has_opaque
= true;
1251 fdsetfd_info
->opaque
= g_strdup(mon_fdset_fd
->opaque
);
1253 fdsetfd_info
->has_opaque
= false;
1256 QAPI_LIST_PREPEND(fdset_info
->fds
, fdsetfd_info
);
1259 QAPI_LIST_PREPEND(fdset_list
, fdset_info
);
1265 AddfdInfo
*monitor_fdset_add_fd(int fd
, bool has_fdset_id
, int64_t fdset_id
,
1266 bool has_opaque
, const char *opaque
,
1269 MonFdset
*mon_fdset
= NULL
;
1270 MonFdsetFd
*mon_fdset_fd
;
1273 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1275 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1276 /* Break if match found or match impossible due to ordering by ID */
1277 if (fdset_id
<= mon_fdset
->id
) {
1278 if (fdset_id
< mon_fdset
->id
) {
1286 if (mon_fdset
== NULL
) {
1287 int64_t fdset_id_prev
= -1;
1288 MonFdset
*mon_fdset_cur
= QLIST_FIRST(&mon_fdsets
);
1292 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "fdset-id",
1293 "a non-negative value");
1296 /* Use specified fdset ID */
1297 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1298 mon_fdset_cur
= mon_fdset
;
1299 if (fdset_id
< mon_fdset_cur
->id
) {
1304 /* Use first available fdset ID */
1305 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1306 mon_fdset_cur
= mon_fdset
;
1307 if (fdset_id_prev
== mon_fdset_cur
->id
- 1) {
1308 fdset_id_prev
= mon_fdset_cur
->id
;
1315 mon_fdset
= g_malloc0(sizeof(*mon_fdset
));
1317 mon_fdset
->id
= fdset_id
;
1319 mon_fdset
->id
= fdset_id_prev
+ 1;
1322 /* The fdset list is ordered by fdset ID */
1323 if (!mon_fdset_cur
) {
1324 QLIST_INSERT_HEAD(&mon_fdsets
, mon_fdset
, next
);
1325 } else if (mon_fdset
->id
< mon_fdset_cur
->id
) {
1326 QLIST_INSERT_BEFORE(mon_fdset_cur
, mon_fdset
, next
);
1328 QLIST_INSERT_AFTER(mon_fdset_cur
, mon_fdset
, next
);
1332 mon_fdset_fd
= g_malloc0(sizeof(*mon_fdset_fd
));
1333 mon_fdset_fd
->fd
= fd
;
1334 mon_fdset_fd
->removed
= false;
1336 mon_fdset_fd
->opaque
= g_strdup(opaque
);
1338 QLIST_INSERT_HEAD(&mon_fdset
->fds
, mon_fdset_fd
, next
);
1340 fdinfo
= g_malloc0(sizeof(*fdinfo
));
1341 fdinfo
->fdset_id
= mon_fdset
->id
;
1342 fdinfo
->fd
= mon_fdset_fd
->fd
;
1347 int monitor_fdset_dup_fd_add(int64_t fdset_id
, int flags
)
1352 MonFdset
*mon_fdset
;
1354 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1355 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1356 MonFdsetFd
*mon_fdset_fd
;
1357 MonFdsetFd
*mon_fdset_fd_dup
;
1362 if (mon_fdset
->id
!= fdset_id
) {
1366 QLIST_FOREACH(mon_fdset_fd
, &mon_fdset
->fds
, next
) {
1367 mon_fd_flags
= fcntl(mon_fdset_fd
->fd
, F_GETFL
);
1368 if (mon_fd_flags
== -1) {
1372 if ((flags
& O_ACCMODE
) == (mon_fd_flags
& O_ACCMODE
)) {
1373 fd
= mon_fdset_fd
->fd
;
1383 dup_fd
= qemu_dup_flags(fd
, flags
);
1388 mon_fdset_fd_dup
= g_malloc0(sizeof(*mon_fdset_fd_dup
));
1389 mon_fdset_fd_dup
->fd
= dup_fd
;
1390 QLIST_INSERT_HEAD(&mon_fdset
->dup_fds
, mon_fdset_fd_dup
, next
);
1399 static int64_t monitor_fdset_dup_fd_find_remove(int dup_fd
, bool remove
)
1401 MonFdset
*mon_fdset
;
1402 MonFdsetFd
*mon_fdset_fd_dup
;
1404 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1405 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1406 QLIST_FOREACH(mon_fdset_fd_dup
, &mon_fdset
->dup_fds
, next
) {
1407 if (mon_fdset_fd_dup
->fd
== dup_fd
) {
1409 QLIST_REMOVE(mon_fdset_fd_dup
, next
);
1410 g_free(mon_fdset_fd_dup
);
1411 if (QLIST_EMPTY(&mon_fdset
->dup_fds
)) {
1412 monitor_fdset_cleanup(mon_fdset
);
1416 return mon_fdset
->id
;
1425 int64_t monitor_fdset_dup_fd_find(int dup_fd
)
1427 return monitor_fdset_dup_fd_find_remove(dup_fd
, false);
1430 void monitor_fdset_dup_fd_remove(int dup_fd
)
1432 monitor_fdset_dup_fd_find_remove(dup_fd
, true);
1435 int monitor_fd_param(Monitor
*mon
, const char *fdname
, Error
**errp
)
1438 Error
*local_err
= NULL
;
1440 if (!qemu_isdigit(fdname
[0]) && mon
) {
1441 fd
= monitor_get_fd(mon
, fdname
, &local_err
);
1443 fd
= qemu_parse_fd(fdname
);
1445 error_setg(&local_err
, "Invalid file descriptor number '%s'",
1450 error_propagate(errp
, local_err
);
1459 /* Please update hmp-commands.hx when adding or changing commands */
1460 static HMPCommand hmp_info_cmds
[] = {
1461 #include "hmp-commands-info.h"
1465 /* hmp_cmds and hmp_info_cmds would be sorted at runtime */
1466 HMPCommand hmp_cmds
[] = {
1467 #include "hmp-commands.h"
1472 * Set @pval to the value in the register identified by @name.
1473 * return 0 if OK, -1 if not found
1475 int get_monitor_def(Monitor
*mon
, int64_t *pval
, const char *name
)
1477 const MonitorDef
*md
= target_monitor_defs();
1478 CPUState
*cs
= mon_get_cpu(mon
);
1483 if (cs
== NULL
|| md
== NULL
) {
1487 for(; md
->name
!= NULL
; md
++) {
1488 if (hmp_compare_cmd(name
, md
->name
)) {
1489 if (md
->get_value
) {
1490 *pval
= md
->get_value(mon
, md
, md
->offset
);
1492 CPUArchState
*env
= mon_get_cpu_env(mon
);
1493 ptr
= (uint8_t *)env
+ md
->offset
;
1496 *pval
= *(int32_t *)ptr
;
1499 *pval
= *(target_long
*)ptr
;
1510 ret
= target_get_monitor_def(cs
, name
, &tmp
);
1512 *pval
= (target_long
) tmp
;
1518 static void add_completion_option(ReadLineState
*rs
, const char *str
,
1521 if (!str
|| !option
) {
1524 if (!strncmp(option
, str
, strlen(str
))) {
1525 readline_add_completion(rs
, option
);
1529 void chardev_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1532 ChardevBackendInfoList
*list
, *start
;
1538 readline_set_completion_index(rs
, len
);
1540 start
= list
= qmp_query_chardev_backends(NULL
);
1542 const char *chr_name
= list
->value
->name
;
1544 if (!strncmp(chr_name
, str
, len
)) {
1545 readline_add_completion(rs
, chr_name
);
1549 qapi_free_ChardevBackendInfoList(start
);
1552 void netdev_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1561 readline_set_completion_index(rs
, len
);
1562 for (i
= 0; i
< NET_CLIENT_DRIVER__MAX
; i
++) {
1563 add_completion_option(rs
, str
, NetClientDriver_str(i
));
1567 void device_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1577 readline_set_completion_index(rs
, len
);
1578 list
= elt
= object_class_get_list(TYPE_DEVICE
, false);
1581 DeviceClass
*dc
= OBJECT_CLASS_CHECK(DeviceClass
, elt
->data
,
1583 name
= object_class_get_name(OBJECT_CLASS(dc
));
1585 if (dc
->user_creatable
1586 && !strncmp(name
, str
, len
)) {
1587 readline_add_completion(rs
, name
);
1594 void object_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1604 readline_set_completion_index(rs
, len
);
1605 list
= elt
= object_class_get_list(TYPE_USER_CREATABLE
, false);
1609 name
= object_class_get_name(OBJECT_CLASS(elt
->data
));
1610 if (!strncmp(name
, str
, len
) && strcmp(name
, TYPE_USER_CREATABLE
)) {
1611 readline_add_completion(rs
, name
);
1618 static int qdev_add_hotpluggable_device(Object
*obj
, void *opaque
)
1620 GSList
**list
= opaque
;
1621 DeviceState
*dev
= (DeviceState
*)object_dynamic_cast(obj
, TYPE_DEVICE
);
1627 if (dev
->realized
&& object_property_get_bool(obj
, "hotpluggable", NULL
)) {
1628 *list
= g_slist_append(*list
, dev
);
1634 static GSList
*qdev_build_hotpluggable_device_list(Object
*peripheral
)
1636 GSList
*list
= NULL
;
1638 object_child_foreach(peripheral
, qdev_add_hotpluggable_device
, &list
);
1643 static void peripheral_device_del_completion(ReadLineState
*rs
,
1644 const char *str
, size_t len
)
1646 Object
*peripheral
= container_get(qdev_get_machine(), "/peripheral");
1647 GSList
*list
, *item
;
1649 list
= qdev_build_hotpluggable_device_list(peripheral
);
1654 for (item
= list
; item
; item
= g_slist_next(item
)) {
1655 DeviceState
*dev
= item
->data
;
1657 if (dev
->id
&& !strncmp(str
, dev
->id
, len
)) {
1658 readline_add_completion(rs
, dev
->id
);
1665 void chardev_remove_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1668 ChardevInfoList
*list
, *start
;
1674 readline_set_completion_index(rs
, len
);
1676 start
= list
= qmp_query_chardev(NULL
);
1678 ChardevInfo
*chr
= list
->value
;
1680 if (!strncmp(chr
->label
, str
, len
)) {
1681 readline_add_completion(rs
, chr
->label
);
1685 qapi_free_ChardevInfoList(start
);
1688 static void ringbuf_completion(ReadLineState
*rs
, const char *str
)
1691 ChardevInfoList
*list
, *start
;
1694 readline_set_completion_index(rs
, len
);
1696 start
= list
= qmp_query_chardev(NULL
);
1698 ChardevInfo
*chr_info
= list
->value
;
1700 if (!strncmp(chr_info
->label
, str
, len
)) {
1701 Chardev
*chr
= qemu_chr_find(chr_info
->label
);
1702 if (chr
&& CHARDEV_IS_RINGBUF(chr
)) {
1703 readline_add_completion(rs
, chr_info
->label
);
1708 qapi_free_ChardevInfoList(start
);
1711 void ringbuf_write_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1716 ringbuf_completion(rs
, str
);
1719 void device_del_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1728 readline_set_completion_index(rs
, len
);
1729 peripheral_device_del_completion(rs
, str
, len
);
1732 void object_del_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1734 ObjectPropertyInfoList
*list
, *start
;
1741 readline_set_completion_index(rs
, len
);
1743 start
= list
= qmp_qom_list("/objects", NULL
);
1745 ObjectPropertyInfo
*info
= list
->value
;
1747 if (!strncmp(info
->type
, "child<", 5)
1748 && !strncmp(info
->name
, str
, len
)) {
1749 readline_add_completion(rs
, info
->name
);
1753 qapi_free_ObjectPropertyInfoList(start
);
1756 void sendkey_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1765 sep
= strrchr(str
, '-');
1770 readline_set_completion_index(rs
, len
);
1771 for (i
= 0; i
< Q_KEY_CODE__MAX
; i
++) {
1772 if (!strncmp(str
, QKeyCode_str(i
), len
)) {
1773 readline_add_completion(rs
, QKeyCode_str(i
));
1778 void set_link_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1783 readline_set_completion_index(rs
, len
);
1785 NetClientState
*ncs
[MAX_QUEUE_NUM
];
1787 count
= qemu_find_net_clients_except(NULL
, ncs
,
1788 NET_CLIENT_DRIVER_NONE
,
1790 for (i
= 0; i
< MIN(count
, MAX_QUEUE_NUM
); i
++) {
1791 const char *name
= ncs
[i
]->name
;
1792 if (!strncmp(str
, name
, len
)) {
1793 readline_add_completion(rs
, name
);
1796 } else if (nb_args
== 3) {
1797 add_completion_option(rs
, str
, "on");
1798 add_completion_option(rs
, str
, "off");
1802 void netdev_del_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1805 NetClientState
*ncs
[MAX_QUEUE_NUM
];
1812 readline_set_completion_index(rs
, len
);
1813 count
= qemu_find_net_clients_except(NULL
, ncs
, NET_CLIENT_DRIVER_NIC
,
1815 for (i
= 0; i
< MIN(count
, MAX_QUEUE_NUM
); i
++) {
1816 const char *name
= ncs
[i
]->name
;
1817 if (strncmp(str
, name
, len
)) {
1820 if (ncs
[i
]->is_netdev
) {
1821 readline_add_completion(rs
, name
);
1826 void info_trace_events_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1831 readline_set_completion_index(rs
, len
);
1833 TraceEventIter iter
;
1835 char *pattern
= g_strdup_printf("%s*", str
);
1836 trace_event_iter_init(&iter
, pattern
);
1837 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
1838 readline_add_completion(rs
, trace_event_get_name(ev
));
1844 void trace_event_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1849 readline_set_completion_index(rs
, len
);
1851 TraceEventIter iter
;
1853 char *pattern
= g_strdup_printf("%s*", str
);
1854 trace_event_iter_init(&iter
, pattern
);
1855 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
1856 readline_add_completion(rs
, trace_event_get_name(ev
));
1859 } else if (nb_args
== 3) {
1860 add_completion_option(rs
, str
, "on");
1861 add_completion_option(rs
, str
, "off");
1865 void watchdog_action_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1872 readline_set_completion_index(rs
, strlen(str
));
1873 for (i
= 0; i
< WATCHDOG_ACTION__MAX
; i
++) {
1874 add_completion_option(rs
, str
, WatchdogAction_str(i
));
1878 void migrate_set_capability_completion(ReadLineState
*rs
, int nb_args
,
1884 readline_set_completion_index(rs
, len
);
1887 for (i
= 0; i
< MIGRATION_CAPABILITY__MAX
; i
++) {
1888 const char *name
= MigrationCapability_str(i
);
1889 if (!strncmp(str
, name
, len
)) {
1890 readline_add_completion(rs
, name
);
1893 } else if (nb_args
== 3) {
1894 add_completion_option(rs
, str
, "on");
1895 add_completion_option(rs
, str
, "off");
1899 void migrate_set_parameter_completion(ReadLineState
*rs
, int nb_args
,
1905 readline_set_completion_index(rs
, len
);
1908 for (i
= 0; i
< MIGRATION_PARAMETER__MAX
; i
++) {
1909 const char *name
= MigrationParameter_str(i
);
1910 if (!strncmp(str
, name
, len
)) {
1911 readline_add_completion(rs
, name
);
1917 static void vm_completion(ReadLineState
*rs
, const char *str
)
1920 BlockDriverState
*bs
;
1921 BdrvNextIterator it
;
1924 readline_set_completion_index(rs
, len
);
1926 for (bs
= bdrv_first(&it
); bs
; bs
= bdrv_next(&it
)) {
1927 SnapshotInfoList
*snapshots
, *snapshot
;
1928 AioContext
*ctx
= bdrv_get_aio_context(bs
);
1931 aio_context_acquire(ctx
);
1932 if (bdrv_can_snapshot(bs
)) {
1933 ok
= bdrv_query_snapshot_info_list(bs
, &snapshots
, NULL
) == 0;
1935 aio_context_release(ctx
);
1940 snapshot
= snapshots
;
1942 char *completion
= snapshot
->value
->name
;
1943 if (!strncmp(str
, completion
, len
)) {
1944 readline_add_completion(rs
, completion
);
1946 completion
= snapshot
->value
->id
;
1947 if (!strncmp(str
, completion
, len
)) {
1948 readline_add_completion(rs
, completion
);
1950 snapshot
= snapshot
->next
;
1952 qapi_free_SnapshotInfoList(snapshots
);
1957 void delvm_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1960 vm_completion(rs
, str
);
1964 void loadvm_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1967 vm_completion(rs
, str
);
1972 compare_mon_cmd(const void *a
, const void *b
)
1974 return strcmp(((const HMPCommand
*)a
)->name
,
1975 ((const HMPCommand
*)b
)->name
);
1978 static void sortcmdlist(void)
1980 qsort(hmp_cmds
, ARRAY_SIZE(hmp_cmds
) - 1,
1983 qsort(hmp_info_cmds
, ARRAY_SIZE(hmp_info_cmds
) - 1,
1984 sizeof(*hmp_info_cmds
),
1988 void monitor_init_globals(void)
1990 monitor_init_globals_core();
1991 monitor_init_qmp_commands();
1993 qemu_mutex_init(&mon_fdsets_lock
);