cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
9ae3a8
From 231682fd6a7ca6fc5eecbec3df2f96133b9f3729 Mon Sep 17 00:00:00 2001
9ae3a8
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
9ae3a8
Date: Wed, 13 Dec 2017 13:39:04 +0100
9ae3a8
Subject: [PATCH 33/41] scripts/dump-guest-memory.py: Move constants to the top
9ae3a8
MIME-Version: 1.0
9ae3a8
Content-Type: text/plain; charset=UTF-8
9ae3a8
Content-Transfer-Encoding: 8bit
9ae3a8
9ae3a8
RH-Author: Marc-André Lureau <marcandre.lureau@redhat.com>
9ae3a8
Message-id: <20171213133912.26176-34-marcandre.lureau@redhat.com>
9ae3a8
Patchwork-id: 78378
9ae3a8
O-Subject: [RHEL-7.5 qemu-kvm PATCH v3 33/41] scripts/dump-guest-memory.py: Move constants to the top
9ae3a8
Bugzilla: 1411490
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
9ae3a8
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
9ae3a8
From: Janosch Frank <frankja@linux.vnet.ibm.com>
9ae3a8
9ae3a8
The constants bloated the class definition and were therefore moved to
9ae3a8
the top.
9ae3a8
9ae3a8
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
Signed-off-by: Janosch Frank <frankja@linux.vnet.ibm.com>
9ae3a8
Message-Id: <1453464520-3882-2-git-send-email-frankja@linux.vnet.ibm.com>
9ae3a8
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
9ae3a8
(cherry picked from commit ca81ce72b4d12494424d1813c6437035c1f89a8c)
9ae3a8
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 scripts/dump-guest-memory.py | 126 +++++++++++++++++++++----------------------
9ae3a8
 1 file changed, 63 insertions(+), 63 deletions(-)
9ae3a8
9ae3a8
diff --git a/scripts/dump-guest-memory.py b/scripts/dump-guest-memory.py
9ae3a8
index 1ed8b67..29f7c5b 100644
9ae3a8
--- a/scripts/dump-guest-memory.py
9ae3a8
+++ b/scripts/dump-guest-memory.py
9ae3a8
@@ -17,6 +17,55 @@
9ae3a8
 
9ae3a8
 import struct
9ae3a8
 
9ae3a8
+TARGET_PAGE_SIZE = 0x1000
9ae3a8
+TARGET_PAGE_MASK = 0xFFFFFFFFFFFFF000
9ae3a8
+
9ae3a8
+# Various ELF constants
9ae3a8
+EM_X86_64   = 62        # AMD x86-64 target machine
9ae3a8
+ELFDATA2LSB = 1         # little endian
9ae3a8
+ELFCLASS64  = 2
9ae3a8
+ELFMAG      = "\x7FELF"
9ae3a8
+EV_CURRENT  = 1
9ae3a8
+ET_CORE     = 4
9ae3a8
+PT_LOAD     = 1
9ae3a8
+PT_NOTE     = 4
9ae3a8
+
9ae3a8
+# Special value for e_phnum. This indicates that the real number of
9ae3a8
+# program headers is too large to fit into e_phnum. Instead the real
9ae3a8
+# value is in the field sh_info of section 0.
9ae3a8
+PN_XNUM = 0xFFFF
9ae3a8
+
9ae3a8
+# Format strings for packing and header size calculation.
9ae3a8
+ELF64_EHDR = ("4s" # e_ident/magic
9ae3a8
+              "B"  # e_ident/class
9ae3a8
+              "B"  # e_ident/data
9ae3a8
+              "B"  # e_ident/version
9ae3a8
+              "B"  # e_ident/osabi
9ae3a8
+              "8s" # e_ident/pad
9ae3a8
+              "H"  # e_type
9ae3a8
+              "H"  # e_machine
9ae3a8
+              "I"  # e_version
9ae3a8
+              "Q"  # e_entry
9ae3a8
+              "Q"  # e_phoff
9ae3a8
+              "Q"  # e_shoff
9ae3a8
+              "I"  # e_flags
9ae3a8
+              "H"  # e_ehsize
9ae3a8
+              "H"  # e_phentsize
9ae3a8
+              "H"  # e_phnum
9ae3a8
+              "H"  # e_shentsize
9ae3a8
+              "H"  # e_shnum
9ae3a8
+              "H"  # e_shstrndx
9ae3a8
+          )
9ae3a8
+ELF64_PHDR = ("I"  # p_type
9ae3a8
+              "I"  # p_flags
9ae3a8
+              "Q"  # p_offset
9ae3a8
+              "Q"  # p_vaddr
9ae3a8
+              "Q"  # p_paddr
9ae3a8
+              "Q"  # p_filesz
9ae3a8
+              "Q"  # p_memsz
9ae3a8
+              "Q"  # p_align
9ae3a8
+          )
9ae3a8
+
9ae3a8
 class DumpGuestMemory(gdb.Command):
