2004-03-15 00:38:27 +03:00
|
|
|
/*
|
|
|
|
* QEMU monitor
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2004-03-15 00:38:27 +03:00
|
|
|
* Copyright (c) 2003-2004 Fabrice Bellard
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2004-03-15 00:38:27 +03:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2018-02-01 14:18:31 +03:00
|
|
|
|
2016-01-29 20:50:05 +03:00
|
|
|
#include "qemu/osdep.h"
|
2019-06-13 18:33:59 +03:00
|
|
|
#include "monitor-internal.h"
|
2013-02-04 14:37:52 +04:00
|
|
|
#include "monitor/qdev.h"
|
2007-11-17 20:14:51 +03:00
|
|
|
#include "hw/usb.h"
|
2012-12-12 16:24:50 +04:00
|
|
|
#include "hw/pci/pci.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "sysemu/watchdog.h"
|
2009-10-01 18:42:33 +04:00
|
|
|
#include "hw/loader.h"
|
2012-12-17 21:19:49 +04:00
|
|
|
#include "exec/gdbstub.h"
|
2012-10-24 10:43:34 +04:00
|
|
|
#include "net/net.h"
|
2009-11-25 21:48:54 +03:00
|
|
|
#include "net/slirp.h"
|
2010-10-07 14:22:54 +04:00
|
|
|
#include "ui/qemu-spice.h"
|
2016-12-12 20:22:24 +03:00
|
|
|
#include "qemu/config-file.h"
|
2019-05-23 17:35:06 +03:00
|
|
|
#include "qemu/ctype.h"
|
2012-11-28 15:06:30 +04:00
|
|
|
#include "ui/console.h"
|
2013-12-04 18:02:28 +04:00
|
|
|
#include "ui/input.h"
|
2007-11-17 20:14:51 +03:00
|
|
|
#include "audio/audio.h"
|
2012-10-24 13:12:21 +04:00
|
|
|
#include "disas/disas.h"
|
2012-12-17 21:20:04 +04:00
|
|
|
#include "sysemu/balloon.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/timer.h"
|
2022-02-07 11:27:56 +03:00
|
|
|
#include "qemu/log.h"
|
2017-01-10 13:59:55 +03:00
|
|
|
#include "sysemu/hw_accel.h"
|
2019-08-12 08:23:59 +03:00
|
|
|
#include "sysemu/runstate.h"
|
2016-02-18 21:40:24 +03:00
|
|
|
#include "authz/list.h"
|
|
|
|
#include "qapi/util.h"
|
2019-06-19 23:10:44 +03:00
|
|
|
#include "sysemu/blockdev.h"
|
|
|
|
#include "sysemu/sysemu.h"
|
2013-04-02 20:28:41 +04:00
|
|
|
#include "sysemu/tpm.h"
|
2018-02-01 14:18:39 +03:00
|
|
|
#include "qapi/qmp/qdict.h"
|
2015-03-17 19:22:46 +03:00
|
|
|
#include "qapi/qmp/qerror.h"
|
2018-02-01 14:18:40 +03:00
|
|
|
#include "qapi/qmp/qstring.h"
|
2016-06-22 20:11:19 +03:00
|
|
|
#include "qom/object_interfaces.h"
|
2011-08-31 22:31:24 +04:00
|
|
|
#include "trace/control.h"
|
2015-09-10 18:38:59 +03:00
|
|
|
#include "monitor/hmp-target.h"
|
2019-06-19 23:10:36 +03:00
|
|
|
#include "monitor/hmp.h"
|
2011-08-31 22:30:43 +04:00
|
|
|
#ifdef CONFIG_TRACE_SIMPLE
|
2011-08-31 22:31:24 +04:00
|
|
|
#include "trace/simple.h"
|
2010-06-24 15:34:53 +04:00
|
|
|
#endif
|
2012-12-17 21:19:49 +04:00
|
|
|
#include "exec/memory.h"
|
2016-03-15 15:18:37 +03:00
|
|
|
#include "exec/exec-all.h"
|
2018-02-01 14:18:46 +03:00
|
|
|
#include "qemu/option.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/thread.h"
|
2014-05-28 02:39:37 +04:00
|
|
|
#include "block/qapi.h"
|
2020-03-08 12:24:32 +03:00
|
|
|
#include "block/block-hmp-cmds.h"
|
2019-11-20 21:25:48 +03:00
|
|
|
#include "qapi/qapi-commands-char.h"
|
2020-01-29 13:22:37 +03:00
|
|
|
#include "qapi/qapi-commands-control.h"
|
2019-11-20 21:25:48 +03:00
|
|
|
#include "qapi/qapi-commands-migration.h"
|
|
|
|
#include "qapi/qapi-commands-misc.h"
|
|
|
|
#include "qapi/qapi-commands-qom.h"
|
2021-10-27 16:03:04 +03:00
|
|
|
#include "qapi/qapi-commands-run-state.h"
|
2019-11-20 21:25:48 +03:00
|
|
|
#include "qapi/qapi-commands-trace.h"
|
2021-09-08 12:35:43 +03:00
|
|
|
#include "qapi/qapi-commands-machine.h"
|
2019-11-20 21:25:48 +03:00
|
|
|
#include "qapi/qapi-init-commands.h"
|
2018-02-01 14:18:31 +03:00
|
|
|
#include "qapi/error.h"
|
2014-06-18 10:43:31 +04:00
|
|
|
#include "qapi/qmp-event.h"
|
2017-03-03 14:01:16 +03:00
|
|
|
#include "sysemu/cpus.h"
|
2016-03-20 20:16:19 +03:00
|
|
|
#include "qemu/cutils.h"
|
2007-12-03 20:05:38 +03:00
|
|
|
|
2015-06-26 21:07:21 +03:00
|
|
|
#if defined(TARGET_S390X)
|
|
|
|
#include "hw/s390x/storage-keys.h"
|
2016-08-15 19:44:04 +03:00
|
|
|
#include "hw/s390x/storage-attributes.h"
|
2015-06-26 21:07:21 +03:00
|
|
|
#endif
|
|
|
|
|
2022-05-11 02:54:39 +03:00
|
|
|
/* Make devices configuration available for use in hmp-commands*.hx templates */
|
|
|
|
#include CONFIG_DEVICES
|
|
|
|
|
2009-07-22 12:11:40 +04:00
|
|
|
/* file descriptors passed via SCM_RIGHTS */
|
2009-10-02 01:12:16 +04:00
|
|
|
typedef struct mon_fd_t mon_fd_t;
|
|
|
|
struct mon_fd_t {
|
2009-07-22 12:11:40 +04:00
|
|
|
char *name;
|
|
|
|
int fd;
|
2009-10-02 01:12:16 +04:00
|
|
|
QLIST_ENTRY(mon_fd_t) next;
|
2009-07-22 12:11:40 +04:00
|
|
|
};
|
|
|
|
|
2012-08-15 00:43:43 +04:00
|
|
|
/* file descriptor associated with a file descriptor set */
|
|
|
|
typedef struct MonFdsetFd MonFdsetFd;
|
|
|
|
struct MonFdsetFd {
|
|
|
|
int fd;
|
|
|
|
bool removed;
|
|
|
|
char *opaque;
|
|
|
|
QLIST_ENTRY(MonFdsetFd) next;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* file descriptor set containing fds passed via SCM_RIGHTS */
|
|
|
|
typedef struct MonFdset MonFdset;
|
|
|
|
struct MonFdset {
|
|
|
|
int64_t id;
|
|
|
|
QLIST_HEAD(, MonFdsetFd) fds;
|
2012-08-15 00:43:47 +04:00
|
|
|
QLIST_HEAD(, MonFdsetFd) dup_fds;
|
2012-08-15 00:43:43 +04:00
|
|
|
QLIST_ENTRY(MonFdset) next;
|
|
|
|
};
|
|
|
|
|
2018-06-08 06:55:11 +03:00
|
|
|
/* Protects mon_fdsets */
|
|
|
|
static QemuMutex mon_fdsets_lock;
|
2018-12-06 13:58:10 +03:00
|
|
|
static QLIST_HEAD(, MonFdset) mon_fdsets;
|
2018-06-08 06:55:11 +03:00
|
|
|
|
2019-06-13 18:33:56 +03:00
|
|
|
static HMPCommand hmp_info_cmds[];
|
2004-03-15 00:38:27 +03:00
|
|
|
|
2011-11-25 23:52:45 +04:00
|
|
|
char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
|
|
|
|
int64_t cpu_index, Error **errp)
|
2010-10-22 16:08:02 +04:00
|
|
|
{
|
2011-11-25 23:52:45 +04:00
|
|
|
char *output = NULL;
|
2019-06-13 18:33:54 +03:00
|
|
|
MonitorHMP hmp = {};
|
2010-10-22 16:08:02 +04:00
|
|
|
|
2019-06-13 18:34:03 +03:00
|
|
|
monitor_data_init(&hmp.common, false, true, false);
|
2010-10-22 16:08:02 +04:00
|
|
|
|
2011-11-25 23:52:45 +04:00
|
|
|
if (has_cpu_index) {
|
2020-10-05 18:58:42 +03:00
|
|
|
int ret = monitor_set_cpu(&hmp.common, cpu_index);
|
2010-10-22 16:08:02 +04:00
|
|
|
if (ret < 0) {
|
2015-03-17 13:54:50 +03:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index",
|
|
|
|
"a CPU number");
|
2010-10-22 16:08:02 +04:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-06 21:12:36 +03:00
|
|
|
handle_hmp_command(&hmp, command_line);
|
2010-10-22 16:08:02 +04:00
|
|
|
|
2020-09-22 12:57:41 +03:00
|
|
|
WITH_QEMU_LOCK_GUARD(&hmp.common.mon_lock) {
|
2020-12-11 20:11:34 +03:00
|
|
|
output = g_strdup(hmp.common.outbuf->str);
|
2010-10-22 16:08:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2019-06-13 18:33:54 +03:00
|
|
|
monitor_data_destroy(&hmp.common);
|
2011-11-25 23:52:45 +04:00
|
|
|
return output;
|
2010-10-22 16:08:02 +04:00
|
|
|
}
|
|
|
|
|
2019-06-13 18:34:01 +03:00
|
|
|
/**
|
|
|
|
* Is @name in the '|' separated list of names @list?
|
|
|
|
*/
|
|
|
|
int hmp_compare_cmd(const char *name, const char *list)
|
2004-03-15 00:38:27 +03:00
|
|
|
{
|
|
|
|
const char *p, *pstart;
|
|
|
|
int len;
|
|
|
|
len = strlen(name);
|
|
|
|
p = list;
|
2019-06-13 18:34:01 +03:00
|
|
|
for (;;) {
|
2004-03-15 00:38:27 +03:00
|
|
|
pstart = p;
|
2018-06-29 13:32:10 +03:00
|
|
|
p = qemu_strchrnul(p, '|');
|
2019-06-13 18:34:01 +03:00
|
|
|
if ((p - pstart) == len && !memcmp(pstart, name, len)) {
|
2004-03-15 00:38:27 +03:00
|
|
|
return 1;
|
2013-08-27 16:38:21 +04:00
|
|
|
}
|
|
|
|
if (*p == '\0') {
|
|
|
|
break;
|
|
|
|
}
|
2019-06-13 18:34:01 +03:00
|
|
|
p++;
|
2013-08-27 16:38:21 +04:00
|
|
|
}
|
2013-08-27 16:38:22 +04:00
|
|
|
return 0;
|
2004-03-15 00:38:27 +03:00
|
|
|
}
|
|
|
|
|
2009-08-28 22:27:13 +04:00
|
|
|
static void do_help_cmd(Monitor *mon, const QDict *qdict)
|
2009-08-28 22:27:08 +04:00
|
|
|
{
|
2009-08-28 22:27:13 +04:00
|
|
|
help_cmd(mon, qdict_get_try_str(qdict, "name"));
|
2009-08-28 22:27:08 +04:00
|
|
|
}
|
|
|
|
|
hmp: Name HMP command handler functions hmp_COMMAND()
Some are called do_COMMAND() (old ones, usually), some hmp_COMMAND(),
and sometimes COMMAND pointlessly differs in spelling.
Normalize to hmp_COMMAND(), where COMMAND is exactly the command name
with '-' replaced by '_'.
Exceptions:
* do_device_add() and client_migrate_info() *not* renamed to
hmp_device_add(), hmp_client_migrate_info(), because they're also
QMP handlers. They still need to be converted to QAPI.
* do_memory_dump(), do_physical_memory_dump(), do_ioport_read(),
do_ioport_write() renamed do hmp_* instead of hmp_x(), hmp_xp(),
hmp_i(), hmp_o(), because those names are too cryptic for my taste.
* do_info_help() renamed to hmp_info_help() instead of hmp_info(),
because it only covers help.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-02-06 15:55:43 +03:00
|
|
|
static void hmp_trace_event(Monitor *mon, const QDict *qdict)
|
2010-06-24 15:34:53 +04:00
|
|
|
{
|
|
|
|
const char *tp_name = qdict_get_str(qdict, "name");
|
|
|
|
bool new_state = qdict_get_bool(qdict, "option");
|
2016-07-11 13:53:57 +03:00
|
|
|
bool has_vcpu = qdict_haskey(qdict, "vcpu");
|
|
|
|
int vcpu = qdict_get_try_int(qdict, "vcpu", 0);
|
2014-08-25 15:20:03 +04:00
|
|
|
Error *local_err = NULL;
|
2010-10-13 23:14:29 +04:00
|
|
|
|
2016-07-11 13:53:57 +03:00
|
|
|
if (vcpu < 0) {
|
|
|
|
monitor_printf(mon, "argument vcpu must be positive");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qmp_trace_event_set_state(tp_name, new_state, true, true, has_vcpu, vcpu, &local_err);
|
2014-08-25 15:20:03 +04:00
|
|
|
if (local_err) {
|
2015-02-10 17:15:43 +03:00
|
|
|
error_report_err(local_err);
|
2010-10-13 23:14:29 +04:00
|
|
|
}
|
2010-06-24 15:34:53 +04:00
|
|
|
}
|
2010-07-13 12:26:33 +04:00
|
|
|
|
2011-10-02 17:44:37 +04:00
|
|
|
#ifdef CONFIG_TRACE_SIMPLE
|
hmp: Name HMP command handler functions hmp_COMMAND()
Some are called do_COMMAND() (old ones, usually), some hmp_COMMAND(),
and sometimes COMMAND pointlessly differs in spelling.
Normalize to hmp_COMMAND(), where COMMAND is exactly the command name
with '-' replaced by '_'.
Exceptions:
* do_device_add() and client_migrate_info() *not* renamed to
hmp_device_add(), hmp_client_migrate_info(), because they're also
QMP handlers. They still need to be converted to QAPI.
* do_memory_dump(), do_physical_memory_dump(), do_ioport_read(),
do_ioport_write() renamed do hmp_* instead of hmp_x(), hmp_xp(),
hmp_i(), hmp_o(), because those names are too cryptic for my taste.
* do_info_help() renamed to hmp_info_help() instead of hmp_info(),
because it only covers help.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-02-06 15:55:43 +03:00
|
|
|
static void hmp_trace_file(Monitor *mon, const QDict *qdict)
|
2010-07-13 12:26:33 +04:00
|
|
|
{
|
|
|
|
const char *op = qdict_get_try_str(qdict, "op");
|
|
|
|
const char *arg = qdict_get_try_str(qdict, "arg");
|
|
|
|
|
|
|
|
if (!op) {
|
2019-04-17 22:17:50 +03:00
|
|
|
st_print_trace_file_status();
|
2010-07-13 12:26:33 +04:00
|
|
|
} else if (!strcmp(op, "on")) {
|
|
|
|
st_set_trace_file_enabled(true);
|
|
|
|
} else if (!strcmp(op, "off")) {
|
|
|
|
st_set_trace_file_enabled(false);
|
|
|
|
} else if (!strcmp(op, "flush")) {
|
|
|
|
st_flush_trace_buffer();
|
|
|
|
} else if (!strcmp(op, "set")) {
|
|
|
|
if (arg) {
|
|
|
|
st_set_trace_file(arg);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
monitor_printf(mon, "unexpected argument \"%s\"\n", op);
|
|
|
|
help_cmd(mon, "trace-file");
|
|
|
|
}
|
|
|
|
}
|
2010-06-24 15:34:53 +04:00
|
|
|
#endif
|
|
|
|
|
hmp: Name HMP command handler functions hmp_COMMAND()
Some are called do_COMMAND() (old ones, usually), some hmp_COMMAND(),
and sometimes COMMAND pointlessly differs in spelling.
Normalize to hmp_COMMAND(), where COMMAND is exactly the command name
with '-' replaced by '_'.
Exceptions:
* do_device_add() and client_migrate_info() *not* renamed to
hmp_device_add(), hmp_client_migrate_info(), because they're also
QMP handlers. They still need to be converted to QAPI.
* do_memory_dump(), do_physical_memory_dump(), do_ioport_read(),
do_ioport_write() renamed do hmp_* instead of hmp_x(), hmp_xp(),
hmp_i(), hmp_o(), because those names are too cryptic for my taste.
* do_info_help() renamed to hmp_info_help() instead of hmp_info(),
because it only covers help.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-02-06 15:55:43 +03:00
|
|
|
static void hmp_info_help(Monitor *mon, const QDict *qdict)
|
2004-03-15 00:38:27 +03:00
|
|
|
{
|
2009-10-07 20:41:55 +04:00
|
|
|
help_cmd(mon, "info");
|
2004-03-15 00:38:27 +03:00
|
|
|
}
|
|
|
|
|
2018-03-09 11:59:50 +03:00
|
|
|
static void monitor_init_qmp_commands(void)
|
2016-09-12 12:19:00 +03:00
|
|
|
{
|
qmp: Clean up how we enforce capability negotiation
To enforce capability negotiation before normal operation,
handle_qmp_command() inspects every command before it's handed off to
qmp_dispatch(). This is a bit of a layering violation, and results in
duplicated code.
Before capability negotiation (!cur_mon->in_command_mode), we fail
commands other than "qmp_capabilities". This is what enforces
capability negotiation.
Afterwards, we fail command "qmp_capabilities".
Clean this up as follows.
The obvious place to fail a command is the command itself, so move the
"afterwards" check to qmp_qmp_capabilities().
We do the "before" check in every other command, but that would be
bothersome. Instead, start with an alternate list of commands that
contains only "qmp_capabilities". Switch to the full list in
qmp_qmp_capabilities().
Additionally, replace the generic human-readable error message for
CommandNotFound by one that reminds the user to run qmp_capabilities.
Without that, we'd regress commit 2d5a834.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1488544368-30622-8-git-send-email-armbru@redhat.com>
[Mirco-optimization squashed in, commit message typo fixed]
Reviewed-by: Eric Blake <eblake@redhat.com>
2017-03-03 15:32:27 +03:00
|
|
|
/*
|
|
|
|
* Two command lists:
|
|
|
|
* - qmp_commands contains all QMP commands
|
|
|
|
* - qmp_cap_negotiation_commands contains just
|
|
|
|
* "qmp_capabilities", to enforce capability negotiation
|
|
|
|
*/
|
|
|
|
|
2017-03-03 15:32:25 +03:00
|
|
|
qmp_init_marshal(&qmp_commands);
|
2017-03-03 15:32:24 +03:00
|
|
|
|
2021-10-28 13:25:17 +03:00
|
|
|
qmp_register_command(&qmp_commands, "device_add",
|
|
|
|
qmp_device_add, 0, 0);
|
2016-09-12 12:19:02 +03:00
|
|
|
|
qmp: Clean up how we enforce capability negotiation
To enforce capability negotiation before normal operation,
handle_qmp_command() inspects every command before it's handed off to
qmp_dispatch(). This is a bit of a layering violation, and results in
duplicated code.
Before capability negotiation (!cur_mon->in_command_mode), we fail
commands other than "qmp_capabilities". This is what enforces
capability negotiation.
Afterwards, we fail command "qmp_capabilities".
Clean this up as follows.
The obvious place to fail a command is the command itself, so move the
"afterwards" check to qmp_qmp_capabilities().
We do the "before" check in every other command, but that would be
bothersome. Instead, start with an alternate list of commands that
contains only "qmp_capabilities". Switch to the full list in
qmp_qmp_capabilities().
Additionally, replace the generic human-readable error message for
CommandNotFound by one that reminds the user to run qmp_capabilities.
Without that, we'd regress commit 2d5a834.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1488544368-30622-8-git-send-email-armbru@redhat.com>
[Mirco-optimization squashed in, commit message typo fixed]
Reviewed-by: Eric Blake <eblake@redhat.com>
2017-03-03 15:32:27 +03:00
|
|
|
QTAILQ_INIT(&qmp_cap_negotiation_commands);
|
|
|
|
qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities",
|
2021-10-28 13:25:17 +03:00
|
|
|
qmp_marshal_qmp_capabilities,
|
|
|
|
QCO_ALLOW_PRECONFIG, 0);
|
qmp: Clean up how we enforce capability negotiation
To enforce capability negotiation before normal operation,
handle_qmp_command() inspects every command before it's handed off to
qmp_dispatch(). This is a bit of a layering violation, and results in
duplicated code.
Before capability negotiation (!cur_mon->in_command_mode), we fail
commands other than "qmp_capabilities". This is what enforces
capability negotiation.
Afterwards, we fail command "qmp_capabilities".
Clean this up as follows.
The obvious place to fail a command is the command itself, so move the
"afterwards" check to qmp_qmp_capabilities().
We do the "before" check in every other command, but that would be
bothersome. Instead, start with an alternate list of commands that
contains only "qmp_capabilities". Switch to the full list in
qmp_qmp_capabilities().
Additionally, replace the generic human-readable error message for
CommandNotFound by one that reminds the user to run qmp_capabilities.
Without that, we'd regress commit 2d5a834.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1488544368-30622-8-git-send-email-armbru@redhat.com>
[Mirco-optimization squashed in, commit message typo fixed]
Reviewed-by: Eric Blake <eblake@redhat.com>
2017-03-03 15:32:27 +03:00
|
|
|
}
|
|
|
|
|
2018-06-08 06:55:07 +03:00
|
|
|
/* Set the current CPU defined by the user. Callers must hold BQL. */
|
2020-10-05 18:58:42 +03:00
|
|
|
int monitor_set_cpu(Monitor *mon, int cpu_index)
|
2005-11-22 02:25:50 +03:00
|
|
|
{
|
2012-12-17 09:18:02 +04:00
|
|
|
CPUState *cpu;
|
2005-11-22 02:25:50 +03:00
|
|
|
|
2013-02-15 20:01:09 +04:00
|
|
|
cpu = qemu_get_cpu(cpu_index);
|
|
|
|
if (cpu == NULL) {
|
|
|
|
return -1;
|
2005-11-22 02:25:50 +03:00
|
|
|
}
|
2020-10-05 18:58:42 +03:00
|
|
|
g_free(mon->mon_cpu_path);
|
|
|
|
mon->mon_cpu_path = object_get_canonical_path(OBJECT(cpu));
|
2013-02-15 20:01:09 +04:00
|
|
|
return 0;
|
2005-11-22 02:25:50 +03:00
|
|
|
}
|
|
|
|
|
2018-06-08 06:55:07 +03:00
|
|
|
/* Callers must hold BQL. */
|
2020-10-05 18:58:43 +03:00
|
|
|
static CPUState *mon_get_cpu_sync(Monitor *mon, bool synchronize)
|
2005-11-22 02:25:50 +03:00
|
|
|
{
|
2019-10-04 14:18:20 +03:00
|
|
|
CPUState *cpu = NULL;
|
2017-10-17 11:16:22 +03:00
|
|
|
|
2020-10-05 18:58:43 +03:00
|
|
|
if (mon->mon_cpu_path) {
|
|
|
|
cpu = (CPUState *) object_resolve_path_type(mon->mon_cpu_path,
|
2017-10-17 11:16:22 +03:00
|
|
|
TYPE_CPU, NULL);
|
|
|
|
if (!cpu) {
|
2020-10-05 18:58:43 +03:00
|
|
|
g_free(mon->mon_cpu_path);
|
|
|
|
mon->mon_cpu_path = NULL;
|
2017-10-17 11:16:22 +03:00
|
|
|
}
|
|
|
|
}
|
2020-10-05 18:58:43 +03:00
|
|
|
if (!mon->mon_cpu_path) {
|
2017-01-13 15:12:35 +03:00
|
|
|
if (!first_cpu) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2020-10-05 18:58:43 +03:00
|
|
|
monitor_set_cpu(mon, first_cpu->cpu_index);
|
2017-10-17 11:16:22 +03:00
|
|
|
cpu = first_cpu;
|
2005-11-22 02:25:50 +03:00
|
|
|
}
|
2019-10-04 14:18:20 +03:00
|
|
|
assert(cpu != NULL);
|
2018-02-16 19:08:41 +03:00
|
|
|
if (synchronize) {
|
|
|
|
cpu_synchronize_state(cpu);
|
|
|
|
}
|
2017-10-17 11:16:22 +03:00
|
|
|
return cpu;
|
2015-05-25 00:20:40 +03:00
|
|
|
}
|
|
|
|
|
2020-11-13 14:43:24 +03:00
|
|
|
CPUState *mon_get_cpu(Monitor *mon)
|
2018-02-16 19:08:41 +03:00
|
|
|
{
|
2020-11-13 14:43:24 +03:00
|
|
|
return mon_get_cpu_sync(mon, true);
|
2018-02-16 19:08:41 +03:00
|
|
|
}
|
|
|
|
|
hmp: Pass monitor to mon_get_cpu_env()
mon_get_cpu_env() is indirectly called monitor_parse_arguments() where
the current monitor isn't set yet. Instead of using monitor_cur_env(),
explicitly pass the Monitor pointer to the function.
Without this fix, an HMP command like "x $pc" crashes like this:
#0 0x0000555555caa01f in mon_get_cpu_sync (mon=0x0, synchronize=true) at ../monitor/misc.c:270
#1 0x0000555555caa141 in mon_get_cpu (mon=0x0) at ../monitor/misc.c:294
#2 0x0000555555caa158 in mon_get_cpu_env () at ../monitor/misc.c:299
#3 0x0000555555b19739 in monitor_get_pc (mon=0x555556ad2de0, md=0x5555565d2d40 <monitor_defs+1152>, val=0) at ../target/i386/monitor.c:607
#4 0x0000555555cadbec in get_monitor_def (mon=0x555556ad2de0, pval=0x7fffffffc208, name=0x7fffffffc220 "pc") at ../monitor/misc.c:1681
#5 0x000055555582ec4f in expr_unary (mon=0x555556ad2de0) at ../monitor/hmp.c:387
#6 0x000055555582edbb in expr_prod (mon=0x555556ad2de0) at ../monitor/hmp.c:421
#7 0x000055555582ee79 in expr_logic (mon=0x555556ad2de0) at ../monitor/hmp.c:455
#8 0x000055555582eefe in expr_sum (mon=0x555556ad2de0) at ../monitor/hmp.c:484
#9 0x000055555582efe8 in get_expr (mon=0x555556ad2de0, pval=0x7fffffffc418, pp=0x7fffffffc408) at ../monitor/hmp.c:511
#10 0x000055555582fcd4 in monitor_parse_arguments (mon=0x555556ad2de0, endp=0x7fffffffc890, cmd=0x555556675b50 <hmp_cmds+7920>) at ../monitor/hmp.c:876
#11 0x00005555558306a8 in handle_hmp_command (mon=0x555556ad2de0, cmdline=0x555556ada452 "$pc") at ../monitor/hmp.c:1087
#12 0x000055555582df14 in monitor_command_cb (opaque=0x555556ad2de0, cmdline=0x555556ada450 "x $pc", readline_opaque=0x0) at ../monitor/hmp.c:47
After this fix, nothing is left in monitor_parse_arguments() that can
indirectly call monitor_cur(), so the fix is complete.
Fixes: ff04108a0e36e822519c517bd3bddbc1c7747c18
Reported-by: lichun <lichun@ruijie.com.cn>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20201113114326.97663-4-kwolf@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
2020-11-13 14:43:26 +03:00
|
|
|
CPUArchState *mon_get_cpu_env(Monitor *mon)
|
2015-05-25 00:20:40 +03:00
|
|
|
{
|
hmp: Pass monitor to mon_get_cpu_env()
mon_get_cpu_env() is indirectly called monitor_parse_arguments() where
the current monitor isn't set yet. Instead of using monitor_cur_env(),
explicitly pass the Monitor pointer to the function.
Without this fix, an HMP command like "x $pc" crashes like this:
#0 0x0000555555caa01f in mon_get_cpu_sync (mon=0x0, synchronize=true) at ../monitor/misc.c:270
#1 0x0000555555caa141 in mon_get_cpu (mon=0x0) at ../monitor/misc.c:294
#2 0x0000555555caa158 in mon_get_cpu_env () at ../monitor/misc.c:299
#3 0x0000555555b19739 in monitor_get_pc (mon=0x555556ad2de0, md=0x5555565d2d40 <monitor_defs+1152>, val=0) at ../target/i386/monitor.c:607
#4 0x0000555555cadbec in get_monitor_def (mon=0x555556ad2de0, pval=0x7fffffffc208, name=0x7fffffffc220 "pc") at ../monitor/misc.c:1681
#5 0x000055555582ec4f in expr_unary (mon=0x555556ad2de0) at ../monitor/hmp.c:387
#6 0x000055555582edbb in expr_prod (mon=0x555556ad2de0) at ../monitor/hmp.c:421
#7 0x000055555582ee79 in expr_logic (mon=0x555556ad2de0) at ../monitor/hmp.c:455
#8 0x000055555582eefe in expr_sum (mon=0x555556ad2de0) at ../monitor/hmp.c:484
#9 0x000055555582efe8 in get_expr (mon=0x555556ad2de0, pval=0x7fffffffc418, pp=0x7fffffffc408) at ../monitor/hmp.c:511
#10 0x000055555582fcd4 in monitor_parse_arguments (mon=0x555556ad2de0, endp=0x7fffffffc890, cmd=0x555556675b50 <hmp_cmds+7920>) at ../monitor/hmp.c:876
#11 0x00005555558306a8 in handle_hmp_command (mon=0x555556ad2de0, cmdline=0x555556ada452 "$pc") at ../monitor/hmp.c:1087
#12 0x000055555582df14 in monitor_command_cb (opaque=0x555556ad2de0, cmdline=0x555556ada450 "x $pc", readline_opaque=0x0) at ../monitor/hmp.c:47
After this fix, nothing is left in monitor_parse_arguments() that can
indirectly call monitor_cur(), so the fix is complete.
Fixes: ff04108a0e36e822519c517bd3bddbc1c7747c18
Reported-by: lichun <lichun@ruijie.com.cn>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20201113114326.97663-4-kwolf@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
2020-11-13 14:43:26 +03:00
|
|
|
CPUState *cs = mon_get_cpu(mon);
|
2017-01-13 15:12:35 +03:00
|
|
|
|
|
|
|
return cs ? cs->env_ptr : NULL;
|
2005-11-22 02:25:50 +03:00
|
|
|
}
|
|
|
|
|
2020-10-05 18:58:43 +03:00
|
|
|
int monitor_get_cpu_index(Monitor *mon)
|
2011-10-24 16:53:44 +04:00
|
|
|
{
|
2020-10-05 18:58:43 +03:00
|
|
|
CPUState *cs = mon_get_cpu_sync(mon, false);
|
2017-01-13 15:12:35 +03:00
|
|
|
|
|
|
|
return cs ? cs->cpu_index : UNASSIGNED_CPU_INDEX;
|
2011-10-24 16:53:44 +04:00
|
|
|
}
|
|
|
|
|
2015-02-06 16:18:24 +03:00
|
|
|
static void hmp_info_registers(Monitor *mon, const QDict *qdict)
|
2004-04-04 16:57:25 +04:00
|
|
|
{
|
2017-06-08 08:41:16 +03:00
|
|
|
bool all_cpus = qdict_get_try_bool(qdict, "cpustate_all", false);
|
2022-08-02 10:37:20 +03:00
|
|
|
int vcpu = qdict_get_try_int(qdict, "vcpu", -1);
|
2017-06-08 08:41:16 +03:00
|
|
|
CPUState *cs;
|
2017-01-13 15:12:35 +03:00
|
|
|
|
2017-06-08 08:41:16 +03:00
|
|
|
if (all_cpus) {
|
|
|
|
CPU_FOREACH(cs) {
|
|
|
|
monitor_printf(mon, "\nCPU#%d\n", cs->cpu_index);
|
2019-04-17 22:18:02 +03:00
|
|
|
cpu_dump_state(cs, NULL, CPU_DUMP_FPU);
|
2017-06-08 08:41:16 +03:00
|
|
|
}
|
|
|
|
} else {
|
2022-08-02 10:37:20 +03:00
|
|
|
cs = vcpu >= 0 ? qemu_get_cpu(vcpu) : mon_get_cpu(mon);
|
2017-06-08 08:41:16 +03:00
|
|
|
|
|
|
|
if (!cs) {
|
2022-08-02 10:37:20 +03:00
|
|
|
if (vcpu >= 0) {
|
|
|
|
monitor_printf(mon, "CPU#%d not available\n", vcpu);
|
|
|
|
} else {
|
|
|
|
monitor_printf(mon, "No CPU available\n");
|
|
|
|
}
|
2017-06-08 08:41:16 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-02 10:37:20 +03:00
|
|
|
monitor_printf(mon, "\nCPU#%d\n", cs->cpu_index);
|
2019-04-17 22:18:02 +03:00
|
|
|
cpu_dump_state(cs, NULL, CPU_DUMP_FPU);
|
2017-01-13 15:12:35 +03:00
|
|
|
}
|
2004-04-04 16:57:25 +04:00
|
|
|
}
|
|
|
|
|
2017-08-08 20:54:42 +03:00
|
|
|
static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
|
|
|
|
{
|
|
|
|
int64_t max = qdict_get_try_int(qdict, "max", 10);
|
|
|
|
bool mean = qdict_get_try_bool(qdict, "mean", false);
|
|
|
|
bool coalesce = !qdict_get_try_bool(qdict, "no_coalesce", false);
|
|
|
|
enum QSPSortBy sort_by;
|
|
|
|
|
|
|
|
sort_by = mean ? QSP_SORT_BY_AVG_WAIT_TIME : QSP_SORT_BY_TOTAL_WAIT_TIME;
|
2019-04-17 22:17:54 +03:00
|
|
|
qsp_report(max, sort_by, coalesce);
|
2017-08-08 20:54:42 +03:00
|
|
|
}
|
|
|
|
|
2015-02-06 16:18:24 +03:00
|
|
|
static void hmp_info_history(Monitor *mon, const QDict *qdict)
|
2004-04-04 17:07:25 +04:00
|
|
|
{
|
2019-06-13 18:33:54 +03:00
|
|
|
MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
|
2004-04-04 17:07:25 +04:00
|
|
|
int i;
|
2004-08-02 01:52:19 +04:00
|
|
|
const char *str;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2019-06-13 18:33:54 +03:00
|
|
|
if (!hmp_mon->rs) {
|
2009-03-06 02:01:51 +03:00
|
|
|
return;
|
2019-06-13 18:33:54 +03:00
|
|
|
}
|
2004-08-02 01:52:19 +04:00
|
|
|
i = 0;
|
|
|
|
for(;;) {
|
2019-06-13 18:33:54 +03:00
|
|
|
str = readline_get_history(hmp_mon->rs, i);
|
|
|
|
if (!str) {
|
2004-08-02 01:52:19 +04:00
|
|
|
break;
|
2019-06-13 18:33:54 +03:00
|
|
|
}
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, "%d: '%s'\n", i, str);
|
2004-10-09 21:32:58 +04:00
|
|
|
i++;
|
2004-04-04 17:07:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-06 16:18:24 +03:00
|
|
|
static void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
|
2010-06-24 15:34:53 +04:00
|
|
|
{
|
2016-07-11 13:53:51 +03:00
|
|
|
const char *name = qdict_get_try_str(qdict, "name");
|
2016-07-11 13:53:57 +03:00
|
|
|
bool has_vcpu = qdict_haskey(qdict, "vcpu");
|
|
|
|
int vcpu = qdict_get_try_int(qdict, "vcpu", 0);
|
2016-07-11 13:53:51 +03:00
|
|
|
TraceEventInfoList *events;
|
2014-08-25 15:20:03 +04:00
|
|
|
TraceEventInfoList *elem;
|
2016-07-11 13:53:51 +03:00
|
|
|
Error *local_err = NULL;
|
|
|
|
|
|
|
|
if (name == NULL) {
|
|
|
|
name = "*";
|
|
|
|
}
|
2016-07-11 13:53:57 +03:00
|
|
|
if (vcpu < 0) {
|
|
|
|
monitor_printf(mon, "argument vcpu must be positive");
|
|
|
|
return;
|
|
|
|
}
|
2016-07-11 13:53:51 +03:00
|
|
|
|
2016-07-11 13:53:57 +03:00
|
|
|
events = qmp_trace_event_get_state(name, has_vcpu, vcpu, &local_err);
|
2016-07-11 13:53:51 +03:00
|
|
|
if (local_err) {
|
|
|
|
error_report_err(local_err);
|
|
|
|
return;
|
|
|
|
}
|
2014-08-25 15:20:03 +04:00
|
|
|
|
|
|
|
for (elem = events; elem != NULL; elem = elem->next) {
|
|
|
|
monitor_printf(mon, "%s : state %u\n",
|
|
|
|
elem->value->name,
|
|
|
|
elem->value->state == TRACE_EVENT_STATE_ENABLED ? 1 : 0);
|
|
|
|
}
|
|
|
|
qapi_free_TraceEventInfoList(events);
|
2010-06-24 15:34:53 +04:00
|
|
|
}
|
|
|
|
|
2015-03-05 19:29:02 +03:00
|
|
|
void qmp_client_migrate_info(const char *protocol, const char *hostname,
|
|
|
|
bool has_port, int64_t port,
|
|
|
|
bool has_tls_port, int64_t tls_port,
|
|
|
|
bool has_cert_subject, const char *cert_subject,
|
|
|
|
Error **errp)
|
2010-04-23 15:28:21 +04:00
|
|
|
{
|
|
|
|
if (strcmp(protocol, "spice") == 0) {
|
2015-03-05 19:29:02 +03:00
|
|
|
if (!qemu_using_spice(errp)) {
|
|
|
|
return;
|
2010-04-23 15:28:21 +04:00
|
|
|
}
|
|
|
|
|
2015-03-05 19:29:02 +03:00
|
|
|
if (!has_port && !has_tls_port) {
|
2015-03-17 13:54:50 +03:00
|
|
|
error_setg(errp, QERR_MISSING_PARAMETER, "port/tls-port");
|
2015-03-05 19:29:02 +03:00
|
|
|
return;
|
2012-03-18 11:42:39 +04:00
|
|
|
}
|
|
|
|
|
2020-10-19 10:52:12 +03:00
|
|
|
if (qemu_spice.migrate_info(hostname,
|
2015-03-05 19:29:02 +03:00
|
|
|
has_port ? port : -1,
|
|
|
|
has_tls_port ? tls_port : -1,
|
|
|
|
cert_subject)) {
|
2020-11-13 11:26:21 +03:00
|
|
|
error_setg(errp, "Could not set up display for migration");
|
2015-03-05 19:29:02 +03:00
|
|
|
return;
|
2010-04-23 15:28:21 +04:00
|
|
|
}
|
2015-03-05 19:29:02 +03:00
|
|
|
return;
|
2010-04-23 15:28:21 +04:00
|
|
|
}
|
|
|
|
|
2020-11-13 11:26:22 +03:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "protocol", "'spice'");
|
2010-04-23 15:28:21 +04:00
|
|
|
}
|
|
|
|
|
hmp: Name HMP command handler functions hmp_COMMAND()
Some are called do_COMMAND() (old ones, usually), some hmp_COMMAND(),
and sometimes COMMAND pointlessly differs in spelling.
Normalize to hmp_COMMAND(), where COMMAND is exactly the command name
with '-' replaced by '_'.
Exceptions:
* do_device_add() and client_migrate_info() *not* renamed to
hmp_device_add(), hmp_client_migrate_info(), because they're also
QMP handlers. They still need to be converted to QAPI.
* do_memory_dump(), do_physical_memory_dump(), do_ioport_read(),
do_ioport_write() renamed do hmp_* instead of hmp_x(), hmp_xp(),
hmp_i(), hmp_o(), because those names are too cryptic for my taste.
* do_info_help() renamed to hmp_info_help() instead of hmp_info(),
because it only covers help.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-02-06 15:55:43 +03:00
|
|
|
static void hmp_logfile(Monitor *mon, const QDict *qdict)
|
2007-06-30 17:53:24 +04:00
|
|
|
{
|
2016-06-15 20:27:16 +03:00
|
|
|
Error *err = NULL;
|
|
|
|
|
2022-04-17 21:29:43 +03:00
|
|
|
if (!qemu_set_log_filename(qdict_get_str(qdict, "filename"), &err)) {
|
2016-06-15 20:27:16 +03:00
|
|
|
error_report_err(err);
|
|
|
|
}
|
2007-06-30 17:53:24 +04:00
|
|
|
}
|
|
|
|
|
hmp: Name HMP command handler functions hmp_COMMAND()
Some are called do_COMMAND() (old ones, usually), some hmp_COMMAND(),
and sometimes COMMAND pointlessly differs in spelling.
Normalize to hmp_COMMAND(), where COMMAND is exactly the command name
with '-' replaced by '_'.
Exceptions:
* do_device_add() and client_migrate_info() *not* renamed to
hmp_device_add(), hmp_client_migrate_info(), because they're also
QMP handlers. They still need to be converted to QAPI.
* do_memory_dump(), do_physical_memory_dump(), do_ioport_read(),
do_ioport_write() renamed do hmp_* instead of hmp_x(), hmp_xp(),
hmp_i(), hmp_o(), because those names are too cryptic for my taste.
* do_info_help() renamed to hmp_info_help() instead of hmp_info(),
because it only covers help.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-02-06 15:55:43 +03:00
|
|
|
static void hmp_log(Monitor *mon, const QDict *qdict)
|
2004-03-21 20:06:25 +03:00
|
|
|
{
|
|
|
|
int mask;
|
2009-08-28 22:27:13 +04:00
|
|
|
const char *items = qdict_get_str(qdict, "items");
|
2022-04-17 21:29:44 +03:00
|
|
|
Error *err = NULL;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-04 16:57:25 +04:00
|
|
|
if (!strcmp(items, "none")) {
|
2004-03-21 20:06:25 +03:00
|
|
|
mask = 0;
|
|
|
|
} else {
|
2013-02-11 20:41:22 +04:00
|
|
|
mask = qemu_str_to_log_mask(items);
|
2004-03-21 20:06:25 +03:00
|
|
|
if (!mask) {
|
2009-03-06 02:01:23 +03:00
|
|
|
help_cmd(mon, "log");
|
2004-03-21 20:06:25 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-04-17 21:29:44 +03:00
|
|
|
|
|
|
|
if (!qemu_set_log(mask, &err)) {
|
|
|
|
error_report_err(err);
|
|
|
|
}
|
2004-03-21 20:06:25 +03:00
|
|
|
}
|
|
|
|
|
hmp: Name HMP command handler functions hmp_COMMAND()
Some are called do_COMMAND() (old ones, usually), some hmp_COMMAND(),
and sometimes COMMAND pointlessly differs in spelling.
Normalize to hmp_COMMAND(), where COMMAND is exactly the command name
with '-' replaced by '_'.
Exceptions:
* do_device_add() and client_migrate_info() *not* renamed to
hmp_device_add(), hmp_client_migrate_info(), because they're also
QMP handlers. They still need to be converted to QAPI.
* do_memory_dump(), do_physical_memory_dump(), do_ioport_read(),
do_ioport_write() renamed do hmp_* instead of hmp_x(), hmp_xp(),
hmp_i(), hmp_o(), because those names are too cryptic for my taste.
* do_info_help() renamed to hmp_info_help() instead of hmp_info(),
because it only covers help.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-02-06 15:55:43 +03:00
|
|
|
static void hmp_singlestep(Monitor *mon, const QDict *qdict)
|
2009-04-06 00:08:59 +04:00
|
|
|
{
|
2009-08-28 22:27:13 +04:00
|
|
|
const char *option = qdict_get_try_str(qdict, "option");
|
2009-04-06 00:08:59 +04:00
|
|
|
if (!option || !strcmp(option, "on")) {
|
|
|
|
singlestep = 1;
|
|
|
|
} else if (!strcmp(option, "off")) {
|
|
|
|
singlestep = 0;
|
|
|
|
} else {
|
|
|
|
monitor_printf(mon, "unexpected option %s\n", option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
hmp: Name HMP command handler functions hmp_COMMAND()
Some are called do_COMMAND() (old ones, usually), some hmp_COMMAND(),
and sometimes COMMAND pointlessly differs in spelling.
Normalize to hmp_COMMAND(), where COMMAND is exactly the command name
with '-' replaced by '_'.
Exceptions:
* do_device_add() and client_migrate_info() *not* renamed to
hmp_device_add(), hmp_client_migrate_info(), because they're also
QMP handlers. They still need to be converted to QAPI.
* do_memory_dump(), do_physical_memory_dump(), do_ioport_read(),
do_ioport_write() renamed do hmp_* instead of hmp_x(), hmp_xp(),
hmp_i(), hmp_o(), because those names are too cryptic for my taste.
* do_info_help() renamed to hmp_info_help() instead of hmp_info(),
because it only covers help.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-02-06 15:55:43 +03:00
|
|
|
static void hmp_gdbserver(Monitor *mon, const QDict *qdict)
|
2009-04-05 22:43:41 +04:00
|
|
|
{
|
2009-08-28 22:27:13 +04:00
|
|
|
const char *device = qdict_get_try_str(qdict, "device");
|
2020-11-25 04:45:13 +03:00
|
|
|
if (!device) {
|
2009-04-05 22:43:41 +04:00
|
|
|
device = "tcp::" DEFAULT_GDBSTUB_PORT;
|
2020-11-25 04:45:13 +03:00
|
|
|
}
|
|
|
|
|
2009-04-05 22:43:41 +04:00
|
|
|
if (gdbserver_start(device) < 0) {
|
|
|
|
monitor_printf(mon, "Could not open gdbserver on device '%s'\n",
|
|
|
|
device);
|
|
|
|
} else if (strcmp(device, "none") == 0) {
|
2009-03-28 21:05:53 +03:00
|
|
|
monitor_printf(mon, "Disabled gdbserver\n");
|
2004-03-31 23:00:16 +04:00
|
|
|
} else {
|
2009-04-05 22:43:41 +04:00
|
|
|
monitor_printf(mon, "Waiting for gdb connection on device '%s'\n",
|
|
|
|
device);
|
2004-03-31 23:00:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
hmp: Name HMP command handler functions hmp_COMMAND()
Some are called do_COMMAND() (old ones, usually), some hmp_COMMAND(),
and sometimes COMMAND pointlessly differs in spelling.
Normalize to hmp_COMMAND(), where COMMAND is exactly the command name
with '-' replaced by '_'.
Exceptions:
* do_device_add() and client_migrate_info() *not* renamed to
hmp_device_add(), hmp_client_migrate_info(), because they're also
QMP handlers. They still need to be converted to QAPI.
* do_memory_dump(), do_physical_memory_dump(), do_ioport_read(),
do_ioport_write() renamed do hmp_* instead of hmp_x(), hmp_xp(),
hmp_i(), hmp_o(), because those names are too cryptic for my taste.
* do_info_help() renamed to hmp_info_help() instead of hmp_info(),
because it only covers help.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-02-06 15:55:43 +03:00
|
|
|
static void hmp_watchdog_action(Monitor *mon, const QDict *qdict)
|
2009-04-25 16:56:19 +04:00
|
|
|
{
|
2021-10-27 16:03:04 +03:00
|
|
|
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;
|
2009-04-25 16:56:19 +04:00
|
|
|
}
|
2021-10-27 16:03:04 +03:00
|
|
|
qmp_watchdog_set_action(action, &error_abort);
|
2009-04-25 16:56:19 +04:00
|
|
|
}
|
|
|
|
|
2009-03-06 02:01:23 +03:00
|
|
|
static void monitor_printc(Monitor *mon, int c)
|
2004-04-04 16:57:25 +04:00
|
|
|
{
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, "'");
|
2004-04-04 16:57:25 +04:00
|
|
|
switch(c) {
|
|
|
|
case '\'':
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, "\\'");
|
2004-04-04 16:57:25 +04:00
|
|
|
break;
|
|
|
|
case '\\':
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, "\\\\");
|
2004-04-04 16:57:25 +04:00
|
|
|
break;
|
|
|
|
case '\n':
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, "\\n");
|
2004-04-04 16:57:25 +04:00
|
|
|
break;
|
|
|
|
case '\r':
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, "\\r");
|
2004-04-04 16:57:25 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (c >= 32 && c <= 126) {
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, "%c", c);
|
2004-04-04 16:57:25 +04:00
|
|
|
} else {
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, "\\x%02x", c);
|
2004-04-04 16:57:25 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, "'");
|
2004-04-04 16:57:25 +04:00
|
|
|
}
|
|
|
|
|
2009-03-06 02:01:23 +03:00
|
|
|
static void memory_dump(Monitor *mon, int count, int format, int wsize,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr, int is_physical)
|
2004-04-04 16:57:25 +04:00
|
|
|
{
|
2010-01-12 23:27:43 +03:00
|
|
|
int l, line_size, i, max_digits, len;
|
2004-04-04 16:57:25 +04:00
|
|
|
uint8_t buf[16];
|
|
|
|
uint64_t v;
|
2020-11-13 14:43:24 +03:00
|
|
|
CPUState *cs = mon_get_cpu(mon);
|
2017-01-13 15:12:35 +03:00
|
|
|
|
|
|
|
if (!cs && (format == 'i' || !is_physical)) {
|
|
|
|
monitor_printf(mon, "Can not dump without CPU\n");
|
|
|
|
return;
|
|
|
|
}
|
2004-04-04 16:57:25 +04:00
|
|
|
|
|
|
|
if (format == 'i') {
|
2017-09-14 18:38:35 +03:00
|
|
|
monitor_disas(mon, cs, addr, count, is_physical);
|
2004-04-04 16:57:25 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = wsize * count;
|
2020-11-25 04:45:13 +03:00
|
|
|
if (wsize == 1) {
|
2004-04-04 16:57:25 +04:00
|
|
|
line_size = 8;
|
2020-11-25 04:45:13 +03:00
|
|
|
} else {
|
2004-04-04 16:57:25 +04:00
|
|
|
line_size = 16;
|
2020-11-25 04:45:13 +03:00
|
|
|
}
|
2004-04-04 16:57:25 +04:00
|
|
|
max_digits = 0;
|
|
|
|
|
|
|
|
switch(format) {
|
|
|
|
case 'o':
|
2017-06-22 14:04:16 +03:00
|
|
|
max_digits = DIV_ROUND_UP(wsize * 8, 3);
|
2004-04-04 16:57:25 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case 'x':
|
|
|
|
max_digits = (wsize * 8) / 4;
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
case 'd':
|
2017-06-22 14:04:16 +03:00
|
|
|
max_digits = DIV_ROUND_UP(wsize * 8 * 10, 33);
|
2004-04-04 16:57:25 +04:00
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
wsize = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (len > 0) {
|
2020-11-25 04:45:13 +03:00
|
|
|
if (is_physical) {
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, TARGET_FMT_plx ":", addr);
|
2020-11-25 04:45:13 +03:00
|
|
|
} else {
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, TARGET_FMT_lx ":", (target_ulong)addr);
|
2020-11-25 04:45:13 +03:00
|
|
|
}
|
2004-04-04 16:57:25 +04:00
|
|
|
l = len;
|
|
|
|
if (l > line_size)
|
|
|
|
l = line_size;
|
|
|
|
if (is_physical) {
|
2018-12-14 16:30:49 +03:00
|
|
|
AddressSpace *as = cs ? cs->as : &address_space_memory;
|
|
|
|
MemTxResult r = address_space_read(as, addr,
|
|
|
|
MEMTXATTRS_UNSPECIFIED, buf, l);
|
|
|
|
if (r != MEMTX_OK) {
|
|
|
|
monitor_printf(mon, " Cannot access memory\n");
|
|
|
|
break;
|
|
|
|
}
|
2004-04-04 16:57:25 +04:00
|
|
|
} else {
|
2017-01-13 15:12:35 +03:00
|
|
|
if (cpu_memory_rw_debug(cs, addr, buf, l, 0) < 0) {
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, " Cannot access memory\n");
|
2008-08-18 18:00:20 +04:00
|
|
|
break;
|
|
|
|
}
|
2004-04-04 16:57:25 +04:00
|
|
|
}
|
2007-09-17 01:08:06 +04:00
|
|
|
i = 0;
|
2004-04-04 16:57:25 +04:00
|
|
|
while (i < l) {
|
|
|
|
switch(wsize) {
|
|
|
|
default:
|
|
|
|
case 1:
|
2015-01-20 18:19:32 +03:00
|
|
|
v = ldub_p(buf + i);
|
2004-04-04 16:57:25 +04:00
|
|
|
break;
|
|
|
|
case 2:
|
2015-01-20 18:19:32 +03:00
|
|
|
v = lduw_p(buf + i);
|
2004-04-04 16:57:25 +04:00
|
|
|
break;
|
|
|
|
case 4:
|
2015-01-20 18:19:32 +03:00
|
|
|
v = (uint32_t)ldl_p(buf + i);
|
2004-04-04 16:57:25 +04:00
|
|
|
break;
|
|
|
|
case 8:
|
2015-01-20 18:19:32 +03:00
|
|
|
v = ldq_p(buf + i);
|
2004-04-04 16:57:25 +04:00
|
|
|
break;
|
|
|
|
}
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, " ");
|
2004-04-04 16:57:25 +04:00
|
|
|
switch(format) {
|
|
|
|
case 'o':
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, "%#*" PRIo64, max_digits, v);
|
2004-04-04 16:57:25 +04:00
|
|
|
break;
|
|
|
|
case 'x':
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, "0x%0*" PRIx64, max_digits, v);
|
2004-04-04 16:57:25 +04:00
|
|
|
break;
|
|
|
|
case 'u':
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, "%*" PRIu64, max_digits, v);
|
2004-04-04 16:57:25 +04:00
|
|
|
break;
|
|
|
|
case 'd':
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, "%*" PRId64, max_digits, v);
|
2004-04-04 16:57:25 +04:00
|
|
|
break;
|
|
|
|
case 'c':
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printc(mon, v);
|
2004-04-04 16:57:25 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
i += wsize;
|
|
|
|
}
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, "\n");
|
2004-04-04 16:57:25 +04:00
|
|
|
addr += l;
|
|
|
|
len -= l;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
hmp: Name HMP command handler functions hmp_COMMAND()
Some are called do_COMMAND() (old ones, usually), some hmp_COMMAND(),
and sometimes COMMAND pointlessly differs in spelling.
Normalize to hmp_COMMAND(), where COMMAND is exactly the command name
with '-' replaced by '_'.
Exceptions:
* do_device_add() and client_migrate_info() *not* renamed to
hmp_device_add(), hmp_client_migrate_info(), because they're also
QMP handlers. They still need to be converted to QAPI.
* do_memory_dump(), do_physical_memory_dump(), do_ioport_read(),
do_ioport_write() renamed do hmp_* instead of hmp_x(), hmp_xp(),
hmp_i(), hmp_o(), because those names are too cryptic for my taste.
* do_info_help() renamed to hmp_info_help() instead of hmp_info(),
because it only covers help.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-02-06 15:55:43 +03:00
|
|
|
static void hmp_memory_dump(Monitor *mon, const QDict *qdict)
|
2004-04-04 16:57:25 +04:00
|
|
|
{
|
2009-08-28 22:27:17 +04:00
|
|
|
int count = qdict_get_int(qdict, "count");
|
|
|
|
int format = qdict_get_int(qdict, "format");
|
|
|
|
int size = qdict_get_int(qdict, "size");
|
|
|
|
target_long addr = qdict_get_int(qdict, "addr");
|
|
|
|
|
2009-03-06 02:01:23 +03:00
|
|
|
memory_dump(mon, count, format, size, addr, 0);
|
2004-04-04 16:57:25 +04:00
|
|
|
}
|
|
|
|
|
hmp: Name HMP command handler functions hmp_COMMAND()
Some are called do_COMMAND() (old ones, usually), some hmp_COMMAND(),
and sometimes COMMAND pointlessly differs in spelling.
Normalize to hmp_COMMAND(), where COMMAND is exactly the command name
with '-' replaced by '_'.
Exceptions:
* do_device_add() and client_migrate_info() *not* renamed to
hmp_device_add(), hmp_client_migrate_info(), because they're also
QMP handlers. They still need to be converted to QAPI.
* do_memory_dump(), do_physical_memory_dump(), do_ioport_read(),
do_ioport_write() renamed do hmp_* instead of hmp_x(), hmp_xp(),
hmp_i(), hmp_o(), because those names are too cryptic for my taste.
* do_info_help() renamed to hmp_info_help() instead of hmp_info(),
because it only covers help.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-02-06 15:55:43 +03:00
|
|
|
static void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict)
|
2004-04-04 16:57:25 +04:00
|
|
|
{
|
2009-08-28 22:27:17 +04:00
|
|
|
int count = qdict_get_int(qdict, "count");
|
|
|
|
int format = qdict_get_int(qdict, "format");
|
|
|
|
int size = qdict_get_int(qdict, "size");
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr = qdict_get_int(qdict, "addr");
|
2009-08-28 22:27:17 +04:00
|
|
|
|
2009-03-06 02:01:23 +03:00
|
|
|
memory_dump(mon, count, format, size, addr, 1);
|
2004-04-04 16:57:25 +04:00
|
|
|
}
|
|
|
|
|
2020-10-27 20:03:03 +03:00
|
|
|
void *gpa2hva(MemoryRegion **p_mr, hwaddr addr, uint64_t size, Error **errp)
|
2017-04-20 16:30:58 +03:00
|
|
|
{
|
2020-10-27 20:03:03 +03:00
|
|
|
Int128 gpa_region_size;
|
2017-04-20 16:30:58 +03:00
|
|
|
MemoryRegionSection mrs = memory_region_find(get_system_memory(),
|
2020-10-27 20:03:03 +03:00
|
|
|
addr, size);
|
2017-04-20 16:30:58 +03:00
|
|
|
|
|
|
|
if (!mrs.mr) {
|
|
|
|
error_setg(errp, "No memory is mapped at address 0x%" HWADDR_PRIx, addr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!memory_region_is_ram(mrs.mr) && !memory_region_is_romd(mrs.mr)) {
|
|
|
|
error_setg(errp, "Memory at address 0x%" HWADDR_PRIx "is not RAM", addr);
|
|
|
|
memory_region_unref(mrs.mr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-10-27 20:03:03 +03:00
|
|
|
gpa_region_size = int128_make64(size);
|
|
|
|
if (int128_lt(mrs.size, gpa_region_size)) {
|
|
|
|
error_setg(errp, "Size of memory region at 0x%" HWADDR_PRIx
|
|
|
|
" exceeded.", addr);
|
|
|
|
memory_region_unref(mrs.mr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-04-20 16:30:58 +03:00
|
|
|
*p_mr = mrs.mr;
|
|
|
|
return qemu_map_ram_ptr(mrs.mr->ram_block, mrs.offset_within_region);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
|
|
|
|
{
|
|
|
|
hwaddr addr = qdict_get_int(qdict, "addr");
|
|
|
|
Error *local_err = NULL;
|
|
|
|
MemoryRegion *mr = NULL;
|
|
|
|
void *ptr;
|
|
|
|
|
2020-10-27 20:03:03 +03:00
|
|
|
ptr = gpa2hva(&mr, addr, 1, &local_err);
|
2017-04-20 16:30:58 +03:00
|
|
|
if (local_err) {
|
|
|
|
error_report_err(local_err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
monitor_printf(mon, "Host virtual address for 0x%" HWADDR_PRIx
|
|
|
|
" (%s) is %p\n",
|
|
|
|
addr, mr->name, ptr);
|
|
|
|
|
|
|
|
memory_region_unref(mr);
|
|
|
|
}
|
|
|
|
|
2019-04-12 18:26:52 +03:00
|
|
|
static void hmp_gva2gpa(Monitor *mon, const QDict *qdict)
|
|
|
|
{
|
|
|
|
target_ulong addr = qdict_get_int(qdict, "addr");
|
|
|
|
MemTxAttrs attrs;
|
2020-11-13 14:43:24 +03:00
|
|
|
CPUState *cs = mon_get_cpu(mon);
|
2019-04-12 18:26:52 +03:00
|
|
|
hwaddr gpa;
|
|
|
|
|
|
|
|
if (!cs) {
|
|
|
|
monitor_printf(mon, "No cpu\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-10 21:56:20 +03:00
|
|
|
gpa = cpu_get_phys_page_attrs_debug(cs, addr & TARGET_PAGE_MASK, &attrs);
|
2019-04-12 18:26:52 +03:00
|
|
|
if (gpa == -1) {
|
|
|
|
monitor_printf(mon, "Unmapped\n");
|
|
|
|
} else {
|
|
|
|
monitor_printf(mon, "gpa: %#" HWADDR_PRIx "\n",
|
|
|
|
gpa + (addr & ~TARGET_PAGE_MASK));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-20 16:30:58 +03:00
|
|
|
#ifdef CONFIG_LINUX
|
|
|
|
static uint64_t vtop(void *ptr, Error **errp)
|
|
|
|
{
|
|
|
|
uint64_t pinfo;
|
|
|
|
uint64_t ret = -1;
|
|
|
|
uintptr_t addr = (uintptr_t) ptr;
|
2022-03-23 18:57:22 +03:00
|
|
|
uintptr_t pagesize = qemu_real_host_page_size();
|
2017-04-20 16:30:58 +03:00
|
|
|
off_t offset = addr / pagesize * sizeof(pinfo);
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = open("/proc/self/pagemap", O_RDONLY);
|
|
|
|
if (fd == -1) {
|
|
|
|
error_setg_errno(errp, errno, "Cannot open /proc/self/pagemap");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Force copy-on-write if necessary. */
|
2020-09-23 13:56:46 +03:00
|
|
|
qatomic_add((uint8_t *)ptr, 0);
|
2017-04-20 16:30:58 +03:00
|
|
|
|
|
|
|
if (pread(fd, &pinfo, sizeof(pinfo), offset) != sizeof(pinfo)) {
|
|
|
|
error_setg_errno(errp, errno, "Cannot read pagemap");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if ((pinfo & (1ull << 63)) == 0) {
|
|
|
|
error_setg(errp, "Page not present");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
ret = ((pinfo & 0x007fffffffffffffull) * pagesize) | (addr & (pagesize - 1));
|
|
|
|
|
|
|
|
out:
|
|
|
|
close(fd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
|
|
|
|
{
|
|
|
|
hwaddr addr = qdict_get_int(qdict, "addr");
|
|
|
|
Error *local_err = NULL;
|
|
|
|
MemoryRegion *mr = NULL;
|
|
|
|
void *ptr;
|
|
|
|
uint64_t physaddr;
|
|
|
|
|
2020-10-27 20:03:03 +03:00
|
|
|
ptr = gpa2hva(&mr, addr, 1, &local_err);
|
2017-04-20 16:30:58 +03:00
|
|
|
if (local_err) {
|
|
|
|
error_report_err(local_err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
physaddr = vtop(ptr, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
error_report_err(local_err);
|
|
|
|
} else {
|
|
|
|
monitor_printf(mon, "Host physical address for 0x%" HWADDR_PRIx
|
|
|
|
" (%s) is 0x%" PRIx64 "\n",
|
|
|
|
addr, mr->name, (uint64_t) physaddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
memory_region_unref(mr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-08-28 22:27:17 +04:00
|
|
|
static void do_print(Monitor *mon, const QDict *qdict)
|
2004-04-04 16:57:25 +04:00
|
|
|
{
|
2009-08-28 22:27:17 +04:00
|
|
|
int format = qdict_get_int(qdict, "format");
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr val = qdict_get_int(qdict, "val");
|
2009-08-28 22:27:17 +04:00
|
|
|
|
2004-04-04 16:57:25 +04:00
|
|
|
switch(format) {
|
|
|
|
case 'o':
|
2012-10-23 14:30:10 +04:00
|
|
|
monitor_printf(mon, "%#" HWADDR_PRIo, val);
|
2004-04-04 16:57:25 +04:00
|
|
|
break;
|
|
|
|
case 'x':
|
2012-10-23 14:30:10 +04:00
|
|
|
monitor_printf(mon, "%#" HWADDR_PRIx, val);
|
2004-04-04 16:57:25 +04:00
|
|
|
break;
|
|
|
|
case 'u':
|
2012-10-23 14:30:10 +04:00
|
|
|
monitor_printf(mon, "%" HWADDR_PRIu, val);
|
2004-04-04 16:57:25 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case 'd':
|
2012-10-23 14:30:10 +04:00
|
|
|
monitor_printf(mon, "%" HWADDR_PRId, val);
|
2004-04-04 16:57:25 +04:00
|
|
|
break;
|
|
|
|
case 'c':
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printc(mon, val);
|
2004-04-04 16:57:25 +04:00
|
|
|
break;
|
|
|
|
}
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, "\n");
|
2004-04-04 16:57:25 +04:00
|
|
|
}
|
|
|
|
|
hmp: Name HMP command handler functions hmp_COMMAND()
Some are called do_COMMAND() (old ones, usually), some hmp_COMMAND(),
and sometimes COMMAND pointlessly differs in spelling.
Normalize to hmp_COMMAND(), where COMMAND is exactly the command name
with '-' replaced by '_'.
Exceptions:
* do_device_add() and client_migrate_info() *not* renamed to
hmp_device_add(), hmp_client_migrate_info(), because they're also
QMP handlers. They still need to be converted to QAPI.
* do_memory_dump(), do_physical_memory_dump(), do_ioport_read(),
do_ioport_write() renamed do hmp_* instead of hmp_x(), hmp_xp(),
hmp_i(), hmp_o(), because those names are too cryptic for my taste.
* do_info_help() renamed to hmp_info_help() instead of hmp_info(),
because it only covers help.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-02-06 15:55:43 +03:00
|
|
|
static void hmp_sum(Monitor *mon, const QDict *qdict)
|
2005-06-05 00:15:57 +04:00
|
|
|
{
|
|
|
|
uint32_t addr;
|
|
|
|
uint16_t sum;
|
2009-08-28 22:27:14 +04:00
|
|
|
uint32_t start = qdict_get_int(qdict, "start");
|
|
|
|
uint32_t size = qdict_get_int(qdict, "size");
|
2005-06-05 00:15:57 +04:00
|
|
|
|
|
|
|
sum = 0;
|
|
|
|
for(addr = start; addr < (start + size); addr++) {
|
Switch non-CPU callers from ld/st*_phys to address_space_ld/st*
Switch all the uses of ld/st*_phys to address_space_ld/st*,
except for those cases where the address space is the CPU's
(ie cs->as). This was done with the following script which
generates a Coccinelle patch.
A few over-80-columns lines in the result were rewrapped by
hand where Coccinelle failed to do the wrapping automatically,
as well as one location where it didn't put a line-continuation
'\' when wrapping lines on a change made to a match inside
a macro definition.
===begin===
#!/bin/sh -e
# Usage:
# ./ldst-phys.spatch.sh > ldst-phys.spatch
# spatch -sp_file ldst-phys.spatch -dir . | sed -e '/^+/s/\t/ /g' > out.patch
# patch -p1 < out.patch
for FN in ub uw_le uw_be l_le l_be q_le q_be uw l q; do
cat <<EOF
@ cpu_matches_ld_${FN} @
expression E1,E2;
identifier as;
@@
ld${FN}_phys(E1->as,E2)
@ other_matches_ld_${FN} depends on !cpu_matches_ld_${FN} @
expression E1,E2;
@@
-ld${FN}_phys(E1,E2)
+address_space_ld${FN}(E1,E2, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
for FN in b w_le w_be l_le l_be q_le q_be w l q; do
cat <<EOF
@ cpu_matches_st_${FN} @
expression E1,E2,E3;
identifier as;
@@
st${FN}_phys(E1->as,E2,E3)
@ other_matches_st_${FN} depends on !cpu_matches_st_${FN} @
expression E1,E2,E3;
@@
-st${FN}_phys(E1,E2,E3)
+address_space_st${FN}(E1,E2,E3, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
===endit===
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
2015-04-26 18:49:24 +03:00
|
|
|
uint8_t val = address_space_ldub(&address_space_memory, addr,
|
|
|
|
MEMTXATTRS_UNSPECIFIED, NULL);
|
2005-06-05 00:15:57 +04:00
|
|
|
/* BSD sum algorithm ('sum' Unix command) */
|
|
|
|
sum = (sum >> 1) | (sum << 15);
|
2011-04-10 20:23:39 +04:00
|
|
|
sum += val;
|
2005-06-05 00:15:57 +04:00
|
|
|
}
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, "%05d\n", sum);
|
2005-06-05 00:15:57 +04:00
|
|
|
}
|
|
|
|
|
2006-07-15 02:03:35 +04:00
|
|
|
static int mouse_button_state;
|
|
|
|
|
hmp: Name HMP command handler functions hmp_COMMAND()
Some are called do_COMMAND() (old ones, usually), some hmp_COMMAND(),
and sometimes COMMAND pointlessly differs in spelling.
Normalize to hmp_COMMAND(), where COMMAND is exactly the command name
with '-' replaced by '_'.
Exceptions:
* do_device_add() and client_migrate_info() *not* renamed to
hmp_device_add(), hmp_client_migrate_info(), because they're also
QMP handlers. They still need to be converted to QAPI.
* do_memory_dump(), do_physical_memory_dump(), do_ioport_read(),
do_ioport_write() renamed do hmp_* instead of hmp_x(), hmp_xp(),
hmp_i(), hmp_o(), because those names are too cryptic for my taste.
* do_info_help() renamed to hmp_info_help() instead of hmp_info(),
because it only covers help.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-02-06 15:55:43 +03:00
|
|
|
static void hmp_mouse_move(Monitor *mon, const QDict *qdict)
|
2006-07-15 02:03:35 +04:00
|
|
|
{
|
2013-12-04 18:02:28 +04:00
|
|
|
int dx, dy, dz, button;
|
2009-08-28 22:27:15 +04:00
|
|
|
const char *dx_str = qdict_get_str(qdict, "dx_str");
|
|
|
|
const char *dy_str = qdict_get_str(qdict, "dy_str");
|
|
|
|
const char *dz_str = qdict_get_try_str(qdict, "dz_str");
|
2013-12-04 18:02:28 +04:00
|
|
|
|
2006-07-15 02:03:35 +04:00
|
|
|
dx = strtol(dx_str, NULL, 0);
|
|
|
|
dy = strtol(dy_str, NULL, 0);
|
2013-12-04 18:02:28 +04:00
|
|
|
qemu_input_queue_rel(NULL, INPUT_AXIS_X, dx);
|
|
|
|
qemu_input_queue_rel(NULL, INPUT_AXIS_Y, dy);
|
|
|
|
|
|
|
|
if (dz_str) {
|
2006-07-15 02:03:35 +04:00
|
|
|
dz = strtol(dz_str, NULL, 0);
|
2013-12-04 18:02:28 +04:00
|
|
|
if (dz != 0) {
|
2016-01-12 14:14:12 +03:00
|
|
|
button = (dz > 0) ? INPUT_BUTTON_WHEEL_UP : INPUT_BUTTON_WHEEL_DOWN;
|
2013-12-04 18:02:28 +04:00
|
|
|
qemu_input_queue_btn(NULL, button, true);
|
|
|
|
qemu_input_event_sync();
|
|
|
|
qemu_input_queue_btn(NULL, button, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
qemu_input_event_sync();
|
2006-07-15 02:03:35 +04:00
|
|
|
}
|
|
|
|
|
hmp: Name HMP command handler functions hmp_COMMAND()
Some are called do_COMMAND() (old ones, usually), some hmp_COMMAND(),
and sometimes COMMAND pointlessly differs in spelling.
Normalize to hmp_COMMAND(), where COMMAND is exactly the command name
with '-' replaced by '_'.
Exceptions:
* do_device_add() and client_migrate_info() *not* renamed to
hmp_device_add(), hmp_client_migrate_info(), because they're also
QMP handlers. They still need to be converted to QAPI.
* do_memory_dump(), do_physical_memory_dump(), do_ioport_read(),
do_ioport_write() renamed do hmp_* instead of hmp_x(), hmp_xp(),
hmp_i(), hmp_o(), because those names are too cryptic for my taste.
* do_info_help() renamed to hmp_info_help() instead of hmp_info(),
because it only covers help.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-02-06 15:55:43 +03:00
|
|
|
static void hmp_mouse_button(Monitor *mon, const QDict *qdict)
|
2006-07-15 02:03:35 +04:00
|
|
|
{
|
qapi: Don't let implicit enum MAX member collide
Now that we guarantee the user doesn't have any enum values
beginning with a single underscore, we can use that for our
own purposes. Renaming ENUM_MAX to ENUM__MAX makes it obvious
that the sentinel is generated.
This patch was mostly generated by applying a temporary patch:
|diff --git a/scripts/qapi.py b/scripts/qapi.py
|index e6d014b..b862ec9 100644
|--- a/scripts/qapi.py
|+++ b/scripts/qapi.py
|@@ -1570,6 +1570,7 @@ const char *const %(c_name)s_lookup[] = {
| max_index = c_enum_const(name, 'MAX', prefix)
| ret += mcgen('''
| [%(max_index)s] = NULL,
|+// %(max_index)s
| };
| ''',
| max_index=max_index)
then running:
$ cat qapi-{types,event}.c tests/test-qapi-types.c |
sed -n 's,^// \(.*\)MAX,s|\1MAX|\1_MAX|g,p' > list
$ git grep -l _MAX | xargs sed -i -f list
The only things not generated are the changes in scripts/qapi.py.
Rejecting enum members named 'MAX' is now useless, and will be dropped
in the next patch.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1447836791-369-23-git-send-email-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
[Rebased to current master, commit message tweaked]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-11-18 11:52:57 +03:00
|
|
|
static uint32_t bmap[INPUT_BUTTON__MAX] = {
|
2013-12-04 18:02:28 +04:00
|
|
|
[INPUT_BUTTON_LEFT] = MOUSE_EVENT_LBUTTON,
|
|
|
|
[INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON,
|
|
|
|
[INPUT_BUTTON_RIGHT] = MOUSE_EVENT_RBUTTON,
|
|
|
|
};
|
2009-08-28 22:27:13 +04:00
|
|
|
int button_state = qdict_get_int(qdict, "button_state");
|
2013-12-04 18:02:28 +04:00
|
|
|
|
|
|
|
if (mouse_button_state == button_state) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
qemu_input_update_buttons(NULL, bmap, mouse_button_state, button_state);
|
|
|
|
qemu_input_event_sync();
|
2006-07-15 02:03:35 +04:00
|
|
|
mouse_button_state = button_state;
|
|
|
|
}
|
|
|
|
|
hmp: Name HMP command handler functions hmp_COMMAND()
Some are called do_COMMAND() (old ones, usually), some hmp_COMMAND(),
and sometimes COMMAND pointlessly differs in spelling.
Normalize to hmp_COMMAND(), where COMMAND is exactly the command name
with '-' replaced by '_'.
Exceptions:
* do_device_add() and client_migrate_info() *not* renamed to
hmp_device_add(), hmp_client_migrate_info(), because they're also
QMP handlers. They still need to be converted to QAPI.
* do_memory_dump(), do_physical_memory_dump(), do_ioport_read(),
do_ioport_write() renamed do hmp_* instead of hmp_x(), hmp_xp(),
hmp_i(), hmp_o(), because those names are too cryptic for my taste.
* do_info_help() renamed to hmp_info_help() instead of hmp_info(),
because it only covers help.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-02-06 15:55:43 +03:00
|
|
|
static void hmp_ioport_read(Monitor *mon, const QDict *qdict)
|
2004-06-08 04:55:58 +04:00
|
|
|
{
|
2009-08-28 22:27:18 +04:00
|
|
|
int size = qdict_get_int(qdict, "size");
|
|
|
|
int addr = qdict_get_int(qdict, "addr");
|
|
|
|
int has_index = qdict_haskey(qdict, "index");
|
2004-06-08 04:55:58 +04:00
|
|
|
uint32_t val;
|
|
|
|
int suffix;
|
|
|
|
|
|
|
|
if (has_index) {
|
2009-08-28 22:27:18 +04:00
|
|
|
int index = qdict_get_int(qdict, "index");
|
2009-09-20 20:05:47 +04:00
|
|
|
cpu_outb(addr & IOPORTS_MASK, index & 0xff);
|
2004-06-08 04:55:58 +04:00
|
|
|
addr++;
|
|
|
|
}
|
|
|
|
addr &= 0xffff;
|
|
|
|
|
|
|
|
switch(size) {
|
|
|
|
default:
|
|
|
|
case 1:
|
2009-09-20 20:05:47 +04:00
|
|
|
val = cpu_inb(addr);
|
2004-06-08 04:55:58 +04:00
|
|
|
suffix = 'b';
|
|
|
|
break;
|
|
|
|
case 2:
|
2009-09-20 20:05:47 +04:00
|
|
|
val = cpu_inw(addr);
|
2004-06-08 04:55:58 +04:00
|
|
|
suffix = 'w';
|
|
|
|
break;
|
|
|
|
case 4:
|
2009-09-20 20:05:47 +04:00
|
|
|
val = cpu_inl(addr);
|
2004-06-08 04:55:58 +04:00
|
|
|
suffix = 'l';
|
|
|
|
break;
|
|
|
|
}
|
2020-11-25 04:45:14 +03:00
|
|
|
monitor_printf(mon, "port%c[0x%04x] = 0x%0*x\n",
|
2009-03-06 02:01:23 +03:00
|
|
|
suffix, addr, size * 2, val);
|
2004-06-08 04:55:58 +04:00
|
|
|
}
|
2004-06-04 15:06:21 +04:00
|
|
|
|
hmp: Name HMP command handler functions hmp_COMMAND()
Some are called do_COMMAND() (old ones, usually), some hmp_COMMAND(),
and sometimes COMMAND pointlessly differs in spelling.
Normalize to hmp_COMMAND(), where COMMAND is exactly the command name
with '-' replaced by '_'.
Exceptions:
* do_device_add() and client_migrate_info() *not* renamed to
hmp_device_add(), hmp_client_migrate_info(), because they're also
QMP handlers. They still need to be converted to QAPI.
* do_memory_dump(), do_physical_memory_dump(), do_ioport_read(),
do_ioport_write() renamed do hmp_* instead of hmp_x(), hmp_xp(),
hmp_i(), hmp_o(), because those names are too cryptic for my taste.
* do_info_help() renamed to hmp_info_help() instead of hmp_info(),
because it only covers help.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-02-06 15:55:43 +03:00
|
|
|
static void hmp_ioport_write(Monitor *mon, const QDict *qdict)
|
2009-07-14 12:20:11 +04:00
|
|
|
{
|
2009-08-28 22:27:17 +04:00
|
|
|
int size = qdict_get_int(qdict, "size");
|
|
|
|
int addr = qdict_get_int(qdict, "addr");
|
|
|
|
int val = qdict_get_int(qdict, "val");
|
|
|
|
|
2009-07-14 12:20:11 +04:00
|
|
|
addr &= IOPORTS_MASK;
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
default:
|
|
|
|
case 1:
|
2009-09-20 20:05:47 +04:00
|
|
|
cpu_outb(addr, val);
|
2009-07-14 12:20:11 +04:00
|
|
|
break;
|
|
|
|
case 2:
|
2009-09-20 20:05:47 +04:00
|
|
|
cpu_outw(addr, val);
|
2009-07-14 12:20:11 +04:00
|
|
|
break;
|
|
|
|
case 4:
|
2009-09-20 20:05:47 +04:00
|
|
|
cpu_outl(addr, val);
|
2009-07-14 12:20:11 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
hmp: Name HMP command handler functions hmp_COMMAND()
Some are called do_COMMAND() (old ones, usually), some hmp_COMMAND(),
and sometimes COMMAND pointlessly differs in spelling.
Normalize to hmp_COMMAND(), where COMMAND is exactly the command name
with '-' replaced by '_'.
Exceptions:
* do_device_add() and client_migrate_info() *not* renamed to
hmp_device_add(), hmp_client_migrate_info(), because they're also
QMP handlers. They still need to be converted to QAPI.
* do_memory_dump(), do_physical_memory_dump(), do_ioport_read(),
do_ioport_write() renamed do hmp_* instead of hmp_x(), hmp_xp(),
hmp_i(), hmp_o(), because those names are too cryptic for my taste.
* do_info_help() renamed to hmp_info_help() instead of hmp_info(),
because it only covers help.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-02-06 15:55:43 +03:00
|
|
|
static void hmp_boot_set(Monitor *mon, const QDict *qdict)
|
2008-05-05 00:11:34 +04:00
|
|
|
{
|
2014-12-03 21:20:58 +03:00
|
|
|
Error *local_err = NULL;
|
2009-08-28 22:27:13 +04:00
|
|
|
const char *bootdevice = qdict_get_str(qdict, "bootdevice");
|
2008-05-05 00:11:34 +04:00
|
|
|
|
2014-12-03 21:20:58 +03:00
|
|
|
qemu_boot_set(bootdevice, &local_err);
|
|
|
|
if (local_err) {
|
error: Use error_report_err() instead of monitor_printf()
Both error_report_err() and monitor_printf() print to the same
destination when monitor_printf() is used correctly, i.e. within an
HMP monitor. Elsewhere, monitor_printf() does nothing, while
error_report_err() reports to stderr.
Most changed functions are HMP command handlers. These should only
run within an HMP monitor. The one exception is bdrv_password_cb(),
which should also only run within an HMP monitor.
Four command handlers prefix the error message with the command name:
balloon, migrate_set_capability, migrate_set_parameter, migrate.
Pointless, drop.
Unlike monitor_printf(), error_report_err() uses the error whole
instead of just its message obtained with error_get_pretty(). This
avoids suppressing its hint (see commit 50b7b00). Example:
(qemu) device_add ivshmem,id=666
Parameter 'id' expects an identifier
Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.
Try "help device_add" for more information
The "Identifiers consist of..." line is new with this patch.
Coccinelle semantic patch:
@@
expression M, E;
@@
- monitor_printf(M, "%s\n", error_get_pretty(E));
- error_free(E);
+ error_report_err(E);
@r1@
expression M, E;
format F;
position p;
@@
- monitor_printf(M, "...%@F@\n", error_get_pretty(E));@p
- error_free(E);
+ error_report_err(E);
@script:python@
p << r1.p;
@@
print "%s:%s:%s: prefix dropped" % (p[0].file, p[0].line, p[0].column)
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <1450452927-8346-4-git-send-email-armbru@redhat.com>
2015-12-18 18:35:06 +03:00
|
|
|
error_report_err(local_err);
|
2008-05-05 00:11:34 +04:00
|
|
|
} else {
|
2014-12-03 21:20:58 +03:00
|
|
|
monitor_printf(mon, "boot device list now set to %s\n", bootdevice);
|
2008-05-05 00:11:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-06 16:18:24 +03:00
|
|
|
static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
|
2011-09-12 00:22:05 +04:00
|
|
|
{
|
2017-01-16 11:40:05 +03:00
|
|
|
bool flatview = qdict_get_try_bool(qdict, "flatview", false);
|
2017-09-21 11:51:06 +03:00
|
|
|
bool dispatch_tree = qdict_get_try_bool(qdict, "dispatch_tree", false);
|
2018-06-04 06:25:11 +03:00
|
|
|
bool owner = qdict_get_try_bool(qdict, "owner", false);
|
memory: Make 'info mtree' not display disabled regions by default
We might have many disabled memory regions, making the 'info mtree'
output too verbose to be useful.
Remove the disabled regions in the default output, but allow the
monitor user to display them using the '-D' option.
Before:
(qemu) info mtree
memory-region: system
0000000000000000-ffffffffffffffff (prio 0, i/o): system
0000000000000000-0000000007ffffff (prio 0, ram): alias ram-below-4g @pc.ram 0000000000000000-0000000007ffffff
0000000000000000-ffffffffffffffff (prio -1, i/o): pci
00000000000a0000-00000000000bffff (prio 1, i/o): vga-lowmem
00000000000c0000-00000000000dffff (prio 1, rom): pc.rom
00000000000e0000-00000000000fffff (prio 1, rom): alias isa-bios @pc.bios 0000000000020000-000000000003ffff
00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios
00000000000a0000-00000000000bffff (prio 1, i/o): alias smram-region @pci 00000000000a0000-00000000000bffff
00000000000c0000-00000000000c3fff (prio 1, ram): alias pam-ram @pc.ram 00000000000c0000-00000000000c3fff [disabled]
00000000000c0000-00000000000c3fff (prio 1, ram): alias pam-pci @pc.ram 00000000000c0000-00000000000c3fff [disabled]
00000000000c0000-00000000000c3fff (prio 1, ram): alias pam-rom @pc.ram 00000000000c0000-00000000000c3fff [disabled]
00000000000c0000-00000000000c3fff (prio 1, i/o): alias pam-pci @pci 00000000000c0000-00000000000c3fff
00000000000c4000-00000000000c7fff (prio 1, ram): alias pam-ram @pc.ram 00000000000c4000-00000000000c7fff [disabled]
00000000000c4000-00000000000c7fff (prio 1, ram): alias pam-pci @pc.ram 00000000000c4000-00000000000c7fff [disabled]
00000000000c4000-00000000000c7fff (prio 1, ram): alias pam-rom @pc.ram 00000000000c4000-00000000000c7fff [disabled]
00000000000c4000-00000000000c7fff (prio 1, i/o): alias pam-pci @pci 00000000000c4000-00000000000c7fff
00000000000c8000-00000000000cbfff (prio 1, ram): alias pam-ram @pc.ram 00000000000c8000-00000000000cbfff [disabled]
00000000000c8000-00000000000cbfff (prio 1, ram): alias pam-pci @pc.ram 00000000000c8000-00000000000cbfff [disabled]
00000000000c8000-00000000000cbfff (prio 1, ram): alias pam-rom @pc.ram 00000000000c8000-00000000000cbfff [disabled]
00000000000c8000-00000000000cbfff (prio 1, i/o): alias pam-pci @pci 00000000000c8000-00000000000cbfff
00000000000cc000-00000000000cffff (prio 1, ram): alias pam-ram @pc.ram 00000000000cc000-00000000000cffff [disabled]
00000000000cc000-00000000000cffff (prio 1, ram): alias pam-pci @pc.ram 00000000000cc000-00000000000cffff [disabled]
00000000000cc000-00000000000cffff (prio 1, ram): alias pam-rom @pc.ram 00000000000cc000-00000000000cffff [disabled]
00000000000cc000-00000000000cffff (prio 1, i/o): alias pam-pci @pci 00000000000cc000-00000000000cffff
00000000000d0000-00000000000d3fff (prio 1, ram): alias pam-ram @pc.ram 00000000000d0000-00000000000d3fff [disabled]
00000000000d0000-00000000000d3fff (prio 1, ram): alias pam-pci @pc.ram 00000000000d0000-00000000000d3fff [disabled]
00000000000d0000-00000000000d3fff (prio 1, ram): alias pam-rom @pc.ram 00000000000d0000-00000000000d3fff [disabled]
00000000000d0000-00000000000d3fff (prio 1, i/o): alias pam-pci @pci 00000000000d0000-00000000000d3fff
00000000000d4000-00000000000d7fff (prio 1, ram): alias pam-ram @pc.ram 00000000000d4000-00000000000d7fff [disabled]
00000000000d4000-00000000000d7fff (prio 1, ram): alias pam-pci @pc.ram 00000000000d4000-00000000000d7fff [disabled]
00000000000d4000-00000000000d7fff (prio 1, ram): alias pam-rom @pc.ram 00000000000d4000-00000000000d7fff [disabled]
00000000000d4000-00000000000d7fff (prio 1, i/o): alias pam-pci @pci 00000000000d4000-00000000000d7fff
00000000000d8000-00000000000dbfff (prio 1, ram): alias pam-ram @pc.ram 00000000000d8000-00000000000dbfff [disabled]
00000000000d8000-00000000000dbfff (prio 1, ram): alias pam-pci @pc.ram 00000000000d8000-00000000000dbfff [disabled]
00000000000d8000-00000000000dbfff (prio 1, ram): alias pam-rom @pc.ram 00000000000d8000-00000000000dbfff [disabled]
00000000000d8000-00000000000dbfff (prio 1, i/o): alias pam-pci @pci 00000000000d8000-00000000000dbfff
00000000000dc000-00000000000dffff (prio 1, ram): alias pam-ram @pc.ram 00000000000dc000-00000000000dffff [disabled]
00000000000dc000-00000000000dffff (prio 1, ram): alias pam-pci @pc.ram 00000000000dc000-00000000000dffff [disabled]
00000000000dc000-00000000000dffff (prio 1, ram): alias pam-rom @pc.ram 00000000000dc000-00000000000dffff [disabled]
00000000000dc000-00000000000dffff (prio 1, i/o): alias pam-pci @pci 00000000000dc000-00000000000dffff
00000000000e0000-00000000000e3fff (prio 1, ram): alias pam-ram @pc.ram 00000000000e0000-00000000000e3fff [disabled]
00000000000e0000-00000000000e3fff (prio 1, ram): alias pam-pci @pc.ram 00000000000e0000-00000000000e3fff [disabled]
00000000000e0000-00000000000e3fff (prio 1, ram): alias pam-rom @pc.ram 00000000000e0000-00000000000e3fff [disabled]
00000000000e0000-00000000000e3fff (prio 1, i/o): alias pam-pci @pci 00000000000e0000-00000000000e3fff
00000000000e4000-00000000000e7fff (prio 1, ram): alias pam-ram @pc.ram 00000000000e4000-00000000000e7fff [disabled]
00000000000e4000-00000000000e7fff (prio 1, ram): alias pam-pci @pc.ram 00000000000e4000-00000000000e7fff [disabled]
00000000000e4000-00000000000e7fff (prio 1, ram): alias pam-rom @pc.ram 00000000000e4000-00000000000e7fff [disabled]
00000000000e4000-00000000000e7fff (prio 1, i/o): alias pam-pci @pci 00000000000e4000-00000000000e7fff
00000000000e8000-00000000000ebfff (prio 1, ram): alias pam-ram @pc.ram 00000000000e8000-00000000000ebfff [disabled]
00000000000e8000-00000000000ebfff (prio 1, ram): alias pam-pci @pc.ram 00000000000e8000-00000000000ebfff [disabled]
00000000000e8000-00000000000ebfff (prio 1, ram): alias pam-rom @pc.ram 00000000000e8000-00000000000ebfff [disabled]
00000000000e8000-00000000000ebfff (prio 1, i/o): alias pam-pci @pci 00000000000e8000-00000000000ebfff
00000000000ec000-00000000000effff (prio 1, ram): alias pam-ram @pc.ram 00000000000ec000-00000000000effff [disabled]
00000000000ec000-00000000000effff (prio 1, ram): alias pam-pci @pc.ram 00000000000ec000-00000000000effff [disabled]
00000000000ec000-00000000000effff (prio 1, ram): alias pam-rom @pc.ram 00000000000ec000-00000000000effff [disabled]
00000000000ec000-00000000000effff (prio 1, i/o): alias pam-pci @pci 00000000000ec000-00000000000effff
00000000000f0000-00000000000fffff (prio 1, ram): alias pam-ram @pc.ram 00000000000f0000-00000000000fffff [disabled]
00000000000f0000-00000000000fffff (prio 1, ram): alias pam-pci @pc.ram 00000000000f0000-00000000000fffff [disabled]
00000000000f0000-00000000000fffff (prio 1, ram): alias pam-rom @pc.ram 00000000000f0000-00000000000fffff [disabled]
00000000000f0000-00000000000fffff (prio 1, i/o): alias pam-pci @pci 00000000000f0000-00000000000fffff
00000000fec00000-00000000fec00fff (prio 0, i/o): ioapic
00000000fed00000-00000000fed003ff (prio 0, i/o): hpet
00000000fee00000-00000000feefffff (prio 4096, i/o): apic-msi
After:
(qemu) info mtree
memory-region: system
0000000000000000-ffffffffffffffff (prio 0, i/o): system
0000000000000000-0000000007ffffff (prio 0, ram): alias ram-below-4g @pc.ram 0000000000000000-0000000007ffffff
0000000000000000-ffffffffffffffff (prio -1, i/o): pci
00000000000a0000-00000000000bffff (prio 1, i/o): vga-lowmem
00000000000c0000-00000000000dffff (prio 1, rom): pc.rom
00000000000e0000-00000000000fffff (prio 1, rom): alias isa-bios @pc.bios 0000000000020000-000000000003ffff
00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios
00000000000a0000-00000000000bffff (prio 1, i/o): alias smram-region @pci 00000000000a0000-00000000000bffff
00000000000c0000-00000000000c3fff (prio 1, i/o): alias pam-pci @pci 00000000000c0000-00000000000c3fff
00000000000c4000-00000000000c7fff (prio 1, i/o): alias pam-pci @pci 00000000000c4000-00000000000c7fff
00000000000c8000-00000000000cbfff (prio 1, i/o): alias pam-pci @pci 00000000000c8000-00000000000cbfff
00000000000cc000-00000000000cffff (prio 1, i/o): alias pam-pci @pci 00000000000cc000-00000000000cffff
00000000000d0000-00000000000d3fff (prio 1, i/o): alias pam-pci @pci 00000000000d0000-00000000000d3fff
00000000000d4000-00000000000d7fff (prio 1, i/o): alias pam-pci @pci 00000000000d4000-00000000000d7fff
00000000000d8000-00000000000dbfff (prio 1, i/o): alias pam-pci @pci 00000000000d8000-00000000000dbfff
00000000000dc000-00000000000dffff (prio 1, i/o): alias pam-pci @pci 00000000000dc000-00000000000dffff
00000000000e0000-00000000000e3fff (prio 1, i/o): alias pam-pci @pci 00000000000e0000-00000000000e3fff
00000000000e4000-00000000000e7fff (prio 1, i/o): alias pam-pci @pci 00000000000e4000-00000000000e7fff
00000000000e8000-00000000000ebfff (prio 1, i/o): alias pam-pci @pci 00000000000e8000-00000000000ebfff
00000000000ec000-00000000000effff (prio 1, i/o): alias pam-pci @pci 00000000000ec000-00000000000effff
00000000000f0000-00000000000fffff (prio 1, i/o): alias pam-pci @pci 00000000000f0000-00000000000fffff
00000000fec00000-00000000fec00fff (prio 0, i/o): ioapic
00000000fed00000-00000000fed003ff (prio 0, i/o): hpet
00000000fee00000-00000000feefffff (prio 4096, i/o): apic-msi
The old behavior is preserved using 'info mtree -D'.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-05-29 15:53:25 +03:00
|
|
|
bool disabled = qdict_get_try_bool(qdict, "disabled", false);
|
2017-01-16 11:40:05 +03:00
|
|
|
|
memory: Make 'info mtree' not display disabled regions by default
We might have many disabled memory regions, making the 'info mtree'
output too verbose to be useful.
Remove the disabled regions in the default output, but allow the
monitor user to display them using the '-D' option.
Before:
(qemu) info mtree
memory-region: system
0000000000000000-ffffffffffffffff (prio 0, i/o): system
0000000000000000-0000000007ffffff (prio 0, ram): alias ram-below-4g @pc.ram 0000000000000000-0000000007ffffff
0000000000000000-ffffffffffffffff (prio -1, i/o): pci
00000000000a0000-00000000000bffff (prio 1, i/o): vga-lowmem
00000000000c0000-00000000000dffff (prio 1, rom): pc.rom
00000000000e0000-00000000000fffff (prio 1, rom): alias isa-bios @pc.bios 0000000000020000-000000000003ffff
00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios
00000000000a0000-00000000000bffff (prio 1, i/o): alias smram-region @pci 00000000000a0000-00000000000bffff
00000000000c0000-00000000000c3fff (prio 1, ram): alias pam-ram @pc.ram 00000000000c0000-00000000000c3fff [disabled]
00000000000c0000-00000000000c3fff (prio 1, ram): alias pam-pci @pc.ram 00000000000c0000-00000000000c3fff [disabled]
00000000000c0000-00000000000c3fff (prio 1, ram): alias pam-rom @pc.ram 00000000000c0000-00000000000c3fff [disabled]
00000000000c0000-00000000000c3fff (prio 1, i/o): alias pam-pci @pci 00000000000c0000-00000000000c3fff
00000000000c4000-00000000000c7fff (prio 1, ram): alias pam-ram @pc.ram 00000000000c4000-00000000000c7fff [disabled]
00000000000c4000-00000000000c7fff (prio 1, ram): alias pam-pci @pc.ram 00000000000c4000-00000000000c7fff [disabled]
00000000000c4000-00000000000c7fff (prio 1, ram): alias pam-rom @pc.ram 00000000000c4000-00000000000c7fff [disabled]
00000000000c4000-00000000000c7fff (prio 1, i/o): alias pam-pci @pci 00000000000c4000-00000000000c7fff
00000000000c8000-00000000000cbfff (prio 1, ram): alias pam-ram @pc.ram 00000000000c8000-00000000000cbfff [disabled]
00000000000c8000-00000000000cbfff (prio 1, ram): alias pam-pci @pc.ram 00000000000c8000-00000000000cbfff [disabled]
00000000000c8000-00000000000cbfff (prio 1, ram): alias pam-rom @pc.ram 00000000000c8000-00000000000cbfff [disabled]
00000000000c8000-00000000000cbfff (prio 1, i/o): alias pam-pci @pci 00000000000c8000-00000000000cbfff
00000000000cc000-00000000000cffff (prio 1, ram): alias pam-ram @pc.ram 00000000000cc000-00000000000cffff [disabled]
00000000000cc000-00000000000cffff (prio 1, ram): alias pam-pci @pc.ram 00000000000cc000-00000000000cffff [disabled]
00000000000cc000-00000000000cffff (prio 1, ram): alias pam-rom @pc.ram 00000000000cc000-00000000000cffff [disabled]
00000000000cc000-00000000000cffff (prio 1, i/o): alias pam-pci @pci 00000000000cc000-00000000000cffff
00000000000d0000-00000000000d3fff (prio 1, ram): alias pam-ram @pc.ram 00000000000d0000-00000000000d3fff [disabled]
00000000000d0000-00000000000d3fff (prio 1, ram): alias pam-pci @pc.ram 00000000000d0000-00000000000d3fff [disabled]
00000000000d0000-00000000000d3fff (prio 1, ram): alias pam-rom @pc.ram 00000000000d0000-00000000000d3fff [disabled]
00000000000d0000-00000000000d3fff (prio 1, i/o): alias pam-pci @pci 00000000000d0000-00000000000d3fff
00000000000d4000-00000000000d7fff (prio 1, ram): alias pam-ram @pc.ram 00000000000d4000-00000000000d7fff [disabled]
00000000000d4000-00000000000d7fff (prio 1, ram): alias pam-pci @pc.ram 00000000000d4000-00000000000d7fff [disabled]
00000000000d4000-00000000000d7fff (prio 1, ram): alias pam-rom @pc.ram 00000000000d4000-00000000000d7fff [disabled]
00000000000d4000-00000000000d7fff (prio 1, i/o): alias pam-pci @pci 00000000000d4000-00000000000d7fff
00000000000d8000-00000000000dbfff (prio 1, ram): alias pam-ram @pc.ram 00000000000d8000-00000000000dbfff [disabled]
00000000000d8000-00000000000dbfff (prio 1, ram): alias pam-pci @pc.ram 00000000000d8000-00000000000dbfff [disabled]
00000000000d8000-00000000000dbfff (prio 1, ram): alias pam-rom @pc.ram 00000000000d8000-00000000000dbfff [disabled]
00000000000d8000-00000000000dbfff (prio 1, i/o): alias pam-pci @pci 00000000000d8000-00000000000dbfff
00000000000dc000-00000000000dffff (prio 1, ram): alias pam-ram @pc.ram 00000000000dc000-00000000000dffff [disabled]
00000000000dc000-00000000000dffff (prio 1, ram): alias pam-pci @pc.ram 00000000000dc000-00000000000dffff [disabled]
00000000000dc000-00000000000dffff (prio 1, ram): alias pam-rom @pc.ram 00000000000dc000-00000000000dffff [disabled]
00000000000dc000-00000000000dffff (prio 1, i/o): alias pam-pci @pci 00000000000dc000-00000000000dffff
00000000000e0000-00000000000e3fff (prio 1, ram): alias pam-ram @pc.ram 00000000000e0000-00000000000e3fff [disabled]
00000000000e0000-00000000000e3fff (prio 1, ram): alias pam-pci @pc.ram 00000000000e0000-00000000000e3fff [disabled]
00000000000e0000-00000000000e3fff (prio 1, ram): alias pam-rom @pc.ram 00000000000e0000-00000000000e3fff [disabled]
00000000000e0000-00000000000e3fff (prio 1, i/o): alias pam-pci @pci 00000000000e0000-00000000000e3fff
00000000000e4000-00000000000e7fff (prio 1, ram): alias pam-ram @pc.ram 00000000000e4000-00000000000e7fff [disabled]
00000000000e4000-00000000000e7fff (prio 1, ram): alias pam-pci @pc.ram 00000000000e4000-00000000000e7fff [disabled]
00000000000e4000-00000000000e7fff (prio 1, ram): alias pam-rom @pc.ram 00000000000e4000-00000000000e7fff [disabled]
00000000000e4000-00000000000e7fff (prio 1, i/o): alias pam-pci @pci 00000000000e4000-00000000000e7fff
00000000000e8000-00000000000ebfff (prio 1, ram): alias pam-ram @pc.ram 00000000000e8000-00000000000ebfff [disabled]
00000000000e8000-00000000000ebfff (prio 1, ram): alias pam-pci @pc.ram 00000000000e8000-00000000000ebfff [disabled]
00000000000e8000-00000000000ebfff (prio 1, ram): alias pam-rom @pc.ram 00000000000e8000-00000000000ebfff [disabled]
00000000000e8000-00000000000ebfff (prio 1, i/o): alias pam-pci @pci 00000000000e8000-00000000000ebfff
00000000000ec000-00000000000effff (prio 1, ram): alias pam-ram @pc.ram 00000000000ec000-00000000000effff [disabled]
00000000000ec000-00000000000effff (prio 1, ram): alias pam-pci @pc.ram 00000000000ec000-00000000000effff [disabled]
00000000000ec000-00000000000effff (prio 1, ram): alias pam-rom @pc.ram 00000000000ec000-00000000000effff [disabled]
00000000000ec000-00000000000effff (prio 1, i/o): alias pam-pci @pci 00000000000ec000-00000000000effff
00000000000f0000-00000000000fffff (prio 1, ram): alias pam-ram @pc.ram 00000000000f0000-00000000000fffff [disabled]
00000000000f0000-00000000000fffff (prio 1, ram): alias pam-pci @pc.ram 00000000000f0000-00000000000fffff [disabled]
00000000000f0000-00000000000fffff (prio 1, ram): alias pam-rom @pc.ram 00000000000f0000-00000000000fffff [disabled]
00000000000f0000-00000000000fffff (prio 1, i/o): alias pam-pci @pci 00000000000f0000-00000000000fffff
00000000fec00000-00000000fec00fff (prio 0, i/o): ioapic
00000000fed00000-00000000fed003ff (prio 0, i/o): hpet
00000000fee00000-00000000feefffff (prio 4096, i/o): apic-msi
After:
(qemu) info mtree
memory-region: system
0000000000000000-ffffffffffffffff (prio 0, i/o): system
0000000000000000-0000000007ffffff (prio 0, ram): alias ram-below-4g @pc.ram 0000000000000000-0000000007ffffff
0000000000000000-ffffffffffffffff (prio -1, i/o): pci
00000000000a0000-00000000000bffff (prio 1, i/o): vga-lowmem
00000000000c0000-00000000000dffff (prio 1, rom): pc.rom
00000000000e0000-00000000000fffff (prio 1, rom): alias isa-bios @pc.bios 0000000000020000-000000000003ffff
00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios
00000000000a0000-00000000000bffff (prio 1, i/o): alias smram-region @pci 00000000000a0000-00000000000bffff
00000000000c0000-00000000000c3fff (prio 1, i/o): alias pam-pci @pci 00000000000c0000-00000000000c3fff
00000000000c4000-00000000000c7fff (prio 1, i/o): alias pam-pci @pci 00000000000c4000-00000000000c7fff
00000000000c8000-00000000000cbfff (prio 1, i/o): alias pam-pci @pci 00000000000c8000-00000000000cbfff
00000000000cc000-00000000000cffff (prio 1, i/o): alias pam-pci @pci 00000000000cc000-00000000000cffff
00000000000d0000-00000000000d3fff (prio 1, i/o): alias pam-pci @pci 00000000000d0000-00000000000d3fff
00000000000d4000-00000000000d7fff (prio 1, i/o): alias pam-pci @pci 00000000000d4000-00000000000d7fff
00000000000d8000-00000000000dbfff (prio 1, i/o): alias pam-pci @pci 00000000000d8000-00000000000dbfff
00000000000dc000-00000000000dffff (prio 1, i/o): alias pam-pci @pci 00000000000dc000-00000000000dffff
00000000000e0000-00000000000e3fff (prio 1, i/o): alias pam-pci @pci 00000000000e0000-00000000000e3fff
00000000000e4000-00000000000e7fff (prio 1, i/o): alias pam-pci @pci 00000000000e4000-00000000000e7fff
00000000000e8000-00000000000ebfff (prio 1, i/o): alias pam-pci @pci 00000000000e8000-00000000000ebfff
00000000000ec000-00000000000effff (prio 1, i/o): alias pam-pci @pci 00000000000ec000-00000000000effff
00000000000f0000-00000000000fffff (prio 1, i/o): alias pam-pci @pci 00000000000f0000-00000000000fffff
00000000fec00000-00000000fec00fff (prio 0, i/o): ioapic
00000000fed00000-00000000fed003ff (prio 0, i/o): hpet
00000000fee00000-00000000feefffff (prio 4096, i/o): apic-msi
The old behavior is preserved using 'info mtree -D'.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-05-29 15:53:25 +03:00
|
|
|
mtree_info(flatview, dispatch_tree, owner, disabled);
|
2011-09-12 00:22:05 +04:00
|
|
|
}
|
|
|
|
|
2006-07-16 22:57:03 +04:00
|
|
|
/* Capture support */
|
2009-09-12 11:36:22 +04:00
|
|
|
static QLIST_HEAD (capture_list_head, CaptureState) capture_head;
|
2006-07-16 22:57:03 +04:00
|
|
|
|
2015-02-06 16:18:24 +03:00
|
|
|
static void hmp_info_capture(Monitor *mon, const QDict *qdict)
|
2006-07-16 22:57:03 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
CaptureState *s;
|
|
|
|
|
|
|
|
for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) {
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, "[%d]: ", i);
|
2006-07-16 22:57:03 +04:00
|
|
|
s->ops.info (s->opaque);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
hmp: Name HMP command handler functions hmp_COMMAND()
Some are called do_COMMAND() (old ones, usually), some hmp_COMMAND(),
and sometimes COMMAND pointlessly differs in spelling.
Normalize to hmp_COMMAND(), where COMMAND is exactly the command name
with '-' replaced by '_'.
Exceptions:
* do_device_add() and client_migrate_info() *not* renamed to
hmp_device_add(), hmp_client_migrate_info(), because they're also
QMP handlers. They still need to be converted to QAPI.
* do_memory_dump(), do_physical_memory_dump(), do_ioport_read(),
do_ioport_write() renamed do hmp_* instead of hmp_x(), hmp_xp(),
hmp_i(), hmp_o(), because those names are too cryptic for my taste.
* do_info_help() renamed to hmp_info_help() instead of hmp_info(),
because it only covers help.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-02-06 15:55:43 +03:00
|
|
|
static void hmp_stopcapture(Monitor *mon, const QDict *qdict)
|
2006-07-16 22:57:03 +04:00
|
|
|
{
|
|
|
|
int i;
|
2009-08-28 22:27:13 +04:00
|
|
|
int n = qdict_get_int(qdict, "n");
|
2006-07-16 22:57:03 +04:00
|
|
|
CaptureState *s;
|
|
|
|
|
|
|
|
for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) {
|
|
|
|
if (i == n) {
|
|
|
|
s->ops.destroy (s->opaque);
|
2009-09-12 11:36:22 +04:00
|
|
|
QLIST_REMOVE (s, entries);
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free (s);
|
2006-07-16 22:57:03 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
hmp: Name HMP command handler functions hmp_COMMAND()
Some are called do_COMMAND() (old ones, usually), some hmp_COMMAND(),
and sometimes COMMAND pointlessly differs in spelling.
Normalize to hmp_COMMAND(), where COMMAND is exactly the command name
with '-' replaced by '_'.
Exceptions:
* do_device_add() and client_migrate_info() *not* renamed to
hmp_device_add(), hmp_client_migrate_info(), because they're also
QMP handlers. They still need to be converted to QAPI.
* do_memory_dump(), do_physical_memory_dump(), do_ioport_read(),
do_ioport_write() renamed do hmp_* instead of hmp_x(), hmp_xp(),
hmp_i(), hmp_o(), because those names are too cryptic for my taste.
* do_info_help() renamed to hmp_info_help() instead of hmp_info(),
because it only covers help.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-02-06 15:55:43 +03:00
|
|
|
static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
|
2009-08-28 22:27:19 +04:00
|
|
|
{
|
|
|
|
const char *path = qdict_get_str(qdict, "path");
|
2019-08-19 02:06:48 +03:00
|
|
|
int freq = qdict_get_try_int(qdict, "freq", 44100);
|
|
|
|
int bits = qdict_get_try_int(qdict, "bits", 16);
|
|
|
|
int nchannels = qdict_get_try_int(qdict, "nchannels", 2);
|
|
|
|
const char *audiodev = qdict_get_str(qdict, "audiodev");
|
2006-07-16 22:57:03 +04:00
|
|
|
CaptureState *s;
|
2019-08-19 02:06:48 +03:00
|
|
|
AudioState *as = audio_state_by_name(audiodev);
|
2006-07-16 22:57:03 +04:00
|
|
|
|
2019-08-19 02:06:48 +03:00
|
|
|
if (!as) {
|
|
|
|
monitor_printf(mon, "Audiodev '%s' not found\n", audiodev);
|
|
|
|
return;
|
|
|
|
}
|
2006-07-16 22:57:03 +04:00
|
|
|
|
2019-08-19 02:06:48 +03:00
|
|
|
s = g_malloc0 (sizeof (*s));
|
2006-07-16 22:57:03 +04:00
|
|
|
|
2019-08-19 02:06:48 +03:00
|
|
|
if (wav_start_capture(as, s, path, freq, bits, nchannels)) {
|
2011-01-21 13:53:55 +03:00
|
|
|
monitor_printf(mon, "Failed to add wave capture\n");
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free (s);
|
2011-01-21 13:53:55 +03:00
|
|
|
return;
|
2006-07-16 22:57:03 +04:00
|
|
|
}
|
2009-09-12 11:36:22 +04:00
|
|
|
QLIST_INSERT_HEAD (&capture_head, s, entries);
|
2006-07-16 22:57:03 +04:00
|
|
|
}
|
|
|
|
|
2012-06-22 22:36:09 +04:00
|
|
|
void qmp_getfd(const char *fdname, Error **errp)
|
2009-07-22 12:11:40 +04:00
|
|
|
{
|
2020-10-05 18:58:44 +03:00
|
|
|
Monitor *cur_mon = monitor_cur();
|
2009-10-02 01:12:16 +04:00
|
|
|
mon_fd_t *monfd;
|
2018-06-08 06:55:06 +03:00
|
|
|
int fd, tmp_fd;
|
2009-07-22 12:11:40 +04:00
|
|
|
|
2016-10-22 12:52:55 +03:00
|
|
|
fd = qemu_chr_fe_get_msgfd(&cur_mon->chr);
|
2009-07-22 12:11:40 +04:00
|
|
|
if (fd == -1) {
|
2020-11-13 11:26:18 +03:00
|
|
|
error_setg(errp, "No file descriptor supplied via SCM_RIGHTS");
|
2012-06-22 22:36:09 +04:00
|
|
|
return;
|
2009-07-22 12:11:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (qemu_isdigit(fdname[0])) {
|
2014-04-24 15:58:18 +04:00
|
|
|
close(fd);
|
2015-03-17 13:54:50 +03:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "fdname",
|
|
|
|
"a name not starting with a digit");
|
2012-06-22 22:36:09 +04:00
|
|
|
return;
|
2009-07-22 12:11:40 +04:00
|
|
|
}
|
|
|
|
|
2020-09-22 12:57:41 +03:00
|
|
|
QEMU_LOCK_GUARD(&cur_mon->mon_lock);
|
2012-06-22 22:36:09 +04:00
|
|
|
QLIST_FOREACH(monfd, &cur_mon->fds, next) {
|
2009-07-22 12:11:40 +04:00
|
|
|
if (strcmp(monfd->name, fdname) != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-06-08 06:55:06 +03:00
|
|
|
tmp_fd = monfd->fd;
|
2009-07-22 12:11:40 +04:00
|
|
|
monfd->fd = fd;
|
2018-07-03 11:53:57 +03:00
|
|
|
/* Make sure close() is outside critical section */
|
2018-06-08 06:55:06 +03:00
|
|
|
close(tmp_fd);
|
2012-06-22 22:36:09 +04:00
|
|
|
return;
|
2009-07-22 12:11:40 +04:00
|
|
|
}
|
|
|
|
|
2022-03-15 17:41:56 +03:00
|
|
|
monfd = g_new0(mon_fd_t, 1);
|
2011-08-21 07:09:37 +04:00
|
|
|
monfd->name = g_strdup(fdname);
|
2009-07-22 12:11:40 +04:00
|
|
|
monfd->fd = fd;
|
|
|
|
|
2012-06-22 22:36:09 +04:00
|
|
|
QLIST_INSERT_HEAD(&cur_mon->fds, monfd, next);
|
2009-07-22 12:11:40 +04:00
|
|
|
}
|
|
|
|
|
2012-06-22 22:36:09 +04:00
|
|
|
void qmp_closefd(const char *fdname, Error **errp)
|
2009-07-22 12:11:40 +04:00
|
|
|
{
|
2020-10-05 18:58:44 +03:00
|
|
|
Monitor *cur_mon = monitor_cur();
|
2009-10-02 01:12:16 +04:00
|
|
|
mon_fd_t *monfd;
|
2018-06-08 06:55:06 +03:00
|
|
|
int tmp_fd;
|
2009-07-22 12:11:40 +04:00
|
|
|
|
2018-06-08 06:55:06 +03:00
|
|
|
qemu_mutex_lock(&cur_mon->mon_lock);
|
2012-06-22 22:36:09 +04:00
|
|
|
QLIST_FOREACH(monfd, &cur_mon->fds, next) {
|
2009-07-22 12:11:40 +04:00
|
|
|
if (strcmp(monfd->name, fdname) != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-09-12 11:36:22 +04:00
|
|
|
QLIST_REMOVE(monfd, next);
|
2018-06-08 06:55:06 +03:00
|
|
|
tmp_fd = monfd->fd;
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(monfd->name);
|
|
|
|
g_free(monfd);
|
2018-06-08 06:55:06 +03:00
|
|
|
qemu_mutex_unlock(&cur_mon->mon_lock);
|
2018-07-03 11:53:57 +03:00
|
|
|
/* Make sure close() is outside critical section */
|
2018-06-08 06:55:06 +03:00
|
|
|
close(tmp_fd);
|
2012-06-22 22:36:09 +04:00
|
|
|
return;
|
2009-07-22 12:11:40 +04:00
|
|
|
}
|
|
|
|
|
2018-06-08 06:55:06 +03:00
|
|
|
qemu_mutex_unlock(&cur_mon->mon_lock);
|
2020-11-13 11:26:18 +03:00
|
|
|
error_setg(errp, "File descriptor named '%s' not found", fdname);
|
2009-07-22 12:11:40 +04:00
|
|
|
}
|
|
|
|
|
2012-09-20 18:50:32 +04:00
|
|
|
int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp)
|
2009-07-22 12:11:41 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
mon_fd_t *monfd;
|
2009-07-22 12:11:41 +04:00
|
|
|
|
2020-09-22 12:57:41 +03:00
|
|
|
QEMU_LOCK_GUARD(&mon->mon_lock);
|
2009-09-12 11:36:22 +04:00
|
|
|
QLIST_FOREACH(monfd, &mon->fds, next) {
|
2009-07-22 12:11:41 +04:00
|
|
|
int fd;
|
|
|
|
|
|
|
|
if (strcmp(monfd->name, fdname) != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = monfd->fd;
|
|
|
|
|
|
|
|
/* caller takes ownership of fd */
|
2009-09-12 11:36:22 +04:00
|
|
|
QLIST_REMOVE(monfd, next);
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(monfd->name);
|
|
|
|
g_free(monfd);
|
2009-07-22 12:11:41 +04:00
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2012-09-20 18:50:32 +04:00
|
|
|
error_setg(errp, "File descriptor named '%s' has not been found", fdname);
|
2009-07-22 12:11:41 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-08-15 00:43:43 +04:00
|
|
|
static void monitor_fdset_cleanup(MonFdset *mon_fdset)
|
|
|
|
{
|
|
|
|
MonFdsetFd *mon_fdset_fd;
|
|
|
|
MonFdsetFd *mon_fdset_fd_next;
|
|
|
|
|
|
|
|
QLIST_FOREACH_SAFE(mon_fdset_fd, &mon_fdset->fds, next, mon_fdset_fd_next) {
|
2012-10-18 23:19:33 +04:00
|
|
|
if ((mon_fdset_fd->removed ||
|
|
|
|
(QLIST_EMPTY(&mon_fdset->dup_fds) && mon_refcount == 0)) &&
|
|
|
|
runstate_is_running()) {
|
2012-08-15 00:43:43 +04:00
|
|
|
close(mon_fdset_fd->fd);
|
|
|
|
g_free(mon_fdset_fd->opaque);
|
|
|
|
QLIST_REMOVE(mon_fdset_fd, next);
|
|
|
|
g_free(mon_fdset_fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-15 00:43:47 +04:00
|
|
|
if (QLIST_EMPTY(&mon_fdset->fds) && QLIST_EMPTY(&mon_fdset->dup_fds)) {
|
2012-08-15 00:43:43 +04:00
|
|
|
QLIST_REMOVE(mon_fdset, next);
|
|
|
|
g_free(mon_fdset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-13 18:34:00 +03:00
|
|
|
void monitor_fdsets_cleanup(void)
|
2012-08-15 00:43:48 +04:00
|
|
|
{
|
|
|
|
MonFdset *mon_fdset;
|
|
|
|
MonFdset *mon_fdset_next;
|
|
|
|
|
2020-09-22 12:57:41 +03:00
|
|
|
QEMU_LOCK_GUARD(&mon_fdsets_lock);
|
2012-08-15 00:43:48 +04:00
|
|
|
QLIST_FOREACH_SAFE(mon_fdset, &mon_fdsets, next, mon_fdset_next) {
|
|
|
|
monitor_fdset_cleanup(mon_fdset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-15 00:43:43 +04:00
|
|
|
AddfdInfo *qmp_add_fd(bool has_fdset_id, int64_t fdset_id, bool has_opaque,
|
|
|
|
const char *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
int fd;
|
2020-10-05 18:58:44 +03:00
|
|
|
Monitor *mon = monitor_cur();
|
2012-08-15 00:43:43 +04:00
|
|
|
AddfdInfo *fdinfo;
|
|
|
|
|
2016-10-22 12:52:55 +03:00
|
|
|
fd = qemu_chr_fe_get_msgfd(&mon->chr);
|
2012-08-15 00:43:43 +04:00
|
|
|
if (fd == -1) {
|
2020-11-13 11:26:18 +03:00
|
|
|
error_setg(errp, "No file descriptor supplied via SCM_RIGHTS");
|
2012-08-15 00:43:43 +04:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2012-10-18 23:19:32 +04:00
|
|
|
fdinfo = monitor_fdset_add_fd(fd, has_fdset_id, fdset_id,
|
|
|
|
has_opaque, opaque, errp);
|
|
|
|
if (fdinfo) {
|
|
|
|
return fdinfo;
|
2012-08-15 00:43:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (fd != -1) {
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void qmp_remove_fd(int64_t fdset_id, bool has_fd, int64_t fd, Error **errp)
|
|
|
|
{
|
|
|
|
MonFdset *mon_fdset;
|
|
|
|
MonFdsetFd *mon_fdset_fd;
|
|
|
|
char fd_str[60];
|
|
|
|
|
2020-09-22 12:57:41 +03:00
|
|
|
QEMU_LOCK_GUARD(&mon_fdsets_lock);
|
2012-08-15 00:43:43 +04:00
|
|
|
QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
|
|
|
|
if (mon_fdset->id != fdset_id) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
QLIST_FOREACH(mon_fdset_fd, &mon_fdset->fds, next) {
|
|
|
|
if (has_fd) {
|
|
|
|
if (mon_fdset_fd->fd != fd) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
mon_fdset_fd->removed = true;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
mon_fdset_fd->removed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (has_fd && !mon_fdset_fd) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
monitor_fdset_cleanup(mon_fdset);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (has_fd) {
|
|
|
|
snprintf(fd_str, sizeof(fd_str), "fdset-id:%" PRId64 ", fd:%" PRId64,
|
|
|
|
fdset_id, fd);
|
|
|
|
} else {
|
|
|
|
snprintf(fd_str, sizeof(fd_str), "fdset-id:%" PRId64, fdset_id);
|
|
|
|
}
|
2020-11-13 11:26:18 +03:00
|
|
|
error_setg(errp, "File descriptor named '%s' not found", fd_str);
|
2012-08-15 00:43:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
FdsetInfoList *qmp_query_fdsets(Error **errp)
|
|
|
|
{
|
|
|
|
MonFdset *mon_fdset;
|
|
|
|
MonFdsetFd *mon_fdset_fd;
|
|
|
|
FdsetInfoList *fdset_list = NULL;
|
|
|
|
|
2020-09-22 12:57:41 +03:00
|
|
|
QEMU_LOCK_GUARD(&mon_fdsets_lock);
|
2012-08-15 00:43:43 +04:00
|
|
|
QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
|
2020-11-13 04:13:37 +03:00
|
|
|
FdsetInfo *fdset_info = g_malloc0(sizeof(*fdset_info));
|
2012-08-15 00:43:43 +04:00
|
|
|
|
2020-11-13 04:13:37 +03:00
|
|
|
fdset_info->fdset_id = mon_fdset->id;
|
2012-08-15 00:43:43 +04:00
|
|
|
|
|
|
|
QLIST_FOREACH(mon_fdset_fd, &mon_fdset->fds, next) {
|
2020-11-13 04:13:37 +03:00
|
|
|
FdsetFdInfo *fdsetfd_info;
|
2012-08-15 00:43:43 +04:00
|
|
|
|
|
|
|
fdsetfd_info = g_malloc0(sizeof(*fdsetfd_info));
|
2020-11-13 04:13:37 +03:00
|
|
|
fdsetfd_info->fd = mon_fdset_fd->fd;
|
2012-08-15 00:43:43 +04:00
|
|
|
if (mon_fdset_fd->opaque) {
|
2020-11-13 04:13:37 +03:00
|
|
|
fdsetfd_info->has_opaque = true;
|
|
|
|
fdsetfd_info->opaque = g_strdup(mon_fdset_fd->opaque);
|
2012-08-15 00:43:43 +04:00
|
|
|
} else {
|
2020-11-13 04:13:37 +03:00
|
|
|
fdsetfd_info->has_opaque = false;
|
2012-08-15 00:43:43 +04:00
|
|
|
}
|
|
|
|
|
2020-11-13 04:13:37 +03:00
|
|
|
QAPI_LIST_PREPEND(fdset_info->fds, fdsetfd_info);
|
2012-08-15 00:43:43 +04:00
|
|
|
}
|
|
|
|
|
2020-11-13 04:13:37 +03:00
|
|
|
QAPI_LIST_PREPEND(fdset_list, fdset_info);
|
2012-08-15 00:43:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return fdset_list;
|
|
|
|
}
|
|
|
|
|
2012-10-18 23:19:32 +04:00
|
|
|
AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
|
|
|
|
bool has_opaque, const char *opaque,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
MonFdset *mon_fdset = NULL;
|
|
|
|
MonFdsetFd *mon_fdset_fd;
|
|
|
|
AddfdInfo *fdinfo;
|
|
|
|
|
2020-04-04 07:21:08 +03:00
|
|
|
QEMU_LOCK_GUARD(&mon_fdsets_lock);
|
2012-10-18 23:19:32 +04:00
|
|
|
if (has_fdset_id) {
|
|
|
|
QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
|
|
|
|
/* Break if match found or match impossible due to ordering by ID */
|
|
|
|
if (fdset_id <= mon_fdset->id) {
|
|
|
|
if (fdset_id < mon_fdset->id) {
|
|
|
|
mon_fdset = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mon_fdset == NULL) {
|
|
|
|
int64_t fdset_id_prev = -1;
|
|
|
|
MonFdset *mon_fdset_cur = QLIST_FIRST(&mon_fdsets);
|
|
|
|
|
|
|
|
if (has_fdset_id) {
|
|
|
|
if (fdset_id < 0) {
|
2015-03-17 13:54:50 +03:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "fdset-id",
|
|
|
|
"a non-negative value");
|
2012-10-18 23:19:32 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* Use specified fdset ID */
|
|
|
|
QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
|
|
|
|
mon_fdset_cur = mon_fdset;
|
|
|
|
if (fdset_id < mon_fdset_cur->id) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Use first available fdset ID */
|
|
|
|
QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
|
|
|
|
mon_fdset_cur = mon_fdset;
|
|
|
|
if (fdset_id_prev == mon_fdset_cur->id - 1) {
|
|
|
|
fdset_id_prev = mon_fdset_cur->id;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mon_fdset = g_malloc0(sizeof(*mon_fdset));
|
|
|
|
if (has_fdset_id) {
|
|
|
|
mon_fdset->id = fdset_id;
|
|
|
|
} else {
|
|
|
|
mon_fdset->id = fdset_id_prev + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The fdset list is ordered by fdset ID */
|
|
|
|
if (!mon_fdset_cur) {
|
|
|
|
QLIST_INSERT_HEAD(&mon_fdsets, mon_fdset, next);
|
|
|
|
} else if (mon_fdset->id < mon_fdset_cur->id) {
|
|
|
|
QLIST_INSERT_BEFORE(mon_fdset_cur, mon_fdset, next);
|
|
|
|
} else {
|
|
|
|
QLIST_INSERT_AFTER(mon_fdset_cur, mon_fdset, next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mon_fdset_fd = g_malloc0(sizeof(*mon_fdset_fd));
|
|
|
|
mon_fdset_fd->fd = fd;
|
|
|
|
mon_fdset_fd->removed = false;
|
|
|
|
if (has_opaque) {
|
|
|
|
mon_fdset_fd->opaque = g_strdup(opaque);
|
|
|
|
}
|
|
|
|
QLIST_INSERT_HEAD(&mon_fdset->fds, mon_fdset_fd, next);
|
|
|
|
|
|
|
|
fdinfo = g_malloc0(sizeof(*fdinfo));
|
|
|
|
fdinfo->fdset_id = mon_fdset->id;
|
|
|
|
fdinfo->fd = mon_fdset_fd->fd;
|
|
|
|
|
|
|
|
return fdinfo;
|
|
|
|
}
|
|
|
|
|
2020-08-27 15:27:00 +03:00
|
|
|
int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags)
|
2012-08-15 00:43:47 +04:00
|
|
|
{
|
2018-06-08 06:55:11 +03:00
|
|
|
#ifdef _WIN32
|
|
|
|
return -ENOENT;
|
|
|
|
#else
|
2012-08-15 00:43:47 +04:00
|
|
|
MonFdset *mon_fdset;
|
|
|
|
|
2020-09-22 12:57:41 +03:00
|
|
|
QEMU_LOCK_GUARD(&mon_fdsets_lock);
|
2012-08-15 00:43:47 +04:00
|
|
|
QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
|
2020-08-27 15:27:00 +03:00
|
|
|
MonFdsetFd *mon_fdset_fd;
|
|
|
|
MonFdsetFd *mon_fdset_fd_dup;
|
|
|
|
int fd = -1;
|
|
|
|
int dup_fd;
|
|
|
|
int mon_fd_flags;
|
|
|
|
|
2012-08-15 00:43:47 +04:00
|
|
|
if (mon_fdset->id != fdset_id) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-08-27 15:27:00 +03:00
|
|
|
|
2012-08-15 00:43:47 +04:00
|
|
|
QLIST_FOREACH(mon_fdset_fd, &mon_fdset->fds, next) {
|
|
|
|
mon_fd_flags = fcntl(mon_fdset_fd->fd, F_GETFL);
|
|
|
|
if (mon_fd_flags == -1) {
|
2020-08-27 15:27:00 +03:00
|
|
|
return -1;
|
2012-08-15 00:43:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((flags & O_ACCMODE) == (mon_fd_flags & O_ACCMODE)) {
|
2020-08-27 15:27:00 +03:00
|
|
|
fd = mon_fdset_fd->fd;
|
|
|
|
break;
|
2012-08-15 00:43:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-27 15:27:00 +03:00
|
|
|
if (fd == -1) {
|
|
|
|
errno = EACCES;
|
|
|
|
return -1;
|
2012-08-15 00:43:47 +04:00
|
|
|
}
|
2020-08-27 15:27:00 +03:00
|
|
|
|
|
|
|
dup_fd = qemu_dup_flags(fd, flags);
|
|
|
|
if (dup_fd == -1) {
|
|
|
|
return -1;
|
2012-08-15 00:43:47 +04:00
|
|
|
}
|
2020-08-27 15:27:00 +03:00
|
|
|
|
2012-08-15 00:43:47 +04:00
|
|
|
mon_fdset_fd_dup = g_malloc0(sizeof(*mon_fdset_fd_dup));
|
|
|
|
mon_fdset_fd_dup->fd = dup_fd;
|
|
|
|
QLIST_INSERT_HEAD(&mon_fdset->dup_fds, mon_fdset_fd_dup, next);
|
2020-08-27 15:27:00 +03:00
|
|
|
return dup_fd;
|
2012-08-15 00:43:47 +04:00
|
|
|
}
|
2018-06-08 06:55:11 +03:00
|
|
|
|
2020-08-27 15:27:00 +03:00
|
|
|
errno = ENOENT;
|
2012-08-15 00:43:47 +04:00
|
|
|
return -1;
|
2020-08-27 15:27:00 +03:00
|
|
|
#endif
|
2012-08-15 00:43:47 +04:00
|
|
|
}
|
|
|
|
|
2019-05-23 12:44:33 +03:00
|
|
|
static int64_t monitor_fdset_dup_fd_find_remove(int dup_fd, bool remove)
|
2012-08-15 00:43:47 +04:00
|
|
|
{
|
|
|
|
MonFdset *mon_fdset;
|
|
|
|
MonFdsetFd *mon_fdset_fd_dup;
|
|
|
|
|
2020-09-22 12:57:41 +03:00
|
|
|
QEMU_LOCK_GUARD(&mon_fdsets_lock);
|
2012-08-15 00:43:47 +04:00
|
|
|
QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
|
|
|
|
QLIST_FOREACH(mon_fdset_fd_dup, &mon_fdset->dup_fds, next) {
|
|
|
|
if (mon_fdset_fd_dup->fd == dup_fd) {
|
|
|
|
if (remove) {
|
|
|
|
QLIST_REMOVE(mon_fdset_fd_dup, next);
|
2020-01-15 10:20:16 +03:00
|
|
|
g_free(mon_fdset_fd_dup);
|
2012-08-15 00:43:47 +04:00
|
|
|
if (QLIST_EMPTY(&mon_fdset->dup_fds)) {
|
|
|
|
monitor_fdset_cleanup(mon_fdset);
|
|
|
|
}
|
2020-09-22 12:57:41 +03:00
|
|
|
return -1;
|
2014-08-17 13:45:17 +04:00
|
|
|
} else {
|
|
|
|
return mon_fdset->id;
|
2012-08-15 00:43:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-06-08 06:55:11 +03:00
|
|
|
|
2012-08-15 00:43:47 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-05-23 12:44:33 +03:00
|
|
|
int64_t monitor_fdset_dup_fd_find(int dup_fd)
|
2012-08-15 00:43:47 +04:00
|
|
|
{
|
|
|
|
return monitor_fdset_dup_fd_find_remove(dup_fd, false);
|
|
|
|
}
|
|
|
|
|
2014-08-17 13:45:17 +04:00
|
|
|
void monitor_fdset_dup_fd_remove(int dup_fd)
|
2012-08-15 00:43:47 +04:00
|
|
|
{
|
2014-08-17 13:45:17 +04:00
|
|
|
monitor_fdset_dup_fd_find_remove(dup_fd, true);
|
2012-08-15 00:43:47 +04:00
|
|
|
}
|
|
|
|
|
2015-02-09 16:03:19 +03:00
|
|
|
int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp)
|
2014-04-10 12:24:31 +04:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
Error *local_err = NULL;
|
2012-08-22 00:52:07 +04:00
|
|
|
|
2014-04-10 12:24:31 +04:00
|
|
|
if (!qemu_isdigit(fdname[0]) && mon) {
|
2012-09-20 18:50:32 +04:00
|
|
|
fd = monitor_get_fd(mon, fdname, &local_err);
|
2014-04-10 12:24:31 +04:00
|
|
|
} else {
|
|
|
|
fd = qemu_parse_fd(fdname);
|
2012-08-22 00:52:07 +04:00
|
|
|
if (fd == -1) {
|
2014-04-10 12:24:31 +04:00
|
|
|
error_setg(&local_err, "Invalid file descriptor number '%s'",
|
|
|
|
fdname);
|
2012-08-22 00:52:07 +04:00
|
|
|
}
|
2014-04-10 12:24:31 +04:00
|
|
|
}
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
assert(fd == -1);
|
2012-08-22 00:52:07 +04:00
|
|
|
} else {
|
2014-04-10 12:24:31 +04:00
|
|
|
assert(fd != -1);
|
2012-08-22 00:52:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2010-09-30 23:00:22 +04:00
|
|
|
/* Please update hmp-commands.hx when adding or changing commands */
|
2019-06-13 18:33:56 +03:00
|
|
|
static HMPCommand hmp_info_cmds[] = {
|
2015-09-10 18:38:58 +03:00
|
|
|
#include "hmp-commands-info.h"
|
|
|
|
{ NULL, NULL, },
|
2004-03-15 00:38:27 +03:00
|
|
|
};
|
|
|
|
|
2019-06-13 18:33:56 +03:00
|
|
|
/* hmp_cmds and hmp_info_cmds would be sorted at runtime */
|
2019-06-13 18:34:01 +03:00
|
|
|
HMPCommand hmp_cmds[] = {
|
2013-01-14 10:06:28 +04:00
|
|
|
#include "hmp-commands.h"
|
|
|
|
{ NULL, NULL, },
|
|
|
|
};
|
|
|
|
|
2019-06-13 18:34:01 +03:00
|
|
|
/*
|
|
|
|
* Set @pval to the value in the register identified by @name.
|
|
|
|
* return 0 if OK, -1 if not found
|
|
|
|
*/
|
2020-11-13 14:43:24 +03:00
|
|
|
int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
|
2004-04-04 16:57:25 +04:00
|
|
|
{
|
2015-09-10 18:38:59 +03:00
|
|
|
const MonitorDef *md = target_monitor_defs();
|
2020-11-13 14:43:24 +03:00
|
|
|
CPUState *cs = mon_get_cpu(mon);
|
2005-02-11 01:00:52 +03:00
|
|
|
void *ptr;
|
2015-11-12 06:44:23 +03:00
|
|
|
uint64_t tmp = 0;
|
|
|
|
int ret;
|
2005-02-11 01:00:52 +03:00
|
|
|
|
2017-01-13 15:12:35 +03:00
|
|
|
if (cs == NULL || md == NULL) {
|
2015-09-10 18:38:59 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(; md->name != NULL; md++) {
|
2019-06-13 18:34:01 +03:00
|
|
|
if (hmp_compare_cmd(name, md->name)) {
|
2004-04-04 16:57:25 +04:00
|
|
|
if (md->get_value) {
|
2020-11-13 14:43:25 +03:00
|
|
|
*pval = md->get_value(mon, md, md->offset);
|
2004-04-04 16:57:25 +04:00
|
|
|
} else {
|
hmp: Pass monitor to mon_get_cpu_env()
mon_get_cpu_env() is indirectly called monitor_parse_arguments() where
the current monitor isn't set yet. Instead of using monitor_cur_env(),
explicitly pass the Monitor pointer to the function.
Without this fix, an HMP command like "x $pc" crashes like this:
#0 0x0000555555caa01f in mon_get_cpu_sync (mon=0x0, synchronize=true) at ../monitor/misc.c:270
#1 0x0000555555caa141 in mon_get_cpu (mon=0x0) at ../monitor/misc.c:294
#2 0x0000555555caa158 in mon_get_cpu_env () at ../monitor/misc.c:299
#3 0x0000555555b19739 in monitor_get_pc (mon=0x555556ad2de0, md=0x5555565d2d40 <monitor_defs+1152>, val=0) at ../target/i386/monitor.c:607
#4 0x0000555555cadbec in get_monitor_def (mon=0x555556ad2de0, pval=0x7fffffffc208, name=0x7fffffffc220 "pc") at ../monitor/misc.c:1681
#5 0x000055555582ec4f in expr_unary (mon=0x555556ad2de0) at ../monitor/hmp.c:387
#6 0x000055555582edbb in expr_prod (mon=0x555556ad2de0) at ../monitor/hmp.c:421
#7 0x000055555582ee79 in expr_logic (mon=0x555556ad2de0) at ../monitor/hmp.c:455
#8 0x000055555582eefe in expr_sum (mon=0x555556ad2de0) at ../monitor/hmp.c:484
#9 0x000055555582efe8 in get_expr (mon=0x555556ad2de0, pval=0x7fffffffc418, pp=0x7fffffffc408) at ../monitor/hmp.c:511
#10 0x000055555582fcd4 in monitor_parse_arguments (mon=0x555556ad2de0, endp=0x7fffffffc890, cmd=0x555556675b50 <hmp_cmds+7920>) at ../monitor/hmp.c:876
#11 0x00005555558306a8 in handle_hmp_command (mon=0x555556ad2de0, cmdline=0x555556ada452 "$pc") at ../monitor/hmp.c:1087
#12 0x000055555582df14 in monitor_command_cb (opaque=0x555556ad2de0, cmdline=0x555556ada450 "x $pc", readline_opaque=0x0) at ../monitor/hmp.c:47
After this fix, nothing is left in monitor_parse_arguments() that can
indirectly call monitor_cur(), so the fix is complete.
Fixes: ff04108a0e36e822519c517bd3bddbc1c7747c18
Reported-by: lichun <lichun@ruijie.com.cn>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20201113114326.97663-4-kwolf@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
2020-11-13 14:43:26 +03:00
|
|
|
CPUArchState *env = mon_get_cpu_env(mon);
|
2005-11-22 02:25:50 +03:00
|
|
|
ptr = (uint8_t *)env + md->offset;
|
2005-02-11 01:00:52 +03:00
|
|
|
switch(md->type) {
|
|
|
|
case MD_I32:
|
|
|
|
*pval = *(int32_t *)ptr;
|
|
|
|
break;
|
|
|
|
case MD_TLONG:
|
|
|
|
*pval = *(target_long *)ptr;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*pval = 0;
|
|
|
|
break;
|
|
|
|
}
|
2004-04-04 16:57:25 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2015-11-12 06:44:23 +03:00
|
|
|
|
2017-01-13 15:12:35 +03:00
|
|
|
ret = target_get_monitor_def(cs, name, &tmp);
|
2015-11-12 06:44:23 +03:00
|
|
|
if (!ret) {
|
|
|
|
*pval = (target_long) tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2004-04-04 16:57:25 +04:00
|
|
|
}
|
|
|
|
|
2014-05-08 02:41:30 +04:00
|
|
|
static void add_completion_option(ReadLineState *rs, const char *str,
|
|
|
|
const char *option)
|
|
|
|
{
|
|
|
|
if (!str || !option) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!strncmp(option, str, strlen(str))) {
|
|
|
|
readline_add_completion(rs, option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-08 02:41:29 +04:00
|
|
|
void chardev_add_completion(ReadLineState *rs, int nb_args, const char *str)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
ChardevBackendInfoList *list, *start;
|
|
|
|
|
|
|
|
if (nb_args != 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
len = strlen(str);
|
|
|
|
readline_set_completion_index(rs, len);
|
|
|
|
|
|
|
|
start = list = qmp_query_chardev_backends(NULL);
|
|
|
|
while (list) {
|
|
|
|
const char *chr_name = list->value->name;
|
|
|
|
|
|
|
|
if (!strncmp(chr_name, str, len)) {
|
|
|
|
readline_add_completion(rs, chr_name);
|
|
|
|
}
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
qapi_free_ChardevBackendInfoList(start);
|
|
|
|
}
|
|
|
|
|
2014-05-08 02:41:31 +04:00
|
|
|
void netdev_add_completion(ReadLineState *rs, int nb_args, const char *str)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (nb_args != 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
len = strlen(str);
|
|
|
|
readline_set_completion_index(rs, len);
|
2017-08-24 11:46:06 +03:00
|
|
|
for (i = 0; i < NET_CLIENT_DRIVER__MAX; i++) {
|
2017-08-24 11:46:08 +03:00
|
|
|
add_completion_option(rs, str, NetClientDriver_str(i));
|
2014-05-08 02:41:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-13 19:25:07 +04:00
|
|
|
void device_add_completion(ReadLineState *rs, int nb_args, const char *str)
|
2014-02-07 02:30:11 +04:00
|
|
|
{
|
|
|
|
GSList *list, *elt;
|
|
|
|
size_t len;
|
|
|
|
|
2014-04-13 19:25:07 +04:00
|
|
|
if (nb_args != 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-07 02:30:11 +04:00
|
|
|
len = strlen(str);
|
|
|
|
readline_set_completion_index(rs, len);
|
|
|
|
list = elt = object_class_get_list(TYPE_DEVICE, false);
|
|
|
|
while (elt) {
|
|
|
|
const char *name;
|
|
|
|
DeviceClass *dc = OBJECT_CLASS_CHECK(DeviceClass, elt->data,
|
|
|
|
TYPE_DEVICE);
|
|
|
|
name = object_class_get_name(OBJECT_CLASS(dc));
|
2014-04-13 19:25:07 +04:00
|
|
|
|
2017-05-03 23:35:44 +03:00
|
|
|
if (dc->user_creatable
|
2014-04-13 19:25:07 +04:00
|
|
|
&& !strncmp(name, str, len)) {
|
2014-02-07 02:30:11 +04:00
|
|
|
readline_add_completion(rs, name);
|
|
|
|
}
|
|
|
|
elt = elt->next;
|
|
|
|
}
|
|
|
|
g_slist_free(list);
|
|
|
|
}
|
|
|
|
|
2014-04-13 19:25:06 +04:00
|
|
|
void object_add_completion(ReadLineState *rs, int nb_args, const char *str)
|
2014-02-07 02:30:13 +04:00
|
|
|
{
|
|
|
|
GSList *list, *elt;
|
|
|
|
size_t len;
|
|
|
|
|
2014-04-13 19:25:06 +04:00
|
|
|
if (nb_args != 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-07 02:30:13 +04:00
|
|
|
len = strlen(str);
|
|
|
|
readline_set_completion_index(rs, len);
|
|
|
|
list = elt = object_class_get_list(TYPE_USER_CREATABLE, false);
|
|
|
|
while (elt) {
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
name = object_class_get_name(OBJECT_CLASS(elt->data));
|
|
|
|
if (!strncmp(name, str, len) && strcmp(name, TYPE_USER_CREATABLE)) {
|
|
|
|
readline_add_completion(rs, name);
|
|
|
|
}
|
|
|
|
elt = elt->next;
|
|
|
|
}
|
|
|
|
g_slist_free(list);
|
|
|
|
}
|
|
|
|
|
2020-01-10 18:30:17 +03:00
|
|
|
static int qdev_add_hotpluggable_device(Object *obj, void *opaque)
|
|
|
|
{
|
|
|
|
GSList **list = opaque;
|
2020-05-12 10:00:19 +03:00
|
|
|
DeviceState *dev = (DeviceState *)object_dynamic_cast(obj, TYPE_DEVICE);
|
2020-01-10 18:30:17 +03:00
|
|
|
|
|
|
|
if (dev == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dev->realized && object_property_get_bool(obj, "hotpluggable", NULL)) {
|
|
|
|
*list = g_slist_append(*list, dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GSList *qdev_build_hotpluggable_device_list(Object *peripheral)
|
|
|
|
{
|
|
|
|
GSList *list = NULL;
|
|
|
|
|
|
|
|
object_child_foreach(peripheral, qdev_add_hotpluggable_device, &list);
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2014-10-21 15:46:05 +04:00
|
|
|
static void peripheral_device_del_completion(ReadLineState *rs,
|
|
|
|
const char *str, size_t len)
|
|
|
|
{
|
2014-11-26 14:50:01 +03:00
|
|
|
Object *peripheral = container_get(qdev_get_machine(), "/peripheral");
|
|
|
|
GSList *list, *item;
|
2014-10-21 15:46:05 +04:00
|
|
|
|
2014-11-26 14:50:01 +03:00
|
|
|
list = qdev_build_hotpluggable_device_list(peripheral);
|
|
|
|
if (!list) {
|
2014-10-21 15:46:05 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (item = list; item; item = g_slist_next(item)) {
|
|
|
|
DeviceState *dev = item->data;
|
|
|
|
|
|
|
|
if (dev->id && !strncmp(str, dev->id, len)) {
|
|
|
|
readline_add_completion(rs, dev->id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free(list);
|
|
|
|
}
|
|
|
|
|
2014-05-08 02:41:28 +04:00
|
|
|
void chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
ChardevInfoList *list, *start;
|
|
|
|
|
|
|
|
if (nb_args != 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
len = strlen(str);
|
|
|
|
readline_set_completion_index(rs, len);
|
|
|
|
|
|
|
|
start = list = qmp_query_chardev(NULL);
|
|
|
|
while (list) {
|
|
|
|
ChardevInfo *chr = list->value;
|
|
|
|
|
|
|
|
if (!strncmp(chr->label, str, len)) {
|
|
|
|
readline_add_completion(rs, chr->label);
|
|
|
|
}
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
qapi_free_ChardevInfoList(start);
|
|
|
|
}
|
|
|
|
|
2014-05-28 02:39:30 +04:00
|
|
|
static void ringbuf_completion(ReadLineState *rs, const char *str)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
ChardevInfoList *list, *start;
|
|
|
|
|
|
|
|
len = strlen(str);
|
|
|
|
readline_set_completion_index(rs, len);
|
|
|
|
|
|
|
|
start = list = qmp_query_chardev(NULL);
|
|
|
|
while (list) {
|
|
|
|
ChardevInfo *chr_info = list->value;
|
|
|
|
|
|
|
|
if (!strncmp(chr_info->label, str, len)) {
|
2016-12-07 16:20:22 +03:00
|
|
|
Chardev *chr = qemu_chr_find(chr_info->label);
|
2016-12-07 18:39:10 +03:00
|
|
|
if (chr && CHARDEV_IS_RINGBUF(chr)) {
|
2014-05-28 02:39:30 +04:00
|
|
|
readline_add_completion(rs, chr_info->label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
qapi_free_ChardevInfoList(start);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ringbuf_write_completion(ReadLineState *rs, int nb_args, const char *str)
|
|
|
|
{
|
|
|
|
if (nb_args != 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ringbuf_completion(rs, str);
|
|
|
|
}
|
|
|
|
|
2014-04-13 19:25:07 +04:00
|
|
|
void device_del_completion(ReadLineState *rs, int nb_args, const char *str)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (nb_args != 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = strlen(str);
|
|
|
|
readline_set_completion_index(rs, len);
|
2014-10-21 15:46:05 +04:00
|
|
|
peripheral_device_del_completion(rs, str, len);
|
2014-04-13 19:25:07 +04:00
|
|
|
}
|
|
|
|
|
2014-04-13 19:25:06 +04:00
|
|
|
void object_del_completion(ReadLineState *rs, int nb_args, const char *str)
|
2014-02-07 02:30:12 +04:00
|
|
|
{
|
|
|
|
ObjectPropertyInfoList *list, *start;
|
|
|
|
size_t len;
|
|
|
|
|
2014-04-13 19:25:06 +04:00
|
|
|
if (nb_args != 2) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-07 02:30:12 +04:00
|
|
|
len = strlen(str);
|
|
|
|
readline_set_completion_index(rs, len);
|
|
|
|
|
|
|
|
start = list = qmp_qom_list("/objects", NULL);
|
|
|
|
while (list) {
|
|
|
|
ObjectPropertyInfo *info = list->value;
|
|
|
|
|
|
|
|
if (!strncmp(info->type, "child<", 5)
|
|
|
|
&& !strncmp(info->name, str, len)) {
|
|
|
|
readline_add_completion(rs, info->name);
|
|
|
|
}
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
qapi_free_ObjectPropertyInfoList(start);
|
|
|
|
}
|
|
|
|
|
2014-05-08 02:41:27 +04:00
|
|
|
void sendkey_completion(ReadLineState *rs, int nb_args, const char *str)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *sep;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (nb_args != 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sep = strrchr(str, '-');
|
|
|
|
if (sep) {
|
|
|
|
str = sep + 1;
|
|
|
|
}
|
|
|
|
len = strlen(str);
|
|
|
|
readline_set_completion_index(rs, len);
|
qapi: Don't let implicit enum MAX member collide
Now that we guarantee the user doesn't have any enum values
beginning with a single underscore, we can use that for our
own purposes. Renaming ENUM_MAX to ENUM__MAX makes it obvious
that the sentinel is generated.
This patch was mostly generated by applying a temporary patch:
|diff --git a/scripts/qapi.py b/scripts/qapi.py
|index e6d014b..b862ec9 100644
|--- a/scripts/qapi.py
|+++ b/scripts/qapi.py
|@@ -1570,6 +1570,7 @@ const char *const %(c_name)s_lookup[] = {
| max_index = c_enum_const(name, 'MAX', prefix)
| ret += mcgen('''
| [%(max_index)s] = NULL,
|+// %(max_index)s
| };
| ''',
| max_index=max_index)
then running:
$ cat qapi-{types,event}.c tests/test-qapi-types.c |
sed -n 's,^// \(.*\)MAX,s|\1MAX|\1_MAX|g,p' > list
$ git grep -l _MAX | xargs sed -i -f list
The only things not generated are the changes in scripts/qapi.py.
Rejecting enum members named 'MAX' is now useless, and will be dropped
in the next patch.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1447836791-369-23-git-send-email-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
[Rebased to current master, commit message tweaked]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-11-18 11:52:57 +03:00
|
|
|
for (i = 0; i < Q_KEY_CODE__MAX; i++) {
|
2017-08-24 11:46:08 +03:00
|
|
|
if (!strncmp(str, QKeyCode_str(i), len)) {
|
|
|
|
readline_add_completion(rs, QKeyCode_str(i));
|
2014-05-08 02:41:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-08 02:41:30 +04:00
|
|
|
void set_link_completion(ReadLineState *rs, int nb_args, const char *str)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
len = strlen(str);
|
|
|
|
readline_set_completion_index(rs, len);
|
|
|
|
if (nb_args == 2) {
|
2015-04-23 09:21:38 +03:00
|
|
|
NetClientState *ncs[MAX_QUEUE_NUM];
|
2014-05-08 02:41:30 +04:00
|
|
|
int count, i;
|
|
|
|
count = qemu_find_net_clients_except(NULL, ncs,
|
qapi: Change Netdev into a flat union
This is a mostly-mechanical conversion that creates a new flat
union 'Netdev' QAPI type that covers all the branches of the
former 'NetClientOptions' simple union, where the branches are
now listed in a new 'NetClientDriver' enum rather than generated
from the simple union. The existence of a flat union has no
change to the command line syntax accepted for new code, and
will make it possible for a future patch to switch the QMP
command to parse a boxed union for no change to valid QMP; but
it does have some ripple effect on the C code when dealing with
the new types.
While making the conversion, note that the 'NetLegacy' type
remains unchanged: it applies only to legacy command line options,
and will not be ported to QMP, so it should remain a wrapper
around a simple union; to avoid confusion, the type named
'NetClientOptions' is now gone, and we introduce 'NetLegacyOptions'
in its place. Then, in the C code, we convert from NetLegacy to
Netdev as soon as possible, so that the bulk of the net stack
only has to deal with one QAPI type, not two. Note that since
the old legacy code always rejected 'hubport', we can just omit
that branch from the new 'NetLegacyOptions' simple union.
Based on an idea originally by Zoltán Kővágó <DirtY.iCE.hu@gmail.com>:
Message-Id: <01a527fbf1a5de880091f98cf011616a78adeeee.1441627176.git.DirtY.iCE.hu@gmail.com>
although the sed script in that patch no longer applies due to
other changes in the tree since then, and I also did some manual
cleanups (such as fixing whitespace to keep checkpatch happy).
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1468468228-27827-13-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Fixup from Eric squashed in]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-07-14 06:50:23 +03:00
|
|
|
NET_CLIENT_DRIVER_NONE,
|
2015-04-23 09:21:38 +03:00
|
|
|
MAX_QUEUE_NUM);
|
2015-04-23 09:21:39 +03:00
|
|
|
for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) {
|
2014-05-08 02:41:30 +04:00
|
|
|
const char *name = ncs[i]->name;
|
|
|
|
if (!strncmp(str, name, len)) {
|
|
|
|
readline_add_completion(rs, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (nb_args == 3) {
|
|
|
|
add_completion_option(rs, str, "on");
|
|
|
|
add_completion_option(rs, str, "off");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-08 02:41:32 +04:00
|
|
|
void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str)
|
|
|
|
{
|
|
|
|
int len, count, i;
|
2015-04-23 09:21:38 +03:00
|
|
|
NetClientState *ncs[MAX_QUEUE_NUM];
|
2014-05-08 02:41:32 +04:00
|
|
|
|
|
|
|
if (nb_args != 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = strlen(str);
|
|
|
|
readline_set_completion_index(rs, len);
|
qapi: Change Netdev into a flat union
This is a mostly-mechanical conversion that creates a new flat
union 'Netdev' QAPI type that covers all the branches of the
former 'NetClientOptions' simple union, where the branches are
now listed in a new 'NetClientDriver' enum rather than generated
from the simple union. The existence of a flat union has no
change to the command line syntax accepted for new code, and
will make it possible for a future patch to switch the QMP
command to parse a boxed union for no change to valid QMP; but
it does have some ripple effect on the C code when dealing with
the new types.
While making the conversion, note that the 'NetLegacy' type
remains unchanged: it applies only to legacy command line options,
and will not be ported to QMP, so it should remain a wrapper
around a simple union; to avoid confusion, the type named
'NetClientOptions' is now gone, and we introduce 'NetLegacyOptions'
in its place. Then, in the C code, we convert from NetLegacy to
Netdev as soon as possible, so that the bulk of the net stack
only has to deal with one QAPI type, not two. Note that since
the old legacy code always rejected 'hubport', we can just omit
that branch from the new 'NetLegacyOptions' simple union.
Based on an idea originally by Zoltán Kővágó <DirtY.iCE.hu@gmail.com>:
Message-Id: <01a527fbf1a5de880091f98cf011616a78adeeee.1441627176.git.DirtY.iCE.hu@gmail.com>
although the sed script in that patch no longer applies due to
other changes in the tree since then, and I also did some manual
cleanups (such as fixing whitespace to keep checkpatch happy).
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1468468228-27827-13-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Fixup from Eric squashed in]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-07-14 06:50:23 +03:00
|
|
|
count = qemu_find_net_clients_except(NULL, ncs, NET_CLIENT_DRIVER_NIC,
|
2015-04-23 09:21:38 +03:00
|
|
|
MAX_QUEUE_NUM);
|
2015-04-23 09:21:39 +03:00
|
|
|
for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) {
|
2014-05-08 02:41:32 +04:00
|
|
|
const char *name = ncs[i]->name;
|
|
|
|
if (strncmp(str, name, len)) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-03-17 23:17:11 +03:00
|
|
|
if (ncs[i]->is_netdev) {
|
2014-05-08 02:41:32 +04:00
|
|
|
readline_add_completion(rs, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-11 13:53:51 +03:00
|
|
|
void info_trace_events_completion(ReadLineState *rs, int nb_args, const char *str)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
len = strlen(str);
|
|
|
|
readline_set_completion_index(rs, len);
|
|
|
|
if (nb_args == 2) {
|
2016-10-04 16:35:43 +03:00
|
|
|
TraceEventIter iter;
|
|
|
|
TraceEvent *ev;
|
|
|
|
char *pattern = g_strdup_printf("%s*", str);
|
2021-06-01 16:24:03 +03:00
|
|
|
trace_event_iter_init_pattern(&iter, pattern);
|
2016-10-04 16:35:43 +03:00
|
|
|
while ((ev = trace_event_iter_next(&iter)) != NULL) {
|
|
|
|
readline_add_completion(rs, trace_event_get_name(ev));
|
2016-07-11 13:53:51 +03:00
|
|
|
}
|
2016-10-04 16:35:43 +03:00
|
|
|
g_free(pattern);
|
2016-07-11 13:53:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-14 13:27:43 +03:00
|
|
|
void trace_event_completion(ReadLineState *rs, int nb_args, const char *str)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
len = strlen(str);
|
|
|
|
readline_set_completion_index(rs, len);
|
|
|
|
if (nb_args == 2) {
|
2016-10-04 16:35:43 +03:00
|
|
|
TraceEventIter iter;
|
|
|
|
TraceEvent *ev;
|
|
|
|
char *pattern = g_strdup_printf("%s*", str);
|
2021-06-01 16:24:03 +03:00
|
|
|
trace_event_iter_init_pattern(&iter, pattern);
|
2016-10-04 16:35:43 +03:00
|
|
|
while ((ev = trace_event_iter_next(&iter)) != NULL) {
|
|
|
|
readline_add_completion(rs, trace_event_get_name(ev));
|
|
|
|
}
|
|
|
|
g_free(pattern);
|
2015-08-14 13:27:43 +03:00
|
|
|
} else if (nb_args == 3) {
|
|
|
|
add_completion_option(rs, str, "on");
|
|
|
|
add_completion_option(rs, str, "off");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-28 02:39:31 +04:00
|
|
|
void watchdog_action_completion(ReadLineState *rs, int nb_args, const char *str)
|
|
|
|
{
|
2014-07-30 02:22:40 +04:00
|
|
|
int i;
|
|
|
|
|
2014-05-28 02:39:31 +04:00
|
|
|
if (nb_args != 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
readline_set_completion_index(rs, strlen(str));
|
2017-09-07 11:05:24 +03:00
|
|
|
for (i = 0; i < WATCHDOG_ACTION__MAX; i++) {
|
|
|
|
add_completion_option(rs, str, WatchdogAction_str(i));
|
2014-07-30 02:22:40 +04:00
|
|
|
}
|
2014-05-28 02:39:31 +04:00
|
|
|
}
|
|
|
|
|
2014-05-28 02:39:32 +04:00
|
|
|
void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
|
|
|
|
const char *str)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
len = strlen(str);
|
|
|
|
readline_set_completion_index(rs, len);
|
|
|
|
if (nb_args == 2) {
|
|
|
|
int i;
|
qapi: Don't let implicit enum MAX member collide
Now that we guarantee the user doesn't have any enum values
beginning with a single underscore, we can use that for our
own purposes. Renaming ENUM_MAX to ENUM__MAX makes it obvious
that the sentinel is generated.
This patch was mostly generated by applying a temporary patch:
|diff --git a/scripts/qapi.py b/scripts/qapi.py
|index e6d014b..b862ec9 100644
|--- a/scripts/qapi.py
|+++ b/scripts/qapi.py
|@@ -1570,6 +1570,7 @@ const char *const %(c_name)s_lookup[] = {
| max_index = c_enum_const(name, 'MAX', prefix)
| ret += mcgen('''
| [%(max_index)s] = NULL,
|+// %(max_index)s
| };
| ''',
| max_index=max_index)
then running:
$ cat qapi-{types,event}.c tests/test-qapi-types.c |
sed -n 's,^// \(.*\)MAX,s|\1MAX|\1_MAX|g,p' > list
$ git grep -l _MAX | xargs sed -i -f list
The only things not generated are the changes in scripts/qapi.py.
Rejecting enum members named 'MAX' is now useless, and will be dropped
in the next patch.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1447836791-369-23-git-send-email-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
[Rebased to current master, commit message tweaked]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-11-18 11:52:57 +03:00
|
|
|
for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
|
2017-08-24 11:46:08 +03:00
|
|
|
const char *name = MigrationCapability_str(i);
|
2014-05-28 02:39:32 +04:00
|
|
|
if (!strncmp(str, name, len)) {
|
|
|
|
readline_add_completion(rs, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (nb_args == 3) {
|
|
|
|
add_completion_option(rs, str, "on");
|
|
|
|
add_completion_option(rs, str, "off");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-23 11:32:29 +03:00
|
|
|
void migrate_set_parameter_completion(ReadLineState *rs, int nb_args,
|
|
|
|
const char *str)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
len = strlen(str);
|
|
|
|
readline_set_completion_index(rs, len);
|
|
|
|
if (nb_args == 2) {
|
|
|
|
int i;
|
qapi: Don't let implicit enum MAX member collide
Now that we guarantee the user doesn't have any enum values
beginning with a single underscore, we can use that for our
own purposes. Renaming ENUM_MAX to ENUM__MAX makes it obvious
that the sentinel is generated.
This patch was mostly generated by applying a temporary patch:
|diff --git a/scripts/qapi.py b/scripts/qapi.py
|index e6d014b..b862ec9 100644
|--- a/scripts/qapi.py
|+++ b/scripts/qapi.py
|@@ -1570,6 +1570,7 @@ const char *const %(c_name)s_lookup[] = {
| max_index = c_enum_const(name, 'MAX', prefix)
| ret += mcgen('''
| [%(max_index)s] = NULL,
|+// %(max_index)s
| };
| ''',
| max_index=max_index)
then running:
$ cat qapi-{types,event}.c tests/test-qapi-types.c |
sed -n 's,^// \(.*\)MAX,s|\1MAX|\1_MAX|g,p' > list
$ git grep -l _MAX | xargs sed -i -f list
The only things not generated are the changes in scripts/qapi.py.
Rejecting enum members named 'MAX' is now useless, and will be dropped
in the next patch.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1447836791-369-23-git-send-email-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
[Rebased to current master, commit message tweaked]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-11-18 11:52:57 +03:00
|
|
|
for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) {
|
2017-08-24 11:46:08 +03:00
|
|
|
const char *name = MigrationParameter_str(i);
|
2015-03-23 11:32:29 +03:00
|
|
|
if (!strncmp(str, name, len)) {
|
|
|
|
readline_add_completion(rs, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-28 02:39:37 +04:00
|
|
|
static void vm_completion(ReadLineState *rs, const char *str)
|
|
|
|
{
|
|
|
|
size_t len;
|
2016-03-22 20:58:50 +03:00
|
|
|
BlockDriverState *bs;
|
2016-05-20 19:49:07 +03:00
|
|
|
BdrvNextIterator it;
|
2014-05-28 02:39:37 +04:00
|
|
|
|
|
|
|
len = strlen(str);
|
|
|
|
readline_set_completion_index(rs, len);
|
2016-03-22 20:58:50 +03:00
|
|
|
|
2016-05-20 19:49:07 +03:00
|
|
|
for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
|
2014-05-28 02:39:37 +04:00
|
|
|
SnapshotInfoList *snapshots, *snapshot;
|
2015-11-04 20:19:42 +03:00
|
|
|
AioContext *ctx = bdrv_get_aio_context(bs);
|
|
|
|
bool ok = false;
|
2014-05-28 02:39:37 +04:00
|
|
|
|
2015-11-04 20:19:42 +03:00
|
|
|
aio_context_acquire(ctx);
|
|
|
|
if (bdrv_can_snapshot(bs)) {
|
|
|
|
ok = bdrv_query_snapshot_info_list(bs, &snapshots, NULL) == 0;
|
2014-05-28 02:39:37 +04:00
|
|
|
}
|
2015-11-04 20:19:42 +03:00
|
|
|
aio_context_release(ctx);
|
|
|
|
if (!ok) {
|
2014-05-28 02:39:37 +04:00
|
|
|
continue;
|
|
|
|
}
|
2015-11-04 20:19:42 +03:00
|
|
|
|
2014-05-28 02:39:37 +04:00
|
|
|
snapshot = snapshots;
|
|
|
|
while (snapshot) {
|
|
|
|
char *completion = snapshot->value->name;
|
|
|
|
if (!strncmp(str, completion, len)) {
|
|
|
|
readline_add_completion(rs, completion);
|
|
|
|
}
|
|
|
|
completion = snapshot->value->id;
|
|
|
|
if (!strncmp(str, completion, len)) {
|
|
|
|
readline_add_completion(rs, completion);
|
|
|
|
}
|
|
|
|
snapshot = snapshot->next;
|
|
|
|
}
|
|
|
|
qapi_free_SnapshotInfoList(snapshots);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void delvm_completion(ReadLineState *rs, int nb_args, const char *str)
|
|
|
|
{
|
|
|
|
if (nb_args == 2) {
|
|
|
|
vm_completion(rs, str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void loadvm_completion(ReadLineState *rs, int nb_args, const char *str)
|
|
|
|
{
|
|
|
|
if (nb_args == 2) {
|
|
|
|
vm_completion(rs, str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-12 07:32:41 +04:00
|
|
|
static int
|
|
|
|
compare_mon_cmd(const void *a, const void *b)
|
|
|
|
{
|
2019-06-13 18:33:56 +03:00
|
|
|
return strcmp(((const HMPCommand *)a)->name,
|
|
|
|
((const HMPCommand *)b)->name);
|
2011-10-12 07:32:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sortcmdlist(void)
|
|
|
|
{
|
2019-06-13 18:33:56 +03:00
|
|
|
qsort(hmp_cmds, ARRAY_SIZE(hmp_cmds) - 1,
|
|
|
|
sizeof(*hmp_cmds),
|
|
|
|
compare_mon_cmd);
|
|
|
|
qsort(hmp_info_cmds, ARRAY_SIZE(hmp_info_cmds) - 1,
|
|
|
|
sizeof(*hmp_info_cmds),
|
|
|
|
compare_mon_cmd);
|
2011-10-12 07:32:41 +04:00
|
|
|
}
|
|
|
|
|
2021-06-24 13:38:32 +03:00
|
|
|
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) {
|
2021-10-08 17:09:00 +03:00
|
|
|
g_assert(table->cmd == NULL && table->cmd_info_hrt == NULL);
|
2021-06-24 13:38:32 +03:00
|
|
|
table->cmd = cmd;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
table++;
|
|
|
|
}
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
|
2021-10-08 17:09:00 +03:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2018-03-09 11:59:50 +03:00
|
|
|
void monitor_init_globals(void)
|
|
|
|
{
|
2019-06-13 18:34:02 +03:00
|
|
|
monitor_init_globals_core();
|
2018-03-09 11:59:50 +03:00
|
|
|
monitor_init_qmp_commands();
|
|
|
|
sortcmdlist();
|
2018-06-08 06:55:11 +03:00
|
|
|
qemu_mutex_init(&mon_fdsets_lock);
|
2004-04-04 17:07:25 +04:00
|
|
|
}
|