Commit f13762e035 for qemu.org

commit f13762e0355530f23181c2c27d74b9e9a08844ef
Author: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Date:   Tue Aug 4 18:17:43 2026 +0300

    scripts/qemugdb: coroutine: Don't touch the coredump for a plain backtrace

    init_coredump() creates a Coredump object for every coredump session.  That
    implies opening and scanning the actual coredump file.   For non-detailed
    'qemu bt' invocation we don't really need it.

    Les't only create the object when the core is about to be patched, i.e.
    for '--detailed'.

    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-10-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 21ed7cbaab..edc1f3cc69 100644
--- a/scripts/qemugdb/coroutine.py
+++ b/scripts/qemugdb/coroutine.py
@@ -328,7 +328,7 @@ def coroutine_to_jmpbuf(co):
     coroutine_pointer = co_cast(co)
     return coroutine_pointer['env']['__jmpbuf']

-def init_coredump():
+def init_coredump(detailed=False):
     global coredump

     files = gdb.execute('info files', False, True)
@@ -337,7 +337,8 @@ def init_coredump():
     if match is None:
         return False

-    if coredump is None:
+    # The object is only needed to patch the coredump
+    if detailed and coredump is None:
         coredump = Coredump(match.group(1), gdb.current_progspace().filename)

     return True
@@ -372,7 +373,7 @@ def invoke(self, arg, from_tty):
         if gdb.selected_thread() is None:
             raise gdb.GdbError('No stack.')

-        is_coredump = init_coredump()
+        is_coredump = init_coredump(detailed)
         if detailed and not is_coredump:
             gdb.write('--detailed is only valid when debugging core dumps\n')
             return
@@ -381,7 +382,7 @@ def invoke(self, arg, from_tty):
             bt_jmpbuf(coroutine_to_jmpbuf(gdb.parse_and_eval(argv[0])),
                       is_coredump, detailed=detailed)
         finally:
-            if is_coredump:
+            if coredump is not None:
                 coredump.restore_regs()

 class CoroutineBt(gdb.Command):
@@ -413,7 +414,7 @@ def invoke(self, arg, from_tty):
         if gdb.selected_thread() is None:
             raise gdb.GdbError('No stack.')

-        is_coredump = init_coredump()
+        is_coredump = init_coredump(detailed)
         if detailed and not is_coredump:
             gdb.write('--detailed is only valid when debugging core dumps\n')
             return
@@ -441,7 +442,7 @@ def invoke(self, arg, from_tty):
                 bt_jmpbuf(coroutine_to_jmpbuf(co_ptr), is_coredump,
                           detailed=detailed)
         finally:
-            if is_coredump:
+            if coredump is not None:
                 coredump.restore_regs()

 class CoroutineSPFunction(gdb.Function):