[PATCH 8/9] scripts/qemugdb: coroutine: Speed up coroutine lookup in a coredump
Andrey Drobyshev <[email protected]> Tue, 4 Aug 2026 18:17:42 +0300
| Newsgroups | gmane.comp.emulators.qemu |
|---|---|
| Message-ID | <[email protected]> |
'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 <[email protected]> --- scripts/qemugdb/coroutine.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/qemugdb/coroutine.py b/scripts/qemugdb/coroutine.py index 3e0b37b73ea..21ed7cbaab8 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 -- 2.47.1