Re: Find out function arguments value from stack pointer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Why function arguments are stored from offset 12 of SP? Also notice
> values at offset 0 to 10 are always same, and value at offset 11
> increases by 20 on each invocation of function foo().

You have to consider that local variables are allocated on the stack,
thus both i, stackptr and sp are allocated on
the stack, so if you print all the stack records you will find this
variables, then the return pointer, the saved frame pointer (if saved)
and then the function parameters.
See http://en.wikipedia.org/wiki/Call_stack for a better explanation.
If you want to access immediately to the function call parameters you
should start from the frame pointer address (if there's one).
To play with backtraces you may find useful the backtrace function[1]
and libraries like libunwind[2] which take care of this details for
you.

[1] http://tdistler.com/2008/11/15/how-to-print-a-stack-backtrace-programatically-in-linux
[2] http://www.nongnu.org/libunwind/

-- 
Saluti,
Fabio Pozzi

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux