From nobody Tue Feb 10 03:38:47 2026 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.zohomail.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 1505149811188435.1110235239746; Mon, 11 Sep 2017 10:10:11 -0700 (PDT) Received: from localhost ([::1]:59215 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drSDp-00062i-GB for importer@patchew.org; Mon, 11 Sep 2017 13:10:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57877) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drS4M-0006Ui-Gg for qemu-devel@nongnu.org; Mon, 11 Sep 2017 13:00:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drS4I-0007Je-Ka for qemu-devel@nongnu.org; Mon, 11 Sep 2017 13:00:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54982) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1drS4I-0007J7-CK for qemu-devel@nongnu.org; Mon, 11 Sep 2017 13:00:18 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5E4991B5C53 for ; Mon, 11 Sep 2017 17:00:17 +0000 (UTC) Received: from localhost (ovpn-112-51.ams2.redhat.com [10.36.112.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id 131FA5C2F4; Mon, 11 Sep 2017 17:00:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5E4991B5C53 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Mon, 11 Sep 2017 18:59:28 +0200 Message-Id: <20170911165929.2791-7-marcandre.lureau@redhat.com> In-Reply-To: <20170911165929.2791-1-marcandre.lureau@redhat.com> References: <20170911165929.2791-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 11 Sep 2017 17:00:17 +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 v6 6/7] 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: ehabkost@redhat.com, mst@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , imammedo@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" Add a vmcoreinfo ELF note in the dump if vmcoreinfo device has the memory location details. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/dump-guest-memory.py | 61 ++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 61 insertions(+) diff --git a/scripts/dump-guest-memory.py b/scripts/dump-guest-memory.py index f7c6635f15..69dd5efadf 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. """ =20 import ctypes +import struct =20 UINTPTR_T =3D gdb.lookup_type("uintptr_t") =20 @@ -45,6 +46,17 @@ EM_S390 =3D 22 EM_AARCH =3D 183 EM_X86_64 =3D 62 =20 +VMCOREINFO_FORMAT_ELF =3D 1 + +def le16_to_cpu(val): + return struct.unpack(" 1 << 20: + print('warning: invalid vmcoreinfo size') + return + # now get the full note + note =3D get_arch_note(self.endianness, + header.n_namesz - 1, header.n_descsz) + ctypes.memmove(ctypes.pointer(note), vmcoreinfo, ctypes.sizeof(not= e)) + + 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 +536,35 @@ shape and this command should mostly work.""" cur +=3D chunk_size left -=3D chunk_size =20 + def phys_memory_read(self, addr, size): + qemu_core =3D gdb.inferiors()[0] + for block in self.guest_phys_blocks: + if block["target_start"] <=3D addr \ + and addr + size <=3D block["target_end"]: + haddr =3D 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 =3D gdb.parse_and_eval("vmcoreinfo_find()->vmcoreinfo.guest_fo= rmat") + addr =3D gdb.parse_and_eval("vmcoreinfo_find()->vmcoreinfo.paddr") + size =3D gdb.parse_and_eval("vmcoreinfo_find()->vmcoreinfo.size") + + fmt =3D le16_to_cpu(fmt) + addr =3D le64_to_cpu(addr) + size =3D le32_to_cpu(size) + + if fmt !=3D VMCOREINFO_FORMAT_ELF: + return + + vmcoreinfo =3D 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.""" =20 @@ -518,6 +578,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.add_vmcoreinfo() =20 with open(argv[0], "wb") as vmcore: self.dump_init(vmcore) --=20 2.14.1.146.gd35faa819