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
,
239 QTAILQ_INIT(&qmp_cap_negotiation_commands
);
240 qmp_register_command(&qmp_cap_negotiation_commands
, "qmp_capabilities",
241 qmp_marshal_qmp_capabilities
, QCO_ALLOW_PRECONFIG
);
244 /* Set the current CPU defined by the user. Callers must hold BQL. */
245 int monitor_set_cpu(Monitor
*mon
, int cpu_index
)
249 cpu
= qemu_get_cpu(cpu_index
);
253 g_free(mon
->mon_cpu_path
);
254 mon
->mon_cpu_path
= object_get_canonical_path(OBJECT(cpu
));
258 /* Callers must hold BQL. */
259 static CPUState
*mon_get_cpu_sync(Monitor
*mon
, bool synchronize
)
261 CPUState
*cpu
= NULL
;
263 if (mon
->mon_cpu_path
) {
264 cpu
= (CPUState
*) object_resolve_path_type(mon
->mon_cpu_path
,
267 g_free(mon
->mon_cpu_path
);
268 mon
->mon_cpu_path
= NULL
;
271 if (!mon
->mon_cpu_path
) {
275 monitor_set_cpu(mon
, first_cpu
->cpu_index
);
280 cpu_synchronize_state(cpu
);
285 CPUState
*mon_get_cpu(Monitor
*mon
)
287 return mon_get_cpu_sync(mon
, true);
290 CPUArchState
*mon_get_cpu_env(Monitor
*mon
)
292 CPUState
*cs
= mon_get_cpu(mon
);
294 return cs
? cs
->env_ptr
: NULL
;
297 int monitor_get_cpu_index(Monitor
*mon
)
299 CPUState
*cs
= mon_get_cpu_sync(mon
, false);
301 return cs
? cs
->cpu_index
: UNASSIGNED_CPU_INDEX
;
304 static void hmp_info_registers(Monitor
*mon
, const QDict
*qdict
)
306 bool all_cpus
= qdict_get_try_bool(qdict
, "cpustate_all", false);
311 monitor_printf(mon
, "\nCPU#%d\n", cs
->cpu_index
);
312 cpu_dump_state(cs
, NULL
, CPU_DUMP_FPU
);
315 cs
= mon_get_cpu(mon
);
318 monitor_printf(mon
, "No CPU available\n");
322 cpu_dump_state(cs
, NULL
, CPU_DUMP_FPU
);
327 static void hmp_info_jit(Monitor
*mon
, const QDict
*qdict
)
329 if (!tcg_enabled()) {
330 error_report("JIT information is only available with accel=tcg");
338 static void hmp_info_opcount(Monitor
*mon
, const QDict
*qdict
)
344 static void hmp_info_sync_profile(Monitor
*mon
, const QDict
*qdict
)
346 int64_t max
= qdict_get_try_int(qdict
, "max", 10);
347 bool mean
= qdict_get_try_bool(qdict
, "mean", false);
348 bool coalesce
= !qdict_get_try_bool(qdict
, "no_coalesce", false);
349 enum QSPSortBy sort_by
;
351 sort_by
= mean
? QSP_SORT_BY_AVG_WAIT_TIME
: QSP_SORT_BY_TOTAL_WAIT_TIME
;
352 qsp_report(max
, sort_by
, coalesce
);
355 static void hmp_info_history(Monitor
*mon
, const QDict
*qdict
)
357 MonitorHMP
*hmp_mon
= container_of(mon
, MonitorHMP
, common
);
366 str
= readline_get_history(hmp_mon
->rs
, i
);
370 monitor_printf(mon
, "%d: '%s'\n", i
, str
);
375 static void hmp_info_cpustats(Monitor
*mon
, const QDict
*qdict
)
377 CPUState
*cs
= mon_get_cpu(mon
);
380 monitor_printf(mon
, "No CPU available\n");
383 cpu_dump_statistics(cs
, 0);
386 static void hmp_info_trace_events(Monitor
*mon
, const QDict
*qdict
)
388 const char *name
= qdict_get_try_str(qdict
, "name");
389 bool has_vcpu
= qdict_haskey(qdict
, "vcpu");
390 int vcpu
= qdict_get_try_int(qdict
, "vcpu", 0);
391 TraceEventInfoList
*events
;
392 TraceEventInfoList
*elem
;
393 Error
*local_err
= NULL
;
399 monitor_printf(mon
, "argument vcpu must be positive");
403 events
= qmp_trace_event_get_state(name
, has_vcpu
, vcpu
, &local_err
);
405 error_report_err(local_err
);
409 for (elem
= events
; elem
!= NULL
; elem
= elem
->next
) {
410 monitor_printf(mon
, "%s : state %u\n",
412 elem
->value
->state
== TRACE_EVENT_STATE_ENABLED
? 1 : 0);
414 qapi_free_TraceEventInfoList(events
);
417 void qmp_client_migrate_info(const char *protocol
, const char *hostname
,
418 bool has_port
, int64_t port
,
419 bool has_tls_port
, int64_t tls_port
,
420 bool has_cert_subject
, const char *cert_subject
,
423 if (strcmp(protocol
, "spice") == 0) {
424 if (!qemu_using_spice(errp
)) {
428 if (!has_port
&& !has_tls_port
) {
429 error_setg(errp
, QERR_MISSING_PARAMETER
, "port/tls-port");
433 if (qemu_spice
.migrate_info(hostname
,
434 has_port
? port
: -1,
435 has_tls_port
? tls_port
: -1,
437 error_setg(errp
, "Could not set up display for migration");
443 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "protocol", "'spice'");
446 static void hmp_logfile(Monitor
*mon
, const QDict
*qdict
)
450 qemu_set_log_filename(qdict_get_str(qdict
, "filename"), &err
);
452 error_report_err(err
);
456 static void hmp_log(Monitor
*mon
, const QDict
*qdict
)
459 const char *items
= qdict_get_str(qdict
, "items");
461 if (!strcmp(items
, "none")) {
464 mask
= qemu_str_to_log_mask(items
);
466 help_cmd(mon
, "log");
473 static void hmp_singlestep(Monitor
*mon
, const QDict
*qdict
)
475 const char *option
= qdict_get_try_str(qdict
, "option");
476 if (!option
|| !strcmp(option
, "on")) {
478 } else if (!strcmp(option
, "off")) {
481 monitor_printf(mon
, "unexpected option %s\n", option
);
485 static void hmp_gdbserver(Monitor
*mon
, const QDict
*qdict
)
487 const char *device
= qdict_get_try_str(qdict
, "device");
489 device
= "tcp::" DEFAULT_GDBSTUB_PORT
;
492 if (gdbserver_start(device
) < 0) {
493 monitor_printf(mon
, "Could not open gdbserver on device '%s'\n",
495 } else if (strcmp(device
, "none") == 0) {
496 monitor_printf(mon
, "Disabled gdbserver\n");
498 monitor_printf(mon
, "Waiting for gdb connection on device '%s'\n",
503 static void hmp_watchdog_action(Monitor
*mon
, const QDict
*qdict
)
505 const char *action
= qdict_get_str(qdict
, "action");
506 if (select_watchdog_action(action
) == -1) {
507 monitor_printf(mon
, "Unknown watchdog action '%s'\n", action
);
511 static void monitor_printc(Monitor
*mon
, int c
)
513 monitor_printf(mon
, "'");
516 monitor_printf(mon
, "\\'");
519 monitor_printf(mon
, "\\\\");
522 monitor_printf(mon
, "\\n");
525 monitor_printf(mon
, "\\r");
528 if (c
>= 32 && c
<= 126) {
529 monitor_printf(mon
, "%c", c
);
531 monitor_printf(mon
, "\\x%02x", c
);
535 monitor_printf(mon
, "'");
538 static void memory_dump(Monitor
*mon
, int count
, int format
, int wsize
,
539 hwaddr addr
, int is_physical
)
541 int l
, line_size
, i
, max_digits
, len
;
544 CPUState
*cs
= mon_get_cpu(mon
);
546 if (!cs
&& (format
== 'i' || !is_physical
)) {
547 monitor_printf(mon
, "Can not dump without CPU\n");
552 monitor_disas(mon
, cs
, addr
, count
, is_physical
);
566 max_digits
= DIV_ROUND_UP(wsize
* 8, 3);
570 max_digits
= (wsize
* 8) / 4;
574 max_digits
= DIV_ROUND_UP(wsize
* 8 * 10, 33);
583 monitor_printf(mon
, TARGET_FMT_plx
":", addr
);
585 monitor_printf(mon
, TARGET_FMT_lx
":", (target_ulong
)addr
);
591 AddressSpace
*as
= cs
? cs
->as
: &address_space_memory
;
592 MemTxResult r
= address_space_read(as
, addr
,
593 MEMTXATTRS_UNSPECIFIED
, buf
, l
);
595 monitor_printf(mon
, " Cannot access memory\n");
599 if (cpu_memory_rw_debug(cs
, addr
, buf
, l
, 0) < 0) {
600 monitor_printf(mon
, " Cannot access memory\n");
615 v
= (uint32_t)ldl_p(buf
+ i
);
621 monitor_printf(mon
, " ");
624 monitor_printf(mon
, "%#*" PRIo64
, max_digits
, v
);
627 monitor_printf(mon
, "0x%0*" PRIx64
, max_digits
, v
);
630 monitor_printf(mon
, "%*" PRIu64
, max_digits
, v
);
633 monitor_printf(mon
, "%*" PRId64
, max_digits
, v
);
636 monitor_printc(mon
, v
);
641 monitor_printf(mon
, "\n");
647 static void hmp_memory_dump(Monitor
*mon
, const QDict
*qdict
)
649 int count
= qdict_get_int(qdict
, "count");
650 int format
= qdict_get_int(qdict
, "format");
651 int size
= qdict_get_int(qdict
, "size");
652 target_long addr
= qdict_get_int(qdict
, "addr");
654 memory_dump(mon
, count
, format
, size
, addr
, 0);
657 static void hmp_physical_memory_dump(Monitor
*mon
, const QDict
*qdict
)
659 int count
= qdict_get_int(qdict
, "count");
660 int format
= qdict_get_int(qdict
, "format");
661 int size
= qdict_get_int(qdict
, "size");
662 hwaddr addr
= qdict_get_int(qdict
, "addr");
664 memory_dump(mon
, count
, format
, size
, addr
, 1);
667 void *gpa2hva(MemoryRegion
**p_mr
, hwaddr addr
, uint64_t size
, Error
**errp
)
669 Int128 gpa_region_size
;
670 MemoryRegionSection mrs
= memory_region_find(get_system_memory(),
674 error_setg(errp
, "No memory is mapped at address 0x%" HWADDR_PRIx
, addr
);
678 if (!memory_region_is_ram(mrs
.mr
) && !memory_region_is_romd(mrs
.mr
)) {
679 error_setg(errp
, "Memory at address 0x%" HWADDR_PRIx
"is not RAM", addr
);
680 memory_region_unref(mrs
.mr
);
684 gpa_region_size
= int128_make64(size
);
685 if (int128_lt(mrs
.size
, gpa_region_size
)) {
686 error_setg(errp
, "Size of memory region at 0x%" HWADDR_PRIx
688 memory_region_unref(mrs
.mr
);
693 return qemu_map_ram_ptr(mrs
.mr
->ram_block
, mrs
.offset_within_region
);
696 static void hmp_gpa2hva(Monitor
*mon
, const QDict
*qdict
)
698 hwaddr addr
= qdict_get_int(qdict
, "addr");
699 Error
*local_err
= NULL
;
700 MemoryRegion
*mr
= NULL
;
703 ptr
= gpa2hva(&mr
, addr
, 1, &local_err
);
705 error_report_err(local_err
);
709 monitor_printf(mon
, "Host virtual address for 0x%" HWADDR_PRIx
711 addr
, mr
->name
, ptr
);
713 memory_region_unref(mr
);
716 static void hmp_gva2gpa(Monitor
*mon
, const QDict
*qdict
)
718 target_ulong addr
= qdict_get_int(qdict
, "addr");
720 CPUState
*cs
= mon_get_cpu(mon
);
724 monitor_printf(mon
, "No cpu\n");
728 gpa
= cpu_get_phys_page_attrs_debug(cs
, addr
& TARGET_PAGE_MASK
, &attrs
);
730 monitor_printf(mon
, "Unmapped\n");
732 monitor_printf(mon
, "gpa: %#" HWADDR_PRIx
"\n",
733 gpa
+ (addr
& ~TARGET_PAGE_MASK
));
738 static uint64_t vtop(void *ptr
, Error
**errp
)
742 uintptr_t addr
= (uintptr_t) ptr
;
743 uintptr_t pagesize
= qemu_real_host_page_size
;
744 off_t offset
= addr
/ pagesize
* sizeof(pinfo
);
747 fd
= open("/proc/self/pagemap", O_RDONLY
);
749 error_setg_errno(errp
, errno
, "Cannot open /proc/self/pagemap");
753 /* Force copy-on-write if necessary. */
754 qatomic_add((uint8_t *)ptr
, 0);
756 if (pread(fd
, &pinfo
, sizeof(pinfo
), offset
) != sizeof(pinfo
)) {
757 error_setg_errno(errp
, errno
, "Cannot read pagemap");
760 if ((pinfo
& (1ull << 63)) == 0) {
761 error_setg(errp
, "Page not present");
764 ret
= ((pinfo
& 0x007fffffffffffffull
) * pagesize
) | (addr
& (pagesize
- 1));
771 static void hmp_gpa2hpa(Monitor
*mon
, const QDict
*qdict
)
773 hwaddr addr
= qdict_get_int(qdict
, "addr");
774 Error
*local_err
= NULL
;
775 MemoryRegion
*mr
= NULL
;
779 ptr
= gpa2hva(&mr
, addr
, 1, &local_err
);
781 error_report_err(local_err
);
785 physaddr
= vtop(ptr
, &local_err
);
787 error_report_err(local_err
);
789 monitor_printf(mon
, "Host physical address for 0x%" HWADDR_PRIx
790 " (%s) is 0x%" PRIx64
"\n",
791 addr
, mr
->name
, (uint64_t) physaddr
);
794 memory_region_unref(mr
);
798 static void do_print(Monitor
*mon
, const QDict
*qdict
)
800 int format
= qdict_get_int(qdict
, "format");
801 hwaddr val
= qdict_get_int(qdict
, "val");
805 monitor_printf(mon
, "%#" HWADDR_PRIo
, val
);
808 monitor_printf(mon
, "%#" HWADDR_PRIx
, val
);
811 monitor_printf(mon
, "%" HWADDR_PRIu
, val
);
815 monitor_printf(mon
, "%" HWADDR_PRId
, val
);
818 monitor_printc(mon
, val
);
821 monitor_printf(mon
, "\n");
824 static void hmp_sum(Monitor
*mon
, const QDict
*qdict
)
828 uint32_t start
= qdict_get_int(qdict
, "start");
829 uint32_t size
= qdict_get_int(qdict
, "size");
832 for(addr
= start
; addr
< (start
+ size
); addr
++) {
833 uint8_t val
= address_space_ldub(&address_space_memory
, addr
,
834 MEMTXATTRS_UNSPECIFIED
, NULL
);
835 /* BSD sum algorithm ('sum' Unix command) */
836 sum
= (sum
>> 1) | (sum
<< 15);
839 monitor_printf(mon
, "%05d\n", sum
);
842 static int mouse_button_state
;
844 static void hmp_mouse_move(Monitor
*mon
, const QDict
*qdict
)
846 int dx
, dy
, dz
, button
;
847 const char *dx_str
= qdict_get_str(qdict
, "dx_str");
848 const char *dy_str
= qdict_get_str(qdict
, "dy_str");
849 const char *dz_str
= qdict_get_try_str(qdict
, "dz_str");
851 dx
= strtol(dx_str
, NULL
, 0);
852 dy
= strtol(dy_str
, NULL
, 0);
853 qemu_input_queue_rel(NULL
, INPUT_AXIS_X
, dx
);
854 qemu_input_queue_rel(NULL
, INPUT_AXIS_Y
, dy
);
857 dz
= strtol(dz_str
, NULL
, 0);
859 button
= (dz
> 0) ? INPUT_BUTTON_WHEEL_UP
: INPUT_BUTTON_WHEEL_DOWN
;
860 qemu_input_queue_btn(NULL
, button
, true);
861 qemu_input_event_sync();
862 qemu_input_queue_btn(NULL
, button
, false);
865 qemu_input_event_sync();
868 static void hmp_mouse_button(Monitor
*mon
, const QDict
*qdict
)
870 static uint32_t bmap
[INPUT_BUTTON__MAX
] = {
871 [INPUT_BUTTON_LEFT
] = MOUSE_EVENT_LBUTTON
,
872 [INPUT_BUTTON_MIDDLE
] = MOUSE_EVENT_MBUTTON
,
873 [INPUT_BUTTON_RIGHT
] = MOUSE_EVENT_RBUTTON
,
875 int button_state
= qdict_get_int(qdict
, "button_state");
877 if (mouse_button_state
== button_state
) {
880 qemu_input_update_buttons(NULL
, bmap
, mouse_button_state
, button_state
);
881 qemu_input_event_sync();
882 mouse_button_state
= button_state
;
885 static void hmp_ioport_read(Monitor
*mon
, const QDict
*qdict
)
887 int size
= qdict_get_int(qdict
, "size");
888 int addr
= qdict_get_int(qdict
, "addr");
889 int has_index
= qdict_haskey(qdict
, "index");
894 int index
= qdict_get_int(qdict
, "index");
895 cpu_outb(addr
& IOPORTS_MASK
, index
& 0xff);
915 monitor_printf(mon
, "port%c[0x%04x] = 0x%0*x\n",
916 suffix
, addr
, size
* 2, val
);
919 static void hmp_ioport_write(Monitor
*mon
, const QDict
*qdict
)
921 int size
= qdict_get_int(qdict
, "size");
922 int addr
= qdict_get_int(qdict
, "addr");
923 int val
= qdict_get_int(qdict
, "val");
925 addr
&= IOPORTS_MASK
;
941 static void hmp_boot_set(Monitor
*mon
, const QDict
*qdict
)
943 Error
*local_err
= NULL
;
944 const char *bootdevice
= qdict_get_str(qdict
, "bootdevice");
946 qemu_boot_set(bootdevice
, &local_err
);
948 error_report_err(local_err
);
950 monitor_printf(mon
, "boot device list now set to %s\n", bootdevice
);
954 static void hmp_info_mtree(Monitor
*mon
, const QDict
*qdict
)
956 bool flatview
= qdict_get_try_bool(qdict
, "flatview", false);
957 bool dispatch_tree
= qdict_get_try_bool(qdict
, "dispatch_tree", false);
958 bool owner
= qdict_get_try_bool(qdict
, "owner", false);
959 bool disabled
= qdict_get_try_bool(qdict
, "disabled", false);
961 mtree_info(flatview
, dispatch_tree
, owner
, disabled
);
964 #ifdef CONFIG_PROFILER
968 static void hmp_info_profile(Monitor
*mon
, const QDict
*qdict
)
970 static int64_t last_cpu_exec_time
;
971 int64_t cpu_exec_time
;
974 cpu_exec_time
= tcg_cpu_exec_time();
975 delta
= cpu_exec_time
- last_cpu_exec_time
;
977 monitor_printf(mon
, "async time %" PRId64
" (%0.3f)\n",
978 dev_time
, dev_time
/ (double)NANOSECONDS_PER_SECOND
);
979 monitor_printf(mon
, "qemu time %" PRId64
" (%0.3f)\n",
980 delta
, delta
/ (double)NANOSECONDS_PER_SECOND
);
981 last_cpu_exec_time
= cpu_exec_time
;
985 static void hmp_info_profile(Monitor
*mon
, const QDict
*qdict
)
987 monitor_printf(mon
, "Internal profiler not compiled\n");
991 /* Capture support */
992 static QLIST_HEAD (capture_list_head
, CaptureState
) capture_head
;
994 static void hmp_info_capture(Monitor
*mon
, const QDict
*qdict
)
999 for (s
= capture_head
.lh_first
, i
= 0; s
; s
= s
->entries
.le_next
, ++i
) {
1000 monitor_printf(mon
, "[%d]: ", i
);
1001 s
->ops
.info (s
->opaque
);
1005 static void hmp_stopcapture(Monitor
*mon
, const QDict
*qdict
)
1008 int n
= qdict_get_int(qdict
, "n");
1011 for (s
= capture_head
.lh_first
, i
= 0; s
; s
= s
->entries
.le_next
, ++i
) {
1013 s
->ops
.destroy (s
->opaque
);
1014 QLIST_REMOVE (s
, entries
);
1021 static void hmp_wavcapture(Monitor
*mon
, const QDict
*qdict
)
1023 const char *path
= qdict_get_str(qdict
, "path");
1024 int freq
= qdict_get_try_int(qdict
, "freq", 44100);
1025 int bits
= qdict_get_try_int(qdict
, "bits", 16);
1026 int nchannels
= qdict_get_try_int(qdict
, "nchannels", 2);
1027 const char *audiodev
= qdict_get_str(qdict
, "audiodev");
1029 AudioState
*as
= audio_state_by_name(audiodev
);
1032 monitor_printf(mon
, "Audiodev '%s' not found\n", audiodev
);
1036 s
= g_malloc0 (sizeof (*s
));
1038 if (wav_start_capture(as
, s
, path
, freq
, bits
, nchannels
)) {
1039 monitor_printf(mon
, "Failed to add wave capture\n");
1043 QLIST_INSERT_HEAD (&capture_head
, s
, entries
);
1046 void qmp_getfd(const char *fdname
, Error
**errp
)
1048 Monitor
*cur_mon
= monitor_cur();
1052 fd
= qemu_chr_fe_get_msgfd(&cur_mon
->chr
);
1054 error_setg(errp
, "No file descriptor supplied via SCM_RIGHTS");
1058 if (qemu_isdigit(fdname
[0])) {
1060 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "fdname",
1061 "a name not starting with a digit");
1065 QEMU_LOCK_GUARD(&cur_mon
->mon_lock
);
1066 QLIST_FOREACH(monfd
, &cur_mon
->fds
, next
) {
1067 if (strcmp(monfd
->name
, fdname
) != 0) {
1073 /* Make sure close() is outside critical section */
1078 monfd
= g_malloc0(sizeof(mon_fd_t
));
1079 monfd
->name
= g_strdup(fdname
);
1082 QLIST_INSERT_HEAD(&cur_mon
->fds
, monfd
, next
);
1085 void qmp_closefd(const char *fdname
, Error
**errp
)
1087 Monitor
*cur_mon
= monitor_cur();
1091 qemu_mutex_lock(&cur_mon
->mon_lock
);
1092 QLIST_FOREACH(monfd
, &cur_mon
->fds
, next
) {
1093 if (strcmp(monfd
->name
, fdname
) != 0) {
1097 QLIST_REMOVE(monfd
, next
);
1099 g_free(monfd
->name
);
1101 qemu_mutex_unlock(&cur_mon
->mon_lock
);
1102 /* Make sure close() is outside critical section */
1107 qemu_mutex_unlock(&cur_mon
->mon_lock
);
1108 error_setg(errp
, "File descriptor named '%s' not found", fdname
);
1111 int monitor_get_fd(Monitor
*mon
, const char *fdname
, Error
**errp
)
1115 QEMU_LOCK_GUARD(&mon
->mon_lock
);
1116 QLIST_FOREACH(monfd
, &mon
->fds
, next
) {
1119 if (strcmp(monfd
->name
, fdname
) != 0) {
1125 /* caller takes ownership of fd */
1126 QLIST_REMOVE(monfd
, next
);
1127 g_free(monfd
->name
);
1133 error_setg(errp
, "File descriptor named '%s' has not been found", fdname
);
1137 static void monitor_fdset_cleanup(MonFdset
*mon_fdset
)
1139 MonFdsetFd
*mon_fdset_fd
;
1140 MonFdsetFd
*mon_fdset_fd_next
;
1142 QLIST_FOREACH_SAFE(mon_fdset_fd
, &mon_fdset
->fds
, next
, mon_fdset_fd_next
) {
1143 if ((mon_fdset_fd
->removed
||
1144 (QLIST_EMPTY(&mon_fdset
->dup_fds
) && mon_refcount
== 0)) &&
1145 runstate_is_running()) {
1146 close(mon_fdset_fd
->fd
);
1147 g_free(mon_fdset_fd
->opaque
);
1148 QLIST_REMOVE(mon_fdset_fd
, next
);
1149 g_free(mon_fdset_fd
);
1153 if (QLIST_EMPTY(&mon_fdset
->fds
) && QLIST_EMPTY(&mon_fdset
->dup_fds
)) {
1154 QLIST_REMOVE(mon_fdset
, next
);
1159 void monitor_fdsets_cleanup(void)
1161 MonFdset
*mon_fdset
;
1162 MonFdset
*mon_fdset_next
;
1164 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1165 QLIST_FOREACH_SAFE(mon_fdset
, &mon_fdsets
, next
, mon_fdset_next
) {
1166 monitor_fdset_cleanup(mon_fdset
);
1170 AddfdInfo
*qmp_add_fd(bool has_fdset_id
, int64_t fdset_id
, bool has_opaque
,
1171 const char *opaque
, Error
**errp
)
1174 Monitor
*mon
= monitor_cur();
1177 fd
= qemu_chr_fe_get_msgfd(&mon
->chr
);
1179 error_setg(errp
, "No file descriptor supplied via SCM_RIGHTS");
1183 fdinfo
= monitor_fdset_add_fd(fd
, has_fdset_id
, fdset_id
,
1184 has_opaque
, opaque
, errp
);
1196 void qmp_remove_fd(int64_t fdset_id
, bool has_fd
, int64_t fd
, Error
**errp
)
1198 MonFdset
*mon_fdset
;
1199 MonFdsetFd
*mon_fdset_fd
;
1202 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1203 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1204 if (mon_fdset
->id
!= fdset_id
) {
1207 QLIST_FOREACH(mon_fdset_fd
, &mon_fdset
->fds
, next
) {
1209 if (mon_fdset_fd
->fd
!= fd
) {
1212 mon_fdset_fd
->removed
= true;
1215 mon_fdset_fd
->removed
= true;
1218 if (has_fd
&& !mon_fdset_fd
) {
1221 monitor_fdset_cleanup(mon_fdset
);
1227 snprintf(fd_str
, sizeof(fd_str
), "fdset-id:%" PRId64
", fd:%" PRId64
,
1230 snprintf(fd_str
, sizeof(fd_str
), "fdset-id:%" PRId64
, fdset_id
);
1232 error_setg(errp
, "File descriptor named '%s' not found", fd_str
);
1235 FdsetInfoList
*qmp_query_fdsets(Error
**errp
)
1237 MonFdset
*mon_fdset
;
1238 MonFdsetFd
*mon_fdset_fd
;
1239 FdsetInfoList
*fdset_list
= NULL
;
1241 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1242 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1243 FdsetInfo
*fdset_info
= g_malloc0(sizeof(*fdset_info
));
1245 fdset_info
->fdset_id
= mon_fdset
->id
;
1247 QLIST_FOREACH(mon_fdset_fd
, &mon_fdset
->fds
, next
) {
1248 FdsetFdInfo
*fdsetfd_info
;
1250 fdsetfd_info
= g_malloc0(sizeof(*fdsetfd_info
));
1251 fdsetfd_info
->fd
= mon_fdset_fd
->fd
;
1252 if (mon_fdset_fd
->opaque
) {
1253 fdsetfd_info
->has_opaque
= true;
1254 fdsetfd_info
->opaque
= g_strdup(mon_fdset_fd
->opaque
);
1256 fdsetfd_info
->has_opaque
= false;
1259 QAPI_LIST_PREPEND(fdset_info
->fds
, fdsetfd_info
);
1262 QAPI_LIST_PREPEND(fdset_list
, fdset_info
);
1268 AddfdInfo
*monitor_fdset_add_fd(int fd
, bool has_fdset_id
, int64_t fdset_id
,
1269 bool has_opaque
, const char *opaque
,
1272 MonFdset
*mon_fdset
= NULL
;
1273 MonFdsetFd
*mon_fdset_fd
;
1276 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1278 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1279 /* Break if match found or match impossible due to ordering by ID */
1280 if (fdset_id
<= mon_fdset
->id
) {
1281 if (fdset_id
< mon_fdset
->id
) {
1289 if (mon_fdset
== NULL
) {
1290 int64_t fdset_id_prev
= -1;
1291 MonFdset
*mon_fdset_cur
= QLIST_FIRST(&mon_fdsets
);
1295 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "fdset-id",
1296 "a non-negative value");
1299 /* Use specified fdset ID */
1300 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1301 mon_fdset_cur
= mon_fdset
;
1302 if (fdset_id
< mon_fdset_cur
->id
) {
1307 /* Use first available fdset ID */
1308 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1309 mon_fdset_cur
= mon_fdset
;
1310 if (fdset_id_prev
== mon_fdset_cur
->id
- 1) {
1311 fdset_id_prev
= mon_fdset_cur
->id
;
1318 mon_fdset
= g_malloc0(sizeof(*mon_fdset
));
1320 mon_fdset
->id
= fdset_id
;
1322 mon_fdset
->id
= fdset_id_prev
+ 1;
1325 /* The fdset list is ordered by fdset ID */
1326 if (!mon_fdset_cur
) {
1327 QLIST_INSERT_HEAD(&mon_fdsets
, mon_fdset
, next
);
1328 } else if (mon_fdset
->id
< mon_fdset_cur
->id
) {
1329 QLIST_INSERT_BEFORE(mon_fdset_cur
, mon_fdset
, next
);
1331 QLIST_INSERT_AFTER(mon_fdset_cur
, mon_fdset
, next
);
1335 mon_fdset_fd
= g_malloc0(sizeof(*mon_fdset_fd
));
1336 mon_fdset_fd
->fd
= fd
;
1337 mon_fdset_fd
->removed
= false;
1339 mon_fdset_fd
->opaque
= g_strdup(opaque
);
1341 QLIST_INSERT_HEAD(&mon_fdset
->fds
, mon_fdset_fd
, next
);
1343 fdinfo
= g_malloc0(sizeof(*fdinfo
));
1344 fdinfo
->fdset_id
= mon_fdset
->id
;
1345 fdinfo
->fd
= mon_fdset_fd
->fd
;
1350 int monitor_fdset_dup_fd_add(int64_t fdset_id
, int flags
)
1355 MonFdset
*mon_fdset
;
1357 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1358 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1359 MonFdsetFd
*mon_fdset_fd
;
1360 MonFdsetFd
*mon_fdset_fd_dup
;
1365 if (mon_fdset
->id
!= fdset_id
) {
1369 QLIST_FOREACH(mon_fdset_fd
, &mon_fdset
->fds
, next
) {
1370 mon_fd_flags
= fcntl(mon_fdset_fd
->fd
, F_GETFL
);
1371 if (mon_fd_flags
== -1) {
1375 if ((flags
& O_ACCMODE
) == (mon_fd_flags
& O_ACCMODE
)) {
1376 fd
= mon_fdset_fd
->fd
;
1386 dup_fd
= qemu_dup_flags(fd
, flags
);
1391 mon_fdset_fd_dup
= g_malloc0(sizeof(*mon_fdset_fd_dup
));
1392 mon_fdset_fd_dup
->fd
= dup_fd
;
1393 QLIST_INSERT_HEAD(&mon_fdset
->dup_fds
, mon_fdset_fd_dup
, next
);
1402 static int64_t monitor_fdset_dup_fd_find_remove(int dup_fd
, bool remove
)
1404 MonFdset
*mon_fdset
;
1405 MonFdsetFd
*mon_fdset_fd_dup
;
1407 QEMU_LOCK_GUARD(&mon_fdsets_lock
);
1408 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
1409 QLIST_FOREACH(mon_fdset_fd_dup
, &mon_fdset
->dup_fds
, next
) {
1410 if (mon_fdset_fd_dup
->fd
== dup_fd
) {
1412 QLIST_REMOVE(mon_fdset_fd_dup
, next
);
1413 g_free(mon_fdset_fd_dup
);
1414 if (QLIST_EMPTY(&mon_fdset
->dup_fds
)) {
1415 monitor_fdset_cleanup(mon_fdset
);
1419 return mon_fdset
->id
;
1428 int64_t monitor_fdset_dup_fd_find(int dup_fd
)
1430 return monitor_fdset_dup_fd_find_remove(dup_fd
, false);
1433 void monitor_fdset_dup_fd_remove(int dup_fd
)
1435 monitor_fdset_dup_fd_find_remove(dup_fd
, true);
1438 int monitor_fd_param(Monitor
*mon
, const char *fdname
, Error
**errp
)
1441 Error
*local_err
= NULL
;
1443 if (!qemu_isdigit(fdname
[0]) && mon
) {
1444 fd
= monitor_get_fd(mon
, fdname
, &local_err
);
1446 fd
= qemu_parse_fd(fdname
);
1448 error_setg(&local_err
, "Invalid file descriptor number '%s'",
1453 error_propagate(errp
, local_err
);
1462 /* Please update hmp-commands.hx when adding or changing commands */
1463 static HMPCommand hmp_info_cmds
[] = {
1464 #include "hmp-commands-info.h"
1468 /* hmp_cmds and hmp_info_cmds would be sorted at runtime */
1469 HMPCommand hmp_cmds
[] = {
1470 #include "hmp-commands.h"
1475 * Set @pval to the value in the register identified by @name.
1476 * return 0 if OK, -1 if not found
1478 int get_monitor_def(Monitor
*mon
, int64_t *pval
, const char *name
)
1480 const MonitorDef
*md
= target_monitor_defs();
1481 CPUState
*cs
= mon_get_cpu(mon
);
1486 if (cs
== NULL
|| md
== NULL
) {
1490 for(; md
->name
!= NULL
; md
++) {
1491 if (hmp_compare_cmd(name
, md
->name
)) {
1492 if (md
->get_value
) {
1493 *pval
= md
->get_value(mon
, md
, md
->offset
);
1495 CPUArchState
*env
= mon_get_cpu_env(mon
);
1496 ptr
= (uint8_t *)env
+ md
->offset
;
1499 *pval
= *(int32_t *)ptr
;
1502 *pval
= *(target_long
*)ptr
;
1513 ret
= target_get_monitor_def(cs
, name
, &tmp
);
1515 *pval
= (target_long
) tmp
;
1521 static void add_completion_option(ReadLineState
*rs
, const char *str
,
1524 if (!str
|| !option
) {
1527 if (!strncmp(option
, str
, strlen(str
))) {
1528 readline_add_completion(rs
, option
);
1532 void chardev_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1535 ChardevBackendInfoList
*list
, *start
;
1541 readline_set_completion_index(rs
, len
);
1543 start
= list
= qmp_query_chardev_backends(NULL
);
1545 const char *chr_name
= list
->value
->name
;
1547 if (!strncmp(chr_name
, str
, len
)) {
1548 readline_add_completion(rs
, chr_name
);
1552 qapi_free_ChardevBackendInfoList(start
);
1555 void netdev_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1564 readline_set_completion_index(rs
, len
);
1565 for (i
= 0; i
< NET_CLIENT_DRIVER__MAX
; i
++) {
1566 add_completion_option(rs
, str
, NetClientDriver_str(i
));
1570 void device_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1580 readline_set_completion_index(rs
, len
);
1581 list
= elt
= object_class_get_list(TYPE_DEVICE
, false);
1584 DeviceClass
*dc
= OBJECT_CLASS_CHECK(DeviceClass
, elt
->data
,
1586 name
= object_class_get_name(OBJECT_CLASS(dc
));
1588 if (dc
->user_creatable
1589 && !strncmp(name
, str
, len
)) {
1590 readline_add_completion(rs
, name
);
1597 void object_add_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1607 readline_set_completion_index(rs
, len
);
1608 list
= elt
= object_class_get_list(TYPE_USER_CREATABLE
, false);
1612 name
= object_class_get_name(OBJECT_CLASS(elt
->data
));
1613 if (!strncmp(name
, str
, len
) && strcmp(name
, TYPE_USER_CREATABLE
)) {
1614 readline_add_completion(rs
, name
);
1621 static int qdev_add_hotpluggable_device(Object
*obj
, void *opaque
)
1623 GSList
**list
= opaque
;
1624 DeviceState
*dev
= (DeviceState
*)object_dynamic_cast(obj
, TYPE_DEVICE
);
1630 if (dev
->realized
&& object_property_get_bool(obj
, "hotpluggable", NULL
)) {
1631 *list
= g_slist_append(*list
, dev
);
1637 static GSList
*qdev_build_hotpluggable_device_list(Object
*peripheral
)
1639 GSList
*list
= NULL
;
1641 object_child_foreach(peripheral
, qdev_add_hotpluggable_device
, &list
);
1646 static void peripheral_device_del_completion(ReadLineState
*rs
,
1647 const char *str
, size_t len
)
1649 Object
*peripheral
= container_get(qdev_get_machine(), "/peripheral");
1650 GSList
*list
, *item
;
1652 list
= qdev_build_hotpluggable_device_list(peripheral
);
1657 for (item
= list
; item
; item
= g_slist_next(item
)) {
1658 DeviceState
*dev
= item
->data
;
1660 if (dev
->id
&& !strncmp(str
, dev
->id
, len
)) {
1661 readline_add_completion(rs
, dev
->id
);
1668 void chardev_remove_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1671 ChardevInfoList
*list
, *start
;
1677 readline_set_completion_index(rs
, len
);
1679 start
= list
= qmp_query_chardev(NULL
);
1681 ChardevInfo
*chr
= list
->value
;
1683 if (!strncmp(chr
->label
, str
, len
)) {
1684 readline_add_completion(rs
, chr
->label
);
1688 qapi_free_ChardevInfoList(start
);
1691 static void ringbuf_completion(ReadLineState
*rs
, const char *str
)
1694 ChardevInfoList
*list
, *start
;
1697 readline_set_completion_index(rs
, len
);
1699 start
= list
= qmp_query_chardev(NULL
);
1701 ChardevInfo
*chr_info
= list
->value
;
1703 if (!strncmp(chr_info
->label
, str
, len
)) {
1704 Chardev
*chr
= qemu_chr_find(chr_info
->label
);
1705 if (chr
&& CHARDEV_IS_RINGBUF(chr
)) {
1706 readline_add_completion(rs
, chr_info
->label
);
1711 qapi_free_ChardevInfoList(start
);
1714 void ringbuf_write_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1719 ringbuf_completion(rs
, str
);
1722 void device_del_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1731 readline_set_completion_index(rs
, len
);
1732 peripheral_device_del_completion(rs
, str
, len
);
1735 void object_del_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1737 ObjectPropertyInfoList
*list
, *start
;
1744 readline_set_completion_index(rs
, len
);
1746 start
= list
= qmp_qom_list("/objects", NULL
);
1748 ObjectPropertyInfo
*info
= list
->value
;
1750 if (!strncmp(info
->type
, "child<", 5)
1751 && !strncmp(info
->name
, str
, len
)) {
1752 readline_add_completion(rs
, info
->name
);
1756 qapi_free_ObjectPropertyInfoList(start
);
1759 void sendkey_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1768 sep
= strrchr(str
, '-');
1773 readline_set_completion_index(rs
, len
);
1774 for (i
= 0; i
< Q_KEY_CODE__MAX
; i
++) {
1775 if (!strncmp(str
, QKeyCode_str(i
), len
)) {
1776 readline_add_completion(rs
, QKeyCode_str(i
));
1781 void set_link_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1786 readline_set_completion_index(rs
, len
);
1788 NetClientState
*ncs
[MAX_QUEUE_NUM
];
1790 count
= qemu_find_net_clients_except(NULL
, ncs
,
1791 NET_CLIENT_DRIVER_NONE
,
1793 for (i
= 0; i
< MIN(count
, MAX_QUEUE_NUM
); i
++) {
1794 const char *name
= ncs
[i
]->name
;
1795 if (!strncmp(str
, name
, len
)) {
1796 readline_add_completion(rs
, name
);
1799 } else if (nb_args
== 3) {
1800 add_completion_option(rs
, str
, "on");
1801 add_completion_option(rs
, str
, "off");
1805 void netdev_del_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1808 NetClientState
*ncs
[MAX_QUEUE_NUM
];
1815 readline_set_completion_index(rs
, len
);
1816 count
= qemu_find_net_clients_except(NULL
, ncs
, NET_CLIENT_DRIVER_NIC
,
1818 for (i
= 0; i
< MIN(count
, MAX_QUEUE_NUM
); i
++) {
1819 const char *name
= ncs
[i
]->name
;
1820 if (strncmp(str
, name
, len
)) {
1823 if (ncs
[i
]->is_netdev
) {
1824 readline_add_completion(rs
, name
);
1829 void info_trace_events_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1834 readline_set_completion_index(rs
, len
);
1836 TraceEventIter iter
;
1838 char *pattern
= g_strdup_printf("%s*", str
);
1839 trace_event_iter_init(&iter
, pattern
);
1840 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
1841 readline_add_completion(rs
, trace_event_get_name(ev
));
1847 void trace_event_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1852 readline_set_completion_index(rs
, len
);
1854 TraceEventIter iter
;
1856 char *pattern
= g_strdup_printf("%s*", str
);
1857 trace_event_iter_init(&iter
, pattern
);
1858 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
1859 readline_add_completion(rs
, trace_event_get_name(ev
));
1862 } else if (nb_args
== 3) {
1863 add_completion_option(rs
, str
, "on");
1864 add_completion_option(rs
, str
, "off");
1868 void watchdog_action_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1875 readline_set_completion_index(rs
, strlen(str
));
1876 for (i
= 0; i
< WATCHDOG_ACTION__MAX
; i
++) {
1877 add_completion_option(rs
, str
, WatchdogAction_str(i
));
1881 void migrate_set_capability_completion(ReadLineState
*rs
, int nb_args
,
1887 readline_set_completion_index(rs
, len
);
1890 for (i
= 0; i
< MIGRATION_CAPABILITY__MAX
; i
++) {
1891 const char *name
= MigrationCapability_str(i
);
1892 if (!strncmp(str
, name
, len
)) {
1893 readline_add_completion(rs
, name
);
1896 } else if (nb_args
== 3) {
1897 add_completion_option(rs
, str
, "on");
1898 add_completion_option(rs
, str
, "off");
1902 void migrate_set_parameter_completion(ReadLineState
*rs
, int nb_args
,
1908 readline_set_completion_index(rs
, len
);
1911 for (i
= 0; i
< MIGRATION_PARAMETER__MAX
; i
++) {
1912 const char *name
= MigrationParameter_str(i
);
1913 if (!strncmp(str
, name
, len
)) {
1914 readline_add_completion(rs
, name
);
1920 static void vm_completion(ReadLineState
*rs
, const char *str
)
1923 BlockDriverState
*bs
;
1924 BdrvNextIterator it
;
1927 readline_set_completion_index(rs
, len
);
1929 for (bs
= bdrv_first(&it
); bs
; bs
= bdrv_next(&it
)) {
1930 SnapshotInfoList
*snapshots
, *snapshot
;
1931 AioContext
*ctx
= bdrv_get_aio_context(bs
);
1934 aio_context_acquire(ctx
);
1935 if (bdrv_can_snapshot(bs
)) {
1936 ok
= bdrv_query_snapshot_info_list(bs
, &snapshots
, NULL
) == 0;
1938 aio_context_release(ctx
);
1943 snapshot
= snapshots
;
1945 char *completion
= snapshot
->value
->name
;
1946 if (!strncmp(str
, completion
, len
)) {
1947 readline_add_completion(rs
, completion
);
1949 completion
= snapshot
->value
->id
;
1950 if (!strncmp(str
, completion
, len
)) {
1951 readline_add_completion(rs
, completion
);
1953 snapshot
= snapshot
->next
;
1955 qapi_free_SnapshotInfoList(snapshots
);
1960 void delvm_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1963 vm_completion(rs
, str
);
1967 void loadvm_completion(ReadLineState
*rs
, int nb_args
, const char *str
)
1970 vm_completion(rs
, str
);
1975 compare_mon_cmd(const void *a
, const void *b
)
1977 return strcmp(((const HMPCommand
*)a
)->name
,
1978 ((const HMPCommand
*)b
)->name
);
1981 static void sortcmdlist(void)
1983 qsort(hmp_cmds
, ARRAY_SIZE(hmp_cmds
) - 1,
1986 qsort(hmp_info_cmds
, ARRAY_SIZE(hmp_info_cmds
) - 1,
1987 sizeof(*hmp_info_cmds
),
1991 void monitor_init_globals(void)
1993 monitor_init_globals_core();
1994 monitor_init_qmp_commands();
1996 qemu_mutex_init(&mon_fdsets_lock
);