From patchwork Fri Jan 22 12:08:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 8089461 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4E35BBEEE5 for ; Fri, 22 Jan 2016 12:13:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7C30B203F7 for ; Fri, 22 Jan 2016 12:13:56 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7730D203E5 for ; Fri, 22 Jan 2016 12:13:55 +0000 (UTC) Received: from localhost ([::1]:52949 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMabC-0003ij-Nw for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 Jan 2016 07:13:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53265) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMaYv-0000bl-CV for qemu-devel@nongnu.org; Fri, 22 Jan 2016 07:11:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aMaYl-0007PK-5p for qemu-devel@nongnu.org; Fri, 22 Jan 2016 07:11:27 -0500 Received: from e06smtp17.uk.ibm.com ([195.75.94.113]:51642) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMaYk-0007OT-P8 for qemu-devel@nongnu.org; Fri, 22 Jan 2016 07:11:23 -0500 Received: from localhost by e06smtp17.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 22 Jan 2016 12:11:20 -0000 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp17.uk.ibm.com (192.168.101.147) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 22 Jan 2016 12:11:18 -0000 X-IBM-Helo: d06dlp01.portsmouth.uk.ibm.com X-IBM-MailFrom: frankja@linux.vnet.ibm.com X-IBM-RcptTo: qemu-devel@nongnu.org Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id EAC0617D8062 for ; Fri, 22 Jan 2016 12:11:23 +0000 (GMT) Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u0MCBHZG4587998 for ; Fri, 22 Jan 2016 12:11:17 GMT Received: from d06av02.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u0MCBHng002096 for ; Fri, 22 Jan 2016 05:11:17 -0700 Received: from s38lp20.boeblingen.de.ibm.com (dyn-9-152-224-160.boeblingen.de.ibm.com [9.152.224.160]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u0MCBGUE002067; Fri, 22 Jan 2016 05:11:17 -0700 From: Janosch Frank To: qemu-devel@nongnu.org Date: Fri, 22 Jan 2016 13:08:35 +0100 Message-Id: <1453464520-3882-2-git-send-email-frankja@linux.vnet.ibm.com> X-Mailer: git-send-email 2.3.0 In-Reply-To: <1453464520-3882-1-git-send-email-frankja@linux.vnet.ibm.com> References: <1453464520-3882-1-git-send-email-frankja@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16012212-0005-0000-0000-00000A173C2C X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.75.94.113 Cc: pbonzini@redhat.com, drjones@redhat.com, lersek@redhat.com, frankja@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 1/6] scripts/dump-guest-memory.py: Move constants to the top X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The constants bloated the class definition and were therefore moved to the top. Reviewed-by: Laszlo Ersek Signed-off-by: Janosch Frank --- scripts/dump-guest-memory.py | 126 +++++++++++++++++++++---------------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/scripts/dump-guest-memory.py b/scripts/dump-guest-memory.py index 08796ff..e49c835 100644 --- a/scripts/dump-guest-memory.py +++ b/scripts/dump-guest-memory.py @@ -17,6 +17,55 @@ import struct +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 + ) + class DumpGuestMemory(gdb.Command): """Extract guest vmcore from qemu process coredump. @@ -47,62 +96,13 @@ deliberately called abort(), or it was dumped in response to a signal at a halfway fortunate point, then its coredump should be in reasonable 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): super(DumpGuestMemory, self).__init__("dump-guest-memory", gdb.COMMAND_DATA, gdb.COMPLETE_FILENAME) self.uintptr_t = gdb.lookup_type("uintptr_t") - self.elf64_ehdr_le = struct.Struct("<%s" % self.ELF64_EHDR) - self.elf64_phdr_le = struct.Struct("<%s" % self.ELF64_PHDR) + self.elf64_ehdr_le = struct.Struct("<%s" % ELF64_EHDR) + self.elf64_phdr_le = struct.Struct("<%s" % ELF64_PHDR) def int128_get64(self, val): assert (val["hi"] == 0) @@ -130,7 +130,7 @@ shape and this command should mostly work.""" 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) + return self.qemu_get_ram_ptr(mr["ram_addr"] & TARGET_PAGE_MASK) def guest_phys_blocks_init(self): self.guest_phys_blocks = [] @@ -198,21 +198,21 @@ shape and this command should mostly work.""" # 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} + self.dump_info = {"d_machine": EM_X86_64, + "d_endian" : ELFDATA2LSB, + "d_class" : ELFCLASS64} def encode_elf64_ehdr_le(self): return self.elf64_ehdr_le.pack( - self.ELFMAG, # e_ident/magic + 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 + EV_CURRENT, # e_ident/version 0, # e_ident/osabi "", # e_ident/pad - self.ET_CORE, # e_type + ET_CORE, # e_type self.dump_info["d_machine"], # e_machine - self.EV_CURRENT, # e_version + EV_CURRENT, # e_version 0, # e_entry self.elf64_ehdr_le.size, # e_phoff 0, # e_shoff @@ -226,7 +226,7 @@ shape and this command should mostly work.""" ) def encode_elf64_note_le(self): - return self.elf64_phdr_le.pack(self.PT_NOTE, # p_type + return self.elf64_phdr_le.pack(PT_NOTE, # p_type 0, # p_flags (self.memory_offset - len(self.note)), # p_offset @@ -238,7 +238,7 @@ shape and this command should mostly work.""" ) def encode_elf64_load_le(self, offset, start_hwaddr, range_size): - return self.elf64_phdr_le.pack(self.PT_LOAD, # p_type + return self.elf64_phdr_le.pack(PT_LOAD, # p_type 0, # p_flags offset, # p_offset 0, # p_vaddr @@ -276,7 +276,7 @@ shape and this command should mostly work.""" # 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) + assert (self.phdr_num < PN_XNUM) # Calculate the ELF file offset where the memory dump commences: # @@ -312,7 +312,7 @@ shape and this command should mostly work.""" print ("dumping range at %016x for length %016x" % (cur.cast(self.uintptr_t), left)) while (left > 0): - chunk_size = min(self.TARGET_PAGE_SIZE, left) + chunk_size = min(TARGET_PAGE_SIZE, left) chunk = qemu_core.read_memory(cur, chunk_size) vmcore.write(chunk) cur += chunk_size