9ae3a8
     """Extract guest vmcore from qemu process coredump.
9ae3a8
 
9ae3a8
@@ -47,62 +96,13 @@ deliberately called abort(), or it was dumped in response to a signal at
9ae3a8
 a halfway fortunate point, then its coredump should be in reasonable
9ae3a8
 shape and this command should mostly work."""
9ae3a8
 
9ae3a8
-    TARGET_PAGE_SIZE = 0x1000
9ae3a8
-    TARGET_PAGE_MASK = 0xFFFFFFFFFFFFF000
9ae3a8
-
9ae3a8
-    # Various ELF constants
9ae3a8
-    EM_X86_64   = 62        # AMD x86-64 target machine
9ae3a8
-    ELFDATA2LSB = 1         # little endian
9ae3a8
-    ELFCLASS64  = 2
9ae3a8
-    ELFMAG      = "\x7FELF"
9ae3a8
-    EV_CURRENT  = 1
9ae3a8
-    ET_CORE     = 4
9ae3a8
-    PT_LOAD     = 1
9ae3a8
-    PT_NOTE     = 4
9ae3a8
-
9ae3a8
-    # Special value for e_phnum. This indicates that the real number of
9ae3a8
-    # program headers is too large to fit into e_phnum. Instead the real
9ae3a8
-    # value is in the field sh_info of section 0.
9ae3a8
-    PN_XNUM = 0xFFFF
9ae3a8
-
9ae3a8
-    # Format strings for packing and header size calculation.
9ae3a8
-    ELF64_EHDR = ("4s" # e_ident/magic
9ae3a8
-                  "B"  # e_ident/class
9ae3a8
-                  "B"  # e_ident/data
9ae3a8
-                  "B"  # e_ident/version
9ae3a8
-                  "B"  # e_ident/osabi
9ae3a8
-                  "8s" # e_ident/pad
9ae3a8
-                  "H"  # e_type
9ae3a8
-                  "H"  # e_machine
9ae3a8
-                  "I"  # e_version
9ae3a8
-                  "Q"  # e_entry
9ae3a8
-                  "Q"  # e_phoff
9ae3a8
-                  "Q"  # e_shoff
9ae3a8
-                  "I"  # e_flags
9ae3a8
-                  "H"  # e_ehsize
9ae3a8
-                  "H"  # e_phentsize
9ae3a8
-                  "H"  # e_phnum
9ae3a8
-                  "H"  # e_shentsize
9ae3a8
-                  "H"  # e_shnum
9ae3a8
-                  "H"  # e_shstrndx
9ae3a8
-                 )
9ae3a8
-    ELF64_PHDR = ("I"  # p_type
9ae3a8
-                  "I"  # p_flags
9ae3a8
-                  "Q"  # p_offset
9ae3a8
-                  "Q"  # p_vaddr
9ae3a8
-                  "Q"  # p_paddr
9ae3a8
-                  "Q"  # p_filesz
9ae3a8
-                  "Q"  # p_memsz
9ae3a8
-                  "Q"  # p_align
9ae3a8
-                 )
9ae3a8
-
9ae3a8
     def __init__(self):
9ae3a8
         super(DumpGuestMemory, self).__init__("dump-guest-memory",
9ae3a8
                                               gdb.COMMAND_DATA,
9ae3a8
                                               gdb.COMPLETE_FILENAME)
9ae3a8
         self.uintptr_t     = gdb.lookup_type("uintptr_t")
9ae3a8
-        self.elf64_ehdr_le = struct.Struct("<%s" % self.ELF64_EHDR)
9ae3a8
-        self.elf64_phdr_le = struct.Struct("<%s" % self.ELF64_PHDR)
9ae3a8
+        self.elf64_ehdr_le = struct.Struct("<%s" % ELF64_EHDR)
9ae3a8
+        self.elf64_phdr_le = struct.Struct("<%s" % ELF64_PHDR)
9ae3a8
 
9ae3a8
     def int128_get64(self, val):
9ae3a8
         assert (val["hi"] == 0)
