From mboxrd@z Thu Jan 1 00:00:00 1970 From: matthias.bgg@gmail.com (Matthias Brugger) Date: Wed, 12 Dec 2012 12:30:13 +0100 Subject: Find out function arguments value from stack pointer In-Reply-To: References: Message-ID: <50C86AC5.9070507@gmail.com> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org On 12/12/2012 12:24 PM, Manavendra Nath Manav wrote: > On Wed, Dec 12, 2012 at 4:38 PM, Fabio Pozzi wrote: >>> When i call print values at offsets starting from >>> __builtin_frame_address (0) the function arguments start from offset >>> 2. How can I confirm that this behavior is always consistent. >> >> Arguments are pushed on the stack before the saved frame pointer, thus >> you have to add an offset equal to the frame pointer address size if >> you start from the beginning of the saved frame pointer record on the >> stack. > > Thanks Fabio! > If I execute the same code on ARM arch, does it needs any changes? > I just wanted to mention. AFAIK who parameters are passed to the called function depends on the architecture (stack or some registers + stack). I vaguely remember some MIPS ASM programming exercises in first year of university... But if gcc has a in built function, that should do on all architectures, though.