#include "qemu/osdep.h"
#include "monitor-internal.h"
-#include "cpu.h"
#include "monitor/qdev.h"
#include "hw/usb.h"
#include "hw/pci/pci.h"
#include "disas/disas.h"
#include "sysemu/balloon.h"
#include "qemu/timer.h"
+#include "qemu/log.h"
#include "sysemu/hw_accel.h"
#include "sysemu/runstate.h"
#include "authz/list.h"
#include "qapi/util.h"
#include "sysemu/blockdev.h"
#include "sysemu/sysemu.h"
-#include "sysemu/tcg.h"
#include "sysemu/tpm.h"
+#include "sysemu/device_tree.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qerror.h"
#include "qapi/qmp/qstring.h"
#include "qapi/qapi-commands-migration.h"
#include "qapi/qapi-commands-misc.h"
#include "qapi/qapi-commands-qom.h"
+#include "qapi/qapi-commands-run-state.h"
#include "qapi/qapi-commands-trace.h"
+#include "qapi/qapi-commands-machine.h"
#include "qapi/qapi-init-commands.h"
#include "qapi/error.h"
#include "qapi/qmp-event.h"
#include "sysemu/cpus.h"
#include "qemu/cutils.h"
-#include "tcg/tcg.h"
#if defined(TARGET_S390X)
#include "hw/s390x/storage-keys.h"
#include "hw/s390x/storage-attributes.h"
#endif
+/* Make devices configuration available for use in hmp-commands*.hx templates */
+#include CONFIG_DEVICES
+
/* file descriptors passed via SCM_RIGHTS */
typedef struct mon_fd_t mon_fd_t;
struct mon_fd_t {
qmp_init_marshal(&qmp_commands);
- qmp_register_command(&qmp_commands, "query-qmp-schema",
- qmp_query_qmp_schema, QCO_ALLOW_PRECONFIG);
- qmp_register_command(&qmp_commands, "device_add", qmp_device_add,
- QCO_NO_OPTIONS);
- qmp_register_command(&qmp_commands, "object-add", qmp_object_add,
- QCO_NO_OPTIONS);
+ qmp_register_command(&qmp_commands, "device_add",
+ qmp_device_add, 0, 0);
QTAILQ_INIT(&qmp_cap_negotiation_commands);
qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities",
- qmp_marshal_qmp_capabilities, QCO_ALLOW_PRECONFIG);
+ qmp_marshal_qmp_capabilities,
+ QCO_ALLOW_PRECONFIG, 0);
}
/* Set the current CPU defined by the user. Callers must hold BQL. */
static void hmp_info_registers(Monitor *mon, const QDict *qdict)
{
bool all_cpus = qdict_get_try_bool(qdict, "cpustate_all", false);
+ int vcpu = qdict_get_try_int(qdict, "vcpu", -1);
CPUState *cs;
if (all_cpus) {
cpu_dump_state(cs, NULL, CPU_DUMP_FPU);
}
} else {
- cs = mon_get_cpu(mon);
+ cs = vcpu >= 0 ? qemu_get_cpu(vcpu) : mon_get_cpu(mon);
if (!cs) {
- monitor_printf(mon, "No CPU available\n");
+ if (vcpu >= 0) {
+ monitor_printf(mon, "CPU#%d not available\n", vcpu);
+ } else {
+ monitor_printf(mon, "No CPU available\n");
+ }
return;
}
+ monitor_printf(mon, "\nCPU#%d\n", cs->cpu_index);
cpu_dump_state(cs, NULL, CPU_DUMP_FPU);
}
}
-#ifdef CONFIG_TCG
-static void hmp_info_jit(Monitor *mon, const QDict *qdict)
-{
- if (!tcg_enabled()) {
- error_report("JIT information is only available with accel=tcg");
- return;
- }
-
- dump_exec_info();
- dump_drift_info();
-}
-
-static void hmp_info_opcount(Monitor *mon, const QDict *qdict)
-{
- dump_opcount_info();
-}
-#endif
-
static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
{
int64_t max = qdict_get_try_int(qdict, "max", 10);
}
}
-static void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
-{
- CPUState *cs = mon_get_cpu(mon);
-
- if (!cs) {
- monitor_printf(mon, "No CPU available\n");
- return;
- }
- cpu_dump_statistics(cs, 0);
-}
-
static void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
{
const char *name = qdict_get_try_str(qdict, "name");
{
Error *err = NULL;
- qemu_set_log_filename(qdict_get_str(qdict, "filename"), &err);
- if (err) {
+ if (!qemu_set_log_filename(qdict_get_str(qdict, "filename"), &err)) {
error_report_err(err);
}
}
{
int mask;
const char *items = qdict_get_str(qdict, "items");
+ Error *err = NULL;
if (!strcmp(items, "none")) {
mask = 0;
return;
}
}
- qemu_set_log(mask);
+
+ if (!qemu_set_log(mask, &err)) {
+ error_report_err(err);
+ }
}
static void hmp_singlestep(Monitor *mon, const QDict *qdict)
static void hmp_gdbserver(Monitor *mon, const QDict *qdict)
{
const char *device = qdict_get_try_str(qdict, "device");
- if (!device)
+ if (!device) {
device = "tcp::" DEFAULT_GDBSTUB_PORT;
+ }
+
if (gdbserver_start(device) < 0) {
monitor_printf(mon, "Could not open gdbserver on device '%s'\n",
device);
static void hmp_watchdog_action(Monitor *mon, const QDict *qdict)
{
- const char *action = qdict_get_str(qdict, "action");
- if (select_watchdog_action(action) == -1) {
- monitor_printf(mon, "Unknown watchdog action '%s'\n", action);
+ Error *err = NULL;
+ WatchdogAction action;
+ char *qapi_value;
+
+ qapi_value = g_ascii_strdown(qdict_get_str(qdict, "action"), -1);
+ action = qapi_enum_parse(&WatchdogAction_lookup, qapi_value, -1, &err);
+ g_free(qapi_value);
+ if (err) {
+ hmp_handle_error(mon, err);
+ return;
}
+ qmp_watchdog_set_action(action, &error_abort);
}
static void monitor_printc(Monitor *mon, int c)
}
len = wsize * count;
- if (wsize == 1)
+ if (wsize == 1) {
line_size = 8;
- else
+ } else {
line_size = 16;
+ }
max_digits = 0;
switch(format) {
}
while (len > 0) {
- if (is_physical)
+ if (is_physical) {
monitor_printf(mon, TARGET_FMT_plx ":", addr);
- else
+ } else {
monitor_printf(mon, TARGET_FMT_lx ":", (target_ulong)addr);
+ }
l = len;
if (l > line_size)
l = line_size;
uint64_t pinfo;
uint64_t ret = -1;
uintptr_t addr = (uintptr_t) ptr;
- uintptr_t pagesize = qemu_real_host_page_size;
+ uintptr_t pagesize = qemu_real_host_page_size();
off_t offset = addr / pagesize * sizeof(pinfo);
int fd;
suffix = 'l';
break;
}
- monitor_printf(mon, "port%c[0x%04x] = %#0*x\n",
+ monitor_printf(mon, "port%c[0x%04x] = 0x%0*x\n",
suffix, addr, size * 2, val);
}
mtree_info(flatview, dispatch_tree, owner, disabled);
}
-#ifdef CONFIG_PROFILER
-
-int64_t dev_time;
-
-static void hmp_info_profile(Monitor *mon, const QDict *qdict)
-{
- static int64_t last_cpu_exec_time;
- int64_t cpu_exec_time;
- int64_t delta;
-
- cpu_exec_time = tcg_cpu_exec_time();
- delta = cpu_exec_time - last_cpu_exec_time;
-
- monitor_printf(mon, "async time %" PRId64 " (%0.3f)\n",
- dev_time, dev_time / (double)NANOSECONDS_PER_SECOND);
- monitor_printf(mon, "qemu time %" PRId64 " (%0.3f)\n",
- delta, delta / (double)NANOSECONDS_PER_SECOND);
- last_cpu_exec_time = cpu_exec_time;
- dev_time = 0;
-}
-#else
-static void hmp_info_profile(Monitor *mon, const QDict *qdict)
-{
- monitor_printf(mon, "Internal profiler not compiled\n");
-}
-#endif
-
/* Capture support */
static QLIST_HEAD (capture_list_head, CaptureState) capture_head;
QLIST_INSERT_HEAD (&capture_head, s, entries);
}
-static QAuthZList *find_auth(Monitor *mon, const char *name)
-{
- Object *obj;
- Object *container;
-
- container = object_get_objects_root();
- obj = object_resolve_path_component(container, name);
- if (!obj) {
- monitor_printf(mon, "acl: unknown list '%s'\n", name);
- return NULL;
- }
-
- return QAUTHZ_LIST(obj);
-}
-
-static bool warn_acl;
-static void hmp_warn_acl(void)
-{
- if (warn_acl) {
- return;
- }
- error_report("The acl_show, acl_reset, acl_policy, acl_add, acl_remove "
- "commands are deprecated with no replacement. Authorization "
- "for VNC should be performed using the pluggable QAuthZ "
- "objects");
- warn_acl = true;
-}
-
-static void hmp_acl_show(Monitor *mon, const QDict *qdict)
-{
- const char *aclname = qdict_get_str(qdict, "aclname");
- QAuthZList *auth = find_auth(mon, aclname);
- QAuthZListRuleList *rules;
- size_t i = 0;
-
- hmp_warn_acl();
-
- if (!auth) {
- return;
- }
-
- monitor_printf(mon, "policy: %s\n",
- QAuthZListPolicy_str(auth->policy));
-
- rules = auth->rules;
- while (rules) {
- QAuthZListRule *rule = rules->value;
- i++;
- monitor_printf(mon, "%zu: %s %s\n", i,
- QAuthZListPolicy_str(rule->policy),
- rule->match);
- rules = rules->next;
- }
-}
-
-static void hmp_acl_reset(Monitor *mon, const QDict *qdict)
-{
- const char *aclname = qdict_get_str(qdict, "aclname");
- QAuthZList *auth = find_auth(mon, aclname);
-
- hmp_warn_acl();
-
- if (!auth) {
- return;
- }
-
- auth->policy = QAUTHZ_LIST_POLICY_DENY;
- qapi_free_QAuthZListRuleList(auth->rules);
- auth->rules = NULL;
- monitor_printf(mon, "acl: removed all rules\n");
-}
-
-static void hmp_acl_policy(Monitor *mon, const QDict *qdict)
-{
- const char *aclname = qdict_get_str(qdict, "aclname");
- const char *policy = qdict_get_str(qdict, "policy");
- QAuthZList *auth = find_auth(mon, aclname);
- int val;
- Error *err = NULL;
-
- hmp_warn_acl();
-
- if (!auth) {
- return;
- }
-
- val = qapi_enum_parse(&QAuthZListPolicy_lookup,
- policy,
- QAUTHZ_LIST_POLICY_DENY,
- &err);
- if (err) {
- error_free(err);
- monitor_printf(mon, "acl: unknown policy '%s', "
- "expected 'deny' or 'allow'\n", policy);
- } else {
- auth->policy = val;
- if (auth->policy == QAUTHZ_LIST_POLICY_ALLOW) {
- monitor_printf(mon, "acl: policy set to 'allow'\n");
- } else {
- monitor_printf(mon, "acl: policy set to 'deny'\n");
- }
- }
-}
-
-static QAuthZListFormat hmp_acl_get_format(const char *match)
-{
- if (strchr(match, '*')) {
- return QAUTHZ_LIST_FORMAT_GLOB;
- } else {
- return QAUTHZ_LIST_FORMAT_EXACT;
- }
-}
-
-static void hmp_acl_add(Monitor *mon, const QDict *qdict)
-{
- const char *aclname = qdict_get_str(qdict, "aclname");
- const char *match = qdict_get_str(qdict, "match");
- const char *policystr = qdict_get_str(qdict, "policy");
- int has_index = qdict_haskey(qdict, "index");
- int index = qdict_get_try_int(qdict, "index", -1);
- QAuthZList *auth = find_auth(mon, aclname);
- Error *err = NULL;
- QAuthZListPolicy policy;
- QAuthZListFormat format;
- size_t i = 0;
-
- hmp_warn_acl();
-
- if (!auth) {
- return;
- }
-
- policy = qapi_enum_parse(&QAuthZListPolicy_lookup,
- policystr,
- QAUTHZ_LIST_POLICY_DENY,
- &err);
- if (err) {
- error_free(err);
- monitor_printf(mon, "acl: unknown policy '%s', "
- "expected 'deny' or 'allow'\n", policystr);
- return;
- }
-
- format = hmp_acl_get_format(match);
-
- if (has_index && index == 0) {
- monitor_printf(mon, "acl: unable to add acl entry\n");
- return;
- }
-
- if (has_index) {
- i = qauthz_list_insert_rule(auth, match, policy,
- format, index - 1, &err);
- } else {
- i = qauthz_list_append_rule(auth, match, policy,
- format, &err);
- }
- if (err) {
- monitor_printf(mon, "acl: unable to add rule: %s",
- error_get_pretty(err));
- error_free(err);
- } else {
- monitor_printf(mon, "acl: added rule at position %zu\n", i + 1);
- }
-}
-
-static void hmp_acl_remove(Monitor *mon, const QDict *qdict)
-{
- const char *aclname = qdict_get_str(qdict, "aclname");
- const char *match = qdict_get_str(qdict, "match");
- QAuthZList *auth = find_auth(mon, aclname);
- ssize_t i = 0;
-
- hmp_warn_acl();
-
- if (!auth) {
- return;
- }
-
- i = qauthz_list_delete_rule(auth, match);
- if (i >= 0) {
- monitor_printf(mon, "acl: removed rule at position %zu\n", i + 1);
- } else {
- monitor_printf(mon, "acl: no matching acl entry\n");
- }
-}
-
void qmp_getfd(const char *fdname, Error **errp)
{
Monitor *cur_mon = monitor_cur();
return;
}
- monfd = g_malloc0(sizeof(mon_fd_t));
+ monfd = g_new0(mon_fd_t, 1);
monfd->name = g_strdup(fdname);
monfd->fd = fd;
TraceEventIter iter;
TraceEvent *ev;
char *pattern = g_strdup_printf("%s*", str);
- trace_event_iter_init(&iter, pattern);
+ trace_event_iter_init_pattern(&iter, pattern);
while ((ev = trace_event_iter_next(&iter)) != NULL) {
readline_add_completion(rs, trace_event_get_name(ev));
}
TraceEventIter iter;
TraceEvent *ev;
char *pattern = g_strdup_printf("%s*", str);
- trace_event_iter_init(&iter, pattern);
+ trace_event_iter_init_pattern(&iter, pattern);
while ((ev = trace_event_iter_next(&iter)) != NULL) {
readline_add_completion(rs, trace_event_get_name(ev));
}
compare_mon_cmd);
}
+void monitor_register_hmp(const char *name, bool info,
+ void (*cmd)(Monitor *mon, const QDict *qdict))
+{
+ HMPCommand *table = info ? hmp_info_cmds : hmp_cmds;
+
+ while (table->name != NULL) {
+ if (strcmp(table->name, name) == 0) {
+ g_assert(table->cmd == NULL && table->cmd_info_hrt == NULL);
+ table->cmd = cmd;
+ return;
+ }
+ table++;
+ }
+ g_assert_not_reached();
+}
+
+void monitor_register_hmp_info_hrt(const char *name,
+ HumanReadableText *(*handler)(Error **errp))
+{
+ HMPCommand *table = hmp_info_cmds;
+
+ while (table->name != NULL) {
+ if (strcmp(table->name, name) == 0) {
+ g_assert(table->cmd == NULL && table->cmd_info_hrt == NULL);
+ table->cmd_info_hrt = handler;
+ return;
+ }
+ table++;
+ }
+ g_assert_not_reached();
+}
+
void monitor_init_globals(void)
{
monitor_init_globals_core();