All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
To: qemu-devel@nongnu.org
Cc: stefanha@redhat.com, kwolf@redhat.com, peterx@redhat.com,
	andrey.drobyshev@virtuozzo.com
Subject: [PATCH 8/9] scripts/qemugdb: coroutine: Speed up coroutine lookup in a coredump
Date: Tue,  4 Aug 2026 18:17:42 +0300	[thread overview]
Message-ID: <20260804151743.937694-9-andrey.drobyshev@virtuozzo.com> (raw)
In-Reply-To: <20260804151743.937694-1-andrey.drobyshev@virtuozzo.com>

'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>
---
 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



  parent reply	other threads:[~2026-08-04 15:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-04 15:17 [PATCH 0/9] scripts/qemugdb: some fixes for 'qemu bt' / 'qemu coroutine' commands Andrey Drobyshev
2026-08-04 15:17 ` [PATCH 1/9] scripts/qemugdb: coroutine: Fix selected frame leak on error path Andrey Drobyshev
2026-08-04 15:17 ` [PATCH 2/9] scripts/qemugdb: coroutine: Get rid of fallback pattern when dumping backtrace Andrey Drobyshev
2026-08-04 15:17 ` [PATCH 3/9] scripts/qemugdb: coroutine: Only attempt to restore regs in coredump Andrey Drobyshev
2026-08-04 15:17 ` [PATCH 4/9] scripts/qemugdb: coroutine: Don't unwind past the outermost frame Andrey Drobyshev
2026-08-04 15:17 ` [PATCH 5/9] scripts/qemugdb: coroutine: Fix patching pt_regs in the coredump Andrey Drobyshev
2026-08-04 15:17 ` [PATCH 6/9] scripts/qemugdb: coroutine: Fix '--detailed' description Andrey Drobyshev
2026-08-04 15:17 ` [PATCH 7/9] scripts/qemugdb: coroutine: Handle target absence gracefully Andrey Drobyshev
2026-08-04 15:17 ` Andrey Drobyshev [this message]
2026-08-04 15:17 ` [PATCH 9/9] scripts/qemugdb: coroutine: Don't touch the coredump for a plain backtrace Andrey Drobyshev
2026-08-26 15:02 ` [PATCH 0/9] scripts/qemugdb: some fixes for 'qemu bt' / 'qemu coroutine' commands Fabiano Rosas
2026-09-23 15:28 ` Andrey Drobyshev
2026-09-25 14:03 ` Kevin Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260804151743.937694-9-andrey.drobyshev@virtuozzo.com \
    --to=andrey.drobyshev@virtuozzo.com \
    --cc=kwolf@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.