public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: Stefan Hajnoczi <stefanha@redhat.com>, gdb@sourceware.org
Cc: qemu-devel@nongnu.org,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	tom@tromey.com
Subject: Re: How to backtrace an separate stack?
Date: Mon, 7 Mar 2022 10:49:47 +0000	[thread overview]
Message-ID: <bb91b504-aa47-49fe-9382-2b366449293f@palves.net> (raw)
In-Reply-To: <YiCk+NNtAGQPhyK5@stefanha-x1.localdomain>

On 2022-03-03 11:22, Stefan Hajnoczi wrote:
> Hi,
> The QEMU emulator uses coroutines with separate stacks. It can be
> challenging to debug coroutines that have yielded because GDB is not
> aware of them (no thread is currently executing them).
> 
> QEMU has a GDB Python script that helps. It "creates" a stack frame for
> a given coroutine by temporarily setting register values and then using
> the "bt" command. This works on a live process under ptrace control but
> not for coredumps where registers can't be set.
> 
> Here is the script (or see the bottom of this email for an inline copy
> of the relevant code):
> https://gitlab.com/qemu-project/qemu/-/blob/master/scripts/qemugdb/coroutine.py
> 
> I hoped that "select-frame address ADDRESS" could be used instead so
> this would work on coredumps too. Unfortunately "select-frame" only
> searches stack frames that GDB is already aware of, so it cannot be used
> to backtrace coroutine stacks.
> 
> Is there a way to backtrace a stack at an arbitrary address in GDB?

I don't think there's an easy/great answer.  Maybe it could
be done with a Python unwinder [1]?  See gdb.python/py-unwind-user-regs.py
in the GDB testsuite for an example you could probably start with.

As for something built-in to GDB, this reminded me of a discussion a while ago
around a "frame create" command.  Here were my thoughts back then, I think
still valid:

  https://sourceware.org/legacy-ml/gdb-patches/2015-09/msg00658.html

[1] https://sourceware.org/gdb/onlinedocs/gdb/Unwinding-Frames-in-Python.html

  reply	other threads:[~2022-03-07 10:49 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-03 11:22 Stefan Hajnoczi
2022-03-07 10:49 ` Pedro Alves [this message]
2022-03-08  9:47   ` Stefan Hajnoczi
2022-03-07 14:49 ` Florian Weimer
2022-03-07 17:30   ` Tom Tromey
2022-03-09 10:06     ` Florian Weimer
2022-03-09 19:50       ` Tom Tromey
2022-03-07 16:58 ` Tom Tromey
2022-03-07 17:18   ` Pedro Alves
2022-03-08  8:43     ` Stefan Hajnoczi
2022-03-14 20:30   ` Tom Tromey
2022-03-15 14:17     ` Stefan Hajnoczi
2022-03-18 21:13       ` Tom Tromey

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=bb91b504-aa47-49fe-9382-2b366449293f@palves.net \
    --to=pedro@palves.net \
    --cc=dgilbert@redhat.com \
    --cc=gdb@sourceware.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=tom@tromey.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).