Understanding disassembly x86 + understanding function call + parameter pass and stack frame

Valdis.Kletnieks at vt.edu Valdis.Kletnieks at vt.edu
Wed Aug 14 07:35:42 EDT 2013

On Wed, 14 Aug 2013 16:14:34 +0530, nidhi mittal hada said:

> 1)if i want to get value of a local variable, of a function,  from stack
> trace thats bt-f output, obtained using crash ..
> No where AMD64 ABI mentions how local variables are stored ..
> is it in some specific sequence of registers ? is it in stack ?

Yes, no, maybe, depends on how smart the compiler is.  Local variables
are local, and thus by definition not part of the ABI.  The compiler
may decide that a given 'int' can be kept in %r8 for most of the
time, but stored at 24 bytes into the stack across 1 function call,
and another variable is in %r9 most of the time, but in that same location
24 bytes into the stack across a different function call (and that's
OK, because it always knows which variable is using that location
24 bytes into the stack when).

In some cases, a variable may even be totally optimized out of existence.
For example, if you have

int foo ( int c ) {
int a, b;

   b = c * 5;
   a = b + getpid();
   return a;

the compiler can (and probably *will*) optimize both a and b
away and convert it to 'return (c*5 + getpid());'
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 865 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130814/6c358146/attachment.bin 

More information about the Kernelnewbies mailing list