Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Kevin Buettner <kevinb@redhat.com>
To: Fabian Cenedese <Cenedese@indel.ch>
Cc: <gdb@sources.redhat.com>
Subject: Re: View registers from stack frames
Date: Mon, 11 Oct 2004 19:16:00 -0000	[thread overview]
Message-ID: <20041011115403.57327509@saguaro> (raw)
In-Reply-To: <5.2.0.9.1.20041008105008.01d72828@NT_SERVER>

On Fri, 08 Oct 2004 10:54:34 +0200
Fabian Cenedese <Cenedese@indel.ch> wrote:

> >> In frame 0 pc and lr are correct (different), but in the other frames
> >> they always have the same value whereas lr should have the
> >> value of the pc of the next frame, right?
> >
> >Recent versions of GDB show the same value for lr and pc for the later
> >frames.  I think this is okay.
> >
> >Kevin
> 
> I have only tested the --target=powerpc-eabi version so I don't know about
> other processors. Is this true that gdb is supposed to show pc and lr with
> the same values for stack frames >0? Isn't the purpose of the lr to point
> to the previous stack frame (and so be different from the actual pc)?
> And if the actual behaviour is correct then why is it different for frame 0?

I agree that this seems counter-intuitive, particularly after working
with it behaving the "other" way for so long.

If you set a breakpoint at the start of a function and the run until that
breakpoint, you'll find that LR does indeed point to the address at which
execution will continue when the current function returns in a normal
manner.  PC will be the address of the instruction at which you've
stopped.  These values should be different.

Now, suppose you step through the function until you reach a call.  If
you step over that call and examine PC and LR, you'll find that they
have the same value.  Why is this so?  It's because the "call" (bl)
instruction puts pc+4 into LR and branches to the function.  Since
you've stepped over the function, and since LR is restored in that
function's prologue, you'll find that LR contains the address at which
you're currently stopped which is in fact the current PC value.

Those lower frames are in the same situation that our top-most frame
is in in the second case.  A "call" was the last instruction to be
executed in that frame; this means that the LR value is actually set to
the value of the PC just after the call.

Looking at it another way, the reason that PC and LR are the same
value for frames other than the topmost frame (excluding possible
sigtramp frames, where they may in fact be different), is because LR
changes over the lifetime of the function.  GDB is reporting this as
accurately as it can.

Kevin


  reply	other threads:[~2004-10-11 18:54 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <5.2.0.9.1.20041007134711.01d12d90@NT_SERVER>
     [not found] ` <20041007085738.45b5b55a@saguaro>
2004-10-08 10:14   ` Fabian Cenedese
2004-10-11 19:16     ` Kevin Buettner [this message]
2004-10-12 14:03       ` Fabian Cenedese
2004-10-16 15:11         ` Kevin Buettner
2004-10-07 17:50 Xinan Tang
  -- strict thread matches above, loose matches on Subject: below --
2004-10-05 12:48 Fabian Cenedese
2004-10-05 13:30 ` Andrew Cagney
2004-10-05 14:02   ` Fabian Cenedese
2004-10-05 14:03     ` Daniel Jacobowitz
2004-10-05 15:00       ` Fabian Cenedese
2004-10-05 17:57         ` Fabian Cenedese
2004-10-06  1:57           ` Andrew Cagney
2004-10-06  7:18             ` Fabian Cenedese
2004-10-06 16:41               ` Kevin Buettner
2004-10-07  9:04                 ` Fabian Cenedese
2004-10-11 19:21                   ` Kevin Buettner

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=20041011115403.57327509@saguaro \
    --to=kevinb@redhat.com \
    --cc=Cenedese@indel.ch \
    --cc=gdb@sources.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox