#include "hw/pc.h"
#include "hw/pci.h"
#include "hw/watchdog.h"
+#include "hw/loader.h"
#include "gdbstub.h"
#include "net.h"
#include "qemu-char.h"
#include "kvm.h"
#include "acl.h"
#include "qint.h"
+#include "qlist.h"
#include "qdict.h"
#include "qstring.h"
typedef struct mon_cmd_t {
const char *name;
const char *args_type;
- void *handler;
const char *params;
const char *help;
+ void (*user_print)(Monitor *mon, const QObject *data);
+ union {
+ void (*info)(Monitor *mon);
+ void (*info_new)(Monitor *mon, QObject **ret_data);
+ void (*cmd)(Monitor *mon, const QDict *qdict);
+ void (*cmd_new)(Monitor *mon, const QDict *params, QObject **ret_data);
+ } mhandler;
} mon_cmd_t;
/* file descriptors passed via SCM_RIGHTS */
return 0;
}
+static void monitor_user_noop(Monitor *mon, const QObject *data) { }
+
+static inline int monitor_handler_ported(const mon_cmd_t *cmd)
+{
+ return cmd->user_print != NULL;
+}
+
+static void monitor_print_qobject(Monitor *mon, const QObject *data)
+{
+ switch (qobject_type(data)) {
+ case QTYPE_QSTRING:
+ monitor_printf(mon, "%s",qstring_get_str(qobject_to_qstring(data)));
+ break;
+ case QTYPE_QINT:
+ monitor_printf(mon, "%" PRId64,qint_get_int(qobject_to_qint(data)));
+ break;
+ default:
+ monitor_printf(mon, "ERROR: unsupported type: %d",
+ qobject_type(data));
+ break;
+ }
+
+ monitor_puts(mon, "\n");
+}
+
static int compare_cmd(const char *name, const char *list)
{
const char *p, *pstart;
}
}
-static void do_info(Monitor *mon, const QDict *qdict)
+static void do_info(Monitor *mon, const QDict *qdict, QObject **ret_data)
{
const mon_cmd_t *cmd;
const char *item = qdict_get_try_str(qdict, "item");
- void (*handler)(Monitor *);
if (!item)
goto help;
- for(cmd = info_cmds; cmd->name != NULL; cmd++) {
+
+ for (cmd = info_cmds; cmd->name != NULL; cmd++) {
if (compare_cmd(item, cmd->name))
- goto found;
+ break;
}
- help:
- help_cmd(mon, "info");
+
+ if (cmd->name == NULL)
+ goto help;
+
+ if (monitor_handler_ported(cmd)) {
+ cmd->mhandler.info_new(mon, ret_data);
+ if (*ret_data)
+ cmd->user_print(mon, *ret_data);
+ } else {
+ cmd->mhandler.info(mon);
+ }
+
return;
- found:
- handler = cmd->handler;
- handler(mon);
+
+help:
+ help_cmd(mon, "info");
}
-static void do_info_version(Monitor *mon)
+/**
+ * do_info_version(): Show QEMU version
+ */
+static void do_info_version(Monitor *mon, QObject **ret_data)
{
- monitor_printf(mon, "%s\n", QEMU_VERSION QEMU_PKGVERSION);
+ *ret_data = QOBJECT(qstring_from_str(QEMU_VERSION QEMU_PKGVERSION));
}
static void do_info_name(Monitor *mon)
#endif
}
-static void do_info_cpus(Monitor *mon)
+static void print_cpu_iter(QObject *obj, void *opaque)
+{
+ QDict *cpu;
+ int active = ' ';
+ Monitor *mon = opaque;
+
+ assert(qobject_type(obj) == QTYPE_QDICT);
+ cpu = qobject_to_qdict(obj);
+
+ if (strcmp(qdict_get_str(cpu, "current"), "yes") == 0)
+ active = '*';
+
+ monitor_printf(mon, "%c CPU #%d: ", active, (int)qdict_get_int(cpu, "CPU"));
+
+#if defined(TARGET_I386)
+ monitor_printf(mon, "pc=0x" TARGET_FMT_lx,
+ (target_ulong) qdict_get_int(cpu, "pc"));
+#elif defined(TARGET_PPC)
+ monitor_printf(mon, "nip=0x" TARGET_FMT_lx,
+ (target_long) qdict_get_int(cpu, "nip"));
+#elif defined(TARGET_SPARC)
+ monitor_printf(mon, "pc=0x " TARGET_FMT_lx,
+ (target_long) qdict_get_int(cpu, "pc"));
+ monitor_printf(mon, "npc=0x" TARGET_FMT_lx,
+ (target_long) qdict_get_int(cpu, "npc"));
+#elif defined(TARGET_MIPS)
+ monitor_printf(mon, "PC=0x" TARGET_FMT_lx,
+ (target_long) qdict_get_int(cpu, "PC"));
+#endif
+
+ if (strcmp(qdict_get_str(cpu, "halted"), "yes") == 0)
+ monitor_printf(mon, " (halted)");
+
+ monitor_printf(mon, "\n");
+}
+
+static void monitor_print_cpus(Monitor *mon, const QObject *data)
+{
+ QList *cpu_list;
+
+ assert(qobject_type(data) == QTYPE_QLIST);
+ cpu_list = qobject_to_qlist(data);
+ qlist_iter(cpu_list, print_cpu_iter, mon);
+}
+
+/**
+ * do_info_cpus(): Show CPU information
+ *
+ * Return a QList with a QDict for each CPU.
+ *
+ * For example:
+ *
+ * [ { "CPU": 0, "current": "yes", "pc": 0x..., "halted": "no" },
+ * { "CPU": 1, "current": "no", "pc": 0x..., "halted": "yes" } ]
+ */
+static void do_info_cpus(Monitor *mon, QObject **ret_data)
{
CPUState *env;
+ QList *cpu_list;
+
+ cpu_list = qlist_new();
/* just to set the default cpu if not already done */
mon_get_cpu();
for(env = first_cpu; env != NULL; env = env->next_cpu) {
+ const char *answer;
+ QDict *cpu = qdict_new();
+
cpu_synchronize_state(env);
- monitor_printf(mon, "%c CPU #%d:",
- (env == mon->mon_cpu) ? '*' : ' ',
- env->cpu_index);
+
+ qdict_put(cpu, "CPU", qint_from_int(env->cpu_index));
+ answer = (env == mon->mon_cpu) ? "yes" : "no";
+ qdict_put(cpu, "current", qstring_from_str(answer));
+
#if defined(TARGET_I386)
- monitor_printf(mon, " pc=0x" TARGET_FMT_lx,
- env->eip + env->segs[R_CS].base);
+ qdict_put(cpu, "pc", qint_from_int(env->eip + env->segs[R_CS].base));
#elif defined(TARGET_PPC)
- monitor_printf(mon, " nip=0x" TARGET_FMT_lx, env->nip);
+ qdict_put(cpu, "nip", qint_from_int(env->nip));
#elif defined(TARGET_SPARC)
- monitor_printf(mon, " pc=0x" TARGET_FMT_lx " npc=0x" TARGET_FMT_lx,
- env->pc, env->npc);
+ qdict_put(cpu, "pc", qint_from_int(env->pc));
+ qdict_put(cpu, "npc", qint_from_int(env->npc));
#elif defined(TARGET_MIPS)
- monitor_printf(mon, " PC=0x" TARGET_FMT_lx, env->active_tc.PC);
+ qdict_put(cpu, "PC", qint_from_int(env->active_tc.PC));
#endif
- if (env->halted)
- monitor_printf(mon, " (halted)");
- monitor_printf(mon, "\n");
+ answer = env->halted ? "yes" : "no";
+ qdict_put(cpu, "halted", qstring_from_str(answer));
+
+ qlist_append(cpu_list, cpu);
}
+
+ *ret_data = QOBJECT(cpu_list);
}
static void do_cpu_set(Monitor *mon, const QDict *qdict)
}
#endif
-static void do_quit(Monitor *mon, const QDict *qdict)
+/**
+ * do_quit(): Quit QEMU execution
+ */
+static void do_quit(Monitor *mon, const QDict *qdict, QObject **ret_data)
{
exit(0);
}
}
}
-static void do_stop(Monitor *mon, const QDict *qdict)
+/**
+ * do_stop(): Stop VM execution
+ */
+static void do_stop(Monitor *mon, const QDict *qdict, QObject **ret_data)
{
vm_stop(EXCP_INTERRUPT);
}
int err;
};
-static void do_cont(Monitor *mon, const QDict *qdict)
+/**
+ * do_cont(): Resume emulation.
+ */
+static void do_cont(Monitor *mon, const QDict *qdict, QObject **ret_data)
{
struct bdrv_iterate_context context = { mon, 0 };
/* another key was set successfully, retry to continue */
if (!err)
- do_cont(mon, NULL);
+ do_cont(mon, NULL, NULL);
}
static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs)
}
}
-static void do_system_reset(Monitor *mon, const QDict *qdict)
+/**
+ * do_system_reset(): Issue a machine reset
+ */
+static void do_system_reset(Monitor *mon, const QDict *qdict,
+ QObject **ret_data)
{
qemu_system_reset_request();
}
-static void do_system_powerdown(Monitor *mon, const QDict *qdict)
+/**
+ * do_system_powerdown(): Issue a machine powerdown
+ */
+static void do_system_powerdown(Monitor *mon, const QDict *qdict,
+ QObject **ret_data)
{
qemu_system_powerdown_request();
}
#ifdef CONFIG_PROFILER
+int64_t qemu_time;
+int64_t dev_time;
+
static void do_info_profile(Monitor *mon)
{
int64_t total;
monitor_printf(mon, "VM status: paused\n");
}
-
-static void do_balloon(Monitor *mon, const QDict *qdict)
+/**
+ * do_balloon(): Request VM to change its memory allocation
+ */
+static void do_balloon(Monitor *mon, const QDict *qdict, QObject **ret_data)
{
int value = qdict_get_int(qdict, "value");
ram_addr_t target = value;
qemu_balloon(target << 20);
}
-static void do_info_balloon(Monitor *mon)
+static void monitor_print_balloon(Monitor *mon, const QObject *data)
+{
+ monitor_printf(mon, "balloon: actual=%d\n",
+ (int)qint_get_int(qobject_to_qint(data)));
+}
+
+/**
+ * do_info_balloon(): Balloon information
+ */
+static void do_info_balloon(Monitor *mon, QObject **ret_data)
{
ram_addr_t actual;
else if (actual == 0)
monitor_printf(mon, "Ballooning not activated in VM\n");
else
- monitor_printf(mon, "balloon: actual=%d\n", (int)(actual >> 20));
+ *ret_data = QOBJECT(qint_from_int((int)(actual >> 20)));
}
static qemu_acl *find_acl(Monitor *mon, const char *name)
/* Please update qemu-monitor.hx when adding or changing commands */
static const mon_cmd_t info_cmds[] = {
- { "version", "", do_info_version,
- "", "show the version of QEMU" },
- { "network", "", do_info_network,
- "", "show the network state" },
- { "chardev", "", qemu_chr_info,
- "", "show the character devices" },
- { "block", "", bdrv_info,
- "", "show the block devices" },
- { "blockstats", "", bdrv_info_stats,
- "", "show block device statistics" },
- { "registers", "", do_info_registers,
- "", "show the cpu registers" },
- { "cpus", "", do_info_cpus,
- "", "show infos for each CPU" },
- { "history", "", do_info_history,
- "", "show the command line history", },
- { "irq", "", irq_info,
- "", "show the interrupts statistics (if available)", },
- { "pic", "", pic_info,
- "", "show i8259 (PIC) state", },
- { "pci", "", pci_info,
- "", "show PCI info", },
+ {
+ .name = "version",
+ .args_type = "",
+ .params = "",
+ .help = "show the version of QEMU",
+ .user_print = monitor_print_qobject,
+ .mhandler.info_new = do_info_version,
+ },
+ {
+ .name = "network",
+ .args_type = "",
+ .params = "",
+ .help = "show the network state",
+ .mhandler.info = do_info_network,
+ },
+ {
+ .name = "chardev",
+ .args_type = "",
+ .params = "",
+ .help = "show the character devices",
+ .mhandler.info = qemu_chr_info,
+ },
+ {
+ .name = "block",
+ .args_type = "",
+ .params = "",
+ .help = "show the block devices",
+ .mhandler.info = bdrv_info,
+ },
+ {
+ .name = "blockstats",
+ .args_type = "",
+ .params = "",
+ .help = "show block device statistics",
+ .mhandler.info = bdrv_info_stats,
+ },
+ {
+ .name = "registers",
+ .args_type = "",
+ .params = "",
+ .help = "show the cpu registers",
+ .mhandler.info = do_info_registers,
+ },
+ {
+ .name = "cpus",
+ .args_type = "",
+ .params = "",
+ .help = "show infos for each CPU",
+ .user_print = monitor_print_cpus,
+ .mhandler.info_new = do_info_cpus,
+ },
+ {
+ .name = "history",
+ .args_type = "",
+ .params = "",
+ .help = "show the command line history",
+ .mhandler.info = do_info_history,
+ },
+ {
+ .name = "irq",
+ .args_type = "",
+ .params = "",
+ .help = "show the interrupts statistics (if available)",
+ .mhandler.info = irq_info,
+ },
+ {
+ .name = "pic",
+ .args_type = "",
+ .params = "",
+ .help = "show i8259 (PIC) state",
+ .mhandler.info = pic_info,
+ },
+ {
+ .name = "pci",
+ .args_type = "",
+ .params = "",
+ .help = "show PCI info",
+ .mhandler.info = pci_info,
+ },
#if defined(TARGET_I386) || defined(TARGET_SH4)
- { "tlb", "", tlb_info,
- "", "show virtual to physical memory mappings", },
+ {
+ .name = "tlb",
+ .args_type = "",
+ .params = "",
+ .help = "show virtual to physical memory mappings",
+ .mhandler.info = tlb_info,
+ },
#endif
#if defined(TARGET_I386)
- { "mem", "", mem_info,
- "", "show the active virtual memory mappings", },
- { "hpet", "", do_info_hpet,
- "", "show state of HPET", },
+ {
+ .name = "mem",
+ .args_type = "",
+ .params = "",
+ .help = "show the active virtual memory mappings",
+ .mhandler.info = mem_info,
+ },
+ {
+ .name = "hpet",
+ .args_type = "",
+ .params = "",
+ .help = "show state of HPET",
+ .mhandler.info = do_info_hpet,
+ },
#endif
- { "jit", "", do_info_jit,
- "", "show dynamic compiler info", },
- { "kvm", "", do_info_kvm,
- "", "show KVM information", },
- { "numa", "", do_info_numa,
- "", "show NUMA information", },
- { "usb", "", usb_info,
- "", "show guest USB devices", },
- { "usbhost", "", usb_host_info,
- "", "show host USB devices", },
- { "profile", "", do_info_profile,
- "", "show profiling information", },
- { "capture", "", do_info_capture,
- "", "show capture information" },
- { "snapshots", "", do_info_snapshots,
- "", "show the currently saved VM snapshots" },
- { "status", "", do_info_status,
- "", "show the current VM status (running|paused)" },
- { "pcmcia", "", pcmcia_info,
- "", "show guest PCMCIA status" },
- { "mice", "", do_info_mice,
- "", "show which guest mouse is receiving events" },
- { "vnc", "", do_info_vnc,
- "", "show the vnc server status"},
- { "name", "", do_info_name,
- "", "show the current VM name" },
- { "uuid", "", do_info_uuid,
- "", "show the current VM UUID" },
+ {
+ .name = "jit",
+ .args_type = "",
+ .params = "",
+ .help = "show dynamic compiler info",
+ .mhandler.info = do_info_jit,
+ },
+ {
+ .name = "kvm",
+ .args_type = "",
+ .params = "",
+ .help = "show KVM information",
+ .mhandler.info = do_info_kvm,
+ },
+ {
+ .name = "numa",
+ .args_type = "",
+ .params = "",
+ .help = "show NUMA information",
+ .mhandler.info = do_info_numa,
+ },
+ {
+ .name = "usb",
+ .args_type = "",
+ .params = "",
+ .help = "show guest USB devices",
+ .mhandler.info = usb_info,
+ },
+ {
+ .name = "usbhost",
+ .args_type = "",
+ .params = "",
+ .help = "show host USB devices",
+ .mhandler.info = usb_host_info,
+ },
+ {
+ .name = "profile",
+ .args_type = "",
+ .params = "",
+ .help = "show profiling information",
+ .mhandler.info = do_info_profile,
+ },
+ {
+ .name = "capture",
+ .args_type = "",
+ .params = "",
+ .help = "show capture information",
+ .mhandler.info = do_info_capture,
+ },
+ {
+ .name = "snapshots",
+ .args_type = "",
+ .params = "",
+ .help = "show the currently saved VM snapshots",
+ .mhandler.info = do_info_snapshots,
+ },
+ {
+ .name = "status",
+ .args_type = "",
+ .params = "",
+ .help = "show the current VM status (running|paused)",
+ .mhandler.info = do_info_status,
+ },
+ {
+ .name = "pcmcia",
+ .args_type = "",
+ .params = "",
+ .help = "show guest PCMCIA status",
+ .mhandler.info = pcmcia_info,
+ },
+ {
+ .name = "mice",
+ .args_type = "",
+ .params = "",
+ .help = "show which guest mouse is receiving events",
+ .mhandler.info = do_info_mice,
+ },
+ {
+ .name = "vnc",
+ .args_type = "",
+ .params = "",
+ .help = "show the vnc server status",
+ .mhandler.info = do_info_vnc,
+ },
+ {
+ .name = "name",
+ .args_type = "",
+ .params = "",
+ .help = "show the current VM name",
+ .mhandler.info = do_info_name,
+ },
+ {
+ .name = "uuid",
+ .args_type = "",
+ .params = "",
+ .help = "show the current VM UUID",
+ .mhandler.info = do_info_uuid,
+ },
#if defined(TARGET_PPC)
- { "cpustats", "", do_info_cpu_stats,
- "", "show CPU statistics", },
+ {
+ .name = "cpustats",
+ .args_type = "",
+ .params = "",
+ .help = "show CPU statistics",
+ .mhandler.info = do_info_cpu_stats,
+ },
#endif
#if defined(CONFIG_SLIRP)
- { "usernet", "", do_info_usernet,
- "", "show user network stack connection states", },
+ {
+ .name = "usernet",
+ .args_type = "",
+ .params = "",
+ .help = "show user network stack connection states",
+ .mhandler.info = do_info_usernet,
+ },
#endif
- { "migrate", "", do_info_migrate, "", "show migration status" },
- { "balloon", "", do_info_balloon,
- "", "show balloon information" },
- { "qtree", "", do_info_qtree,
- "", "show device tree" },
- { "qdm", "", do_info_qdm,
- "", "show qdev device model list" },
- { NULL, NULL, },
+ {
+ .name = "migrate",
+ .args_type = "",
+ .params = "",
+ .help = "show migration status",
+ .mhandler.info = do_info_migrate,
+ },
+ {
+ .name = "balloon",
+ .args_type = "",
+ .params = "",
+ .help = "show balloon information",
+ .user_print = monitor_print_balloon,
+ .mhandler.info_new = do_info_balloon,
+ },
+ {
+ .name = "qtree",
+ .args_type = "",
+ .params = "",
+ .help = "show device tree",
+ .mhandler.info = do_info_qtree,
+ },
+ {
+ .name = "qdm",
+ .args_type = "",
+ .params = "",
+ .help = "show qdev device model list",
+ .mhandler.info = do_info_qdm,
+ },
+ {
+ .name = "roms",
+ .args_type = "",
+ .params = "",
+ .help = "show roms",
+ .mhandler.info = do_info_roms,
+ },
+ {
+ .name = NULL,
+ },
};
/*******************************************************************/
qdict = qdict_new();
cmd = monitor_parse_command(mon, cmdline, qdict);
- if (cmd) {
- void (*handler)(Monitor *mon, const QDict *qdict);
+ if (!cmd)
+ goto out;
+
+ qemu_errors_to_mon(mon);
- qemu_errors_to_mon(mon);
+ if (monitor_handler_ported(cmd)) {
+ QObject *data = NULL;
- handler = cmd->handler;
- handler(mon, qdict);
+ cmd->mhandler.cmd_new(mon, qdict, &data);
+ if (data)
+ cmd->user_print(mon, data);
- qemu_errors_to_previous();
+ qobject_decref(data);
+ } else {
+ cmd->mhandler.cmd(mon, qdict);
}
+ qemu_errors_to_previous();
+
+out:
QDECREF(qdict);
}