aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2017-10-16 17:29:16 +0100
committerPeter Maydell <peter.maydell@linaro.org>2017-10-16 17:29:16 +0100
commitc5bbcaa4b7c0f8a322bebe9ec563560178a68b55 (patch)
treedf49749a080033a983e0080ad6ce58ffe8d119cf /scripts
parent79b2a13aa81724228166c794f48eb75bfb696b88 (diff)
parentab06ec43577177a442e8e5ca28d0154efe4ff60f (diff)
downloadqemu-c5bbcaa4b7c0f8a322bebe9ec563560178a68b55.zip
qemu-c5bbcaa4b7c0f8a322bebe9ec563560178a68b55.tar.gz
qemu-c5bbcaa4b7c0f8a322bebe9ec563560178a68b55.tar.bz2
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging
pc, pci, virtio: fixes, features A bunch of fixes all over the place. A new vmcore device - the user interface around it is still somewhat controversial, but I feel most of the code is fine, suggestions can be addressed by adding patches on top. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> # gpg: Signature made Sun 15 Oct 2017 04:02:23 BST # gpg: using RSA key 0x281F0DB8D28D5469 # gpg: Good signature from "Michael S. Tsirkin <mst@kernel.org>" # gpg: aka "Michael S. Tsirkin <mst@redhat.com>" # Primary key fingerprint: 0270 606B 6F3C DF3D 0B17 0970 C350 3912 AFBE 8E67 # Subkey fingerprint: 5D09 FD08 71C8 F85B 94CA 8A0D 281F 0DB8 D28D 5469 * remotes/mst/tags/for_upstream: (26 commits) tests/pxe: Test more NICs when running in SPEED=slow mode pc: remove useless hot_add_cpu initialisation isapc: Remove unnecessary migration compatibility code virtio-pci: Replace modern_as with direct access to modern_bar virtio: fix descriptor counting in virtqueue_pop hw/gen_pcie_root_port: make IO RO 0 on IO disabled pci: Validate interfaces on base_class_init xen/pt: Mark TYPE_XEN_PT_DEVICE as hybrid pci: Add INTERFACE_CONVENTIONAL_PCI_DEVICE to Conventional PCI devices pci: Add INTERFACE_PCIE_DEVICE to all PCIe devices pci: Add interface names to hybrid PCI devices pci: conventional-pci-device and pci-express-device interfaces PCI: PCIe access should always be little endian virtio/pci/migration: Convert to VMState hw/pci-bridge/pcie_pci_bridge: properly handle MSI unavailability case pci: allow 32-bit PCI IO accesses to pass through the PCI bridge virtio/vhost: reset dev->log after syncing MAINTAINERS: add Dump maintainers scripts/dump-guest-memory.py: add vmcoreinfo kdump: set vmcoreinfo location ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/dump-guest-memory.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/scripts/dump-guest-memory.py b/scripts/dump-guest-memory.py
index f7c6635..69dd5ef 100644
--- a/scripts/dump-guest-memory.py
+++ b/scripts/dump-guest-memory.py
@@ -14,6 +14,7 @@ the COPYING file in the top-level directory.
"""
import ctypes
+import struct
UINTPTR_T = gdb.lookup_type("uintptr_t")
@@ -45,6 +46,17 @@ EM_S390 = 22
EM_AARCH = 183
EM_X86_64 = 62
+VMCOREINFO_FORMAT_ELF = 1
+
+def le16_to_cpu(val):
+ return struct.unpack("<H", struct.pack("=H", val))[0]
+
+def le32_to_cpu(val):
+ return struct.unpack("<I", struct.pack("=I", val))[0]
+
+def le64_to_cpu(val):
+ return struct.unpack("<Q", struct.pack("=Q", val))[0]
+
class ELF(object):
"""Representation of a ELF file."""
@@ -120,6 +132,25 @@ class ELF(object):
self.segments[0].p_filesz += ctypes.sizeof(note)
self.segments[0].p_memsz += ctypes.sizeof(note)
+
+ def add_vmcoreinfo_note(self, vmcoreinfo):
+ """Adds a vmcoreinfo note to the ELF dump."""
+ # compute the header size, and copy that many bytes from the note
+ header = get_arch_note(self.endianness, 0, 0)
+ ctypes.memmove(ctypes.pointer(header),
+ vmcoreinfo, ctypes.sizeof(header))
+ if header.n_descsz > 1 << 20:
+ print('warning: invalid vmcoreinfo size')
+ return
+ # now get the full note
+ note = get_arch_note(self.endianness,
+ header.n_namesz - 1, header.n_descsz)
+ ctypes.memmove(ctypes.pointer(note), vmcoreinfo, ctypes.sizeof(note))
+
+ 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."""
@@ -505,6 +536,35 @@ shape and this command should mostly work."""
cur += chunk_size
left -= chunk_size
+ def phys_memory_read(self, addr, size):
+ qemu_core = gdb.inferiors()[0]
+ for block in self.guest_phys_blocks:
+ if block["target_start"] <= addr \
+ and addr + size <= block["target_end"]:
+ haddr = block["host_addr"] + (addr - block["target_start"])
+ return qemu_core.read_memory(haddr, size)
+ return None
+
+ def add_vmcoreinfo(self):
+ if not gdb.parse_and_eval("vmcoreinfo_find()") \
+ or not gdb.parse_and_eval("vmcoreinfo_find()->has_vmcoreinfo"):
+ return
+
+ fmt = gdb.parse_and_eval("vmcoreinfo_find()->vmcoreinfo.guest_format")
+ addr = gdb.parse_and_eval("vmcoreinfo_find()->vmcoreinfo.paddr")
+ size = gdb.parse_and_eval("vmcoreinfo_find()->vmcoreinfo.size")
+
+ fmt = le16_to_cpu(fmt)
+ addr = le64_to_cpu(addr)
+ size = le32_to_cpu(size)
+
+ if fmt != VMCOREINFO_FORMAT_ELF:
+ return
+
+ vmcoreinfo = self.phys_memory_read(addr, size)
+ if vmcoreinfo:
+ self.elf.add_vmcoreinfo_note(vmcoreinfo.tobytes())
+
def invoke(self, args, from_tty):
"""Handles command invocation from gdb."""
@@ -518,6 +578,7 @@ shape and this command should mostly work."""
self.elf = ELF(argv[1])
self.guest_phys_blocks = get_guest_phys_blocks()
+ self.add_vmcoreinfo()
with open(argv[0], "wb") as vmcore:
self.dump_init(vmcore)