From nobody Thu Nov 6 16:24:28 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489239404097128.79416224415206; Sat, 11 Mar 2017 05:36:44 -0800 (PST) Received: from localhost ([::1]:43454 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmhCL-000482-I5 for importer@patchew.org; Sat, 11 Mar 2017 08:36:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58983) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh0U-0002sk-V3 for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmh0R-0002oV-0e for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47988) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmh0Q-0002oP-O7 for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:22 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E56AF85363; Sat, 11 Mar 2017 13:24:22 +0000 (UTC) Received: from localhost (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C6BC2D655; Sat, 11 Mar 2017 13:24:21 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 17:22:56 +0400 Message-Id: <20170311132256.22951-22-marcandre.lureau@redhat.com> In-Reply-To: <20170311132256.22951-1-marcandre.lureau@redhat.com> References: <20170311132256.22951-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sat, 11 Mar 2017 13:24:22 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 21/21] scripts/dump-guest-memory.py: add VMCOREINFO X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/dump-guest-memory.py | 52 ++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 52 insertions(+) diff --git a/scripts/dump-guest-memory.py b/scripts/dump-guest-memory.py index f7c6635f15..0ce32b2a3f 100644 --- a/scripts/dump-guest-memory.py +++ b/scripts/dump-guest-memory.py @@ -120,6 +120,33 @@ class ELF(object): self.segments[0].p_filesz +=3D ctypes.sizeof(note) self.segments[0].p_memsz +=3D ctypes.sizeof(note) =20 + + def add_vmcoreinfo_note(self, vmcoreinfo, phys_base=3DNone): + """Adds a vmcoreinfo note to the ELF.""" + chead =3D type(get_arch_note(self.endianness, 0, 0)) + header =3D chead.from_buffer_copy(vmcoreinfo[0:ctypes.sizeof(chead= )]) + note =3D get_arch_note(self.endianness, + header.n_namesz - 1, header.n_descsz) + ctypes.memmove(ctypes.pointer(note), vmcoreinfo, ctypes.sizeof(not= e)) + header_size =3D ctypes.sizeof(note) - header.n_descsz + + if phys_base: + desc =3D bytearray(note.n_desc).decode().split() + if not next((v for v in desc if v.startswith('NUMBER(phys_base= )=3D')), + False): + desc.append('NUMBER(phys_base)=3D%ld' % phys_base) + desc =3D "\n".join(desc) + '\n' + descsz =3D (len(desc) + 3) // 4 * 4 + desc +=3D '\0' * (descsz - len(desc)) + note =3D get_arch_note(self.endianness, header.n_namesz - 1, d= escsz) + ctypes.memmove(ctypes.pointer(note), vmcoreinfo, header_size) + note.n_descsz =3D descsz + ctypes.memmove(note.n_desc, desc.encode(), descsz) + + self.notes.append(note) + self.segments[0].p_filesz +=3D ctypes.sizeof(note) + self.segments[0].p_memsz +=3D ctypes.sizeof(note) + def add_segment(self, p_type, p_paddr, p_size): """Adds a segment to the elf.""" =20 @@ -505,6 +532,30 @@ shape and this command should mostly work.""" cur +=3D chunk_size left -=3D chunk_size =20 + def get_vmcoreinfo(self): + qemu_core =3D gdb.inferiors()[0] + + try: + coreinfo =3D gdb.parse_and_eval("dump_info.vmcoreinfo") + except gdb.error: + return + + if coreinfo =3D=3D 0: + return + + phys_base =3D None + has_phys_base =3D gdb.parse_and_eval("dump_info.has_phys_base") + if has_phys_base: + phys_base =3D int(gdb.parse_and_eval("dump_info.phys_base")) + + addr, size =3D [int(val, 16) for val in coreinfo.string().split()] + for block in self.guest_phys_blocks: + if block["target_start"] <=3D addr < block["target_end"]: + haddr =3D block["host_addr"] + (addr - block["target_start= "]) + vmcoreinfo =3D qemu_core.read_memory(haddr, size) + self.elf.add_vmcoreinfo_note(vmcoreinfo.tobytes(), phys_ba= se) + return + def invoke(self, args, from_tty): """Handles command invocation from gdb.""" =20 @@ -518,6 +569,7 @@ shape and this command should mostly work.""" =20 self.elf =3D ELF(argv[1]) self.guest_phys_blocks =3D get_guest_phys_blocks() + self.get_vmcoreinfo() =20 with open(argv[0], "wb") as vmcore: self.dump_init(vmcore) --=20 2.12.0.191.gc5d8de91d