9ae3a8
@@ -130,7 +130,7 @@ shape and this command should mostly work."""
9ae3a8
         if (mr["alias"] != 0):
9ae3a8
             return (self.memory_region_get_ram_ptr(mr["alias"].dereference()) +
9ae3a8
                     mr["alias_offset"])
9ae3a8
-        return self.qemu_get_ram_ptr(mr["ram_addr"] & self.TARGET_PAGE_MASK)
9ae3a8
+        return self.qemu_get_ram_ptr(mr["ram_addr"] & TARGET_PAGE_MASK)
9ae3a8
 
9ae3a8
     def guest_phys_blocks_init(self):
9ae3a8
         self.guest_phys_blocks = []
9ae3a8
@@ -198,21 +198,21 @@ shape and this command should mostly work."""
9ae3a8
         # most common values. This also means that instruction pointer
9ae3a8
         # etc. will be bogus in the dump, but at least the RAM contents
9ae3a8
         # should be valid.
9ae3a8
-        self.dump_info = {"d_machine": self.EM_X86_64,
9ae3a8
-                          "d_endian" : self.ELFDATA2LSB,
9ae3a8
-                          "d_class"  : self.ELFCLASS64}
9ae3a8
+        self.dump_info = {"d_machine": EM_X86_64,
9ae3a8
+                          "d_endian" : ELFDATA2LSB,
9ae3a8
+                          "d_class"  : ELFCLASS64}
9ae3a8
 
9ae3a8
     def encode_elf64_ehdr_le(self):
9ae3a8
         return self.elf64_ehdr_le.pack(
9ae3a8
-                                 self.ELFMAG,                 # e_ident/magic
9ae3a8
+                                 ELFMAG,                      # e_ident/magic
9ae3a8
                                  self.dump_info["d_class"],   # e_ident/class
9ae3a8
                                  self.dump_info["d_endian"],  # e_ident/data
9ae3a8
-                                 self.EV_CURRENT,             # e_ident/version
9ae3a8
+                                 EV_CURRENT,                  # e_ident/version
9ae3a8
                                  0,                           # e_ident/osabi
9ae3a8
                                  "",                          # e_ident/pad
9ae3a8
-                                 self.ET_CORE,                # e_type
9ae3a8
+                                 ET_CORE,                     # e_type
9ae3a8
                                  self.dump_info["d_machine"], # e_machine
9ae3a8
-                                 self.EV_CURRENT,             # e_version
9ae3a8
+                                 EV_CURRENT,                  # e_version
9ae3a8
                                  0,                           # e_entry
9ae3a8
                                  self.elf64_ehdr_le.size,     # e_phoff
9ae3a8
                                  0,                           # e_shoff
9ae3a8
@@ -226,7 +226,7 @@ shape and this command should mostly work."""
9ae3a8
                                 )
9ae3a8
 
9ae3a8
     def encode_elf64_note_le(self):
9ae3a8
-        return self.elf64_phdr_le.pack(self.PT_NOTE,         # p_type
9ae3a8
+        return self.elf64_phdr_le.pack(PT_NOTE,              # p_type
9ae3a8
                                        0,                    # p_flags
9ae3a8
                                        (self.memory_offset -
9ae3a8
                                         len(self.note)),     # p_offset
9ae3a8
@@ -238,7 +238,7 @@ shape and this command should mostly work."""
9ae3a8
                                       )
9ae3a8
 
9ae3a8
     def encode_elf64_load_le(self, offset, start_hwaddr, range_size):
9ae3a8
-        return self.elf64_phdr_le.pack(self.PT_LOAD, # p_type
9ae3a8
+        return self.elf64_phdr_le.pack(PT_LOAD,      # p_type
9ae3a8
                                        0,            # p_flags
9ae3a8
                                        offset,       # p_offset
9ae3a8
                                        0,            # p_vaddr
9ae3a8
@@ -276,7 +276,7 @@ shape and this command should mostly work."""
9ae3a8
         # We should never reach PN_XNUM for paging=false dumps: there's
9ae3a8
         # just a handful of discontiguous ranges after merging.
9ae3a8
         self.phdr_num += len(self.guest_phys_blocks)
9ae3a8
-        assert (self.phdr_num < self.PN_XNUM)
9ae3a8
+        assert (self.phdr_num < PN_XNUM)
9ae3a8
 
9ae3a8
         # Calculate the ELF file offset where the memory dump commences:
9ae3a8
         #
9ae3a8
@@ -312,7 +312,7 @@ shape and this command should mostly work."""
9ae3a8
             print ("dumping range at %016x for length %016x" %
9ae3a8
                    (cur.cast(self.uintptr_t), left))
9ae3a8
             while (left > 0):
9ae3a8
-                chunk_size = min(self.TARGET_PAGE_SIZE, left)
9ae3a8
+                chunk_size = min(TARGET_PAGE_SIZE, left)
9ae3a8
                 chunk = qemu_core.read_memory(cur, chunk_size)
9ae3a8
                 vmcore.write(chunk)
9ae3a8
                 cur  += chunk_size
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8