Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Dan McGuirk <mcguirk@indirect.com>
Subject: How to find caller's frame pointer?
Date: Sun, 1 Dec 1996 23:50:25 +0000 (`\x02. \x01)	[thread overview]
Message-ID: <856a95de7de103d9ed147d00e2fa9dde.axp-list@archive.invalid> (raw)

Hi.  I know this question isn't at quite the same level as most on this
list, but if some of the more technical people here could help me out, I'd
appreciate it. 

I'm trying to figure out how to find the caller's frame pointer in a
function compiled by gcc on an Alpha under Linux.  On an Intel processor,
gcc-compiled functions start with

        pushl %ebp
        movl %esp,%ebp

(assuming frame pointers aren't turned off).  So the stack looks something
like

		<arguments>
		return address
     EBP _____	previous frame pointer
     ESP _____  <local variables>

So if I just keep dereferencing %ebp a bunch of times, I can go up as many
stack frames as I want.

On the Alpha it's almost the same--functions start with something like:

        lda $30,-32($30)
        .frame $15,32,$26,0
        stq $26,0($30)
        stq $15,8($30)
        .mask 0x4008000,-32
        bis $30,$30,$15

So that's fine--I know the old frame pointer is at 8($15), and I should be
able to keep dereferencing as long as I move over eight bytes each time.
But the problem is, if a function clobbers any of the registers $9-$14,
they get pushed to the stack before $15, the old frame pointer, like this:

        lda $30,-64($30)
        .frame $15,64,$26,0
        stq $26,0($30)
        stq $9,8($30)
        stq $15,16($30)
        .mask 0x4008200,-64
        bis $30,$30,$15

So there doesn't seem to be any way to reliably tell where the old frame
pointer is going to be relative to the current one.

Or is there?  Am I missing something here?  Or is tracing frame pointers
back like this just not a legitimate thing to do?  (The reason would be
either to tell how deeply nested I am, or to locate the beginning of the
overall program stack.)

Thanks very much for any help anyone can provide.

--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

                 reply	other threads:[~1996-12-01 23:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox