Re: How to backtrace an separate stack?

Pedro Alves <[email protected]>
Newsgroups gmane.comp.gdb.devel,gmane.comp.emulators.qemu
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.