Commit 974fd683f3 for qemu.org
commit 974fd683f30770e593e350021e3775b42c65055a
Author: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Date: Tue Aug 4 18:17:42 2026 +0300
scripts/qemugdb: coroutine: Speed up coroutine lookup in a coredump
'qemu bt' on a coredump takes significant time before the first
coroutine frame is even printed. The bulk of the delay is resolving a
name.
co_tls_current is a file static variable, and CoroutineUContext is defined
in the same compilation unit, so resolving either of them by name makes gdb
expand every symtab in the binary.
Look the static up with gdb.lookup_static_symbol(), which is served from
the gdb's in-memory index, and scope the type lookup to the symtab that
comes with it. This significantly speeds up 'qemu bt' processing.
Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Message-ID: <20260804151743.937694-9-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 3e0b37b73e..21ed7cbaab 100644
--- a/scripts/qemugdb/coroutine.py
+++ b/scripts/qemugdb/coroutine.py
@@ -313,7 +313,16 @@ def bt_jmpbuf(jmpbuf, is_coredump, detailed=False):
dump_backtrace(regs)
def co_cast(co):
- return co.cast(gdb.lookup_type('CoroutineUContext').pointer())
+ # Unscoped type lookup expands every symtab in the binary.
+ # Better scope it to the symtab of the ucontext backend
+ sym = gdb.lookup_static_symbol('co_tls_current')
+ if sym is not None:
+ co_type = gdb.lookup_type('CoroutineUContext',
+ sym.symtab.static_block())
+ else:
+ co_type = gdb.lookup_type('CoroutineUContext')
+
+ return co.cast(co_type.pointer())
def coroutine_to_jmpbuf(co):
coroutine_pointer = co_cast(co)
@@ -416,7 +425,8 @@ def invoke(self, arg, from_tty):
co_ptr = gdb.parse_and_eval("qemu_coroutine_self()")
else:
# Fallback to use hard-coded ucontext vars if it's coredump
- co_ptr = gdb.parse_and_eval("co_tls_current")
+ sym = gdb.lookup_static_symbol("co_tls_current")
+ co_ptr = sym.value() if sym else gdb.parse_and_eval("co_tls_current")
if co_ptr == False:
return