Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Jean Christophe Beyler <jean.christophe.beyler@gmail.com>
To: David Daney <ddaney@caviumnetworks.com>
Cc: gdb@sourceware.org
Subject: Re: GDB interactions with GCC
Date: Tue, 03 Nov 2009 17:22:00 -0000	[thread overview]
Message-ID: <c568a2600911030922x1607ce68ic34acb186f0bc291@mail.gmail.com> (raw)
In-Reply-To: <4AEF6834.1080208@caviumnetworks.com>

> That is an simplified answer based on my limited knowledge of the subject.

Thanks, it's a start.

I am first gathering information and these seem to be like huge newbie
questions, for which I apologize. Can someone explain how GDB does to
remember what arguments were used in a backtrace ? Is it necessary
that they all reside on the stack or does GDB copy them somewhere for
later use, it the case of architectures that do not need to pass the
arguments on the stack?

Technically, on my architecture, if we had:

int bar (int a)
{
    return a;
}

int foo (int a, int b)
{
   return a + b;
}

the compiler would generate for foo something like:

...
add FirstInputRegister, FirstInputRegister, SecondInputRegister
call bar
...

Therefore, if I put a breakpoint at bar, if I look at
FirstInputRegister, I would have a+b but if I backtraced to foo, how
would GDB remember the values of a and b.

In this case, must GCC generate something like this instead :

...
store FirstInputRegister, 0(stack_pointer)
store SecondInputRegister, 8(stack_pointer)  #8 is just an offset,
let's suppose int is 8 bytes...
add FirstInputRegister, FirstInputRegister, SecondInputRegister
call bar
...

so that the arguments reside on the stack so that GDB can get them at
a later date ?

If so, doesn't that mean that if we want GDB on an architecture that
does not require any stack copies, we still have to generate those
uselessly (except for GDB ;-)) ?

Thanks again,
Jc

On Mon, Nov 2, 2009 at 6:16 PM, David Daney <ddaney@caviumnetworks.com> wrote:
> Jean Christophe Beyler wrote:
> [...]
>>
>> For example, on my architecture, the return address is passed in one
>> register that the function can push on the stack if it's necessary (if
>> a call happens) but not if it's a leaf function. The local variables
>> are also sent via registers and therefore, potentially are never
>> stored on the stack.
>
> This is similar to MIPS which is supported by gdb.
>
> [...]
>
>> And if someone can answer these questions:
>>
>> - It seems to me that GCC outputs debug information that helps GDB
>> follow the course of the program:
>>   - With this information, is GDB able to follow where the local
>> variables are kept (register or stack) depending on what the program
>> is doing ?
>
> Usually.
>
>>   - Does GCC need to output anything in particular to allow GDB to
>> give the information of the backtrace for example?
>>
>
> Yes.
>
>> In other words:
>>
>> - Does the ABI need to store the stack pointer for each frame in order
>> for GDB to give all the backtrace, variable information? Or does GDB
>> keep track of this independantly of the ABI.
>
> For some (many) archectures, the compiler emits debug information describing
> the information needed to generate a backtrace.  Look at .debug_frame
> sections in DWARF for example.  Given a lack of frame meta-data, you can
> have target specific code that does ad hoc stack and code examination to try
> to generate a backtrace.
>
>
>>
>> - Does GDB require that the ABI store arguments at some point on the
>> stack in order to provide information about a function calls
>> arguments? I would assume not because otherwise register-based ABIs
>> would have to redundantly copy things on the stack for GDB use...
>>
>
> The debug data emitted by the compiler should allow gdb to track variable
> locations.  For most Linux systems this is specified by DWARF.
>
> That is an simplified answer based on my limited knowledge of the subject.
>
> David Daney
>
>


  reply	other threads:[~2009-11-03 17:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-02 22:44 Jean Christophe Beyler
2009-11-02 23:16 ` David Daney
2009-11-03 17:22   ` Jean Christophe Beyler [this message]
2009-11-03 17:38     ` Paul Pluzhnikov
2009-11-03 17:55       ` Jean Christophe Beyler
2009-11-03 18:01         ` Daniel Jacobowitz
2009-11-03 18:09           ` Jean Christophe Beyler
2009-11-03 18:14             ` Daniel Jacobowitz

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=c568a2600911030922x1607ce68ic34acb186f0bc291@mail.gmail.com \
    --to=jean.christophe.beyler@gmail.com \
    --cc=ddaney@caviumnetworks.com \
    --cc=gdb@sourceware.org \
    /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