Commit 9834785d56 for qemu.org
commit 9834785d56ad20b0a85b43bc128039da2968f033
Author: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Date: Tue Aug 4 18:17:39 2026 +0300
scripts/qemugdb: coroutine: Fix patching pt_regs in the coredump
patch_regs() and restore_regs() open the coredump with 'ab', i.e. with
O_APPEND. This repositions the file offset to the end of the file before
every write. The seek() to pt_regs therefore has no effect: instead of
patching the saved registers, we just append the binary blob with patched
regs at the end of the file.
Nothing fails, and the gdb subprocess still prints a plausible backtrace.
However it's a backtrace of the crashed thread rather than of the
requested coroutine. The .ptregs blob kept for recovery is dead for the
same reason as there's never anything to restore.
Open the file with 'r+b' so that the writes actually land where seek()
points.
Fixes: 42f3c143c3a0 ("scripts/qemugdb: coroutine: Add option for obtaining detailed trace in coredump")
Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Message-ID: <20260804151743.937694-6-andrey.drobyshev@virtuozzo.com>
Tested-by: Fabiano Rosas <farosas@suse.de>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
diff --git a/scripts/qemugdb/coroutine.py b/scripts/qemugdb/coroutine.py
index da395a1a13..4803914dde 100644
--- a/scripts/qemugdb/coroutine.py
+++ b/scripts/qemugdb/coroutine.py
@@ -90,7 +90,7 @@ def patch_regs(self, regs):
int_regs = {k: int(v) for k, v in regs.items()}
patched_ptregs.update(int_regs)
- with open(self.coredump, 'ab') as f:
+ with open(self.coredump, 'r+b') as f:
gdb.write(f'assume pt_regs at 0x{self._ptregs_offset:x}\n')
f.seek(self._ptregs_offset, 0)
gdb.write('writing regs:\n')
@@ -106,7 +106,7 @@ def restore_regs(self):
return
gdb.write(f'\nrestoring original regs in core file {self.coredump}\n')
- with open(self.coredump, 'ab') as f:
+ with open(self.coredump, 'r+b') as f:
gdb.write(f'assume pt_regs at 0x{self._ptregs_offset:x}\n')
f.seek(self._ptregs_offset, 0)
f.write(struct.pack(f"={len(PT_REGS)}q",