Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 23 Jul 2001 16:36:39 -0700 (PDT)
From:      John Baldwin <jhb@FreeBSD.org>
To:        j mckitrick <jcm@FreeBSD-uk.eu.org>
Cc:        freebsd-chat@FreeBSD.org
Subject:   Re: stack use preference
Message-ID:  <XFMail.010723163639.jhb@FreeBSD.org>
In-Reply-To: <20010724002816.A62305@dogma.freebsd-uk.eu.org>

next in thread | previous in thread | raw e-mail | index | archive | help

On 23-Jul-01 j mckitrick wrote:
>| > memory.  So the question (if it still stands) is do you subtract the space
>| > for local vars before or after moving esp to ebp?  I've seen both ways in
>| > Win32 and Unix code.
>| 
>| After.  This way you can always get to the old frame at [ebp] and the IP of
>| the
>| previous frame at [ebp+4].  These constant offets are quite handy for
>| walking
>| back stack traces by hand.  See the descriptions of the 286+ enter and leave
>| instructions.
> 
> Hmmm.  The argument I heard for moving esp to ebp before making room for
> local variables is that function parameters are accessible at positive
> offsets from esp, and all locals are negative.  I guess that puts the
> previous IP and stack frame at [total space req'd by local vars + 0] and
> [+4] respectively.

Right, and 'total space req'd by local vars' is an opaque value that you don't
know when you are walking back through a stack dump. :(  About like walking
back on a stack dump on an alpha.  Alpha's use a function prologue that define
what registers are saved on the stack when a functoin is called, so you have to
just look for addresses that "look right" in the dump.  Nor can you do a
traceback on the alpha w/o a symbole table, which we can do on x86 in ddb for
example.  (Alpha also doesn't push the frame pointer, but that is another
matter).

-- 

John Baldwin <jhb@FreeBSD.org> -- http://www.FreeBSD.org/~jhb/
PGP Key: http://www.baldwin.cx/~john/pgpkey.asc
"Power Users Use the Power to Serve!"  -  http://www.FreeBSD.org/

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-chat" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.010723163639.jhb>