]> git.proxmox.com Git - mirror_qemu.git/blob - monitor/misc.c
monitor: Use GString instead of QString for output buffer
[mirror_qemu.git] / monitor / misc.c
1 /*
2 * QEMU monitor
3 *
4 * Copyright (c) 2003-2004 Fabrice Bellard
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
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
22 * THE SOFTWARE.
23 */
24
25 #include "qemu/osdep.h"
26 #include "monitor-internal.h"
27 #include "cpu.h"
28 #include "monitor/qdev.h"
29 #include "hw/usb.h"
30 #include "hw/pci/pci.h"
31 #include "sysemu/watchdog.h"
32 #include "hw/loader.h"
33 #include "exec/gdbstub.h"
34 #include "net/net.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"
40 #include "ui/input.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"
62 #endif
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"
80 #include "tcg/tcg.h"
81
82 #if defined(TARGET_S390X)
83 #include "hw/s390x/storage-keys.h"
84 #include "hw/s390x/storage-attributes.h"
85 #endif
86
87 /* file descriptors passed via SCM_RIGHTS */
88 typedef struct mon_fd_t mon_fd_t;
89 struct mon_fd_t {
90 char *name;
91 int fd;
92 QLIST_ENTRY(mon_fd_t) next;
93 };
94
95 /* file descriptor associated with a file descriptor set */
96 typedef struct MonFdsetFd MonFdsetFd;
97 struct MonFdsetFd {
98 int fd;
99 bool removed;
100 char *opaque;
101 QLIST_ENTRY(MonFdsetFd) next;
102 };
103
104 /* file descriptor set containing fds passed via SCM_RIGHTS */
105 typedef struct MonFdset MonFdset;
106 struct MonFdset {
107 int64_t id;
108 QLIST_HEAD(, MonFdsetFd) fds;
109 QLIST_HEAD(, MonFdsetFd) dup_fds;
110 QLIST_ENTRY(MonFdset) next;
111 };
112
113 /* Protects mon_fdsets */
114 static QemuMutex mon_fdsets_lock;
115 static QLIST_HEAD(, MonFdset) mon_fdsets;
116
117 static HMPCommand hmp_info_cmds[];
118
119 char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
120 int64_t cpu_index, Error **errp)
121 {
122 char *output = NULL;
123 MonitorHMP hmp = {};
124
125 monitor_data_init(&hmp.common, false, true, false);
126
127 if (has_cpu_index) {
128 int ret = monitor_set_cpu(&hmp.common, cpu_index);
129 if (ret < 0) {
130 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index",
131 "a CPU number");
132 goto out;
133 }
134 }
135
136 handle_hmp_command(&hmp, command_line);
137
138 WITH_QEMU_LOCK_GUARD(&hmp.common.mon_lock) {
139 output = g_strdup(hmp.common.outbuf->str);
140 }
141
142 out:
143 monitor_data_destroy(&hmp.common);
144 return output;
145 }
146
147 /**
148 * Is @name in the '|' separated list of names @list?
149 */
150 int hmp_compare_cmd(const char *name, const char *list)
151 {
152 const char *p, *pstart;
153 int len;
154 len = strlen(name);
155 p = list;
156 for (;;) {
157 pstart = p;
158 p = qemu_strchrnul(p, '|');
159 if ((p - pstart) == len && !memcmp(pstart, name, len)) {
160 return 1;
161 }
162 if (*p == '\0') {
163 break;
164 }
165 p++;
166 }
167 return 0;
168 }
169
170 static void do_help_cmd(Monitor *mon, const QDict *qdict)
171 {
172 help_cmd(mon, qdict_get_try_str(qdict, "name"));
173 }
174
175 static void hmp_trace_event(Monitor *mon, const QDict *qdict)
176 {
177 const char *tp_name = qdict_get_str(qdict, "name");
178 bool new_state = qdict_get_bool(qdict, "option");
179 bool has_vcpu = qdict_haskey(qdict, "vcpu");
180 int vcpu = qdict_get_try_int(qdict, "vcpu", 0);
181 Error *local_err = NULL;
182
183 if (vcpu < 0) {
184 monitor_printf(mon, "argument vcpu must be positive");
185 return;
186 }
187
188 qmp_trace_event_set_state(tp_name, new_state, true, true, has_vcpu, vcpu, &local_err);
189 if (local_err) {
190 error_report_err(local_err);
191 }
192 }
193
194 #ifdef CONFIG_TRACE_SIMPLE
195 static void hmp_trace_file(Monitor *mon, const QDict *qdict)
196 {
197 const char *op = qdict_get_try_str(qdict, "op");
198 const char *arg = qdict_get_try_str(qdict, "arg");
199
200 if (!op) {
201 st_print_trace_file_status();
202 } else if (!strcmp(op, "on")) {
203 st_set_trace_file_enabled(true);
204 } else if (!strcmp(op, "off")) {
205 st_set_trace_file_enabled(false);
206 } else if (!strcmp(op, "flush")) {
207 st_flush_trace_buffer();
208 } else if (!strcmp(op, "set")) {
209 if (arg) {
210 st_set_trace_file(arg);
211 }
212 } else {
213 monitor_printf(mon, "unexpected argument \"%s\"\n", op);
214 help_cmd(mon, "trace-file");
215 }
216 }
217 #endif
218
219 static void hmp_info_help(Monitor *mon, const QDict *qdict)
220 {
221 help_cmd(mon, "info");
222 }
223
224 static void monitor_init_qmp_commands(void)
225 {
226 /*
227 * Two command lists:
228 * - qmp_commands contains all QMP commands
229 * - qmp_cap_negotiation_commands contains just
230 * "qmp_capabilities", to enforce capability negotiation
231 */
232
233 qmp_init_marshal(&qmp_commands);
234
235 qmp_register_command(&qmp_commands, "query-qmp-schema",
236 qmp_query_qmp_schema, QCO_ALLOW_PRECONFIG);
237 qmp_register_command(&qmp_commands, "device_add", qmp_device_add,
238 QCO_NO_OPTIONS);
239 qmp_register_command(&qmp_commands, "object-add", qmp_object_add,
240 QCO_NO_OPTIONS);
241
242 QTAILQ_INIT(&qmp_cap_negotiation_commands);
243 qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities",
244 qmp_marshal_qmp_capabilities, QCO_ALLOW_PRECONFIG);
245 }
246
247 /* Set the current CPU defined by the user. Callers must hold BQL. */
248 int monitor_set_cpu(Monitor *mon, int cpu_index)
249 {
250 CPUState *cpu;
251
252 cpu = qemu_get_cpu(cpu_index);
253 if (cpu == NULL) {
254 return -1;
255 }
256 g_free(mon->mon_cpu_path);
257 mon->mon_cpu_path = object_get_canonical_path(OBJECT(cpu));
258 return 0;
259 }
260
261 /* Callers must hold BQL. */
262 static CPUState *mon_get_cpu_sync(Monitor *mon, bool synchronize)
263 {
264 CPUState *cpu = NULL;
265
266 if (mon->mon_cpu_path) {
267 cpu = (CPUState *) object_resolve_path_type(mon->mon_cpu_path,
268 TYPE_CPU, NULL);
269 if (!cpu) {
270 g_free(mon->mon_cpu_path);
271 mon->mon_cpu_path = NULL;
272 }
273 }
274 if (!mon->mon_cpu_path) {
275 if (!first_cpu) {
276 return NULL;
277 }
278 monitor_set_cpu(mon, first_cpu->cpu_index);
279 cpu = first_cpu;
280 }
281 assert(cpu != NULL);
282 if (synchronize) {
283 cpu_synchronize_state(cpu);
284 }
285 return cpu;
286 }
287
288 CPUState *mon_get_cpu(Monitor *mon)
289 {
290 return mon_get_cpu_sync(mon, true);
291 }
292
293 CPUArchState *mon_get_cpu_env(Monitor *mon)
294 {
295 CPUState *cs = mon_get_cpu(mon);
296
297 return cs ? cs->env_ptr : NULL;
298 }
299
300 int monitor_get_cpu_index(Monitor *mon)
301 {
302 CPUState *cs = mon_get_cpu_sync(mon, false);
303
304 return cs ? cs->cpu_index : UNASSIGNED_CPU_INDEX;
305 }
306
307 static void hmp_info_registers(Monitor *mon, const QDict *qdict)
308 {
309 bool all_cpus = qdict_get_try_bool(qdict, "cpustate_all", false);
310 CPUState *cs;
311
312 if (all_cpus) {
313 CPU_FOREACH(cs) {
314 monitor_printf(mon, "\nCPU#%d\n", cs->cpu_index);
315 cpu_dump_state(cs, NULL, CPU_DUMP_FPU);
316 }
317 } else {
318 cs = mon_get_cpu(mon);
319
320 if (!cs) {
321 monitor_printf(mon, "No CPU available\n");
322 return;
323 }
324
325 cpu_dump_state(cs, NULL, CPU_DUMP_FPU);
326 }
327 }
328
329 #ifdef CONFIG_TCG
330 static void hmp_info_jit(Monitor *mon, const QDict *qdict)
331 {
332 if (!tcg_enabled()) {
333 error_report("JIT information is only available with accel=tcg");
334 return;
335 }
336
337 dump_exec_info();
338 dump_drift_info();
339 }
340
341 static void hmp_info_opcount(Monitor *mon, const QDict *qdict)
342 {
343 dump_opcount_info();
344 }
345 #endif
346
347 static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
348 {
349 int64_t max = qdict_get_try_int(qdict, "max", 10);
350 bool mean = qdict_get_try_bool(qdict, "mean", false);
351 bool coalesce = !qdict_get_try_bool(qdict, "no_coalesce", false);
352 enum QSPSortBy sort_by;
353
354 sort_by = mean ? QSP_SORT_BY_AVG_WAIT_TIME : QSP_SORT_BY_TOTAL_WAIT_TIME;
355 qsp_report(max, sort_by, coalesce);
356 }
357
358 static void hmp_info_history(Monitor *mon, const QDict *qdict)
359 {
360 MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
361 int i;
362 const char *str;
363
364 if (!hmp_mon->rs) {
365 return;
366 }
367 i = 0;
368 for(;;) {
369 str = readline_get_history(hmp_mon->rs, i);
370 if (!str) {
371 break;
372 }
373 monitor_printf(mon, "%d: '%s'\n", i, str);
374 i++;
375 }
376 }
377
378 static void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
379 {
380 CPUState *cs = mon_get_cpu(mon);
381
382 if (!cs) {
383 monitor_printf(mon, "No CPU available\n");
384 return;
385 }
386 cpu_dump_statistics(cs, 0);
387 }
388
389 static void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
390 {
391 const char *name = qdict_get_try_str(qdict, "name");
392 bool has_vcpu = qdict_haskey(qdict, "vcpu");
393 int vcpu = qdict_get_try_int(qdict, "vcpu", 0);
394 TraceEventInfoList *events;
395 TraceEventInfoList *elem;
396 Error *local_err = NULL;
397
398 if (name == NULL) {
399 name = "*";
400 }
401 if (vcpu < 0) {
402 monitor_printf(mon, "argument vcpu must be positive");
403 return;
404 }
405
406 events = qmp_trace_event_get_state(name, has_vcpu, vcpu, &local_err);
407 if (local_err) {
408 error_report_err(local_err);
409 return;
410 }
411
412 for (elem = events; elem != NULL; elem = elem->next) {
413 monitor_printf(mon, "%s : state %u\n",
414 elem->value->name,
415 elem->value->state == TRACE_EVENT_STATE_ENABLED ? 1 : 0);
416 }
417 qapi_free_TraceEventInfoList(events);
418 }
419
420 void qmp_client_migrate_info(const char *protocol, const char *hostname,
421 bool has_port, int64_t port,
422 bool has_tls_port, int64_t tls_port,
423 bool has_cert_subject, const char *cert_subject,
424 Error **errp)
425 {
426 if (strcmp(protocol, "spice") == 0) {
427 if (!qemu_using_spice(errp)) {
428 return;
429 }
430
431 if (!has_port && !has_tls_port) {
432 error_setg(errp, QERR_MISSING_PARAMETER, "port/tls-port");
433 return;
434 }
435
436 if (qemu_spice.migrate_info(hostname,
437 has_port ? port : -1,
438 has_tls_port ? tls_port : -1,
439 cert_subject)) {
440 error_setg(errp, "Could not set up display for migration");
441 return;
442 }
443 return;
444 }
445
446 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "protocol", "'spice'");
447 }
448
449 static void hmp_logfile(Monitor *mon, const QDict *qdict)
450 {
451 Error *err = NULL;
452
453 qemu_set_log_filename(qdict_get_str(qdict, "filename"), &err);
454 if (err) {
455 error_report_err(err);
456 }
457 }
458
459 static void hmp_log(Monitor *mon, const QDict *qdict)
460 {
461 int mask;
462 const char *items = qdict_get_str(qdict, "items");
463
464 if (!strcmp(items, "none")) {
465 mask = 0;
466 } else {
467 mask = qemu_str_to_log_mask(items);
468 if (!mask) {
469 help_cmd(mon, "log");
470 return;
471 }
472 }
473 qemu_set_log(mask);
474 }
475
476 static void hmp_singlestep(Monitor *mon, const QDict *qdict)
477 {
478 const char *option = qdict_get_try_str(qdict, "option");
479 if (!option || !strcmp(option, "on")) {
480 singlestep = 1;
481 } else if (!strcmp(option, "off")) {
482 singlestep = 0;
483 } else {
484 monitor_printf(mon, "unexpected option %s\n", option);
485 }
486 }
487
488 static void hmp_gdbserver(Monitor *mon, const QDict *qdict)
489 {
490 const char *device = qdict_get_try_str(qdict, "device");
491 if (!device)
492 device = "tcp::" DEFAULT_GDBSTUB_PORT;
493 if (gdbserver_start(device) < 0) {
494 monitor_printf(mon, "Could not open gdbserver on device '%s'\n",
495 device);
496 } else if (strcmp(device, "none") == 0) {
497 monitor_printf(mon, "Disabled gdbserver\n");
498 } else {
499 monitor_printf(mon, "Waiting for gdb connection on device '%s'\n",
500 device);
501 }
502 }
503
504 static void hmp_watchdog_action(Monitor *mon, const QDict *qdict)
505 {
506 const char *action = qdict_get_str(qdict, "action");
507 if (select_watchdog_action(action) == -1) {
508 monitor_printf(mon, "Unknown watchdog action '%s'\n", action);
509 }
510 }
511
512 static void monitor_printc(Monitor *mon, int c)
513 {
514 monitor_printf(mon, "'");
515 switch(c) {
516 case '\'':
517 monitor_printf(mon, "\\'");
518 break;
519 case '\\':
520 monitor_printf(mon, "\\\\");
521 break;
522 case '\n':
523 monitor_printf(mon, "\\n");
524 break;
525 case '\r':
526 monitor_printf(mon, "\\r");
527 break;
528 default:
529 if (c >= 32 && c <= 126) {
530 monitor_printf(mon, "%c", c);
531 } else {
532 monitor_printf(mon, "\\x%02x", c);
533 }
534 break;
535 }
536 monitor_printf(mon, "'");
537 }
538
539 static void memory_dump(Monitor *mon, int count, int format, int wsize,
540 hwaddr addr, int is_physical)
541 {
542 int l, line_size, i, max_digits, len;
543 uint8_t buf[16];
544 uint64_t v;
545 CPUState *cs = mon_get_cpu(mon);
546
547 if (!cs && (format == 'i' || !is_physical)) {
548 monitor_printf(mon, "Can not dump without CPU\n");
549 return;
550 }
551
552 if (format == 'i') {
553 monitor_disas(mon, cs, addr, count, is_physical);
554 return;
555 }
556
557 len = wsize * count;
558 if (wsize == 1)
559 line_size = 8;
560 else
561 line_size = 16;
562 max_digits = 0;
563
564 switch(format) {
565 case 'o':
566 max_digits = DIV_ROUND_UP(wsize * 8, 3);
567 break;
568 default:
569 case 'x':
570 max_digits = (wsize * 8) / 4;
571 break;
572 case 'u':
573 case 'd':
574 max_digits = DIV_ROUND_UP(wsize * 8 * 10, 33);
575 break;
576 case 'c':
577 wsize = 1;
578 break;
579 }
580
581 while (len > 0) {
582 if (is_physical)
583 monitor_printf(mon, TARGET_FMT_plx ":", addr);
584 else
585 monitor_printf(mon, TARGET_FMT_lx ":", (target_ulong)addr);
586 l = len;
587 if (l > line_size)
588 l = line_size;
589 if (is_physical) {
590 AddressSpace *as = cs ? cs->as : &address_space_memory;
591 MemTxResult r = address_space_read(as, addr,
592 MEMTXATTRS_UNSPECIFIED, buf, l);
593 if (r != MEMTX_OK) {
594 monitor_printf(mon, " Cannot access memory\n");
595 break;
596 }
597 } else {
598 if (cpu_memory_rw_debug(cs, addr, buf, l, 0) < 0) {
599 monitor_printf(mon, " Cannot access memory\n");
600 break;
601 }
602 }
603 i = 0;
604 while (i < l) {
605 switch(wsize) {
606 default:
607 case 1:
608 v = ldub_p(buf + i);
609 break;
610 case 2:
611 v = lduw_p(buf + i);
612 break;
613 case 4:
614 v = (uint32_t)ldl_p(buf + i);
615 break;
616 case 8:
617 v = ldq_p(buf + i);
618 break;
619 }
620 monitor_printf(mon, " ");
621 switch(format) {
622 case 'o':
623 monitor_printf(mon, "%#*" PRIo64, max_digits, v);
624 break;
625 case 'x':
626 monitor_printf(mon, "0x%0*" PRIx64, max_digits, v);
627 break;
628 case 'u':
629 monitor_printf(mon, "%*" PRIu64, max_digits, v);
630 break;
631 case 'd':
632 monitor_printf(mon, "%*" PRId64, max_digits, v);
633 break;
634 case 'c':
635 monitor_printc(mon, v);
636 break;
637 }
638 i += wsize;
639 }
640 monitor_printf(mon, "\n");
641 addr += l;
642 len -= l;
643 }
644 }
645
646 static void hmp_memory_dump(Monitor *mon, const QDict *qdict)
647 {
648 int count = qdict_get_int(qdict, "count");
649 int format = qdict_get_int(qdict, "format");
650 int size = qdict_get_int(qdict, "size");
651 target_long addr = qdict_get_int(qdict, "addr");
652
653 memory_dump(mon, count, format, size, addr, 0);
654 }
655
656 static void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict)
657 {
658 int count = qdict_get_int(qdict, "count");
659 int format = qdict_get_int(qdict, "format");
660 int size = qdict_get_int(qdict, "size");
661 hwaddr addr = qdict_get_int(qdict, "addr");
662
663 memory_dump(mon, count, format, size, addr, 1);
664 }
665
666 void *gpa2hva(MemoryRegion **p_mr, hwaddr addr, uint64_t size, Error **errp)
667 {
668 Int128 gpa_region_size;
669 MemoryRegionSection mrs = memory_region_find(get_system_memory(),
670 addr, size);
671
672 if (!mrs.mr) {
673 error_setg(errp, "No memory is mapped at address 0x%" HWADDR_PRIx, addr);
674 return NULL;
675 }
676
677 if (!memory_region_is_ram(mrs.mr) && !memory_region_is_romd(mrs.mr)) {
678 error_setg(errp, "Memory at address 0x%" HWADDR_PRIx "is not RAM", addr);
679 memory_region_unref(mrs.mr);
680 return NULL;
681 }
682
683 gpa_region_size = int128_make64(size);
684 if (int128_lt(mrs.size, gpa_region_size)) {
685 error_setg(errp, "Size of memory region at 0x%" HWADDR_PRIx
686 " exceeded.", addr);
687 memory_region_unref(mrs.mr);
688 return NULL;
689 }
690
691 *p_mr = mrs.mr;
692 return qemu_map_ram_ptr(mrs.mr->ram_block, mrs.offset_within_region);
693 }
694
695 static void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
696 {
697 hwaddr addr = qdict_get_int(qdict, "addr");
698 Error *local_err = NULL;
699 MemoryRegion *mr = NULL;
700 void *ptr;
701
702 ptr = gpa2hva(&mr, addr, 1, &local_err);
703 if (local_err) {
704 error_report_err(local_err);
705 return;
706 }
707
708 monitor_printf(mon, "Host virtual address for 0x%" HWADDR_PRIx
709 " (%s) is %p\n",
710 addr, mr->name, ptr);
711
712 memory_region_unref(mr);
713 }
714
715 static void hmp_gva2gpa(Monitor *mon, const QDict *qdict)
716 {
717 target_ulong addr = qdict_get_int(qdict, "addr");
718 MemTxAttrs attrs;
719 CPUState *cs = mon_get_cpu(mon);
720 hwaddr gpa;
721
722 if (!cs) {
723 monitor_printf(mon, "No cpu\n");
724 return;
725 }
726
727 gpa = cpu_get_phys_page_attrs_debug(cs, addr & TARGET_PAGE_MASK, &attrs);
728 if (gpa == -1) {
729 monitor_printf(mon, "Unmapped\n");
730 } else {
731 monitor_printf(mon, "gpa: %#" HWADDR_PRIx "\n",
732 gpa + (addr & ~TARGET_PAGE_MASK));
733 }
734 }
735
736 #ifdef CONFIG_LINUX
737 static uint64_t vtop(void *ptr, Error **errp)
738 {
739 uint64_t pinfo;
740 uint64_t ret = -1;
741 uintptr_t addr = (uintptr_t) ptr;
742 uintptr_t pagesize = qemu_real_host_page_size;
743 off_t offset = addr / pagesize * sizeof(pinfo);
744 int fd;
745
746 fd = open("/proc/self/pagemap", O_RDONLY);
747 if (fd == -1) {
748 error_setg_errno(errp, errno, "Cannot open /proc/self/pagemap");
749 return -1;
750 }
751
752 /* Force copy-on-write if necessary. */
753 qatomic_add((uint8_t *)ptr, 0);
754
755 if (pread(fd, &pinfo, sizeof(pinfo), offset) != sizeof(pinfo)) {
756 error_setg_errno(errp, errno, "Cannot read pagemap");
757 goto out;
758 }
759 if ((pinfo & (1ull << 63)) == 0) {
760 error_setg(errp, "Page not present");
761 goto out;
762 }
763 ret = ((pinfo & 0x007fffffffffffffull) * pagesize) | (addr & (pagesize - 1));
764
765 out:
766 close(fd);
767 return ret;
768 }
769
770 static void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
771 {
772 hwaddr addr = qdict_get_int(qdict, "addr");
773 Error *local_err = NULL;
774 MemoryRegion *mr = NULL;
775 void *ptr;
776 uint64_t physaddr;
777
778 ptr = gpa2hva(&mr, addr, 1, &local_err);
779 if (local_err) {
780 error_report_err(local_err);
781 return;
782 }
783
784 physaddr = vtop(ptr, &local_err);
785 if (local_err) {
786 error_report_err(local_err);
787 } else {
788 monitor_printf(mon, "Host physical address for 0x%" HWADDR_PRIx
789 " (%s) is 0x%" PRIx64 "\n",
790 addr, mr->name, (uint64_t) physaddr);
791 }
792
793 memory_region_unref(mr);
794 }
795 #endif
796
797 static void do_print(Monitor *mon, const QDict *qdict)
798 {
799 int format = qdict_get_int(qdict, "format");
800 hwaddr val = qdict_get_int(qdict, "val");
801
802 switch(format) {
803 case 'o':
804 monitor_printf(mon, "%#" HWADDR_PRIo, val);
805 break;
806 case 'x':
807 monitor_printf(mon, "%#" HWADDR_PRIx, val);
808 break;
809 case 'u':
810 monitor_printf(mon, "%" HWADDR_PRIu, val);
811 break;
812 default:
813 case 'd':
814 monitor_printf(mon, "%" HWADDR_PRId, val);
815 break;
816 case 'c':
817 monitor_printc(mon, val);
818 break;
819 }
820 monitor_printf(mon, "\n");
821 }
822
823 static void hmp_sum(Monitor *mon, const QDict *qdict)
824 {
825 uint32_t addr;
826 uint16_t sum;
827 uint32_t start = qdict_get_int(qdict, "start");
828 uint32_t size = qdict_get_int(qdict, "size");
829
830 sum = 0;
831 for(addr = start; addr < (start + size); addr++) {
832 uint8_t val = address_space_ldub(&address_space_memory, addr,
833 MEMTXATTRS_UNSPECIFIED, NULL);
834 /* BSD sum algorithm ('sum' Unix command) */
835 sum = (sum >> 1) | (sum << 15);
836 sum += val;
837 }
838 monitor_printf(mon, "%05d\n", sum);
839 }
840
841 static int mouse_button_state;
842
843 static void hmp_mouse_move(Monitor *mon, const QDict *qdict)
844 {
845 int dx, dy, dz, button;
846 const char *dx_str = qdict_get_str(qdict, "dx_str");
847 const char *dy_str = qdict_get_str(qdict, "dy_str");
848 const char *dz_str = qdict_get_try_str(qdict, "dz_str");
849
850 dx = strtol(dx_str, NULL, 0);
851 dy = strtol(dy_str, NULL, 0);
852 qemu_input_queue_rel(NULL, INPUT_AXIS_X, dx);
853 qemu_input_queue_rel(NULL, INPUT_AXIS_Y, dy);
854
855 if (dz_str) {
856 dz = strtol(dz_str, NULL, 0);
857 if (dz != 0) {
858 button = (dz > 0) ? INPUT_BUTTON_WHEEL_UP : INPUT_BUTTON_WHEEL_DOWN;
859 qemu_input_queue_btn(NULL, button, true);
860 qemu_input_event_sync();
861 qemu_input_queue_btn(NULL, button, false);
862 }
863 }
864 qemu_input_event_sync();
865 }
866
867 static void hmp_mouse_button(Monitor *mon, const QDict *qdict)
868 {
869 static uint32_t bmap[INPUT_BUTTON__MAX] = {
870 [INPUT_BUTTON_LEFT] = MOUSE_EVENT_LBUTTON,
871 [INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON,
872 [INPUT_BUTTON_RIGHT] = MOUSE_EVENT_RBUTTON,
873 };
874 int button_state = qdict_get_int(qdict, "button_state");
875
876 if (mouse_button_state == button_state) {
877 return;
878 }
879 qemu_input_update_buttons(NULL, bmap, mouse_button_state, button_state);
880 qemu_input_event_sync();
881 mouse_button_state = button_state;
882 }
883
884 static void hmp_ioport_read(Monitor *mon, const QDict *qdict)
885 {
886 int size = qdict_get_int(qdict, "size");
887 int addr = qdict_get_int(qdict, "addr");
888 int has_index = qdict_haskey(qdict, "index");
889 uint32_t val;
890 int suffix;
891
892 if (has_index) {
893 int index = qdict_get_int(qdict, "index");
894 cpu_outb(addr & IOPORTS_MASK, index & 0xff);
895 addr++;
896 }
897 addr &= 0xffff;
898
899 switch(size) {
900 default:
901 case 1:
902 val = cpu_inb(addr);
903 suffix = 'b';
904 break;
905 case 2:
906 val = cpu_inw(addr);
907 suffix = 'w';
908 break;
909 case 4:
910 val = cpu_inl(addr);
911 suffix = 'l';
912 break;
913 }
914 monitor_printf(mon, "port%c[0x%04x] = %#0*x\n",
915 suffix, addr, size * 2, val);
916 }
917
918 static void hmp_ioport_write(Monitor *mon, const QDict *qdict)
919 {
920 int size = qdict_get_int(qdict, "size");
921 int addr = qdict_get_int(qdict, "addr");
922 int val = qdict_get_int(qdict, "val");
923
924 addr &= IOPORTS_MASK;
925
926 switch (size) {
927 default:
928 case 1:
929 cpu_outb(addr, val);
930 break;
931 case 2:
932 cpu_outw(addr, val);
933 break;
934 case 4:
935 cpu_outl(addr, val);
936 break;
937 }
938 }
939
940 static void hmp_boot_set(Monitor *mon, const QDict *qdict)
941 {
942 Error *local_err = NULL;
943 const char *bootdevice = qdict_get_str(qdict, "bootdevice");
944
945 qemu_boot_set(bootdevice, &local_err);
946 if (local_err) {
947 error_report_err(local_err);
948 } else {
949 monitor_printf(mon, "boot device list now set to %s\n", bootdevice);
950 }
951 }
952
953 static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
954 {
955 bool flatview = qdict_get_try_bool(qdict, "flatview", false);
956 bool dispatch_tree = qdict_get_try_bool(qdict, "dispatch_tree", false);
957 bool owner = qdict_get_try_bool(qdict, "owner", false);
958 bool disabled = qdict_get_try_bool(qdict, "disabled", false);
959
960 mtree_info(flatview, dispatch_tree, owner, disabled);
961 }
962
963 #ifdef CONFIG_PROFILER
964
965 int64_t dev_time;
966
967 static void hmp_info_profile(Monitor *mon, const QDict *qdict)
968 {
969 static int64_t last_cpu_exec_time;
970 int64_t cpu_exec_time;
971 int64_t delta;
972
973 cpu_exec_time = tcg_cpu_exec_time();
974 delta = cpu_exec_time - last_cpu_exec_time;
975
976 monitor_printf(mon, "async time %" PRId64 " (%0.3f)\n",
977 dev_time, dev_time / (double)NANOSECONDS_PER_SECOND);
978 monitor_printf(mon, "qemu time %" PRId64 " (%0.3f)\n",
979 delta, delta / (double)NANOSECONDS_PER_SECOND);
980 last_cpu_exec_time = cpu_exec_time;
981 dev_time = 0;
982 }
983 #else
984 static void hmp_info_profile(Monitor *mon, const QDict *qdict)
985 {
986 monitor_printf(mon, "Internal profiler not compiled\n");
987 }
988 #endif
989
990 /* Capture support */
991 static QLIST_HEAD (capture_list_head, CaptureState) capture_head;
992
993 static void hmp_info_capture(Monitor *mon, const QDict *qdict)
994 {
995 int i;
996 CaptureState *s;
997
998 for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) {
999 monitor_printf(mon, "[%d]: ", i);
1000 s->ops.info (s->opaque);
1001 }
1002 }
1003
1004 static void hmp_stopcapture(Monitor *mon, const QDict *qdict)
1005 {
1006 int i;
1007 int n = qdict_get_int(qdict, "n");
1008 CaptureState *s;
1009
1010 for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) {
1011 if (i == n) {
1012 s->ops.destroy (s->opaque);
1013 QLIST_REMOVE (s, entries);
1014 g_free (s);
1015 return;
1016 }
1017 }
1018 }
1019
1020 static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
1021 {
1022 const char *path = qdict_get_str(qdict, "path");
1023 int freq = qdict_get_try_int(qdict, "freq", 44100);
1024 int bits = qdict_get_try_int(qdict, "bits", 16);
1025 int nchannels = qdict_get_try_int(qdict, "nchannels", 2);
1026 const char *audiodev = qdict_get_str(qdict, "audiodev");
1027 CaptureState *s;
1028 AudioState *as = audio_state_by_name(audiodev);
1029
1030 if (!as) {
1031 monitor_printf(mon, "Audiodev '%s' not found\n", audiodev);
1032 return;
1033 }
1034
1035 s = g_malloc0 (sizeof (*s));
1036
1037 if (wav_start_capture(as, s, path, freq, bits, nchannels)) {
1038 monitor_printf(mon, "Failed to add wave capture\n");
1039 g_free (s);
1040 return;
1041 }
1042 QLIST_INSERT_HEAD (&capture_head, s, entries);
1043 }
1044
1045 static QAuthZList *find_auth(Monitor *mon, const char *name)
1046 {
1047 Object *obj;
1048 Object *container;
1049
1050 container = object_get_objects_root();
1051 obj = object_resolve_path_component(container, name);
1052 if (!obj) {
1053 monitor_printf(mon, "acl: unknown list '%s'\n", name);
1054 return NULL;
1055 }
1056
1057 return QAUTHZ_LIST(obj);
1058 }
1059
1060 static bool warn_acl;
1061 static void hmp_warn_acl(void)
1062 {
1063 if (warn_acl) {
1064 return;
1065 }
1066 error_report("The acl_show, acl_reset, acl_policy, acl_add, acl_remove "
1067 "commands are deprecated with no replacement. Authorization "
1068 "for VNC should be performed using the pluggable QAuthZ "
1069 "objects");
1070 warn_acl = true;
1071 }
1072
1073 static void hmp_acl_show(Monitor *mon, const QDict *qdict)
1074 {
1075 const char *aclname = qdict_get_str(qdict, "aclname");
1076 QAuthZList *auth = find_auth(mon, aclname);
1077 QAuthZListRuleList *rules;
1078 size_t i = 0;
1079
1080 hmp_warn_acl();
1081
1082 if (!auth) {
1083 return;
1084 }
1085
1086 monitor_printf(mon, "policy: %s\n",
1087 QAuthZListPolicy_str(auth->policy));
1088
1089 rules = auth->rules;
1090 while (rules) {
1091 QAuthZListRule *rule = rules->value;
1092 i++;
1093 monitor_printf(mon, "%zu: %s %s\n", i,
1094 QAuthZListPolicy_str(rule->policy),
1095 rule->match);
1096 rules = rules->next;
1097 }
1098 }
1099
1100 static void hmp_acl_reset(Monitor *mon, const QDict *qdict)
1101 {
1102 const char *aclname = qdict_get_str(qdict, "aclname");
1103 QAuthZList *auth = find_auth(mon, aclname);
1104
1105 hmp_warn_acl();
1106
1107 if (!auth) {
1108 return;
1109 }
1110
1111 auth->policy = QAUTHZ_LIST_POLICY_DENY;
1112 qapi_free_QAuthZListRuleList(auth->rules);
1113 auth->rules = NULL;
1114 monitor_printf(mon, "acl: removed all rules\n");
1115 }
1116
1117 static void hmp_acl_policy(Monitor *mon, const QDict *qdict)
1118 {
1119 const char *aclname = qdict_get_str(qdict, "aclname");
1120 const char *policy = qdict_get_str(qdict, "policy");
1121 QAuthZList *auth = find_auth(mon, aclname);
1122 int val;
1123 Error *err = NULL;
1124
1125 hmp_warn_acl();
1126
1127 if (!auth) {
1128 return;
1129 }
1130
1131 val = qapi_enum_parse(&QAuthZListPolicy_lookup,
1132 policy,
1133 QAUTHZ_LIST_POLICY_DENY,
1134 &err);
1135 if (err) {
1136 error_free(err);
1137 monitor_printf(mon, "acl: unknown policy '%s', "
1138 "expected 'deny' or 'allow'\n", policy);
1139 } else {
1140 auth->policy = val;
1141 if (auth->policy == QAUTHZ_LIST_POLICY_ALLOW) {
1142 monitor_printf(mon, "acl: policy set to 'allow'\n");
1143 } else {
1144 monitor_printf(mon, "acl: policy set to 'deny'\n");
1145 }
1146 }
1147 }
1148
1149 static QAuthZListFormat hmp_acl_get_format(const char *match)
1150 {
1151 if (strchr(match, '*')) {
1152 return QAUTHZ_LIST_FORMAT_GLOB;
1153 } else {
1154 return QAUTHZ_LIST_FORMAT_EXACT;
1155 }
1156 }
1157
1158 static void hmp_acl_add(Monitor *mon, const QDict *qdict)
1159 {
1160 const char *aclname = qdict_get_str(qdict, "aclname");
1161 const char *match = qdict_get_str(qdict, "match");
1162 const char *policystr = qdict_get_str(qdict, "policy");
1163 int has_index = qdict_haskey(qdict, "index");
1164 int index = qdict_get_try_int(qdict, "index", -1);
1165 QAuthZList *auth = find_auth(mon, aclname);
1166 Error *err = NULL;
1167 QAuthZListPolicy policy;
1168 QAuthZListFormat format;
1169 size_t i = 0;
1170
1171 hmp_warn_acl();
1172
1173 if (!auth) {
1174 return;
1175 }
1176
1177 policy = qapi_enum_parse(&QAuthZListPolicy_lookup,
1178 policystr,
1179 QAUTHZ_LIST_POLICY_DENY,
1180 &err);
1181 if (err) {
1182 error_free(err);
1183 monitor_printf(mon, "acl: unknown policy '%s', "
1184 "expected 'deny' or 'allow'\n", policystr);
1185 return;
1186 }
1187
1188 format = hmp_acl_get_format(match);
1189
1190 if (has_index && index == 0) {
1191 monitor_printf(mon, "acl: unable to add acl entry\n");
1192 return;
1193 }
1194
1195 if (has_index) {
1196 i = qauthz_list_insert_rule(auth, match, policy,
1197 format, index - 1, &err);
1198 } else {
1199 i = qauthz_list_append_rule(auth, match, policy,
1200 format, &err);
1201 }
1202 if (err) {
1203 monitor_printf(mon, "acl: unable to add rule: %s",
1204 error_get_pretty(err));
1205 error_free(err);
1206 } else {
1207 monitor_printf(mon, "acl: added rule at position %zu\n", i + 1);
1208 }
1209 }
1210
1211 static void hmp_acl_remove(Monitor *mon, const QDict *qdict)
1212 {
1213 const char *aclname = qdict_get_str(qdict, "aclname");
1214 const char *match = qdict_get_str(qdict, "match");
1215 QAuthZList *auth = find_auth(mon, aclname);
1216 ssize_t i = 0;
1217
1218 hmp_warn_acl();
1219
1220 if (!auth) {
1221 return;
1222 }
1223
1224 i = qauthz_list_delete_rule(auth, match);
1225 if (i >= 0) {
1226 monitor_printf(mon, "acl: removed rule at position %zu\n", i + 1);
1227 } else {
1228 monitor_printf(mon, "acl: no matching acl entry\n");
1229 }
1230 }
1231
1232 void qmp_getfd(const char *fdname, Error **errp)
1233 {
1234 Monitor *cur_mon = monitor_cur();
1235 mon_fd_t *monfd;
1236 int fd, tmp_fd;
1237
1238 fd = qemu_chr_fe_get_msgfd(&cur_mon->chr);
1239 if (fd == -1) {
1240 error_setg(errp, "No file descriptor supplied via SCM_RIGHTS");
1241 return;
1242 }
1243
1244 if (qemu_isdigit(fdname[0])) {
1245 close(fd);
1246 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "fdname",
1247 "a name not starting with a digit");
1248 return;
1249 }
1250
1251 QEMU_LOCK_GUARD(&cur_mon->mon_lock);
1252 QLIST_FOREACH(monfd, &cur_mon->fds, next) {
1253 if (strcmp(monfd->name, fdname) != 0) {
1254 continue;
1255 }
1256
1257 tmp_fd = monfd->fd;
1258 monfd->fd = fd;
1259 /* Make sure close() is outside critical section */
1260 close(tmp_fd);
1261 return;
1262 }
1263
1264 monfd = g_malloc0(sizeof(mon_fd_t));
1265 monfd->name = g_strdup(fdname);
1266 monfd->fd = fd;
1267
1268 QLIST_INSERT_HEAD(&cur_mon->fds, monfd, next);
1269 }
1270
1271 void qmp_closefd(const char *fdname, Error **errp)
1272 {
1273 Monitor *cur_mon = monitor_cur();
1274 mon_fd_t *monfd;
1275 int tmp_fd;
1276
1277 qemu_mutex_lock(&cur_mon->mon_lock);
1278 QLIST_FOREACH(monfd, &cur_mon->fds, next) {
1279 if (strcmp(monfd->name, fdname) != 0) {
1280 continue;
1281 }
1282
1283 QLIST_REMOVE(monfd, next);
1284 tmp_fd = monfd->fd;
1285 g_free(monfd->name);
1286 g_free(monfd);
1287 qemu_mutex_unlock(&cur_mon->mon_lock);
1288 /* Make sure close() is outside critical section */
1289 close(tmp_fd);
1290 return;
1291 }
1292
1293 qemu_mutex_unlock(&cur_mon->mon_lock);
1294 error_setg(errp, "File descriptor named '%s' not found", fdname);
1295 }
1296
1297 int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp)
1298 {
1299 mon_fd_t *monfd;
1300
1301 QEMU_LOCK_GUARD(&mon->mon_lock);
1302 QLIST_FOREACH(monfd, &mon->fds, next) {
1303 int fd;
1304
1305 if (strcmp(monfd->name, fdname) != 0) {
1306 continue;
1307 }
1308
1309 fd = monfd->fd;
1310
1311 /* caller takes ownership of fd */
1312 QLIST_REMOVE(monfd, next);
1313 g_free(monfd->name);
1314 g_free(monfd);
1315
1316 return fd;
1317 }
1318
1319 error_setg(errp, "File descriptor named '%s' has not been found", fdname);
1320 return -1;
1321 }
1322
1323 static void monitor_fdset_cleanup(MonFdset *mon_fdset)
1324 {
1325 MonFdsetFd *mon_fdset_fd;
1326 MonFdsetFd *mon_fdset_fd_next;
1327
1328 QLIST_FOREACH_SAFE(mon_fdset_fd, &mon_fdset->fds, next, mon_fdset_fd_next) {
1329 if ((mon_fdset_fd->removed ||
1330 (QLIST_EMPTY(&mon_fdset->dup_fds) && mon_refcount == 0)) &&
1331 runstate_is_running()) {
1332 close(mon_fdset_fd->fd);
1333 g_free(mon_fdset_fd->opaque);
1334 QLIST_REMOVE(mon_fdset_fd, next);
1335 g_free(mon_fdset_fd);
1336 }
1337 }
1338
1339 if (QLIST_EMPTY(&mon_fdset->fds) && QLIST_EMPTY(&mon_fdset->dup_fds)) {
1340 QLIST_REMOVE(mon_fdset, next);
1341 g_free(mon_fdset);
1342 }
1343 }
1344
1345 void monitor_fdsets_cleanup(void)
1346 {
1347 MonFdset *mon_fdset;
1348 MonFdset *mon_fdset_next;
1349
1350 QEMU_LOCK_GUARD(&mon_fdsets_lock);
1351 QLIST_FOREACH_SAFE(mon_fdset, &mon_fdsets, next, mon_fdset_next) {
1352 monitor_fdset_cleanup(mon_fdset);
1353 }
1354 }
1355
1356 AddfdInfo *qmp_add_fd(bool has_fdset_id, int64_t fdset_id, bool has_opaque,
1357 const char *opaque, Error **errp)
1358 {
1359 int fd;
1360 Monitor *mon = monitor_cur();
1361 AddfdInfo *fdinfo;
1362
1363 fd = qemu_chr_fe_get_msgfd(&mon->chr);
1364 if (fd == -1) {
1365 error_setg(errp, "No file descriptor supplied via SCM_RIGHTS");
1366 goto error;
1367 }
1368
1369 fdinfo = monitor_fdset_add_fd(fd, has_fdset_id, fdset_id,
1370 has_opaque, opaque, errp);
1371 if (fdinfo) {
1372 return fdinfo;
1373 }
1374
1375 error:
1376 if (fd != -1) {
1377 close(fd);
1378 }
1379 return NULL;
1380 }
1381
1382 void qmp_remove_fd(int64_t fdset_id, bool has_fd, int64_t fd, Error **errp)
1383 {
1384 MonFdset *mon_fdset;
1385 MonFdsetFd *mon_fdset_fd;
1386 char fd_str[60];
1387
1388 QEMU_LOCK_GUARD(&mon_fdsets_lock);
1389 QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
1390 if (mon_fdset->id != fdset_id) {
1391 continue;
1392 }
1393 QLIST_FOREACH(mon_fdset_fd, &mon_fdset->fds, next) {
1394 if (has_fd) {
1395 if (mon_fdset_fd->fd != fd) {
1396 continue;
1397 }
1398 mon_fdset_fd->removed = true;
1399 break;
1400 } else {
1401 mon_fdset_fd->removed = true;
1402 }
1403 }
1404 if (has_fd && !mon_fdset_fd) {
1405 goto error;
1406 }
1407 monitor_fdset_cleanup(mon_fdset);
1408 return;
1409 }
1410
1411 error:
1412 if (has_fd) {
1413 snprintf(fd_str, sizeof(fd_str), "fdset-id:%" PRId64 ", fd:%" PRId64,
1414 fdset_id, fd);
1415 } else {
1416 snprintf(fd_str, sizeof(fd_str), "fdset-id:%" PRId64, fdset_id);
1417 }
1418 error_setg(errp, "File descriptor named '%s' not found", fd_str);
1419 }
1420
1421 FdsetInfoList *qmp_query_fdsets(Error **errp)
1422 {
1423 MonFdset *mon_fdset;
1424 MonFdsetFd *mon_fdset_fd;
1425 FdsetInfoList *fdset_list = NULL;
1426
1427 QEMU_LOCK_GUARD(&mon_fdsets_lock);
1428 QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
1429 FdsetInfo *fdset_info = g_malloc0(sizeof(*fdset_info));
1430
1431 fdset_info->fdset_id = mon_fdset->id;
1432
1433 QLIST_FOREACH(mon_fdset_fd, &mon_fdset->fds, next) {
1434 FdsetFdInfo *fdsetfd_info;
1435
1436 fdsetfd_info = g_malloc0(sizeof(*fdsetfd_info));
1437 fdsetfd_info->fd = mon_fdset_fd->fd;
1438 if (mon_fdset_fd->opaque) {
1439 fdsetfd_info->has_opaque = true;
1440 fdsetfd_info->opaque = g_strdup(mon_fdset_fd->opaque);
1441 } else {
1442 fdsetfd_info->has_opaque = false;
1443 }
1444
1445 QAPI_LIST_PREPEND(fdset_info->fds, fdsetfd_info);
1446 }
1447
1448 QAPI_LIST_PREPEND(fdset_list, fdset_info);
1449 }
1450
1451 return fdset_list;
1452 }
1453
1454 AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
1455 bool has_opaque, const char *opaque,
1456 Error **errp)
1457 {
1458 MonFdset *mon_fdset = NULL;
1459 MonFdsetFd *mon_fdset_fd;
1460 AddfdInfo *fdinfo;
1461
1462 QEMU_LOCK_GUARD(&mon_fdsets_lock);
1463 if (has_fdset_id) {
1464 QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
1465 /* Break if match found or match impossible due to ordering by ID */
1466 if (fdset_id <= mon_fdset->id) {
1467 if (fdset_id < mon_fdset->id) {
1468 mon_fdset = NULL;
1469 }
1470 break;
1471 }
1472 }
1473 }
1474
1475 if (mon_fdset == NULL) {
1476 int64_t fdset_id_prev = -1;
1477 MonFdset *mon_fdset_cur = QLIST_FIRST(&mon_fdsets);
1478
1479 if (has_fdset_id) {
1480 if (fdset_id < 0) {
1481 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "fdset-id",
1482 "a non-negative value");
1483 return NULL;
1484 }
1485 /* Use specified fdset ID */
1486 QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
1487 mon_fdset_cur = mon_fdset;
1488 if (fdset_id < mon_fdset_cur->id) {
1489 break;
1490 }
1491 }
1492 } else {
1493 /* Use first available fdset ID */
1494 QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
1495 mon_fdset_cur = mon_fdset;
1496 if (fdset_id_prev == mon_fdset_cur->id - 1) {
1497 fdset_id_prev = mon_fdset_cur->id;
1498 continue;
1499 }
1500 break;
1501 }
1502 }
1503
1504 mon_fdset = g_malloc0(sizeof(*mon_fdset));
1505 if (has_fdset_id) {
1506 mon_fdset->id = fdset_id;
1507 } else {
1508 mon_fdset->id = fdset_id_prev + 1;
1509 }
1510
1511 /* The fdset list is ordered by fdset ID */
1512 if (!mon_fdset_cur) {
1513 QLIST_INSERT_HEAD(&mon_fdsets, mon_fdset, next);
1514 } else if (mon_fdset->id < mon_fdset_cur->id) {
1515 QLIST_INSERT_BEFORE(mon_fdset_cur, mon_fdset, next);
1516 } else {
1517 QLIST_INSERT_AFTER(mon_fdset_cur, mon_fdset, next);
1518 }
1519 }
1520
1521 mon_fdset_fd = g_malloc0(sizeof(*mon_fdset_fd));
1522 mon_fdset_fd->fd = fd;
1523 mon_fdset_fd->removed = false;
1524 if (has_opaque) {
1525 mon_fdset_fd->opaque = g_strdup(opaque);
1526 }
1527 QLIST_INSERT_HEAD(&mon_fdset->fds, mon_fdset_fd, next);
1528
1529 fdinfo = g_malloc0(sizeof(*fdinfo));
1530 fdinfo->fdset_id = mon_fdset->id;
1531 fdinfo->fd = mon_fdset_fd->fd;
1532
1533 return fdinfo;
1534 }
1535
1536 int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags)
1537 {
1538 #ifdef _WIN32
1539 return -ENOENT;
1540 #else
1541 MonFdset *mon_fdset;
1542
1543 QEMU_LOCK_GUARD(&mon_fdsets_lock);
1544 QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
1545 MonFdsetFd *mon_fdset_fd;
1546 MonFdsetFd *mon_fdset_fd_dup;
1547 int fd = -1;
1548 int dup_fd;
1549 int mon_fd_flags;
1550
1551 if (mon_fdset->id != fdset_id) {
1552 continue;
1553 }
1554
1555 QLIST_FOREACH(mon_fdset_fd, &mon_fdset->fds, next) {
1556 mon_fd_flags = fcntl(mon_fdset_fd->fd, F_GETFL);
1557 if (mon_fd_flags == -1) {
1558 return -1;
1559 }
1560
1561 if ((flags & O_ACCMODE) == (mon_fd_flags & O_ACCMODE)) {
1562 fd = mon_fdset_fd->fd;
1563 break;
1564 }
1565 }
1566
1567 if (fd == -1) {
1568 errno = EACCES;
1569 return -1;
1570 }
1571
1572 dup_fd = qemu_dup_flags(fd, flags);
1573 if (dup_fd == -1) {
1574 return -1;
1575 }
1576
1577 mon_fdset_fd_dup = g_malloc0(sizeof(*mon_fdset_fd_dup));
1578 mon_fdset_fd_dup->fd = dup_fd;
1579 QLIST_INSERT_HEAD(&mon_fdset->dup_fds, mon_fdset_fd_dup, next);
1580 return dup_fd;
1581 }
1582
1583 errno = ENOENT;
1584 return -1;
1585 #endif
1586 }
1587
1588 static int64_t monitor_fdset_dup_fd_find_remove(int dup_fd, bool remove)
1589 {
1590 MonFdset *mon_fdset;
1591 MonFdsetFd *mon_fdset_fd_dup;
1592
1593 QEMU_LOCK_GUARD(&mon_fdsets_lock);
1594 QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
1595 QLIST_FOREACH(mon_fdset_fd_dup, &mon_fdset->dup_fds, next) {
1596 if (mon_fdset_fd_dup->fd == dup_fd) {
1597 if (remove) {
1598 QLIST_REMOVE(mon_fdset_fd_dup, next);
1599 g_free(mon_fdset_fd_dup);
1600 if (QLIST_EMPTY(&mon_fdset->dup_fds)) {
1601 monitor_fdset_cleanup(mon_fdset);
1602 }
1603 return -1;
1604 } else {
1605 return mon_fdset->id;
1606 }
1607 }
1608 }
1609 }
1610
1611 return -1;
1612 }
1613
1614 int64_t monitor_fdset_dup_fd_find(int dup_fd)
1615 {
1616 return monitor_fdset_dup_fd_find_remove(dup_fd, false);
1617 }
1618
1619 void monitor_fdset_dup_fd_remove(int dup_fd)
1620 {
1621 monitor_fdset_dup_fd_find_remove(dup_fd, true);
1622 }
1623
1624 int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp)
1625 {
1626 int fd;
1627 Error *local_err = NULL;
1628
1629 if (!qemu_isdigit(fdname[0]) && mon) {
1630 fd = monitor_get_fd(mon, fdname, &local_err);
1631 } else {
1632 fd = qemu_parse_fd(fdname);
1633 if (fd == -1) {
1634 error_setg(&local_err, "Invalid file descriptor number '%s'",
1635 fdname);
1636 }
1637 }
1638 if (local_err) {
1639 error_propagate(errp, local_err);
1640 assert(fd == -1);
1641 } else {
1642 assert(fd != -1);
1643 }
1644
1645 return fd;
1646 }
1647
1648 /* Please update hmp-commands.hx when adding or changing commands */
1649 static HMPCommand hmp_info_cmds[] = {
1650 #include "hmp-commands-info.h"
1651 { NULL, NULL, },
1652 };
1653
1654 /* hmp_cmds and hmp_info_cmds would be sorted at runtime */
1655 HMPCommand hmp_cmds[] = {
1656 #include "hmp-commands.h"
1657 { NULL, NULL, },
1658 };
1659
1660 /*
1661 * Set @pval to the value in the register identified by @name.
1662 * return 0 if OK, -1 if not found
1663 */
1664 int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
1665 {
1666 const MonitorDef *md = target_monitor_defs();
1667 CPUState *cs = mon_get_cpu(mon);
1668 void *ptr;
1669 uint64_t tmp = 0;
1670 int ret;
1671
1672 if (cs == NULL || md == NULL) {
1673 return -1;
1674 }
1675
1676 for(; md->name != NULL; md++) {
1677 if (hmp_compare_cmd(name, md->name)) {
1678 if (md->get_value) {
1679 *pval = md->get_value(mon, md, md->offset);
1680 } else {
1681 CPUArchState *env = mon_get_cpu_env(mon);
1682 ptr = (uint8_t *)env + md->offset;
1683 switch(md->type) {
1684 case MD_I32:
1685 *pval = *(int32_t *)ptr;
1686 break;
1687 case MD_TLONG:
1688 *pval = *(target_long *)ptr;
1689 break;
1690 default:
1691 *pval = 0;
1692 break;
1693 }
1694 }
1695 return 0;
1696 }
1697 }
1698
1699 ret = target_get_monitor_def(cs, name, &tmp);
1700 if (!ret) {
1701 *pval = (target_long) tmp;
1702 }
1703
1704 return ret;
1705 }
1706
1707 static void add_completion_option(ReadLineState *rs, const char *str,
1708 const char *option)
1709 {
1710 if (!str || !option) {
1711 return;
1712 }
1713 if (!strncmp(option, str, strlen(str))) {
1714 readline_add_completion(rs, option);
1715 }
1716 }
1717
1718 void chardev_add_completion(ReadLineState *rs, int nb_args, const char *str)
1719 {
1720 size_t len;
1721 ChardevBackendInfoList *list, *start;
1722
1723 if (nb_args != 2) {
1724 return;
1725 }
1726 len = strlen(str);
1727 readline_set_completion_index(rs, len);
1728
1729 start = list = qmp_query_chardev_backends(NULL);
1730 while (list) {
1731 const char *chr_name = list->value->name;
1732
1733 if (!strncmp(chr_name, str, len)) {
1734 readline_add_completion(rs, chr_name);
1735 }
1736 list = list->next;
1737 }
1738 qapi_free_ChardevBackendInfoList(start);
1739 }
1740
1741 void netdev_add_completion(ReadLineState *rs, int nb_args, const char *str)
1742 {
1743 size_t len;
1744 int i;
1745
1746 if (nb_args != 2) {
1747 return;
1748 }
1749 len = strlen(str);
1750 readline_set_completion_index(rs, len);
1751 for (i = 0; i < NET_CLIENT_DRIVER__MAX; i++) {
1752 add_completion_option(rs, str, NetClientDriver_str(i));
1753 }
1754 }
1755
1756 void device_add_completion(ReadLineState *rs, int nb_args, const char *str)
1757 {
1758 GSList *list, *elt;
1759 size_t len;
1760
1761 if (nb_args != 2) {
1762 return;
1763 }
1764
1765 len = strlen(str);
1766 readline_set_completion_index(rs, len);
1767 list = elt = object_class_get_list(TYPE_DEVICE, false);
1768 while (elt) {
1769 const char *name;
1770 DeviceClass *dc = OBJECT_CLASS_CHECK(DeviceClass, elt->data,
1771 TYPE_DEVICE);
1772 name = object_class_get_name(OBJECT_CLASS(dc));
1773
1774 if (dc->user_creatable
1775 && !strncmp(name, str, len)) {
1776 readline_add_completion(rs, name);
1777 }
1778 elt = elt->next;
1779 }
1780 g_slist_free(list);
1781 }
1782
1783 void object_add_completion(ReadLineState *rs, int nb_args, const char *str)
1784 {
1785 GSList *list, *elt;
1786 size_t len;
1787
1788 if (nb_args != 2) {
1789 return;
1790 }
1791
1792 len = strlen(str);
1793 readline_set_completion_index(rs, len);
1794 list = elt = object_class_get_list(TYPE_USER_CREATABLE, false);
1795 while (elt) {
1796 const char *name;
1797
1798 name = object_class_get_name(OBJECT_CLASS(elt->data));
1799 if (!strncmp(name, str, len) && strcmp(name, TYPE_USER_CREATABLE)) {
1800 readline_add_completion(rs, name);
1801 }
1802 elt = elt->next;
1803 }
1804 g_slist_free(list);
1805 }
1806
1807 static int qdev_add_hotpluggable_device(Object *obj, void *opaque)
1808 {
1809 GSList **list = opaque;
1810 DeviceState *dev = (DeviceState *)object_dynamic_cast(obj, TYPE_DEVICE);
1811
1812 if (dev == NULL) {
1813 return 0;
1814 }
1815
1816 if (dev->realized && object_property_get_bool(obj, "hotpluggable", NULL)) {
1817 *list = g_slist_append(*list, dev);
1818 }
1819
1820 return 0;
1821 }
1822
1823 static GSList *qdev_build_hotpluggable_device_list(Object *peripheral)
1824 {
1825 GSList *list = NULL;
1826
1827 object_child_foreach(peripheral, qdev_add_hotpluggable_device, &list);
1828
1829 return list;
1830 }
1831
1832 static void peripheral_device_del_completion(ReadLineState *rs,
1833 const char *str, size_t len)
1834 {
1835 Object *peripheral = container_get(qdev_get_machine(), "/peripheral");
1836 GSList *list, *item;
1837
1838 list = qdev_build_hotpluggable_device_list(peripheral);
1839 if (!list) {
1840 return;
1841 }
1842
1843 for (item = list; item; item = g_slist_next(item)) {
1844 DeviceState *dev = item->data;
1845
1846 if (dev->id && !strncmp(str, dev->id, len)) {
1847 readline_add_completion(rs, dev->id);
1848 }
1849 }
1850
1851 g_slist_free(list);
1852 }
1853
1854 void chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str)
1855 {
1856 size_t len;
1857 ChardevInfoList *list, *start;
1858
1859 if (nb_args != 2) {
1860 return;
1861 }
1862 len = strlen(str);
1863 readline_set_completion_index(rs, len);
1864
1865 start = list = qmp_query_chardev(NULL);
1866 while (list) {
1867 ChardevInfo *chr = list->value;
1868
1869 if (!strncmp(chr->label, str, len)) {
1870 readline_add_completion(rs, chr->label);
1871 }
1872 list = list->next;
1873 }
1874 qapi_free_ChardevInfoList(start);
1875 }
1876
1877 static void ringbuf_completion(ReadLineState *rs, const char *str)
1878 {
1879 size_t len;
1880 ChardevInfoList *list, *start;
1881
1882 len = strlen(str);
1883 readline_set_completion_index(rs, len);
1884
1885 start = list = qmp_query_chardev(NULL);
1886 while (list) {
1887 ChardevInfo *chr_info = list->value;
1888
1889 if (!strncmp(chr_info->label, str, len)) {
1890 Chardev *chr = qemu_chr_find(chr_info->label);
1891 if (chr && CHARDEV_IS_RINGBUF(chr)) {
1892 readline_add_completion(rs, chr_info->label);
1893 }
1894 }
1895 list = list->next;
1896 }
1897 qapi_free_ChardevInfoList(start);
1898 }
1899
1900 void ringbuf_write_completion(ReadLineState *rs, int nb_args, const char *str)
1901 {
1902 if (nb_args != 2) {
1903 return;
1904 }
1905 ringbuf_completion(rs, str);
1906 }
1907
1908 void device_del_completion(ReadLineState *rs, int nb_args, const char *str)
1909 {
1910 size_t len;
1911
1912 if (nb_args != 2) {
1913 return;
1914 }
1915
1916 len = strlen(str);
1917 readline_set_completion_index(rs, len);
1918 peripheral_device_del_completion(rs, str, len);
1919 }
1920
1921 void object_del_completion(ReadLineState *rs, int nb_args, const char *str)
1922 {
1923 ObjectPropertyInfoList *list, *start;
1924 size_t len;
1925
1926 if (nb_args != 2) {
1927 return;
1928 }
1929 len = strlen(str);
1930 readline_set_completion_index(rs, len);
1931
1932 start = list = qmp_qom_list("/objects", NULL);
1933 while (list) {
1934 ObjectPropertyInfo *info = list->value;
1935
1936 if (!strncmp(info->type, "child<", 5)
1937 && !strncmp(info->name, str, len)) {
1938 readline_add_completion(rs, info->name);
1939 }
1940 list = list->next;
1941 }
1942 qapi_free_ObjectPropertyInfoList(start);
1943 }
1944
1945 void sendkey_completion(ReadLineState *rs, int nb_args, const char *str)
1946 {
1947 int i;
1948 char *sep;
1949 size_t len;
1950
1951 if (nb_args != 2) {
1952 return;
1953 }
1954 sep = strrchr(str, '-');
1955 if (sep) {
1956 str = sep + 1;
1957 }
1958 len = strlen(str);
1959 readline_set_completion_index(rs, len);
1960 for (i = 0; i < Q_KEY_CODE__MAX; i++) {
1961 if (!strncmp(str, QKeyCode_str(i), len)) {
1962 readline_add_completion(rs, QKeyCode_str(i));
1963 }
1964 }
1965 }
1966
1967 void set_link_completion(ReadLineState *rs, int nb_args, const char *str)
1968 {
1969 size_t len;
1970
1971 len = strlen(str);
1972 readline_set_completion_index(rs, len);
1973 if (nb_args == 2) {
1974 NetClientState *ncs[MAX_QUEUE_NUM];
1975 int count, i;
1976 count = qemu_find_net_clients_except(NULL, ncs,
1977 NET_CLIENT_DRIVER_NONE,
1978 MAX_QUEUE_NUM);
1979 for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) {
1980 const char *name = ncs[i]->name;
1981 if (!strncmp(str, name, len)) {
1982 readline_add_completion(rs, name);
1983 }
1984 }
1985 } else if (nb_args == 3) {
1986 add_completion_option(rs, str, "on");
1987 add_completion_option(rs, str, "off");
1988 }
1989 }
1990
1991 void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str)
1992 {
1993 int len, count, i;
1994 NetClientState *ncs[MAX_QUEUE_NUM];
1995
1996 if (nb_args != 2) {
1997 return;
1998 }
1999
2000 len = strlen(str);
2001 readline_set_completion_index(rs, len);
2002 count = qemu_find_net_clients_except(NULL, ncs, NET_CLIENT_DRIVER_NIC,
2003 MAX_QUEUE_NUM);
2004 for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) {
2005 const char *name = ncs[i]->name;
2006 if (strncmp(str, name, len)) {
2007 continue;
2008 }
2009 if (ncs[i]->is_netdev) {
2010 readline_add_completion(rs, name);
2011 }
2012 }
2013 }
2014
2015 void info_trace_events_completion(ReadLineState *rs, int nb_args, const char *str)
2016 {
2017 size_t len;
2018
2019 len = strlen(str);
2020 readline_set_completion_index(rs, len);
2021 if (nb_args == 2) {
2022 TraceEventIter iter;
2023 TraceEvent *ev;
2024 char *pattern = g_strdup_printf("%s*", str);
2025 trace_event_iter_init(&iter, pattern);
2026 while ((ev = trace_event_iter_next(&iter)) != NULL) {
2027 readline_add_completion(rs, trace_event_get_name(ev));
2028 }
2029 g_free(pattern);
2030 }
2031 }
2032
2033 void trace_event_completion(ReadLineState *rs, int nb_args, const char *str)
2034 {
2035 size_t len;
2036
2037 len = strlen(str);
2038 readline_set_completion_index(rs, len);
2039 if (nb_args == 2) {
2040 TraceEventIter iter;
2041 TraceEvent *ev;
2042 char *pattern = g_strdup_printf("%s*", str);
2043 trace_event_iter_init(&iter, pattern);
2044 while ((ev = trace_event_iter_next(&iter)) != NULL) {
2045 readline_add_completion(rs, trace_event_get_name(ev));
2046 }
2047 g_free(pattern);
2048 } else if (nb_args == 3) {
2049 add_completion_option(rs, str, "on");
2050 add_completion_option(rs, str, "off");
2051 }
2052 }
2053
2054 void watchdog_action_completion(ReadLineState *rs, int nb_args, const char *str)
2055 {
2056 int i;
2057
2058 if (nb_args != 2) {
2059 return;
2060 }
2061 readline_set_completion_index(rs, strlen(str));
2062 for (i = 0; i < WATCHDOG_ACTION__MAX; i++) {
2063 add_completion_option(rs, str, WatchdogAction_str(i));
2064 }
2065 }
2066
2067 void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
2068 const char *str)
2069 {
2070 size_t len;
2071
2072 len = strlen(str);
2073 readline_set_completion_index(rs, len);
2074 if (nb_args == 2) {
2075 int i;
2076 for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
2077 const char *name = MigrationCapability_str(i);
2078 if (!strncmp(str, name, len)) {
2079 readline_add_completion(rs, name);
2080 }
2081 }
2082 } else if (nb_args == 3) {
2083 add_completion_option(rs, str, "on");
2084 add_completion_option(rs, str, "off");
2085 }
2086 }
2087
2088 void migrate_set_parameter_completion(ReadLineState *rs, int nb_args,
2089 const char *str)
2090 {
2091 size_t len;
2092
2093 len = strlen(str);
2094 readline_set_completion_index(rs, len);
2095 if (nb_args == 2) {
2096 int i;
2097 for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) {
2098 const char *name = MigrationParameter_str(i);
2099 if (!strncmp(str, name, len)) {
2100 readline_add_completion(rs, name);
2101 }
2102 }
2103 }
2104 }
2105
2106 static void vm_completion(ReadLineState *rs, const char *str)
2107 {
2108 size_t len;
2109 BlockDriverState *bs;
2110 BdrvNextIterator it;
2111
2112 len = strlen(str);
2113 readline_set_completion_index(rs, len);
2114
2115 for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
2116 SnapshotInfoList *snapshots, *snapshot;
2117 AioContext *ctx = bdrv_get_aio_context(bs);
2118 bool ok = false;
2119
2120 aio_context_acquire(ctx);
2121 if (bdrv_can_snapshot(bs)) {
2122 ok = bdrv_query_snapshot_info_list(bs, &snapshots, NULL) == 0;
2123 }
2124 aio_context_release(ctx);
2125 if (!ok) {
2126 continue;
2127 }
2128
2129 snapshot = snapshots;
2130 while (snapshot) {
2131 char *completion = snapshot->value->name;
2132 if (!strncmp(str, completion, len)) {
2133 readline_add_completion(rs, completion);
2134 }
2135 completion = snapshot->value->id;
2136 if (!strncmp(str, completion, len)) {
2137 readline_add_completion(rs, completion);
2138 }
2139 snapshot = snapshot->next;
2140 }
2141 qapi_free_SnapshotInfoList(snapshots);
2142 }
2143
2144 }
2145
2146 void delvm_completion(ReadLineState *rs, int nb_args, const char *str)
2147 {
2148 if (nb_args == 2) {
2149 vm_completion(rs, str);
2150 }
2151 }
2152
2153 void loadvm_completion(ReadLineState *rs, int nb_args, const char *str)
2154 {
2155 if (nb_args == 2) {
2156 vm_completion(rs, str);
2157 }
2158 }
2159
2160 static int
2161 compare_mon_cmd(const void *a, const void *b)
2162 {
2163 return strcmp(((const HMPCommand *)a)->name,
2164 ((const HMPCommand *)b)->name);
2165 }
2166
2167 static void sortcmdlist(void)
2168 {
2169 qsort(hmp_cmds, ARRAY_SIZE(hmp_cmds) - 1,
2170 sizeof(*hmp_cmds),
2171 compare_mon_cmd);
2172 qsort(hmp_info_cmds, ARRAY_SIZE(hmp_info_cmds) - 1,
2173 sizeof(*hmp_info_cmds),
2174 compare_mon_cmd);
2175 }
2176
2177 void monitor_init_globals(void)
2178 {
2179 monitor_init_globals_core();
2180 monitor_init_qmp_commands();
2181 sortcmdlist();
2182 qemu_mutex_init(&mon_fdsets_lock);
2183 }