mirror of https://github.com/xemu-project/xemu.git
* chardev support for TLS and leak fix
* NBD fix from Denis * condvar fix from Dave * kvm_stat and dump-guest-memory almost rewrite * mem-prealloc fix from Luiz * manpage style improvement -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQEcBAABAgAGBQJWp4mKAAoJEL/70l94x66DersH/iUfwRTL7tmGOiUX73Qm32da QseRiC5E5OaTLOGm+Q0Aehjq6Q18zgdiz/+/wSTPjnLmOiSDn6Sr6yB/URSMwhOE +JVX3+UOpfHpQ1KHlBesIjS/WBSS1691ND1OPcHbHHa6UYbwEUTEc00hus8nVx6J wyeteUoBryZA177rjVNb9sH7ncNFuuiQDfkr5pmC5f5JEsDiSK9hDmlg9sFnTWrO XIVqQb0PD+EbOuufR4z3PTLIgbZEXegEgWOsE1FLBTVY/CZAkujynccOENIujFVv CEhHJrGWo2NU0yeVJ1UlHREQyK+suIHgsiJlQKvAW8ZyFNqpy3+sWSEo7ZBpB6U= =bVe7 -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging * chardev support for TLS and leak fix * NBD fix from Denis * condvar fix from Dave * kvm_stat and dump-guest-memory almost rewrite * mem-prealloc fix from Luiz * manpage style improvement # gpg: Signature made Tue 26 Jan 2016 14:58:18 GMT using RSA key ID 78C7AE83 # gpg: Good signature from "Paolo Bonzini <bonzini@gnu.org>" # gpg: aka "Paolo Bonzini <pbonzini@redhat.com>" * remotes/bonzini/tags/for-upstream: (49 commits) scripts/dump-guest-memory.py: Fix module docstring scripts/dump-guest-memory.py: Introduce multi-arch support scripts/dump-guest-memory.py: Cleanup functions scripts/dump-guest-memory.py: Improve python 3 compatibility scripts/dump-guest-memory.py: Make methods functions scripts/dump-guest-memory.py: Move constants to the top nbd: add missed aio_context_acquire in nbd_export_new memory: exit when hugepage allocation fails if mem-prealloc cpus: use broadcast on qemu_pause_cond scripts/kvm/kvm_stat: Add optparse description scripts/kvm/kvm_stat: Add interactive filtering scripts/kvm/kvm_stat: Fixup filtering scripts/kvm/kvm_stat: Fix rlimit for unprivileged users scripts/kvm/kvm_stat: Read event values as u64 scripts/kvm/kvm_stat: Cleanup and pre-init perf_event_attr scripts/kvm/kvm_stat: Fix output formatting scripts/kvm/kvm_stat: Make tui function a class scripts/kvm/kvm_stat: Remove unneeded X86_EXIT_REASONS scripts/kvm/kvm_stat: Group arch specific data scripts/kvm/kvm_stat: Cleanup of Event class ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
ba3fb2f023
4
cpus.c
4
cpus.c
|
@ -986,7 +986,7 @@ static void qemu_wait_io_event_common(CPUState *cpu)
|
||||||
if (cpu->stop) {
|
if (cpu->stop) {
|
||||||
cpu->stop = false;
|
cpu->stop = false;
|
||||||
cpu->stopped = true;
|
cpu->stopped = true;
|
||||||
qemu_cond_signal(&qemu_pause_cond);
|
qemu_cond_broadcast(&qemu_pause_cond);
|
||||||
}
|
}
|
||||||
flush_queued_work(cpu);
|
flush_queued_work(cpu);
|
||||||
cpu->thread_kicked = false;
|
cpu->thread_kicked = false;
|
||||||
|
@ -1396,7 +1396,7 @@ void cpu_stop_current(void)
|
||||||
current_cpu->stop = false;
|
current_cpu->stop = false;
|
||||||
current_cpu->stopped = true;
|
current_cpu->stopped = true;
|
||||||
cpu_exit(current_cpu);
|
cpu_exit(current_cpu);
|
||||||
qemu_cond_signal(&qemu_pause_cond);
|
qemu_cond_broadcast(&qemu_pause_cond);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
@example
|
@example
|
||||||
@c man begin SYNOPSIS
|
@c man begin SYNOPSIS
|
||||||
usage: virtfs-proxy-helper options
|
@command{virtfs-proxy-helper} @var{options}
|
||||||
@c man end
|
@c man end
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
|
|
|
@ -671,7 +671,9 @@ NBDExport *nbd_export_new(BlockBackend *blk, off_t dev_offset, off_t size,
|
||||||
* that BDRV_O_INACTIVE is cleared and the image is ready for write
|
* that BDRV_O_INACTIVE is cleared and the image is ready for write
|
||||||
* access since the export could be available before migration handover.
|
* access since the export could be available before migration handover.
|
||||||
*/
|
*/
|
||||||
|
aio_context_acquire(exp->ctx);
|
||||||
blk_invalidate_cache(blk, NULL);
|
blk_invalidate_cache(blk, NULL);
|
||||||
|
aio_context_release(exp->ctx);
|
||||||
return exp;
|
return exp;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
|
11
numa.c
11
numa.c
|
@ -418,12 +418,15 @@ static void allocate_system_memory_nonnuma(MemoryRegion *mr, Object *owner,
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
memory_region_init_ram_from_file(mr, owner, name, ram_size, false,
|
memory_region_init_ram_from_file(mr, owner, name, ram_size, false,
|
||||||
mem_path, &err);
|
mem_path, &err);
|
||||||
|
|
||||||
/* Legacy behavior: if allocation failed, fall back to
|
|
||||||
* regular RAM allocation.
|
|
||||||
*/
|
|
||||||
if (err) {
|
if (err) {
|
||||||
error_report_err(err);
|
error_report_err(err);
|
||||||
|
if (mem_prealloc) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Legacy behavior: if allocation failed, fall back to
|
||||||
|
* regular RAM allocation.
|
||||||
|
*/
|
||||||
memory_region_init_ram(mr, owner, name, ram_size, &error_fatal);
|
memory_region_init_ram(mr, owner, name, ram_size, &error_fatal);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -3146,6 +3146,7 @@
|
||||||
#
|
#
|
||||||
# @addr: socket address to listen on (server=true)
|
# @addr: socket address to listen on (server=true)
|
||||||
# or connect to (server=false)
|
# or connect to (server=false)
|
||||||
|
# @tls-creds: #optional the ID of the TLS credentials object (since 2.6)
|
||||||
# @server: #optional create server socket (default: true)
|
# @server: #optional create server socket (default: true)
|
||||||
# @wait: #optional wait for incoming connection on server
|
# @wait: #optional wait for incoming connection on server
|
||||||
# sockets (default: false).
|
# sockets (default: false).
|
||||||
|
@ -3160,6 +3161,7 @@
|
||||||
# Since: 1.4
|
# Since: 1.4
|
||||||
##
|
##
|
||||||
{ 'struct': 'ChardevSocket', 'data': { 'addr' : 'SocketAddress',
|
{ 'struct': 'ChardevSocket', 'data': { 'addr' : 'SocketAddress',
|
||||||
|
'*tls-creds' : 'str',
|
||||||
'*server' : 'bool',
|
'*server' : 'bool',
|
||||||
'*wait' : 'bool',
|
'*wait' : 'bool',
|
||||||
'*nodelay' : 'bool',
|
'*nodelay' : 'bool',
|
||||||
|
|
926
qemu-char.c
926
qemu-char.c
File diff suppressed because it is too large
Load Diff
|
@ -259,7 +259,7 @@ Linux should boot and give you a prompt.
|
||||||
|
|
||||||
@example
|
@example
|
||||||
@c man begin SYNOPSIS
|
@c man begin SYNOPSIS
|
||||||
usage: qemu-system-i386 [options] [@var{disk_image}]
|
@command{qemu-system-i386} [@var{options}] [@var{disk_image}]
|
||||||
@c man end
|
@c man end
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
|
@ -1406,7 +1406,7 @@ no type is given, the HCI logic corresponds to @code{-bt hci,vlan=0}.
|
||||||
This USB device implements the USB Transport Layer of HCI. Example
|
This USB device implements the USB Transport Layer of HCI. Example
|
||||||
usage:
|
usage:
|
||||||
@example
|
@example
|
||||||
qemu-system-i386 [...OPTIONS...] -usbdevice bt:hci,vlan=3 -bt device:keyboard,vlan=3
|
@command{qemu-system-i386} [...@var{OPTIONS}...] @option{-usbdevice} bt:hci,vlan=3 @option{-bt} device:keyboard,vlan=3
|
||||||
@end example
|
@end example
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
|
@ -2755,7 +2755,7 @@ qemu-i386 /usr/local/qemu-i386/wine/bin/wine \
|
||||||
@subsection Command line options
|
@subsection Command line options
|
||||||
|
|
||||||
@example
|
@example
|
||||||
usage: qemu-i386 [-h] [-d] [-L path] [-s size] [-cpu model] [-g port] [-B offset] [-R size] program [arguments...]
|
@command{qemu-i386} [@option{-h]} [@option{-d]} [@option{-L} @var{path}] [@option{-s} @var{size}] [@option{-cpu} @var{model}] [@option{-g} @var{port}] [@option{-B} @var{offset}] [@option{-R} @var{size}] @var{program} [@var{arguments}...]
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
@table @option
|
@table @option
|
||||||
|
@ -2897,7 +2897,7 @@ qemu-sparc64 /bin/ls
|
||||||
@subsection Command line options
|
@subsection Command line options
|
||||||
|
|
||||||
@example
|
@example
|
||||||
usage: qemu-sparc64 [-h] [-d] [-L path] [-s size] [-bsd type] program [arguments...]
|
@command{qemu-sparc64} [@option{-h]} [@option{-d]} [@option{-L} @var{path}] [@option{-s} @var{size}] [@option{-bsd} @var{type}] @var{program} [@var{arguments}...]
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
@table @option
|
@table @option
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
@example
|
@example
|
||||||
@c man begin SYNOPSIS
|
@c man begin SYNOPSIS
|
||||||
usage: qemu-ga [OPTIONS]
|
@command{qemu-ga} [@var{OPTIONS}]
|
||||||
@c man end
|
@c man end
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
@example
|
@example
|
||||||
@c man begin SYNOPSIS
|
@c man begin SYNOPSIS
|
||||||
usage: qemu-img command [command options]
|
@command{qemu-img} @var{command} [@var{command} @var{options}]
|
||||||
@c man end
|
@c man end
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
|
|
|
@ -2092,7 +2092,7 @@ DEF("chardev", HAS_ARG, QEMU_OPTION_chardev,
|
||||||
"-chardev null,id=id[,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
|
"-chardev null,id=id[,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
|
||||||
"-chardev socket,id=id[,host=host],port=port[,to=to][,ipv4][,ipv6][,nodelay][,reconnect=seconds]\n"
|
"-chardev socket,id=id[,host=host],port=port[,to=to][,ipv4][,ipv6][,nodelay][,reconnect=seconds]\n"
|
||||||
" [,server][,nowait][,telnet][,reconnect=seconds][,mux=on|off]\n"
|
" [,server][,nowait][,telnet][,reconnect=seconds][,mux=on|off]\n"
|
||||||
" [,logfile=PATH][,logappend=on|off] (tcp)\n"
|
" [,logfile=PATH][,logappend=on|off][,tls-creds=ID] (tcp)\n"
|
||||||
"-chardev socket,id=id,path=path[,server][,nowait][,telnet][,reconnect=seconds]\n"
|
"-chardev socket,id=id,path=path[,server][,nowait][,telnet][,reconnect=seconds]\n"
|
||||||
" [,mux=on|off][,logfile=PATH][,logappend=on|off] (unix)\n"
|
" [,mux=on|off][,logfile=PATH][,logappend=on|off] (unix)\n"
|
||||||
"-chardev udp,id=id[,host=host],port=port[,localaddr=localaddr]\n"
|
"-chardev udp,id=id[,host=host],port=port[,localaddr=localaddr]\n"
|
||||||
|
@ -2172,7 +2172,7 @@ Further options to each backend are described below.
|
||||||
A void device. This device will not emit any data, and will drop any data it
|
A void device. This device will not emit any data, and will drop any data it
|
||||||
receives. The null backend does not take any options.
|
receives. The null backend does not take any options.
|
||||||
|
|
||||||
@item -chardev socket ,id=@var{id} [@var{TCP options} or @var{unix options}] [,server] [,nowait] [,telnet] [,reconnect=@var{seconds}]
|
@item -chardev socket ,id=@var{id} [@var{TCP options} or @var{unix options}] [,server] [,nowait] [,telnet] [,reconnect=@var{seconds}] [,tls-creds=@var{id}]
|
||||||
|
|
||||||
Create a two-way stream socket, which can be either a TCP or a unix socket. A
|
Create a two-way stream socket, which can be either a TCP or a unix socket. A
|
||||||
unix socket will be created if @option{path} is specified. Behaviour is
|
unix socket will be created if @option{path} is specified. Behaviour is
|
||||||
|
@ -2190,6 +2190,11 @@ escape sequences.
|
||||||
the remote end goes away. qemu will delay this many seconds and then attempt
|
the remote end goes away. qemu will delay this many seconds and then attempt
|
||||||
to reconnect. Zero disables reconnecting, and is the default.
|
to reconnect. Zero disables reconnecting, and is the default.
|
||||||
|
|
||||||
|
@option{tls-creds} requests enablement of the TLS protocol for encryption,
|
||||||
|
and specifies the id of the TLS credentials to use for the handshake. The
|
||||||
|
credentials must be previously created with the @option{-object tls-creds}
|
||||||
|
argument.
|
||||||
|
|
||||||
TCP and unix socket options are given below:
|
TCP and unix socket options are given below:
|
||||||
|
|
||||||
@table @option
|
@table @option
|
||||||
|
|
|
@ -1,39 +1,456 @@
|
||||||
# This python script adds a new gdb command, "dump-guest-memory". It
|
"""
|
||||||
# should be loaded with "source dump-guest-memory.py" at the (gdb)
|
This python script adds a new gdb command, "dump-guest-memory". It
|
||||||
# prompt.
|
should be loaded with "source dump-guest-memory.py" at the (gdb)
|
||||||
#
|
prompt.
|
||||||
# Copyright (C) 2013, Red Hat, Inc.
|
|
||||||
#
|
Copyright (C) 2013, Red Hat, Inc.
|
||||||
# Authors:
|
|
||||||
# Laszlo Ersek <lersek@redhat.com>
|
Authors:
|
||||||
#
|
Laszlo Ersek <lersek@redhat.com>
|
||||||
# This work is licensed under the terms of the GNU GPL, version 2 or later. See
|
Janosch Frank <frankja@linux.vnet.ibm.com>
|
||||||
# the COPYING file in the top-level directory.
|
|
||||||
#
|
This work is licensed under the terms of the GNU GPL, version 2 or later. See
|
||||||
|
the COPYING file in the top-level directory.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import ctypes
|
||||||
|
|
||||||
|
UINTPTR_T = gdb.lookup_type("uintptr_t")
|
||||||
|
|
||||||
|
TARGET_PAGE_SIZE = 0x1000
|
||||||
|
TARGET_PAGE_MASK = 0xFFFFFFFFFFFFF000
|
||||||
|
|
||||||
|
# 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.
|
||||||
|
PN_XNUM = 0xFFFF
|
||||||
|
|
||||||
|
EV_CURRENT = 1
|
||||||
|
|
||||||
|
ELFCLASS32 = 1
|
||||||
|
ELFCLASS64 = 2
|
||||||
|
|
||||||
|
ELFDATA2LSB = 1
|
||||||
|
ELFDATA2MSB = 2
|
||||||
|
|
||||||
|
ET_CORE = 4
|
||||||
|
|
||||||
|
PT_LOAD = 1
|
||||||
|
PT_NOTE = 4
|
||||||
|
|
||||||
|
EM_386 = 3
|
||||||
|
EM_PPC = 20
|
||||||
|
EM_PPC64 = 21
|
||||||
|
EM_S390 = 22
|
||||||
|
EM_AARCH = 183
|
||||||
|
EM_X86_64 = 62
|
||||||
|
|
||||||
|
class ELF(object):
|
||||||
|
"""Representation of a ELF file."""
|
||||||
|
|
||||||
|
def __init__(self, arch):
|
||||||
|
self.ehdr = None
|
||||||
|
self.notes = []
|
||||||
|
self.segments = []
|
||||||
|
self.notes_size = 0
|
||||||
|
self.endianess = None
|
||||||
|
self.elfclass = ELFCLASS64
|
||||||
|
|
||||||
|
if arch == 'aarch64-le':
|
||||||
|
self.endianess = ELFDATA2LSB
|
||||||
|
self.elfclass = ELFCLASS64
|
||||||
|
self.ehdr = get_arch_ehdr(self.endianess, self.elfclass)
|
||||||
|
self.ehdr.e_machine = EM_AARCH
|
||||||
|
|
||||||
|
elif arch == 'aarch64-be':
|
||||||
|
self.endianess = ELFDATA2MSB
|
||||||
|
self.ehdr = get_arch_ehdr(self.endianess, self.elfclass)
|
||||||
|
self.ehdr.e_machine = EM_AARCH
|
||||||
|
|
||||||
|
elif arch == 'X86_64':
|
||||||
|
self.endianess = ELFDATA2LSB
|
||||||
|
self.ehdr = get_arch_ehdr(self.endianess, self.elfclass)
|
||||||
|
self.ehdr.e_machine = EM_X86_64
|
||||||
|
|
||||||
|
elif arch == '386':
|
||||||
|
self.endianess = ELFDATA2LSB
|
||||||
|
self.elfclass = ELFCLASS32
|
||||||
|
self.ehdr = get_arch_ehdr(self.endianess, self.elfclass)
|
||||||
|
self.ehdr.e_machine = EM_386
|
||||||
|
|
||||||
|
elif arch == 's390':
|
||||||
|
self.endianess = ELFDATA2MSB
|
||||||
|
self.ehdr = get_arch_ehdr(self.endianess, self.elfclass)
|
||||||
|
self.ehdr.e_machine = EM_S390
|
||||||
|
|
||||||
|
elif arch == 'ppc64-le':
|
||||||
|
self.endianess = ELFDATA2LSB
|
||||||
|
self.ehdr = get_arch_ehdr(self.endianess, self.elfclass)
|
||||||
|
self.ehdr.e_machine = EM_PPC64
|
||||||
|
|
||||||
|
elif arch == 'ppc64-be':
|
||||||
|
self.endianess = ELFDATA2MSB
|
||||||
|
self.ehdr = get_arch_ehdr(self.endianess, self.elfclass)
|
||||||
|
self.ehdr.e_machine = EM_PPC64
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise gdb.GdbError("No valid arch type specified.\n"
|
||||||
|
"Currently supported types:\n"
|
||||||
|
"aarch64-be, aarch64-le, X86_64, 386, s390, "
|
||||||
|
"ppc64-be, ppc64-le")
|
||||||
|
|
||||||
|
self.add_segment(PT_NOTE, 0, 0)
|
||||||
|
|
||||||
|
def add_note(self, n_name, n_desc, n_type):
|
||||||
|
"""Adds a note to the ELF."""
|
||||||
|
|
||||||
|
note = get_arch_note(self.endianess, len(n_name), len(n_desc))
|
||||||
|
note.n_namesz = len(n_name) + 1
|
||||||
|
note.n_descsz = len(n_desc)
|
||||||
|
note.n_name = n_name.encode()
|
||||||
|
note.n_type = n_type
|
||||||
|
|
||||||
|
# Desc needs to be 4 byte aligned (although the 64bit spec
|
||||||
|
# specifies 8 byte). When defining n_desc as uint32 it will be
|
||||||
|
# automatically aligned but we need the memmove to copy the
|
||||||
|
# string into it.
|
||||||
|
ctypes.memmove(note.n_desc, n_desc.encode(), len(n_desc))
|
||||||
|
|
||||||
|
self.notes.append(note)
|
||||||
|
self.segments[0].p_filesz += ctypes.sizeof(note)
|
||||||
|
self.segments[0].p_memsz += ctypes.sizeof(note)
|
||||||
|
|
||||||
|
def add_segment(self, p_type, p_paddr, p_size):
|
||||||
|
"""Adds a segment to the elf."""
|
||||||
|
|
||||||
|
phdr = get_arch_phdr(self.endianess, self.elfclass)
|
||||||
|
phdr.p_type = p_type
|
||||||
|
phdr.p_paddr = p_paddr
|
||||||
|
phdr.p_filesz = p_size
|
||||||
|
phdr.p_memsz = p_size
|
||||||
|
self.segments.append(phdr)
|
||||||
|
self.ehdr.e_phnum += 1
|
||||||
|
|
||||||
|
def to_file(self, elf_file):
|
||||||
|
"""Writes all ELF structures to the the passed file.
|
||||||
|
|
||||||
|
Structure:
|
||||||
|
Ehdr
|
||||||
|
Segment 0:PT_NOTE
|
||||||
|
Segment 1:PT_LOAD
|
||||||
|
Segment N:PT_LOAD
|
||||||
|
Note 0..N
|
||||||
|
Dump contents
|
||||||
|
"""
|
||||||
|
elf_file.write(self.ehdr)
|
||||||
|
off = ctypes.sizeof(self.ehdr) + \
|
||||||
|
len(self.segments) * ctypes.sizeof(self.segments[0])
|
||||||
|
|
||||||
|
for phdr in self.segments:
|
||||||
|
phdr.p_offset = off
|
||||||
|
elf_file.write(phdr)
|
||||||
|
off += phdr.p_filesz
|
||||||
|
|
||||||
|
for note in self.notes:
|
||||||
|
elf_file.write(note)
|
||||||
|
|
||||||
|
|
||||||
|
def get_arch_note(endianess, len_name, len_desc):
|
||||||
|
"""Returns a Note class with the specified endianess."""
|
||||||
|
|
||||||
|
if endianess == ELFDATA2LSB:
|
||||||
|
superclass = ctypes.LittleEndianStructure
|
||||||
|
else:
|
||||||
|
superclass = ctypes.BigEndianStructure
|
||||||
|
|
||||||
|
len_name = len_name + 1
|
||||||
|
|
||||||
|
class Note(superclass):
|
||||||
|
"""Represents an ELF note, includes the content."""
|
||||||
|
|
||||||
|
_fields_ = [("n_namesz", ctypes.c_uint32),
|
||||||
|
("n_descsz", ctypes.c_uint32),
|
||||||
|
("n_type", ctypes.c_uint32),
|
||||||
|
("n_name", ctypes.c_char * len_name),
|
||||||
|
("n_desc", ctypes.c_uint32 * ((len_desc + 3) // 4))]
|
||||||
|
return Note()
|
||||||
|
|
||||||
|
|
||||||
|
class Ident(ctypes.Structure):
|
||||||
|
"""Represents the ELF ident array in the ehdr structure."""
|
||||||
|
|
||||||
|
_fields_ = [('ei_mag0', ctypes.c_ubyte),
|
||||||
|
('ei_mag1', ctypes.c_ubyte),
|
||||||
|
('ei_mag2', ctypes.c_ubyte),
|
||||||
|
('ei_mag3', ctypes.c_ubyte),
|
||||||
|
('ei_class', ctypes.c_ubyte),
|
||||||
|
('ei_data', ctypes.c_ubyte),
|
||||||
|
('ei_version', ctypes.c_ubyte),
|
||||||
|
('ei_osabi', ctypes.c_ubyte),
|
||||||
|
('ei_abiversion', ctypes.c_ubyte),
|
||||||
|
('ei_pad', ctypes.c_ubyte * 7)]
|
||||||
|
|
||||||
|
def __init__(self, endianess, elfclass):
|
||||||
|
self.ei_mag0 = 0x7F
|
||||||
|
self.ei_mag1 = ord('E')
|
||||||
|
self.ei_mag2 = ord('L')
|
||||||
|
self.ei_mag3 = ord('F')
|
||||||
|
self.ei_class = elfclass
|
||||||
|
self.ei_data = endianess
|
||||||
|
self.ei_version = EV_CURRENT
|
||||||
|
|
||||||
|
|
||||||
|
def get_arch_ehdr(endianess, elfclass):
|
||||||
|
"""Returns a EHDR64 class with the specified endianess."""
|
||||||
|
|
||||||
|
if endianess == ELFDATA2LSB:
|
||||||
|
superclass = ctypes.LittleEndianStructure
|
||||||
|
else:
|
||||||
|
superclass = ctypes.BigEndianStructure
|
||||||
|
|
||||||
|
class EHDR64(superclass):
|
||||||
|
"""Represents the 64 bit ELF header struct."""
|
||||||
|
|
||||||
|
_fields_ = [('e_ident', Ident),
|
||||||
|
('e_type', ctypes.c_uint16),
|
||||||
|
('e_machine', ctypes.c_uint16),
|
||||||
|
('e_version', ctypes.c_uint32),
|
||||||
|
('e_entry', ctypes.c_uint64),
|
||||||
|
('e_phoff', ctypes.c_uint64),
|
||||||
|
('e_shoff', ctypes.c_uint64),
|
||||||
|
('e_flags', ctypes.c_uint32),
|
||||||
|
('e_ehsize', ctypes.c_uint16),
|
||||||
|
('e_phentsize', ctypes.c_uint16),
|
||||||
|
('e_phnum', ctypes.c_uint16),
|
||||||
|
('e_shentsize', ctypes.c_uint16),
|
||||||
|
('e_shnum', ctypes.c_uint16),
|
||||||
|
('e_shstrndx', ctypes.c_uint16)]
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super(superclass, self).__init__()
|
||||||
|
self.e_ident = Ident(endianess, elfclass)
|
||||||
|
self.e_type = ET_CORE
|
||||||
|
self.e_version = EV_CURRENT
|
||||||
|
self.e_ehsize = ctypes.sizeof(self)
|
||||||
|
self.e_phoff = ctypes.sizeof(self)
|
||||||
|
self.e_phentsize = ctypes.sizeof(get_arch_phdr(endianess, elfclass))
|
||||||
|
self.e_phnum = 0
|
||||||
|
|
||||||
|
|
||||||
|
class EHDR32(superclass):
|
||||||
|
"""Represents the 32 bit ELF header struct."""
|
||||||
|
|
||||||
|
_fields_ = [('e_ident', Ident),
|
||||||
|
('e_type', ctypes.c_uint16),
|
||||||
|
('e_machine', ctypes.c_uint16),
|
||||||
|
('e_version', ctypes.c_uint32),
|
||||||
|
('e_entry', ctypes.c_uint32),
|
||||||
|
('e_phoff', ctypes.c_uint32),
|
||||||
|
('e_shoff', ctypes.c_uint32),
|
||||||
|
('e_flags', ctypes.c_uint32),
|
||||||
|
('e_ehsize', ctypes.c_uint16),
|
||||||
|
('e_phentsize', ctypes.c_uint16),
|
||||||
|
('e_phnum', ctypes.c_uint16),
|
||||||
|
('e_shentsize', ctypes.c_uint16),
|
||||||
|
('e_shnum', ctypes.c_uint16),
|
||||||
|
('e_shstrndx', ctypes.c_uint16)]
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super(superclass, self).__init__()
|
||||||
|
self.e_ident = Ident(endianess, elfclass)
|
||||||
|
self.e_type = ET_CORE
|
||||||
|
self.e_version = EV_CURRENT
|
||||||
|
self.e_ehsize = ctypes.sizeof(self)
|
||||||
|
self.e_phoff = ctypes.sizeof(self)
|
||||||
|
self.e_phentsize = ctypes.sizeof(get_arch_phdr(endianess, elfclass))
|
||||||
|
self.e_phnum = 0
|
||||||
|
|
||||||
|
# End get_arch_ehdr
|
||||||
|
if elfclass == ELFCLASS64:
|
||||||
|
return EHDR64()
|
||||||
|
else:
|
||||||
|
return EHDR32()
|
||||||
|
|
||||||
|
|
||||||
|
def get_arch_phdr(endianess, elfclass):
|
||||||
|
"""Returns a 32 or 64 bit PHDR class with the specified endianess."""
|
||||||
|
|
||||||
|
if endianess == ELFDATA2LSB:
|
||||||
|
superclass = ctypes.LittleEndianStructure
|
||||||
|
else:
|
||||||
|
superclass = ctypes.BigEndianStructure
|
||||||
|
|
||||||
|
class PHDR64(superclass):
|
||||||
|
"""Represents the 64 bit ELF program header struct."""
|
||||||
|
|
||||||
|
_fields_ = [('p_type', ctypes.c_uint32),
|
||||||
|
('p_flags', ctypes.c_uint32),
|
||||||
|
('p_offset', ctypes.c_uint64),
|
||||||
|
('p_vaddr', ctypes.c_uint64),
|
||||||
|
('p_paddr', ctypes.c_uint64),
|
||||||
|
('p_filesz', ctypes.c_uint64),
|
||||||
|
('p_memsz', ctypes.c_uint64),
|
||||||
|
('p_align', ctypes.c_uint64)]
|
||||||
|
|
||||||
|
class PHDR32(superclass):
|
||||||
|
"""Represents the 32 bit ELF program header struct."""
|
||||||
|
|
||||||
|
_fields_ = [('p_type', ctypes.c_uint32),
|
||||||
|
('p_offset', ctypes.c_uint32),
|
||||||
|
('p_vaddr', ctypes.c_uint32),
|
||||||
|
('p_paddr', ctypes.c_uint32),
|
||||||
|
('p_filesz', ctypes.c_uint32),
|
||||||
|
('p_memsz', ctypes.c_uint32),
|
||||||
|
('p_flags', ctypes.c_uint32),
|
||||||
|
('p_align', ctypes.c_uint32)]
|
||||||
|
|
||||||
|
# End get_arch_phdr
|
||||||
|
if elfclass == ELFCLASS64:
|
||||||
|
return PHDR64()
|
||||||
|
else:
|
||||||
|
return PHDR32()
|
||||||
|
|
||||||
|
|
||||||
|
def int128_get64(val):
|
||||||
|
"""Returns low 64bit part of Int128 struct."""
|
||||||
|
|
||||||
|
assert val["hi"] == 0
|
||||||
|
return val["lo"]
|
||||||
|
|
||||||
|
|
||||||
|
def qlist_foreach(head, field_str):
|
||||||
|
"""Generator for qlists."""
|
||||||
|
|
||||||
|
var_p = head["lh_first"]
|
||||||
|
while var_p != 0:
|
||||||
|
var = var_p.dereference()
|
||||||
|
var_p = var[field_str]["le_next"]
|
||||||
|
yield var
|
||||||
|
|
||||||
|
|
||||||
|
def qemu_get_ram_block(ram_addr):
|
||||||
|
"""Returns the RAMBlock struct to which the given address belongs."""
|
||||||
|
|
||||||
|
ram_blocks = gdb.parse_and_eval("ram_list.blocks")
|
||||||
|
|
||||||
|
for block in qlist_foreach(ram_blocks, "next"):
|
||||||
|
if (ram_addr - block["offset"]) < block["used_length"]:
|
||||||
|
return block
|
||||||
|
|
||||||
|
raise gdb.GdbError("Bad ram offset %x" % ram_addr)
|
||||||
|
|
||||||
|
|
||||||
|
def qemu_get_ram_ptr(ram_addr):
|
||||||
|
"""Returns qemu vaddr for given guest physical address."""
|
||||||
|
|
||||||
|
block = qemu_get_ram_block(ram_addr)
|
||||||
|
return block["host"] + (ram_addr - block["offset"])
|
||||||
|
|
||||||
|
|
||||||
|
def memory_region_get_ram_ptr(memory_region):
|
||||||
|
if memory_region["alias"] != 0:
|
||||||
|
return (memory_region_get_ram_ptr(memory_region["alias"].dereference())
|
||||||
|
+ memory_region["alias_offset"])
|
||||||
|
|
||||||
|
return qemu_get_ram_ptr(memory_region["ram_addr"] & TARGET_PAGE_MASK)
|
||||||
|
|
||||||
|
|
||||||
|
def get_guest_phys_blocks():
|
||||||
|
"""Returns a list of ram blocks.
|
||||||
|
|
||||||
|
Each block entry contains:
|
||||||
|
'target_start': guest block phys start address
|
||||||
|
'target_end': guest block phys end address
|
||||||
|
'host_addr': qemu vaddr of the block's start
|
||||||
|
"""
|
||||||
|
|
||||||
|
guest_phys_blocks = []
|
||||||
|
|
||||||
|
print("guest RAM blocks:")
|
||||||
|
print("target_start target_end host_addr message "
|
||||||
|
"count")
|
||||||
|
print("---------------- ---------------- ---------------- ------- "
|
||||||
|
"-----")
|
||||||
|
|
||||||
|
current_map_p = gdb.parse_and_eval("address_space_memory.current_map")
|
||||||
|
current_map = current_map_p.dereference()
|
||||||
|
|
||||||
|
# Conversion to int is needed for python 3
|
||||||
|
# compatibility. Otherwise range doesn't cast the value itself and
|
||||||
|
# breaks.
|
||||||
|
for cur in range(int(current_map["nr"])):
|
||||||
|
flat_range = (current_map["ranges"] + cur).dereference()
|
||||||
|
memory_region = flat_range["mr"].dereference()
|
||||||
|
|
||||||
|
# we only care about RAM
|
||||||
|
if not memory_region["ram"]:
|
||||||
|
continue
|
||||||
|
|
||||||
|
section_size = int128_get64(flat_range["addr"]["size"])
|
||||||
|
target_start = int128_get64(flat_range["addr"]["start"])
|
||||||
|
target_end = target_start + section_size
|
||||||
|
host_addr = (memory_region_get_ram_ptr(memory_region)
|
||||||
|
+ flat_range["offset_in_region"])
|
||||||
|
predecessor = None
|
||||||
|
|
||||||
|
# find continuity in guest physical address space
|
||||||
|
if len(guest_phys_blocks) > 0:
|
||||||
|
predecessor = guest_phys_blocks[-1]
|
||||||
|
predecessor_size = (predecessor["target_end"] -
|
||||||
|
predecessor["target_start"])
|
||||||
|
|
||||||
|
# the memory API guarantees monotonically increasing
|
||||||
|
# traversal
|
||||||
|
assert predecessor["target_end"] <= target_start
|
||||||
|
|
||||||
|
# we want continuity in both guest-physical and
|
||||||
|
# host-virtual memory
|
||||||
|
if (predecessor["target_end"] < target_start or
|
||||||
|
predecessor["host_addr"] + predecessor_size != host_addr):
|
||||||
|
predecessor = None
|
||||||
|
|
||||||
|
if predecessor is None:
|
||||||
|
# isolated mapping, add it to the list
|
||||||
|
guest_phys_blocks.append({"target_start": target_start,
|
||||||
|
"target_end": target_end,
|
||||||
|
"host_addr": host_addr})
|
||||||
|
message = "added"
|
||||||
|
else:
|
||||||
|
# expand predecessor until @target_end; predecessor's
|
||||||
|
# start doesn't change
|
||||||
|
predecessor["target_end"] = target_end
|
||||||
|
message = "joined"
|
||||||
|
|
||||||
|
print("%016x %016x %016x %-7s %5u" %
|
||||||
|
(target_start, target_end, host_addr.cast(UINTPTR_T),
|
||||||
|
message, len(guest_phys_blocks)))
|
||||||
|
|
||||||
|
return guest_phys_blocks
|
||||||
|
|
||||||
|
|
||||||
# The leading docstring doesn't have idiomatic Python formatting. It is
|
# The leading docstring doesn't have idiomatic Python formatting. It is
|
||||||
# printed by gdb's "help" command (the first line is printed in the
|
# printed by gdb's "help" command (the first line is printed in the
|
||||||
# "help data" summary), and it should match how other help texts look in
|
# "help data" summary), and it should match how other help texts look in
|
||||||
# gdb.
|
# gdb.
|
||||||
|
|
||||||
import struct
|
|
||||||
|
|
||||||
class DumpGuestMemory(gdb.Command):
|
class DumpGuestMemory(gdb.Command):
|
||||||
"""Extract guest vmcore from qemu process coredump.
|
"""Extract guest vmcore from qemu process coredump.
|
||||||
|
|
||||||
The sole argument is FILE, identifying the target file to write the
|
The two required arguments are FILE and ARCH:
|
||||||
guest vmcore to.
|
FILE identifies the target file to write the guest vmcore to.
|
||||||
|
ARCH specifies the architecture for which the core will be generated.
|
||||||
|
|
||||||
This GDB command reimplements the dump-guest-memory QMP command in
|
This GDB command reimplements the dump-guest-memory QMP command in
|
||||||
python, using the representation of guest memory as captured in the qemu
|
python, using the representation of guest memory as captured in the qemu
|
||||||
coredump. The qemu process that has been dumped must have had the
|
coredump. The qemu process that has been dumped must have had the
|
||||||
command line option "-machine dump-guest-core=on".
|
command line option "-machine dump-guest-core=on" which is the default.
|
||||||
|
|
||||||
For simplicity, the "paging", "begin" and "end" parameters of the QMP
|
For simplicity, the "paging", "begin" and "end" parameters of the QMP
|
||||||
command are not supported -- no attempt is made to get the guest's
|
command are not supported -- no attempt is made to get the guest's
|
||||||
internal paging structures (ie. paging=false is hard-wired), and guest
|
internal paging structures (ie. paging=false is hard-wired), and guest
|
||||||
memory is always fully dumped.
|
memory is always fully dumped.
|
||||||
|
|
||||||
Only x86_64 guests are supported.
|
Currently aarch64-be, aarch64-le, X86_64, 386, s390, ppc64-be,
|
||||||
|
ppc64-le guests are supported.
|
||||||
|
|
||||||
The CORE/NT_PRSTATUS and QEMU notes (that is, the VCPUs' statuses) are
|
The CORE/NT_PRSTATUS and QEMU notes (that is, the VCPUs' statuses) are
|
||||||
not written to the vmcore. Preparing these would require context that is
|
not written to the vmcore. Preparing these would require context that is
|
||||||
|
@ -47,293 +464,66 @@ deliberately called abort(), or it was dumped in response to a signal at
|
||||||
a halfway fortunate point, then its coredump should be in reasonable
|
a halfway fortunate point, then its coredump should be in reasonable
|
||||||
shape and this command should mostly work."""
|
shape and this command should mostly work."""
|
||||||
|
|
||||||
TARGET_PAGE_SIZE = 0x1000
|
|
||||||
TARGET_PAGE_MASK = 0xFFFFFFFFFFFFF000
|
|
||||||
|
|
||||||
# Various ELF constants
|
|
||||||
EM_X86_64 = 62 # AMD x86-64 target machine
|
|
||||||
ELFDATA2LSB = 1 # little endian
|
|
||||||
ELFCLASS64 = 2
|
|
||||||
ELFMAG = "\x7FELF"
|
|
||||||
EV_CURRENT = 1
|
|
||||||
ET_CORE = 4
|
|
||||||
PT_LOAD = 1
|
|
||||||
PT_NOTE = 4
|
|
||||||
|
|
||||||
# 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.
|
|
||||||
PN_XNUM = 0xFFFF
|
|
||||||
|
|
||||||
# Format strings for packing and header size calculation.
|
|
||||||
ELF64_EHDR = ("4s" # e_ident/magic
|
|
||||||
"B" # e_ident/class
|
|
||||||
"B" # e_ident/data
|
|
||||||
"B" # e_ident/version
|
|
||||||
"B" # e_ident/osabi
|
|
||||||
"8s" # e_ident/pad
|
|
||||||
"H" # e_type
|
|
||||||
"H" # e_machine
|
|
||||||
"I" # e_version
|
|
||||||
"Q" # e_entry
|
|
||||||
"Q" # e_phoff
|
|
||||||
"Q" # e_shoff
|
|
||||||
"I" # e_flags
|
|
||||||
"H" # e_ehsize
|
|
||||||
"H" # e_phentsize
|
|
||||||
"H" # e_phnum
|
|
||||||
"H" # e_shentsize
|
|
||||||
"H" # e_shnum
|
|
||||||
"H" # e_shstrndx
|
|
||||||
)
|
|
||||||
ELF64_PHDR = ("I" # p_type
|
|
||||||
"I" # p_flags
|
|
||||||
"Q" # p_offset
|
|
||||||
"Q" # p_vaddr
|
|
||||||
"Q" # p_paddr
|
|
||||||
"Q" # p_filesz
|
|
||||||
"Q" # p_memsz
|
|
||||||
"Q" # p_align
|
|
||||||
)
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(DumpGuestMemory, self).__init__("dump-guest-memory",
|
super(DumpGuestMemory, self).__init__("dump-guest-memory",
|
||||||
gdb.COMMAND_DATA,
|
gdb.COMMAND_DATA,
|
||||||
gdb.COMPLETE_FILENAME)
|
gdb.COMPLETE_FILENAME)
|
||||||
self.uintptr_t = gdb.lookup_type("uintptr_t")
|
self.elf = None
|
||||||
self.elf64_ehdr_le = struct.Struct("<%s" % self.ELF64_EHDR)
|
self.guest_phys_blocks = None
|
||||||
self.elf64_phdr_le = struct.Struct("<%s" % self.ELF64_PHDR)
|
|
||||||
|
|
||||||
def int128_get64(self, val):
|
def dump_init(self, vmcore):
|
||||||
assert (val["hi"] == 0)
|
"""Prepares and writes ELF structures to core file."""
|
||||||
return val["lo"]
|
|
||||||
|
|
||||||
def qlist_foreach(self, head, field_str):
|
# Needed to make crash happy, data for more useful notes is
|
||||||
var_p = head["lh_first"]
|
# not available in a qemu core.
|
||||||
while (var_p != 0):
|
self.elf.add_note("NONE", "EMPTY", 0)
|
||||||
var = var_p.dereference()
|
|
||||||
yield var
|
|
||||||
var_p = var[field_str]["le_next"]
|
|
||||||
|
|
||||||
def qemu_get_ram_block(self, ram_addr):
|
# We should never reach PN_XNUM for paging=false dumps,
|
||||||
ram_blocks = gdb.parse_and_eval("ram_list.blocks")
|
# there's just a handful of discontiguous ranges after
|
||||||
for block in self.qlist_foreach(ram_blocks, "next"):
|
# merging.
|
||||||
if (ram_addr - block["offset"] < block["used_length"]):
|
# The constant is needed to account for the PT_NOTE segment.
|
||||||
return block
|
phdr_num = len(self.guest_phys_blocks) + 1
|
||||||
raise gdb.GdbError("Bad ram offset %x" % ram_addr)
|
assert phdr_num < PN_XNUM
|
||||||
|
|
||||||
def qemu_get_ram_ptr(self, ram_addr):
|
|
||||||
block = self.qemu_get_ram_block(ram_addr)
|
|
||||||
return block["host"] + (ram_addr - block["offset"])
|
|
||||||
|
|
||||||
def memory_region_get_ram_ptr(self, mr):
|
|
||||||
if (mr["alias"] != 0):
|
|
||||||
return (self.memory_region_get_ram_ptr(mr["alias"].dereference()) +
|
|
||||||
mr["alias_offset"])
|
|
||||||
return self.qemu_get_ram_ptr(mr["ram_addr"] & self.TARGET_PAGE_MASK)
|
|
||||||
|
|
||||||
def guest_phys_blocks_init(self):
|
|
||||||
self.guest_phys_blocks = []
|
|
||||||
|
|
||||||
def guest_phys_blocks_append(self):
|
|
||||||
print "guest RAM blocks:"
|
|
||||||
print ("target_start target_end host_addr message "
|
|
||||||
"count")
|
|
||||||
print ("---------------- ---------------- ---------------- ------- "
|
|
||||||
"-----")
|
|
||||||
|
|
||||||
current_map_p = gdb.parse_and_eval("address_space_memory.current_map")
|
|
||||||
current_map = current_map_p.dereference()
|
|
||||||
for cur in range(current_map["nr"]):
|
|
||||||
flat_range = (current_map["ranges"] + cur).dereference()
|
|
||||||
mr = flat_range["mr"].dereference()
|
|
||||||
|
|
||||||
# we only care about RAM
|
|
||||||
if (not mr["ram"]):
|
|
||||||
continue
|
|
||||||
|
|
||||||
section_size = self.int128_get64(flat_range["addr"]["size"])
|
|
||||||
target_start = self.int128_get64(flat_range["addr"]["start"])
|
|
||||||
target_end = target_start + section_size
|
|
||||||
host_addr = (self.memory_region_get_ram_ptr(mr) +
|
|
||||||
flat_range["offset_in_region"])
|
|
||||||
predecessor = None
|
|
||||||
|
|
||||||
# find continuity in guest physical address space
|
|
||||||
if (len(self.guest_phys_blocks) > 0):
|
|
||||||
predecessor = self.guest_phys_blocks[-1]
|
|
||||||
predecessor_size = (predecessor["target_end"] -
|
|
||||||
predecessor["target_start"])
|
|
||||||
|
|
||||||
# the memory API guarantees monotonically increasing
|
|
||||||
# traversal
|
|
||||||
assert (predecessor["target_end"] <= target_start)
|
|
||||||
|
|
||||||
# we want continuity in both guest-physical and
|
|
||||||
# host-virtual memory
|
|
||||||
if (predecessor["target_end"] < target_start or
|
|
||||||
predecessor["host_addr"] + predecessor_size != host_addr):
|
|
||||||
predecessor = None
|
|
||||||
|
|
||||||
if (predecessor is None):
|
|
||||||
# isolated mapping, add it to the list
|
|
||||||
self.guest_phys_blocks.append({"target_start": target_start,
|
|
||||||
"target_end" : target_end,
|
|
||||||
"host_addr" : host_addr})
|
|
||||||
message = "added"
|
|
||||||
else:
|
|
||||||
# expand predecessor until @target_end; predecessor's
|
|
||||||
# start doesn't change
|
|
||||||
predecessor["target_end"] = target_end
|
|
||||||
message = "joined"
|
|
||||||
|
|
||||||
print ("%016x %016x %016x %-7s %5u" %
|
|
||||||
(target_start, target_end, host_addr.cast(self.uintptr_t),
|
|
||||||
message, len(self.guest_phys_blocks)))
|
|
||||||
|
|
||||||
def cpu_get_dump_info(self):
|
|
||||||
# We can't synchronize the registers with KVM post-mortem, and
|
|
||||||
# the bits in (first_x86_cpu->env.hflags) seem to be stale; they
|
|
||||||
# may not reflect long mode for example. Hence just assume the
|
|
||||||
# most common values. This also means that instruction pointer
|
|
||||||
# etc. will be bogus in the dump, but at least the RAM contents
|
|
||||||
# should be valid.
|
|
||||||
self.dump_info = {"d_machine": self.EM_X86_64,
|
|
||||||
"d_endian" : self.ELFDATA2LSB,
|
|
||||||
"d_class" : self.ELFCLASS64}
|
|
||||||
|
|
||||||
def encode_elf64_ehdr_le(self):
|
|
||||||
return self.elf64_ehdr_le.pack(
|
|
||||||
self.ELFMAG, # e_ident/magic
|
|
||||||
self.dump_info["d_class"], # e_ident/class
|
|
||||||
self.dump_info["d_endian"], # e_ident/data
|
|
||||||
self.EV_CURRENT, # e_ident/version
|
|
||||||
0, # e_ident/osabi
|
|
||||||
"", # e_ident/pad
|
|
||||||
self.ET_CORE, # e_type
|
|
||||||
self.dump_info["d_machine"], # e_machine
|
|
||||||
self.EV_CURRENT, # e_version
|
|
||||||
0, # e_entry
|
|
||||||
self.elf64_ehdr_le.size, # e_phoff
|
|
||||||
0, # e_shoff
|
|
||||||
0, # e_flags
|
|
||||||
self.elf64_ehdr_le.size, # e_ehsize
|
|
||||||
self.elf64_phdr_le.size, # e_phentsize
|
|
||||||
self.phdr_num, # e_phnum
|
|
||||||
0, # e_shentsize
|
|
||||||
0, # e_shnum
|
|
||||||
0 # e_shstrndx
|
|
||||||
)
|
|
||||||
|
|
||||||
def encode_elf64_note_le(self):
|
|
||||||
return self.elf64_phdr_le.pack(self.PT_NOTE, # p_type
|
|
||||||
0, # p_flags
|
|
||||||
(self.memory_offset -
|
|
||||||
len(self.note)), # p_offset
|
|
||||||
0, # p_vaddr
|
|
||||||
0, # p_paddr
|
|
||||||
len(self.note), # p_filesz
|
|
||||||
len(self.note), # p_memsz
|
|
||||||
0 # p_align
|
|
||||||
)
|
|
||||||
|
|
||||||
def encode_elf64_load_le(self, offset, start_hwaddr, range_size):
|
|
||||||
return self.elf64_phdr_le.pack(self.PT_LOAD, # p_type
|
|
||||||
0, # p_flags
|
|
||||||
offset, # p_offset
|
|
||||||
0, # p_vaddr
|
|
||||||
start_hwaddr, # p_paddr
|
|
||||||
range_size, # p_filesz
|
|
||||||
range_size, # p_memsz
|
|
||||||
0 # p_align
|
|
||||||
)
|
|
||||||
|
|
||||||
def note_init(self, name, desc, type):
|
|
||||||
# name must include a trailing NUL
|
|
||||||
namesz = (len(name) + 1 + 3) / 4 * 4
|
|
||||||
descsz = (len(desc) + 3) / 4 * 4
|
|
||||||
fmt = ("<" # little endian
|
|
||||||
"I" # n_namesz
|
|
||||||
"I" # n_descsz
|
|
||||||
"I" # n_type
|
|
||||||
"%us" # name
|
|
||||||
"%us" # desc
|
|
||||||
% (namesz, descsz))
|
|
||||||
self.note = struct.pack(fmt,
|
|
||||||
len(name) + 1, len(desc), type, name, desc)
|
|
||||||
|
|
||||||
def dump_init(self):
|
|
||||||
self.guest_phys_blocks_init()
|
|
||||||
self.guest_phys_blocks_append()
|
|
||||||
self.cpu_get_dump_info()
|
|
||||||
# we have no way to retrieve the VCPU status from KVM
|
|
||||||
# post-mortem
|
|
||||||
self.note_init("NONE", "EMPTY", 0)
|
|
||||||
|
|
||||||
# Account for PT_NOTE.
|
|
||||||
self.phdr_num = 1
|
|
||||||
|
|
||||||
# We should never reach PN_XNUM for paging=false dumps: there's
|
|
||||||
# just a handful of discontiguous ranges after merging.
|
|
||||||
self.phdr_num += len(self.guest_phys_blocks)
|
|
||||||
assert (self.phdr_num < self.PN_XNUM)
|
|
||||||
|
|
||||||
# Calculate the ELF file offset where the memory dump commences:
|
|
||||||
#
|
|
||||||
# ELF header
|
|
||||||
# PT_NOTE
|
|
||||||
# PT_LOAD: 1
|
|
||||||
# PT_LOAD: 2
|
|
||||||
# ...
|
|
||||||
# PT_LOAD: len(self.guest_phys_blocks)
|
|
||||||
# ELF note
|
|
||||||
# memory dump
|
|
||||||
self.memory_offset = (self.elf64_ehdr_le.size +
|
|
||||||
self.elf64_phdr_le.size * self.phdr_num +
|
|
||||||
len(self.note))
|
|
||||||
|
|
||||||
def dump_begin(self, vmcore):
|
|
||||||
vmcore.write(self.encode_elf64_ehdr_le())
|
|
||||||
vmcore.write(self.encode_elf64_note_le())
|
|
||||||
running = self.memory_offset
|
|
||||||
for block in self.guest_phys_blocks:
|
for block in self.guest_phys_blocks:
|
||||||
range_size = block["target_end"] - block["target_start"]
|
block_size = block["target_end"] - block["target_start"]
|
||||||
vmcore.write(self.encode_elf64_load_le(running,
|
self.elf.add_segment(PT_LOAD, block["target_start"], block_size)
|
||||||
block["target_start"],
|
|
||||||
range_size))
|
self.elf.to_file(vmcore)
|
||||||
running += range_size
|
|
||||||
vmcore.write(self.note)
|
|
||||||
|
|
||||||
def dump_iterate(self, vmcore):
|
def dump_iterate(self, vmcore):
|
||||||
|
"""Writes guest core to file."""
|
||||||
|
|
||||||
qemu_core = gdb.inferiors()[0]
|
qemu_core = gdb.inferiors()[0]
|
||||||
for block in self.guest_phys_blocks:
|
for block in self.guest_phys_blocks:
|
||||||
cur = block["host_addr"]
|
cur = block["host_addr"]
|
||||||
left = block["target_end"] - block["target_start"]
|
left = block["target_end"] - block["target_start"]
|
||||||
print ("dumping range at %016x for length %016x" %
|
print("dumping range at %016x for length %016x" %
|
||||||
(cur.cast(self.uintptr_t), left))
|
(cur.cast(UINTPTR_T), left))
|
||||||
while (left > 0):
|
|
||||||
chunk_size = min(self.TARGET_PAGE_SIZE, left)
|
while left > 0:
|
||||||
|
chunk_size = min(TARGET_PAGE_SIZE, left)
|
||||||
chunk = qemu_core.read_memory(cur, chunk_size)
|
chunk = qemu_core.read_memory(cur, chunk_size)
|
||||||
vmcore.write(chunk)
|
vmcore.write(chunk)
|
||||||
cur += chunk_size
|
cur += chunk_size
|
||||||
left -= chunk_size
|
left -= chunk_size
|
||||||
|
|
||||||
def create_vmcore(self, filename):
|
|
||||||
vmcore = open(filename, "wb")
|
|
||||||
self.dump_begin(vmcore)
|
|
||||||
self.dump_iterate(vmcore)
|
|
||||||
vmcore.close()
|
|
||||||
|
|
||||||
def invoke(self, args, from_tty):
|
def invoke(self, args, from_tty):
|
||||||
|
"""Handles command invocation from gdb."""
|
||||||
|
|
||||||
# Unwittingly pressing the Enter key after the command should
|
# Unwittingly pressing the Enter key after the command should
|
||||||
# not dump the same multi-gig coredump to the same file.
|
# not dump the same multi-gig coredump to the same file.
|
||||||
self.dont_repeat()
|
self.dont_repeat()
|
||||||
|
|
||||||
argv = gdb.string_to_argv(args)
|
argv = gdb.string_to_argv(args)
|
||||||
if (len(argv) != 1):
|
if len(argv) != 2:
|
||||||
raise gdb.GdbError("usage: dump-guest-memory FILE")
|
raise gdb.GdbError("usage: dump-guest-memory FILE ARCH")
|
||||||
|
|
||||||
self.dump_init()
|
self.elf = ELF(argv[1])
|
||||||
self.create_vmcore(argv[0])
|
self.guest_phys_blocks = get_guest_phys_blocks()
|
||||||
|
|
||||||
|
with open(argv[0], "wb") as vmcore:
|
||||||
|
self.dump_init(vmcore)
|
||||||
|
self.dump_iterate(vmcore)
|
||||||
|
|
||||||
DumpGuestMemory()
|
DumpGuestMemory()
|
||||||
|
|
1163
scripts/kvm/kvm_stat
1163
scripts/kvm/kvm_stat
File diff suppressed because it is too large
Load Diff
|
@ -558,7 +558,7 @@ tests/usb-hcd-uhci-test$(EXESUF): tests/usb-hcd-uhci-test.o $(libqos-usb-obj-y)
|
||||||
tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-test.o $(libqos-usb-obj-y)
|
tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-test.o $(libqos-usb-obj-y)
|
||||||
tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb-obj-y)
|
tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb-obj-y)
|
||||||
tests/pc-cpu-test$(EXESUF): tests/pc-cpu-test.o
|
tests/pc-cpu-test$(EXESUF): tests/pc-cpu-test.o
|
||||||
tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-char.o qemu-timer.o $(qtest-obj-y)
|
tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-char.o qemu-timer.o $(qtest-obj-y) $(test-io-obj-y)
|
||||||
tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o
|
tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o
|
||||||
tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o $(test-util-obj-y)
|
tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o $(test-util-obj-y)
|
||||||
tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(test-block-obj-y)
|
tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(test-block-obj-y)
|
||||||
|
|
Loading…
Reference in New Issue