From patchwork Tue Jan 26 13:47:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8122791 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 33D759F6DA for ; Tue, 26 Jan 2016 14:03:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8D94A2021F for ; Tue, 26 Jan 2016 14:03:29 +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 8D2FA2021A for ; Tue, 26 Jan 2016 14:03:22 +0000 (UTC) Received: from localhost ([::1]:44055 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aO4DJ-0005zG-1j for patchwork-qemu-devel@patchwork.kernel.org; Tue, 26 Jan 2016 09:03:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35651) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aO3z4-0001Nc-LV for qemu-devel@nongnu.org; Tue, 26 Jan 2016 08:48:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aO3z0-0004If-6J for qemu-devel@nongnu.org; Tue, 26 Jan 2016 08:48:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41137) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aO3yz-0004Ib-Si for qemu-devel@nongnu.org; Tue, 26 Jan 2016 08:48:34 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 77D843D3F43; Tue, 26 Jan 2016 13:48:33 +0000 (UTC) Received: from 640k.localdomain.com (ovpn-112-67.ams2.redhat.com [10.36.112.67]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0QDlNqt028272; Tue, 26 Jan 2016 08:48:32 -0500 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 26 Jan 2016 14:47:16 +0100 Message-Id: <1453816041-36362-45-git-send-email-pbonzini@redhat.com> In-Reply-To: <1453816041-36362-1-git-send-email-pbonzini@redhat.com> References: <1453816041-36362-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Janosch Frank Subject: [Qemu-devel] [PULL 44/49] 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 From: Janosch Frank The constants bloated the class definition and were therefore moved to the top. Reviewed-by: Laszlo Ersek Signed-off-by: Janosch Frank Message-Id: <1453464520-3882-2-git-send-email-frankja@linux.vnet.ibm.com> Signed-off-by: Paolo Bonzini --- 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