mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
introduce a new monitor command 'dump-guest-memory' to dump guest's memory
The command's usage:
dump-guest-memory [-p] protocol [begin] [length]
The supported protocol can be file or fd:
1. file: the protocol starts with "file:", and the following string is
the file's path.
2. fd: the protocol starts with "fd:", and the following string is the
fd's name.
Note:
1. If you want to use gdb to process the core, please specify -p option.
The reason why the -p option is not default is:
a. guest machine in a catastrophic state can have corrupted memory,
which we cannot trust.
b. The guest machine can be in read-mode even if paging is enabled.
For example: the guest machine uses ACPI to sleep, and ACPI sleep
state goes in real-mode.
2. If you don't want to dump all guest's memory, please specify the start
physical address and the length.
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
This commit is contained in:
committed by
Luiz Capitulino
parent
68f4730c71
commit
783e9b4826
@@ -405,6 +405,8 @@ obj-y += $(addprefix ../, $(trace-obj-y))
|
||||
|
||||
endif # CONFIG_SOFTMMU
|
||||
|
||||
obj-y += dump.o
|
||||
|
||||
ifndef CONFIG_LINUX_USER
|
||||
ifndef CONFIG_BSD_USER
|
||||
# libcacard needs qemu-thread support, and besides is only needed by devices
|
||||
|
||||
@@ -1037,6 +1037,11 @@ typedef struct elf64_sym {
|
||||
|
||||
#define EI_NIDENT 16
|
||||
|
||||
/* Special value for e_phnum. This indicates that the real number of
|
||||
program headers is too large to fit into e_phnum. Instead the real
|
||||
value is in the field sh_info of section 0. */
|
||||
#define PN_XNUM 0xffff
|
||||
|
||||
typedef struct elf32_hdr{
|
||||
unsigned char e_ident[EI_NIDENT];
|
||||
Elf32_Half e_type;
|
||||
|
||||
@@ -878,6 +878,34 @@ server will ask the spice/vnc client to automatically reconnect using the
|
||||
new parameters (if specified) once the vm migration finished successfully.
|
||||
ETEXI
|
||||
|
||||
#if defined(CONFIG_HAVE_CORE_DUMP)
|
||||
{
|
||||
.name = "dump-guest-memory",
|
||||
.args_type = "paging:-p,protocol:s,begin:i?,length:i?",
|
||||
.params = "[-p] protocol [begin] [length]",
|
||||
.help = "dump guest memory to file"
|
||||
"\n\t\t\t begin(optional): the starting physical address"
|
||||
"\n\t\t\t length(optional): the memory size, in bytes",
|
||||
.user_print = monitor_user_noop,
|
||||
.mhandler.cmd = hmp_dump_guest_memory,
|
||||
},
|
||||
|
||||
|
||||
STEXI
|
||||
@item dump-guest-memory [-p] @var{protocol} @var{begin} @var{length}
|
||||
@findex dump-guest-memory
|
||||
Dump guest memory to @var{protocol}. The file can be processed with crash or
|
||||
gdb.
|
||||
protocol: destination file(started with "file:") or destination file
|
||||
descriptor (started with "fd:")
|
||||
paging: do paging to get guest's memory mapping
|
||||
begin: the starting physical address. It's optional, and should be
|
||||
specified with length together.
|
||||
length: the memory size, in bytes. It's optional, and should be specified
|
||||
with begin together.
|
||||
ETEXI
|
||||
#endif
|
||||
|
||||
{
|
||||
.name = "snapshot_blkdev",
|
||||
.args_type = "reuse:-n,device:B,snapshot-file:s?,format:s?",
|
||||
|
||||
@@ -947,3 +947,25 @@ void hmp_device_del(Monitor *mon, const QDict *qdict)
|
||||
qmp_device_del(id, &err);
|
||||
hmp_handle_error(mon, &err);
|
||||
}
|
||||
|
||||
void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
|
||||
{
|
||||
Error *errp = NULL;
|
||||
int paging = qdict_get_try_bool(qdict, "paging", 0);
|
||||
const char *file = qdict_get_str(qdict, "protocol");
|
||||
bool has_begin = qdict_haskey(qdict, "begin");
|
||||
bool has_length = qdict_haskey(qdict, "length");
|
||||
int64_t begin = 0;
|
||||
int64_t length = 0;
|
||||
|
||||
if (has_begin) {
|
||||
begin = qdict_get_int(qdict, "begin");
|
||||
}
|
||||
if (has_length) {
|
||||
length = qdict_get_int(qdict, "length");
|
||||
}
|
||||
|
||||
qmp_dump_guest_memory(paging, file, has_begin, begin, has_length, length,
|
||||
&errp);
|
||||
hmp_handle_error(mon, &errp);
|
||||
}
|
||||
|
||||
@@ -61,5 +61,6 @@ void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict);
|
||||
void hmp_block_job_cancel(Monitor *mon, const QDict *qdict);
|
||||
void hmp_migrate(Monitor *mon, const QDict *qdict);
|
||||
void hmp_device_del(Monitor *mon, const QDict *qdict);
|
||||
void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -220,3 +220,30 @@ void qemu_get_guest_simple_memory_mapping(MemoryMappingList *list)
|
||||
create_new_memory_mapping(list, block->offset, 0, block->length);
|
||||
}
|
||||
}
|
||||
|
||||
void memory_mapping_filter(MemoryMappingList *list, int64_t begin,
|
||||
int64_t length)
|
||||
{
|
||||
MemoryMapping *cur, *next;
|
||||
|
||||
QTAILQ_FOREACH_SAFE(cur, &list->head, next, next) {
|
||||
if (cur->phys_addr >= begin + length ||
|
||||
cur->phys_addr + cur->length <= begin) {
|
||||
QTAILQ_REMOVE(&list->head, cur, next);
|
||||
list->num--;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cur->phys_addr < begin) {
|
||||
cur->length -= begin - cur->phys_addr;
|
||||
if (cur->virt_addr) {
|
||||
cur->virt_addr += begin - cur->phys_addr;
|
||||
}
|
||||
cur->phys_addr = begin;
|
||||
}
|
||||
|
||||
if (cur->phys_addr + cur->length > begin + length) {
|
||||
cur->length -= cur->phys_addr + cur->length - begin - length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,9 @@ static inline int qemu_get_guest_memory_mapping(MemoryMappingList *list)
|
||||
/* get guest's memory mapping without do paging(virtual address is 0). */
|
||||
void qemu_get_guest_simple_memory_mapping(MemoryMappingList *list);
|
||||
|
||||
void memory_mapping_filter(MemoryMappingList *list, int64_t begin,
|
||||
int64_t length);
|
||||
|
||||
#else
|
||||
|
||||
/* We use MemoryMappingList* in cpu-all.h */
|
||||
|
||||
@@ -1755,3 +1755,46 @@
|
||||
# Since: 0.14.0
|
||||
##
|
||||
{ 'command': 'device_del', 'data': {'id': 'str'} }
|
||||
|
||||
##
|
||||
# @dump-guest-memory
|
||||
#
|
||||
# Dump guest's memory to vmcore. It is a synchronous operation that can take
|
||||
# very long depending on the amount of guest memory. This command is only
|
||||
# supported only on i386 and x86_64
|
||||
#
|
||||
# @paging: if true, do paging to get guest's memory mapping. The @paging's
|
||||
# default value of @paging is false, If you want to use gdb to process the
|
||||
# core, please set @paging to true. The reason why the @paging's value is
|
||||
# false:
|
||||
# 1. guest machine in a catastrophic state can have corrupted memory,
|
||||
# which we cannot trust.
|
||||
# 2. The guest machine can be in read-mode even if paging is enabled.
|
||||
# For example: the guest machine uses ACPI to sleep, and ACPI sleep
|
||||
# state goes in real-mode
|
||||
# @protocol: the filename or file descriptor of the vmcore. The supported
|
||||
# protocol can be file or fd:
|
||||
# 1. file: the protocol starts with "file:", and the following string is
|
||||
# the file's path.
|
||||
# 2. fd: the protocol starts with "fd:", and the following string is the
|
||||
# fd's name.
|
||||
# @begin: #optional if specified, the starting physical address.
|
||||
# @length: #optional if specified, the memory size, in bytes. If you don't
|
||||
# want to dump all guest's memory, please specify the start @begin and
|
||||
# @length
|
||||
#
|
||||
# Returns: nothing on success
|
||||
# If @begin contains an invalid address, InvalidParameter
|
||||
# If only one of @begin and @length is specified, MissingParameter
|
||||
# If @protocol stats with "fd:", and the fd cannot be found, FdNotFound
|
||||
# If @protocol starts with "file:", and the file cannot be
|
||||
# opened, OpenFileFailed
|
||||
# If @protocol does not start with "fd:" or "file:", InvalidParameter
|
||||
# If an I/O error occurs while writing the file, IOError
|
||||
# If the target does not support this command, Unsupported
|
||||
#
|
||||
# Since: 1.2
|
||||
##
|
||||
{ 'command': 'dump-guest-memory',
|
||||
'data': { 'paging': 'bool', 'protocol': 'str', '*begin': 'int',
|
||||
'*length': 'int' } }
|
||||
|
||||
@@ -601,6 +601,42 @@ Example:
|
||||
"port": 1234 } }
|
||||
<- { "return": {} }
|
||||
|
||||
EQMP
|
||||
|
||||
{
|
||||
.name = "dump-guest-memory",
|
||||
.args_type = "paging:b,protocol:s,begin:i?,end:i?",
|
||||
.params = "-p protocol [begin] [length]",
|
||||
.help = "dump guest memory to file",
|
||||
.user_print = monitor_user_noop,
|
||||
.mhandler.cmd_new = qmp_marshal_input_dump_guest_memory,
|
||||
},
|
||||
|
||||
SQMP
|
||||
dump
|
||||
|
||||
|
||||
Dump guest memory to file. The file can be processed with crash or gdb.
|
||||
|
||||
Arguments:
|
||||
|
||||
- "paging": do paging to get guest's memory mapping (json-bool)
|
||||
- "protocol": destination file(started with "file:") or destination file
|
||||
descriptor (started with "fd:") (json-string)
|
||||
- "begin": the starting physical address. It's optional, and should be specified
|
||||
with length together (json-int)
|
||||
- "length": the memory size, in bytes. It's optional, and should be specified
|
||||
with begin together (json-int)
|
||||
|
||||
Example:
|
||||
|
||||
-> { "execute": "dump-guest-memory", "arguments": { "protocol": "fd:dump" } }
|
||||
<- { "return": {} }
|
||||
|
||||
Notes:
|
||||
|
||||
(1) All boolean arguments default to false
|
||||
|
||||
EQMP
|
||||
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user