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
, "device_add", qmp_device_add
,
237 QTAILQ_INIT(&qmp_cap_negotiation_commands
);
238 qmp_register_command(&qmp_cap_negotiation_commands
, "qmp_capabilities",
239 qmp_marshal_qmp_capabilities
, QCO_ALLOW_PRECONFIG
);
242 /* Set the current CPU defined by the user. Callers must hold BQL. */
243 int monitor_set_cpu(Monitor
*mon
, int cpu_index
)
247 cpu
= qemu_get_cpu(cpu_index
);
251 g_free(mon
->mon_cpu_path
);
252 mon
->mon_cpu_path
= object_get_canonical_path(OBJECT(cpu
));
256 /* Callers must hold BQL. */
257 static CPUState
*mon_get_cpu_sync(Monitor
*mon
, bool synchronize
)
259 CPUState
*cpu
= NULL
;
261 if (mon
->mon_cpu_path
) {
262 cpu
= (CPUState
*) object_resolve_path_type(mon
->mon_cpu_path
,
265 g_free(mon
->mon_cpu_path
);
266 mon
->mon_cpu_path
= NULL
;
269 if (!mon
->mon_cpu_path
) {
273 monitor_set_cpu(mon
, first_cpu
->cpu_index
);
278 cpu_synchronize_state(cpu
);
283 CPUState
*mon_get_cpu(Monitor
*mon
)
285 return mon_get_cpu_sync(mon
, true);
288 CPUArchState
*mon_get_cpu_env(Monitor
*mon
)
290 CPUState
*cs
= mon_get_cpu(mon
);
292 return cs
? cs
->env_ptr
: NULL
;
295 int monitor_get_cpu_index(Monitor
*mon
)
297 CPUState
*cs
= mon_get_cpu_sync(mon
, false);
299 return cs
? cs
->cpu_index
: UNASSIGNED_CPU_INDEX
;
302 static void hmp_info_registers(Monitor
*mon
, const QDict
*qdict
)
304 bool all_cpus
= qdict_get_try_bool(qdict
, "cpustate_all", false);
309 monitor_printf(mon
, "\nCPU#%d\n", cs
->cpu_index
);
310 cpu_dump_state(cs
, NULL
, CPU_DUMP_FPU
);
313 cs
= mon_get_cpu(mon
);
316 monitor_printf(mon
, "No CPU available\n");
320 cpu_dump_state(cs
, NULL
, CPU_DUMP_FPU
);
325 static void hmp_info_jit(Monitor
*mon
, const QDict
*qdict
)
327 if (!tcg_enabled()) {
328 error_report("JIT information is only available with accel=tcg");
336 static void hmp_info_opcount(Monitor
*mon
, const QDict
*qdict
)
342 static void hmp_info_sync_profile(Monitor
*mon
, const QDict
*qdict
)
344 int64_t max
= qdict_get_try_int(qdict
, "max", 10);
345 bool mean
= qdict_get_try_bool(qdict
, "mean", false);
346 bool coalesce
= !qdict_get_try_bool(qdict
, "no_coalesce", false);
347 enum QSPSortBy sort_by
;
349 sort_by
= mean
? QSP_SORT_BY_AVG_WAIT_TIME
: QSP_SORT_BY_TOTAL_WAIT_TIME
;
350 qsp_report(max
, sort_by
, coalesce
);
353 static void hmp_info_history(Monitor
*mon
, const QDict
*qdict
)
355 MonitorHMP
*hmp_mon
= container_of(mon
, MonitorHMP
, common
);
364 str
= readline_get_history(hmp_mon
->rs
, i
);
368 monitor_printf(mon
, "%d: '%s'\n", i
, str
);
373 static void hmp_info_cpustats(Monitor
*mon
, const QDict
*qdict
)
375 CPUState
*cs
= mon_get_cpu(mon
);
378 monitor_printf(mon
, "No CPU available\n");
381 cpu_dump_statistics(cs
, 0);
384 static void hmp_info_trace_events(Monitor
*mon
, const QDict
*qdict
)
386 const char *name
= qdict_get_try_str(qdict
, "name");
387 bool has_vcpu
= qdict_haskey(qdict
, "vcpu");
388 int vcpu
= qdict_get_try_int(qdict
, "vcpu", 0);
389 TraceEventInfoList
*events
;
390 TraceEventInfoList
*elem
;
391 Error
*local_err
= NULL
;
397 monitor_printf(mon
, "argument vcpu must be positive");
401 events
= qmp_trace_event_get_state(name
, has_vcpu
, vcpu
, &local_err
);
403 error_report_err(local_err
);
407 for (elem
= events
; elem
!= NULL
; elem
= elem
->next
) {
408 monitor_printf(mon
, "%s : state %u\n",
410 elem
->value
->state
== TRACE_EVENT_STATE_ENABLED
? 1 : 0);
412 qapi_free_TraceEventInfoList(events
);
415 void qmp_client_migrate_info(const char *protocol
, const char *hostname
,
416 bool has_port
, int64_t port
,
417 bool has_tls_port
, int64_t tls_port
,
418 bool has_cert_subject
, const char *cert_subject
,
421 if (strcmp(protocol
, "spice") == 0) {
422 if (!qemu_using_spice(errp
)) {
426 if (!has_port
&& !has_tls_port
) {
427 error_setg(errp
, QERR_MISSING_PARAMETER
, "port/tls-port");
431 if (qemu_spice
.migrate_info(hostname
,
432 has_port
? port
: -1,
433 has_tls_port
? tls_port
: -1,
435 error_setg(errp
, "Could not set up display for migration");
441 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "protocol", "'spice'");
444 static void hmp_logfile(Monitor
*mon
, const QDict
*qdict
)
448 qemu_set_log_filename(qdict_get_str(qdict
, "filename"), &err
);
450 error_report_err(err
);
454 static void hmp_log(Monitor
*mon
, const QDict
*qdict
)
457 const char *items
= qdict_get_str(qdict
, "items");
459 if (!strcmp(items
, "none")) {
462 mask
= qemu_str_to_log_mask(items
);
464 help_cmd(mon
, "log");
471 static void hmp_singlestep(Monitor
*mon
, const QDict
*qdict
)
473 const char *option
= qdict_get_try_str(qdict
, "option");
474 if (!option
|| !strcmp(option
, "on")) {
476 } else if (!strcmp(option
, "off")) {
479 monitor_printf(mon
, "unexpected option %s\n", option
);
483 static void hmp_gdbserver(Monitor
*mon
, const QDict
*qdict
)
485 const char *device
= qdict_get_try_str(qdict
, "device");
487 device
= "tcp::" DEFAULT_GDBSTUB_PORT
;
490 if (gdbserver_start(device
) < 0) {
491 monitor_printf(mon
, "Could not open gdbserver on device '%s'\n",
493 } else if (strcmp(device
, "none") == 0) {
494 monitor_printf(mon
, "Disabled gdbserver\n");
496 monitor_printf(mon
, "Waiting for gdb connection on device '%s'\n",
501 static void hmp_watchdog_action(Monitor
*mon
, const QDict
*qdict
)
503 const char *action
= qdict_get_str(qdict
, "action");
504 if (select_watchdog_action(action
) == -1) {
505 monitor_printf(mon
, "Unknown watchdog action '%s'\n", action
);
509 static void monitor_printc(Monitor
*mon
, int c
)
511 monitor_printf(mon
, "'");
514 monitor_printf(mon
, "\\'");
517 monitor_printf(mon
, "\\\\");
520 monitor_printf(mon
, "\\n");
523 monitor_printf(mon
, "\\r");
526 if (c
>= 32 && c
<= 126) {
527 monitor_printf(mon
, "%c", c
);
529 monitor_printf(mon
, "\\x%02x", c
);
533 monitor_printf(mon
, "'");
536 static void memory_dump(Monitor
*mon
, int count
, int format
, int wsize
,
537 hwaddr addr
, int is_physical
)
539 int l
, line_size
, i
, max_digits
, len
;
542 CPUState
*cs
= mon_get_cpu(mon
);
544 if (!cs
&& (format
== 'i' || !is_physical
)) {
545 monitor_printf(mon
, "Can not dump without CPU\n");
550 monitor_disas(mon
, cs
, addr
, count
, is_physical
);
564 max_digits
= DIV_ROUND_UP(wsize
* 8, 3);
568 max_digits
= (wsize
* 8) / 4;
572 max_digits
= DIV_ROUND_UP(wsize
* 8 * 10, 33);
581 monitor_printf(mon
, TARGET_FMT_plx
":", addr
);
583 monitor_printf(mon
, TARGET_FMT_lx
":", (target_ulong
)addr
);
589 AddressSpace
*as
= cs
? cs
->as
: &address_space_memory
;
590 MemTxResult r
= address_space_read(as
, addr
,
591 MEMTXATTRS_UNSPECIFIED
, buf
, l
);
593 monitor_printf(mon
, " Cannot access memory\n");
597 if (cpu_memory_rw_debug(cs
, addr
, buf
, l
, 0) < 0) {
598 monitor_printf(mon
, " Cannot access memory\n");
613 v
= (uint32_t)ldl_p(buf
+ i
);
619 monitor_printf(mon
, " ");
622 monitor_printf(mon
, "%#*" PRIo64
, max_digits
, v
);
625 monitor_printf(mon
, "0x%0*" PRIx64
, max_digits
, v
);
628 monitor_printf(mon
, "%*" PRIu64
, max_digits
, v
);
631 monitor_printf(mon
, "%*" PRId64
, max_digits
, v
);
634 monitor_printc(mon
, v
);
639 monitor_printf(mon
, "\n");
645 static void hmp_memory_dump(Monitor
*mon
, const QDict
*qdict
)
647 int count
= qdict_get_int(qdict
, "count");
648 int format
= qdict_get_int(qdict
, "format");
649 int size
= qdict_get_int(qdict
, "size");
650 target_long addr
= qdict_get_int(qdict
, "addr");
652 memory_dump(mon
, count
, format
, size
, addr
, 0);
655 static void hmp_physical_memory_dump(Monitor
*mon
, const QDict
*qdict
)
657 int count
= qdict_get_int(qdict
, "count");
658 int format
= qdict_get_int(qdict
, "format");
659 int size
= qdict_get_int(qdict
, "size");
660 hwaddr addr
= qdict_get_int(qdict
, "addr");
662 memory_dump(mon
, count
, format
, size
, addr
, 1);
665 void *gpa2hva(MemoryRegion
**p_mr
, hwaddr addr
, uint64_t size
, Error
**errp
)
667 Int128 gpa_region_size
;
668 MemoryRegionSection mrs
= memory_region_find(get_system_memory(),
672 error_setg(errp
, "No memory is mapped at address 0x%" HWADDR_PRIx
, addr
);
676 if (!memory_region_is_ram(mrs
.mr
) && !memory_region_is_romd(mrs
.mr
)) {
677 error_setg(errp
, "Memory at address 0x%" HWADDR_PRIx
"is not RAM", addr
);
678 memory_region_unref(mrs
.mr
);
682 gpa_region_size
= int128_make64(size
);
683 if (int128_lt(mrs
.size
, gpa_region_size
)) {
684 error_setg(errp
, "Size of memory region at 0x%" HWADDR_PRIx
686 memory_region_unref(mrs
.mr
);
691 return qemu_map_ram_ptr(mrs
.mr
->ram_block
, mrs
.offset_within_region
);
694 static void hmp_gpa2hva(Monitor
*mon
, const QDict
*qdict
)
696 hwaddr addr
= qdict_get_int(qdict
, "addr");
697 Error
*local_err
= NULL
;
698 MemoryRegion
*mr
= NULL
;
701 ptr
= gpa2hva(&mr
, addr
, 1, &local_err
);
703 error_report_err(local_err
);
707 monitor_printf(mon
, "Host virtual address for 0x%" HWADDR_PRIx
709 addr
, mr
->name
, ptr
);
711 memory_region_unref(mr
);
714 static void hmp_gva2gpa(Monitor
*mon
, const QDict
*qdict
)
716 target_ulong addr
= qdict_get_int(qdict
, "addr");
718 CPUState
*cs
= mon_get_cpu(mon
);
722 monitor_printf(mon
, "No cpu\n");
726 gpa
= cpu_get_phys_page_attrs_debug(cs
, addr
& TARGET_PAGE_MASK
, &attrs
);
728 monitor_printf(mon
, "Unmapped\n");
730 monitor_printf(mon
, "gpa: %#" HWADDR_PRIx
"\n",
731 gpa
+ (addr
& ~TARGET_PAGE_MASK
));
736 static uint64_t vtop(void *ptr
, Error
**errp
)
740 uintptr_t addr
= (uintptr_t) ptr
;
741 uintptr_t pagesize
= qemu_real_host_page_size
;
742 off_t offset
= addr
/ pagesize
* sizeof(pinfo
);
745 fd
= open("/proc/self/pagemap", O_RDONLY
);
747 error_setg_errno(errp
, errno
, "Cannot open /proc/self/pagemap");
751 /* Force copy-on-write if necessary. */
752 qatomic_add((uint8_t *)ptr
, 0);
754 if (pread(fd
, &pinfo
, sizeof(pinfo
), offset
) != sizeof(pinfo
)) {
755 error_setg_errno(errp
, errno
, "Cannot read pagemap");
758 if ((pinfo
& (1ull << 63)) == 0) {
759 error_setg(errp
, "Page not present");
762 ret
= ((pinfo
& 0x007fffffffffffffull
) * pagesize
) | (addr
& (pagesize
- 1));
769 static void hmp_gpa2hpa(Monitor
*mon
, const QDict
*qdict
)
771 hwaddr addr
= qdict_get_int(qdict
, "addr");
772 Error
*local_err
= NULL
;
773 MemoryRegion
*mr
= NULL
;
777 ptr
= gpa2hva(&mr
, addr
, 1, &local_err
);
779 error_report_err(local_err
);
783 physaddr
= vtop(ptr
, &local_err
);
785 error_report_err(local_err
);
787 monitor_printf(mon
, "Host physical address for 0x%" HWADDR_PRIx
788 " (%s) is 0x%" PRIx64
"\n",
789 addr
, mr
->name
, (uint64_t) physaddr
);
792 memory_region_unref(mr
);
796 static void do_print(Monitor
*mon
, const QDict
*qdict
)
798 int format
= qdict_get_int(qdict
, "format");
799 hwaddr val
= qdict_get_int(qdict
, "val");
803 monitor_printf(mon
, "%#" HWADDR_PRIo
, val
);
806 monitor_printf(mon
, "%#" HWADDR_PRIx
, val
);
809 monitor_printf(mon
, "%" HWADDR_PRIu
, val
);
813 monitor_printf(mon
, "%" HWADDR_PRId
, val
);
816 monitor_printc(mon
, val
);
819 monitor_printf(mon
, "\n");
822 static void hmp_sum(Monitor
*mon
, const QDict
*qdict
)
826 uint32_t start
= qdict_get_int(qdict
, "start");
827 uint32_t size
= qdict_get_int(qdict
, "size");
830 for(addr
= start
; addr
< (start
+ size
); addr
++) {
831 uint8_t val
= address_space_ldub(&address_space_memory
, addr
,
832 MEMTXATTRS_UNSPECIFIED
, NULL
);
833 /* BSD sum algorithm ('sum' Unix command) */
834 sum
= (sum
>> 1) | (sum
<< 15);
837 monitor_printf(mon
, "%05d\n", sum
);
840 static int mouse_button_state
;
842 static void hmp_mouse_move(Monitor
*mon
, const QDict
*qdict
)
844 int dx
, dy
, dz
, button
;
845 const char *dx_str
= qdict_get_str(qdict
, "dx_str");
846 const char *dy_str
= qdict_get_str(qdict
, "dy_str");
847 const char *dz_str
= qdict_get_try_str(qdict
, "dz_str");
849 dx
= strtol(dx_str
, NULL
, 0);
850 dy
= strtol(dy_str
, NULL
, 0);
851 qemu_input_queue_rel(NULL
, INPUT_AXIS_X
, dx
);
852 qemu_input_queue_rel(NULL
, INPUT_AXIS_Y
, dy
);
855 dz
= strtol(dz_str
, NULL
, 0);
857 button
= (dz
> 0) ? INPUT_BUTTON_WHEEL_UP
: INPUT_BUTTON_WHEEL_DOWN
;
858 qemu_input_queue_btn(NULL
, button
, true);
859 qemu_input_event_sync();
860 qemu_input_queue_btn(NULL
, button
, false);
863 qemu_input_event_sync();
866 static void hmp_mouse_button(Monitor
*mon
, const QDict
*qdict
)
868 static uint32_t bmap
[INPUT_BUTTON__MAX
] = {
869 [INPUT_BUTTON_LEFT
] = MOUSE_EVENT_LBUTTON
,
870 [INPUT_BUTTON_MIDDLE
] = MOUSE_EVENT_MBUTTON
,
871 [INPUT_BUTTON_RIGHT
] = MOUSE_EVENT_RBUTTON
,
873 int button_state
= qdict_get_int(qdict
, "button_state");
875 if (mouse_button_state
== button_state
) {
878 qemu_input_update_buttons(NULL
, bmap
, mouse_button_state
, button_state
);
879 qemu_input_event_sync();
880 mouse_button_state
= button_state
;
883 static void hmp_ioport_read(Monitor
*mon
, const QDict
*qdict
)
885 int size
= qdict_get_int(qdict
, "size");
886 int addr
= qdict_get_int(qdict
, "addr");
887 int has_index
= qdict_haskey(qdict
, "index");
892 int index
= qdict_get_int(qdict
, "index");
893 cpu_outb(addr
& IOPORTS_MASK
, index
& 0xff);
913 monitor_printf(mon
, "port%c[0x%04x] = 0x%0*x\n",
914 suffix
, addr
, size
* 2, val
);
917 static void hmp_ioport_write(Monitor
*mon
, const QDict
*qdict
)
919 int size
= qdict_get_int(qdict
, "size");
920 int addr
= qdict_get_int(qdict
, "addr");
921 int val
= qdict_get_int(qdict
, "val");
923 addr
&= IOPORTS_MASK
;
939 static void hmp_boot_set(Monitor
*mon
, const QDict
*qdict
)
941 Error
*local_err
= NULL
;
942 const char *bootdevice
= qdict_get_str(qdict
, "bootdevice");
944 qemu_boot_set(bootdevice
, &local_err
);
946 error_report_err(local_err
);
948 monitor_printf(mon
, "boot device list now set to %s\n", bootdevice
);
952 static void hmp_info_mtree(Monitor
*mon
, const QDict
*qdict
)
954 bool flatview
= qdict_get_try_bool(qdict
, "flatview", false);
955 bool dispatch_tree
= qdict_get_try_bool(qdict
, "dispatch_tree", false);
956 bool owner
= qdict_get_try_bool(qdict
, "owner", false);
957 bool disabled
= qdict_get_try_bool(qdict
, "disabled", false);
959 mtree_info(flatview
, dispatch_tree
, owner
, disabled
);
962 #ifdef CONFIG_PROFILER
966 static void hmp_info_profile(Monitor
*mon
, const QDict
*qdict
)
968 static int64_t last_cpu_exec_time
;
969 int64_t cpu_exec_time
;
972 cpu_exec_time
= tcg_cpu_exec_time();
973 delta
= cpu_exec_time
- last_cpu_exec_time
;
975 monitor_printf(mon
, "async time %" PRId64
" (%0.3f)\n",
976 dev_time
, dev_time
/ (double)NANOSECONDS_PER_SECOND
);
977 monitor_printf(mon
, "qemu time %" PRId64
" (%0.3f)\n",
978 delta
, delta
/ (double)NANOSECONDS_PER_SECOND
);
979 last_cpu_exec_time
= cpu_exec_time
;
983 static void hmp_info_profile(Monitor
*mon
, const QDict
*qdict
)
985 monitor_printf(mon
, "Internal profiler not compiled\n");
989 /* Capture support */
990 static QLIST_HEAD (capture_list_head
, CaptureState
) capture_head
;
992 static void hmp_info_capture(Monitor
*mon
, const QDict
*qdict
)
997 for (s
= capture_head
.lh_first
, i
= 0; s
; s
= s
->entries
.le_next
, ++i
) {
998 monitor_printf(mon
, "[%d]: ", i
);
999 s
->ops
.info (s
->opaque
);
1003 static void hmp_stopcapture(Monitor
*mon
, const QDict
*qdict
)
1006 int n
= qdict_get_int(qdict
, "n");
1009 for (s
= capture_head
.lh_first
, i
= 0; s
; s
= s
->entries
.le_next
, ++i
) {
1011 s
->ops
.destroy (s
->opaque
);
1012 QLIST_REMOVE (s
, entries
);
1019 static void hmp_wavcapture(Monitor
*mon
, const QDict
*qdict
)
1021 const char *path
= qdict_get_str(qdict
, "path");
1022 int freq
= qdict_get_try_int(qdict
, "freq", 44100);
1023 int bits
= qdict_get_try_int(qdict
, "bits", 16);
1024 int nchannels
= qdict_get_try_int(qdict
, "nchannels", 2);
1025 const char *audiodev
= qdict_get_str(qdict
, "audiodev");
1027 AudioState
*as
= audio_state_by_name(audiodev
);
1030 monitor_printf(mon
, "Audiodev '%s' not found\n", audiodev
);
1034 s
= g_malloc0 (sizeof (*s
));
1036 if (wav_start_capture(as
, s
, path
, freq
, bits
, nchannels
)) {
1037 monitor_printf(mon
, "Failed to add wave capture\n");
1041 QLIST_INSERT_HEAD (&capture_head
, s
, entries
);
1044 void qmp_getfd(const char *fdname
, Error
**errp
)
1046 Monitor
*cur_mon
= monitor_cur();
1050 fd
= qemu_chr_fe_get_msgfd(&cur_mon
->chr
);
1052 error_setg(errp
, "No file descriptor supplied via SCM_RIGHTS");
1056 if (qemu_isdigit(fdname
[0])) {
1058 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "fdname",
1059 "a name not starting with a digit");
1063 QEMU_LOCK_GUARD(&cur_mon
->mon_lock
);
1064 QLIST_FOREACH(monfd
, &cur_mon
->fds
, next
) {
1065 if (strcmp(monfd
->name
, fdname
) != 0) {
1071 /* Make sure close() is outside critical section */
1076 monfd
= g_malloc0(sizeof(mon_fd_t
));
1077 monfd
->name
= g_strdup(fdname
);
1080 QLIST_INSERT_HEAD(&cur_mon
->fds
, monfd
, next
);
1083 void qmp_closefd(const char *fdname
, Error
**errp
)
1085 Monitor
*cur_mon
= monitor_cur();
1089 qemu_mutex_lock(&cur_mon
->mon_lock
);
1090 QLIST_FOREACH(monfd
, &cur_mon
->fds
, next
) {
1091 if (strcmp(monfd
->name
, fdname
) != 0) {
1095 QLIST_REMOVE(monfd
, next
);
1097 g_free(monfd
->name
);
1099 qemu_mutex_unlock(&cur_mon
->mon_lock
);
1100 /* Make sure close() is outside critical section */
1105 qemu_mutex_unlock(&cur_mon
->mon_lock
);
1106 error_setg(errp
, "File descriptor named '%s' not found", fdname
);
1109 int monitor_get_fd(Monitor
*mon
, const char *fdname
, Error
**errp
)
1113 QEMU_LOCK_GUARD(&mon
->mon_lock
);
1114 QLIST_FOREACH(monfd
, &mon
->fds
, next
) {
1117 if (strcmp(monfd
->name
, fdname
) != 0) {
1123 /* caller takes ownership of fd */
1124 QLIST_REMOVE(monfd
, next
);
1125 g_free(monfd
->name
);
1131 error_setg(errp
, "File descriptor named '%s' has not been found", fdname
);
1135 static void monitor_fdset_cleanup(MonFdset
*mon_fdset
)
1137 MonFdsetFd
*mon_fdset_fd
;
1138 MonFdsetFd
*mon_fdset_fd_next
;
1140 QLIST_FOREACH_SAFE(mon_fdset_fd
, &mon_fdset
->fds
, next
, mon_fdset_fd_next
) {
1141 if ((mon_fdset_fd
->removed
||
1142 (QLIST_EMPTY(&mon_fdset
->dup_fds
) && mon_refcount
== 0)) &&
1143 runstate_is_running()) {
1144 close(mon_fdset_fd
->fd
);
1145 g_free(mon_fdset_fd
->opaque
);
1146 QLIST_REMOVE(mon_fdset_fd
, next
);
1147 g_free(mon_fdset_fd
);
1151 if (QLIST_EMPTY(&mon_fdset
->fds
) && QLIST_EMPTY(&mon_fdset
->dup_fds
)) {
1152 QLIST_REMOVE(mon_fdset
, next
);
1157 void monitor_fdsets_cleanup(void)
1159 MonFdset
*mon_fdset
;
1160 MonFdset
*mon_fdset_next
;
1162 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1163 QLIST_FOREACH_SAFE(mon_fdset
, &mon_fdsets
, next
, mon_fdset_next
) {
1164 monitor_fdset_cleanup(mon_fdset
);
1168 AddfdInfo
*qmp_add_fd(bool has_fdset_id
, int64_t fdset_id
, bool has_opaque
,
1169 const char *opaque
, Error
**errp
)
1172 Monitor
*mon
= monitor_cur();
1175 fd
= qemu_chr_fe_get_msgfd(&mon
->chr
);
1177 error_setg(errp
, "No file descriptor supplied via SCM_RIGHTS");
1181 fdinfo
= monitor_fdset_add_fd(fd
, has_fdset_id
, fdset_id
,
1182 has_opaque
, opaque
, errp
);
1194 void qmp_remove_fd(int64_t fdset_id
, bool has_fd
, int64_t fd
, Error
**errp
)
1196 MonFdset
*mon_fdset
;
1197 MonFdsetFd
*mon_fdset_fd
;
1200 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1201 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1202 if (mon_fdset
->id
!= fdset_id
) {
1205 QLIST_FOREACH(mon_fdset_fd
, &mon_fdset
->fds
, next
) {
1207 if (mon_fdset_fd
->fd
!= fd
) {
1210 mon_fdset_fd
->removed
= true;
1213 mon_fdset_fd
->removed
= true;
1216 if (has_fd
&& !mon_fdset_fd
) {
1219 monitor_fdset_cleanup(mon_fdset
);
1225 snprintf(fd_str
, sizeof(fd_str
), "fdset-id:%" PRId64
", fd:%" PRId64
,
1228 snprintf(fd_str
, sizeof(fd_str
), "fdset-id:%" PRId64
, fdset_id
);
1230 error_setg(errp
, "File descriptor named '%s' not found", fd_str
);
1233 FdsetInfoList
*qmp_query_fdsets(Error
**errp
)
1235 MonFdset
*mon_fdset
;
1236 MonFdsetFd
*mon_fdset_fd
;
1237 FdsetInfoList
*fdset_list
= NULL
;
1239 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1240 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1241 FdsetInfo
*fdset_info
= g_malloc0(sizeof(*fdset_info
));
1243 fdset_info
->fdset_id
= mon_fdset
->id
;
1245 QLIST_FOREACH(mon_fdset_fd
, &mon_fdset
->fds
, next
) {
1246 FdsetFdInfo
*fdsetfd_info
;
1248 fdsetfd_info
= g_malloc0(sizeof(*fdsetfd_info
));
1249 fdsetfd_info
->fd
= mon_fdset_fd
->fd
;
1250 if (mon_fdset_fd
->opaque
) {
1251 fdsetfd_info
->has_opaque
= true;
1252 fdsetfd_info
->opaque
= g_strdup(mon_fdset_fd
->opaque
);
1254 fdsetfd_info
->has_opaque
= false;
1257 QAPI_LIST_PREPEND(fdset_info
->fds
, fdsetfd_info
);
1260 QAPI_LIST_PREPEND(fdset_list
, fdset_info
);
1266 AddfdInfo
*monitor_fdset_add_fd(int fd
, bool has_fdset_id
, int64_t fdset_id
,
1267 bool has_opaque
, const char *opaque
,
1270 MonFdset
*mon_fdset
= NULL
;
1271 MonFdsetFd
*mon_fdset_fd
;
1274 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1276 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1277 /* Break if match found or match impossible due to ordering by ID */
1278 if (fdset_id
<= mon_fdset
->id
) {
1279 if (fdset_id
< mon_fdset
->id
) {
1287 if (mon_fdset
== NULL
) {
1288 int64_t fdset_id_prev
= -1;
1289 MonFdset
*mon_fdset_cur
= QLIST_FIRST(&mon_fdsets
);
1293 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "fdset-id",
1294 "a non-negative value");
1297 /* Use specified fdset ID */
1298 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1299 mon_fdset_cur
= mon_fdset
;
1300 if (fdset_id
< mon_fdset_cur
->id
) {
1305 /* Use first available fdset ID */
1306 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1307 mon_fdset_cur
= mon_fdset
;
1308 if (fdset_id_prev
== mon_fdset_cur
->id
- 1) {
1309 fdset_id_prev
= mon_fdset_cur
->id
;
1316 mon_fdset
= g_malloc0(sizeof(*mon_fdset
));
1318 mon_fdset
->id
= fdset_id
;
1320 mon_fdset
->id
= fdset_id_prev
+ 1;
1323 /* The fdset list is ordered by fdset ID */
1324 if (!mon_fdset_cur
) {
1325 QLIST_INSERT_HEAD(&mon_fdsets
, mon_fdset
, next
);
1326 } else if (mon_fdset
->id
< mon_fdset_cur
->id
) {
1327 QLIST_INSERT_BEFORE(mon_fdset_cur
, mon_fdset
, next
);
1329 QLIST_INSERT_AFTER(mon_fdset_cur
, mon_fdset
, next
);
1333 mon_fdset_fd
= g_malloc0(sizeof(*mon_fdset_fd
));
1334 mon_fdset_fd
->fd
= fd
;
1335 mon_fdset_fd
->removed
= false;
1337 mon_fdset_fd
->opaque
= g_strdup(opaque
);
1339 QLIST_INSERT_HEAD(&mon_fdset
->fds
, mon_fdset_fd
, next
);
1341 fdinfo
= g_malloc0(sizeof(*fdinfo
));
1342 fdinfo
->fdset_id
= mon_fdset
->id
;
1343 fdinfo
->fd
= mon_fdset_fd
->fd
;
1348 int monitor_fdset_dup_fd_add(int64_t fdset_id
, int flags
)
1353 MonFdset
*mon_fdset
;
1355 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1356 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1357 MonFdsetFd
*mon_fdset_fd
;
1358 MonFdsetFd
*mon_fdset_fd_dup
;
1363 if (mon_fdset
->id
!= fdset_id
) {
1367 QLIST_FOREACH(mon_fdset_fd
, &mon_fdset
->fds
, next
) {
1368 mon_fd_flags
= fcntl(mon_fdset_fd
->fd
, F_GETFL
);
1369 if (mon_fd_flags
== -1) {
1373 if ((flags
& O_ACCMODE
) == (mon_fd_flags
& O_ACCMODE
)) {
1374 fd
= mon_fdset_fd
->fd
;
1384 dup_fd
= qemu_dup_flags(fd
, flags
);
1389 mon_fdset_fd_dup
= g_malloc0(sizeof(*mon_fdset_fd_dup
));
1390 mon_fdset_fd_dup
->fd
= dup_fd
;
1391 QLIST_INSERT_HEAD(&mon_fdset
->dup_fds
, mon_fdset_fd_dup
, next
);
1400 static int64_t monitor_fdset_dup_fd_find_remove(int dup_fd
, bool remove
)
1402 MonFdset
*mon_fdset
;
1403 MonFdsetFd
*mon_fdset_fd_dup
;
1405 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1406 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1407 QLIST_FOREACH(mon_fdset_fd_dup
, &mon_fdset
->dup_fds
, next
) {
1408 if (mon_fdset_fd_dup
->fd
== dup_fd
) {
1410 QLIST_REMOVE(mon_fdset_fd_dup
, next
);
1411 g_free(mon_fdset_fd_dup
);
1412 if (QLIST_EMPTY(&mon_fdset
->dup_fds
)) {
1413 monitor_fdset_cleanup(mon_fdset
);
1417 return mon_fdset
->id
;
1426 int64_t monitor_fdset_dup_fd_find(int dup_fd
)
1428 return monitor_fdset_dup_fd_find_remove(dup_fd
, false);
1431 void monitor_fdset_dup_fd_remove(int dup_fd
)
1433 monitor_fdset_dup_fd_find_remove(dup_fd
, true);
1436 int monitor_fd_param(Monitor
*mon
, const char *fdname
, Error
**errp
)
1439 Error
*local_err
= NULL
;
1441 if (!qemu_isdigit(fdname
[0]) && mon
) {
1442 fd
= monitor_get_fd(mon
, fdname
, &local_err
);
1444 fd
= qemu_parse_fd(fdname
);
1446 error_setg(&local_err
, "Invalid file descriptor number '%s'",
1451 error_propagate(errp
, local_err
);
1460 /* Please update hmp-commands.hx when adding or changing commands */
1461 static HMPCommand hmp_info_cmds
[] = {
1462 #include "hmp-commands-info.h"
1466 /* hmp_cmds and hmp_info_cmds would be sorted at runtime */
1467 HMPCommand hmp_cmds
[] = {
1468 #include "hmp-commands.h"
1473 * Set @pval to the value in the register identified by @name.
1474 * return 0 if OK, -1 if not found
1476 int get_monitor_def(Monitor
*mon
, int64_t *pval
, const char *name
)
1478 const MonitorDef
*md
= target_monitor_defs();
1479 CPUState
*cs
= mon_get_cpu(mon
);
1484 if (cs
== NULL
|| md
== NULL
) {
1488 for(; md
->name
!= NULL
; md
++) {
1489 if (hmp_compare_cmd(name
, md
->name
)) {
1490 if (md
->get_value
) {
1491 *pval
= md
->get_value(mon
, md
, md
->offset
);
1493 CPUArchState
*env
= mon_get_cpu_env(mon
);
1494 ptr
= (uint8_t *)env
+ md
->offset
;
1497 *pval
= *(int32_t *)ptr
;
1500 *pval
= *(target_long
*)ptr
;
1511 ret
= target_get_monitor_def(cs
, name
, &tmp
);
1513 *pval
= (target_long
) tmp
;
1519 static void add_completion_option(ReadLineState
*rs
, const char *str
,
1522 if (!str
|| !option
) {
1525 if (!strncmp(option
, str
, strlen(str
))) {
1526 readline_add_completion(rs
, option
);
1530 void chardev_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1533 ChardevBackendInfoList
*list
, *start
;
1539 readline_set_completion_index(rs
, len
);
1541 start
= list
= qmp_query_chardev_backends(NULL
);
1543 const char *chr_name
= list
->value
->name
;
1545 if (!strncmp(chr_name
, str
, len
)) {
1546 readline_add_completion(rs
, chr_name
);
1550 qapi_free_ChardevBackendInfoList(start
);
1553 void netdev_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1562 readline_set_completion_index(rs
, len
);
1563 for (i
= 0; i
< NET_CLIENT_DRIVER__MAX
; i
++) {
1564 add_completion_option(rs
, str
, NetClientDriver_str(i
));
1568 void device_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1578 readline_set_completion_index(rs
, len
);
1579 list
= elt
= object_class_get_list(TYPE_DEVICE
, false);
1582 DeviceClass
*dc
= OBJECT_CLASS_CHECK(DeviceClass
, elt
->data
,
1584 name
= object_class_get_name(OBJECT_CLASS(dc
));
1586 if (dc
->user_creatable
1587 && !strncmp(name
, str
, len
)) {
1588 readline_add_completion(rs
, name
);
1595 void object_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1605 readline_set_completion_index(rs
, len
);
1606 list
= elt
= object_class_get_list(TYPE_USER_CREATABLE
, false);
1610 name
= object_class_get_name(OBJECT_CLASS(elt
->data
));
1611 if (!strncmp(name
, str
, len
) && strcmp(name
, TYPE_USER_CREATABLE
)) {
1612 readline_add_completion(rs
, name
);
1619 static int qdev_add_hotpluggable_device(Object
*obj
, void *opaque
)
1621 GSList
**list
= opaque
;
1622 DeviceState
*dev
= (DeviceState
*)object_dynamic_cast(obj
, TYPE_DEVICE
);
1628 if (dev
->realized
&& object_property_get_bool(obj
, "hotpluggable", NULL
)) {
1629 *list
= g_slist_append(*list
, dev
);
1635 static GSList
*qdev_build_hotpluggable_device_list(Object
*peripheral
)
1637 GSList
*list
= NULL
;
1639 object_child_foreach(peripheral
, qdev_add_hotpluggable_device
, &list
);
1644 static void peripheral_device_del_completion(ReadLineState
*rs
,
1645 const char *str
, size_t len
)
1647 Object
*peripheral
= container_get(qdev_get_machine(), "/peripheral");
1648 GSList
*list
, *item
;
1650 list
= qdev_build_hotpluggable_device_list(peripheral
);
1655 for (item
= list
; item
; item
= g_slist_next(item
)) {
1656 DeviceState
*dev
= item
->data
;
1658 if (dev
->id
&& !strncmp(str
, dev
->id
, len
)) {
1659 readline_add_completion(rs
, dev
->id
);
1666 void chardev_remove_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1669 ChardevInfoList
*list
, *start
;
1675 readline_set_completion_index(rs
, len
);
1677 start
= list
= qmp_query_chardev(NULL
);
1679 ChardevInfo
*chr
= list
->value
;
1681 if (!strncmp(chr
->label
, str
, len
)) {
1682 readline_add_completion(rs
, chr
->label
);
1686 qapi_free_ChardevInfoList(start
);
1689 static void ringbuf_completion(ReadLineState
*rs
, const char *str
)
1692 ChardevInfoList
*list
, *start
;
1695 readline_set_completion_index(rs
, len
);
1697 start
= list
= qmp_query_chardev(NULL
);
1699 ChardevInfo
*chr_info
= list
->value
;
1701 if (!strncmp(chr_info
->label
, str
, len
)) {
1702 Chardev
*chr
= qemu_chr_find(chr_info
->label
);
1703 if (chr
&& CHARDEV_IS_RINGBUF(chr
)) {
1704 readline_add_completion(rs
, chr_info
->label
);
1709 qapi_free_ChardevInfoList(start
);
1712 void ringbuf_write_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1717 ringbuf_completion(rs
, str
);
1720 void device_del_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1729 readline_set_completion_index(rs
, len
);
1730 peripheral_device_del_completion(rs
, str
, len
);
1733 void object_del_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1735 ObjectPropertyInfoList
*list
, *start
;
1742 readline_set_completion_index(rs
, len
);
1744 start
= list
= qmp_qom_list("/objects", NULL
);
1746 ObjectPropertyInfo
*info
= list
->value
;
1748 if (!strncmp(info
->type
, "child<", 5)
1749 && !strncmp(info
->name
, str
, len
)) {
1750 readline_add_completion(rs
, info
->name
);
1754 qapi_free_ObjectPropertyInfoList(start
);
1757 void sendkey_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1766 sep
= strrchr(str
, '-');
1771 readline_set_completion_index(rs
, len
);
1772 for (i
= 0; i
< Q_KEY_CODE__MAX
; i
++) {
1773 if (!strncmp(str
, QKeyCode_str(i
), len
)) {
1774 readline_add_completion(rs
, QKeyCode_str(i
));
1779 void set_link_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1784 readline_set_completion_index(rs
, len
);
1786 NetClientState
*ncs
[MAX_QUEUE_NUM
];
1788 count
= qemu_find_net_clients_except(NULL
, ncs
,
1789 NET_CLIENT_DRIVER_NONE
,
1791 for (i
= 0; i
< MIN(count
, MAX_QUEUE_NUM
); i
++) {
1792 const char *name
= ncs
[i
]->name
;
1793 if (!strncmp(str
, name
, len
)) {
1794 readline_add_completion(rs
, name
);
1797 } else if (nb_args
== 3) {
1798 add_completion_option(rs
, str
, "on");
1799 add_completion_option(rs
, str
, "off");
1803 void netdev_del_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1806 NetClientState
*ncs
[MAX_QUEUE_NUM
];
1813 readline_set_completion_index(rs
, len
);
1814 count
= qemu_find_net_clients_except(NULL
, ncs
, NET_CLIENT_DRIVER_NIC
,
1816 for (i
= 0; i
< MIN(count
, MAX_QUEUE_NUM
); i
++) {
1817 const char *name
= ncs
[i
]->name
;
1818 if (strncmp(str
, name
, len
)) {
1821 if (ncs
[i
]->is_netdev
) {
1822 readline_add_completion(rs
, name
);
1827 void info_trace_events_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1832 readline_set_completion_index(rs
, len
);
1834 TraceEventIter iter
;
1836 char *pattern
= g_strdup_printf("%s*", str
);
1837 trace_event_iter_init(&iter
, pattern
);
1838 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
1839 readline_add_completion(rs
, trace_event_get_name(ev
));
1845 void trace_event_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1850 readline_set_completion_index(rs
, len
);
1852 TraceEventIter iter
;
1854 char *pattern
= g_strdup_printf("%s*", str
);
1855 trace_event_iter_init(&iter
, pattern
);
1856 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
1857 readline_add_completion(rs
, trace_event_get_name(ev
));
1860 } else if (nb_args
== 3) {
1861 add_completion_option(rs
, str
, "on");
1862 add_completion_option(rs
, str
, "off");
1866 void watchdog_action_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1873 readline_set_completion_index(rs
, strlen(str
));
1874 for (i
= 0; i
< WATCHDOG_ACTION__MAX
; i
++) {
1875 add_completion_option(rs
, str
, WatchdogAction_str(i
));
1879 void migrate_set_capability_completion(ReadLineState
*rs
, int nb_args
,
1885 readline_set_completion_index(rs
, len
);
1888 for (i
= 0; i
< MIGRATION_CAPABILITY__MAX
; i
++) {
1889 const char *name
= MigrationCapability_str(i
);
1890 if (!strncmp(str
, name
, len
)) {
1891 readline_add_completion(rs
, name
);
1894 } else if (nb_args
== 3) {
1895 add_completion_option(rs
, str
, "on");
1896 add_completion_option(rs
, str
, "off");
1900 void migrate_set_parameter_completion(ReadLineState
*rs
, int nb_args
,
1906 readline_set_completion_index(rs
, len
);
1909 for (i
= 0; i
< MIGRATION_PARAMETER__MAX
; i
++) {
1910 const char *name
= MigrationParameter_str(i
);
1911 if (!strncmp(str
, name
, len
)) {
1912 readline_add_completion(rs
, name
);
1918 static void vm_completion(ReadLineState
*rs
, const char *str
)
1921 BlockDriverState
*bs
;
1922 BdrvNextIterator it
;
1925 readline_set_completion_index(rs
, len
);
1927 for (bs
= bdrv_first(&it
); bs
; bs
= bdrv_next(&it
)) {
1928 SnapshotInfoList
*snapshots
, *snapshot
;
1929 AioContext
*ctx
= bdrv_get_aio_context(bs
);
1932 aio_context_acquire(ctx
);
1933 if (bdrv_can_snapshot(bs
)) {
1934 ok
= bdrv_query_snapshot_info_list(bs
, &snapshots
, NULL
) == 0;
1936 aio_context_release(ctx
);
1941 snapshot
= snapshots
;
1943 char *completion
= snapshot
->value
->name
;
1944 if (!strncmp(str
, completion
, len
)) {
1945 readline_add_completion(rs
, completion
);
1947 completion
= snapshot
->value
->id
;
1948 if (!strncmp(str
, completion
, len
)) {
1949 readline_add_completion(rs
, completion
);
1951 snapshot
= snapshot
->next
;
1953 qapi_free_SnapshotInfoList(snapshots
);
1958 void delvm_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1961 vm_completion(rs
, str
);
1965 void loadvm_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1968 vm_completion(rs
, str
);
1973 compare_mon_cmd(const void *a
, const void *b
)
1975 return strcmp(((const HMPCommand
*)a
)->name
,
1976 ((const HMPCommand
*)b
)->name
);
1979 static void sortcmdlist(void)
1981 qsort(hmp_cmds
, ARRAY_SIZE(hmp_cmds
) - 1,
1984 qsort(hmp_info_cmds
, ARRAY_SIZE(hmp_info_cmds
) - 1,
1985 sizeof(*hmp_info_cmds
),
1989 void monitor_init_globals(void)
1991 monitor_init_globals_core();
1992 monitor_init_qmp_commands();
1994 qemu_mutex_init(&mon_fdsets_lock
);