Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: "Petr Hluzín" <petr.hluzin@gmail.com>
To: "Martin Schröder" <lionhead@onlinehome.de>
Cc: gdb@sourceware.org
Subject: Re: Examining copied stack contents
Date: Mon, 05 Jul 2010 18:50:00 -0000	[thread overview]
Message-ID: <AANLkTikSUaTebyLCok1t81hNId3ZUqfLB6BsjoQa6U1m@mail.gmail.com> (raw)
In-Reply-To: <4A25DE879BC24E8DAEAEBD722E363025@igor>

Hello Martin and list

On 3 July 2010 12:46, Martin Schröder <gschroeder@onlinehome.de> wrote:
> Hello everyone.
>
> I'm currently implementing a high-level debugger based on GDB for a
> coroutine-based simulation framework. The platform is GNU/Linux on x86.
>
> That framework implements coroutines by using the C/C++ setjmp/longjmp
> instructions and by copying the call stack that is used by each coroutine to
> dynamically allocated memory on the heap. It's this latter aspect that gives
> me terrible headaches in GDB.
>
> My question is simply: Is it possible to point GDB to the copied contents of
> the call stack and tell it to print out the information contained therein?

(Note I am not familiar in x86 stack-walking stuff.)

In general a debugger needs at least a stack pointer and an
instruction pointer to get a backtrace. If the function containing the
IP uses a frame pointer (a debugger should be able to tell you that)
then debugger needs to know the FP. Which register contains the FP
depends on the prologue type chosen by compiler (on x86 it is always
EBP). Command "info frame <address>" may assume IP is pointed to by
SP. So there are at least 2 arguments (FP+SP) to be provided on any
arch.

Therefore I suspect "info frame <address>" is not general enough to be
used in your case.

> That framework implements coroutines by using the C/C++ setjmp/longjmp
> instructions and by copying the call stack that is used by each coroutine to
> dynamically allocated memory on the heap.

Beware that a function compiled without -fomit-frame-pointer saves SP
to stack and gdb uses the value to obtain stack-trace (this is not
quite exact). If you copy a stack somewhere and use gdb to walk the
stack there then gdb will try to use SP values pointing to the "old"
stack memory.
(And you cannot resume execution of the stack while in the new memory.)

> But I'm also aware that the GDB *should be* able to do what I want it to do.
> For one, the documentation explicitly mentions that the feature works with
> programs that utilize multiple stacks. Furthermore, the GDB is also able to
> debug Multi-Threaded programs, which also need to save the call stack to
> dynamic heap memory.

When doing multithreaded programs gdb gets register values from
pthread library (or linux kernel?) or by remote target command. And
the stack frames stay where they were created - they are not copied.

> So, my question is: Is it possible to examine the copied stack? And if yes,
> what do I need to give to the GDB to allow it?

I do not know. Someone else have to answer that.

-- 
Petr Hluzin


  parent reply	other threads:[~2010-07-05 18:50 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-03 10:48 Martin Schröder
2010-07-05  4:54 ` support biarch gcore? Jon Zhou
2010-07-05  7:12   ` Jan Kratochvil
2010-07-05 11:55     ` Mark Kettenis
2010-07-06 20:48       ` Ulrich Weigand
2010-07-06 21:29         ` Mark Kettenis
2010-07-07 12:30           ` Ulrich Weigand
2010-07-08  2:35             ` Jon Zhou
2010-07-08 11:17               ` Ulrich Weigand
2010-07-08  4:47             ` H.J. Lu
2010-07-08  5:05               ` H.J. Lu
2010-07-08 11:15                 ` Ulrich Weigand
2010-07-08 13:52                   ` H.J. Lu
2010-07-21 22:45                     ` Joseph S. Myers
2010-07-05 18:50 ` Petr Hluzín [this message]
2010-07-05 20:18   ` Examining copied stack contents Martin Schröder
2010-07-05 20:27     ` Joel Brobecker
2010-07-07 17:29   ` Martin Schröder

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=AANLkTikSUaTebyLCok1t81hNId3ZUqfLB6BsjoQa6U1m@mail.gmail.com \
    --to=petr.hluzin@gmail.com \
    --cc=gdb@sourceware.org \
    --cc=lionhead@onlinehome.de \
    /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