Re: Find out function arguments value from stack pointer
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@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: Find out function arguments value from stack pointer
On Wed, Dec 12, 2012 at 3:56 PM, Fabio Pozzi pozzi.fa...@gmail.com wrote: 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 Thanks Fabio, You solved a lot of doubts for me. How to get the frame pointer address? -- Manavendra Nath Manav ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: Find out function arguments value from stack pointer
On Wed, Dec 12, 2012 at 4:02 PM, Manavendra Nath Manav mnm.ker...@gmail.com wrote: On Wed, Dec 12, 2012 at 3:56 PM, Fabio Pozzi pozzi.fa...@gmail.com wrote: 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 Thanks Fabio, You solved a lot of doubts for me. How to get the frame pointer address? I found that gcc has in-build function to retrieve frame pointer address void * __builtin_frame_address (unsigned int level) 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. -- Manavendra Nath Manav ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: Find out function arguments value from stack pointer
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. -- Saluti, Fabio Pozzi ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: Find out function arguments value from stack pointer
On Wed, Dec 12, 2012 at 4:38 PM, Fabio Pozzi pozzi.fa...@gmail.com 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? -- Manavendra Nath Manav ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: Find out function arguments value from stack pointer
On 12/12/2012 12:24 PM, Manavendra Nath Manav wrote: On Wed, Dec 12, 2012 at 4:38 PM, Fabio Pozzi pozzi.fa...@gmail.com 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. ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Regarding testing of OS Development specific Code
I searched on the internet for an apt answer but i couldn't find one so i thought this could be a newbie-friendly place to shoot the doubt I have developed an interest in OS development (kernel) and have successfully built/compiled/configured the kernel source but i would like to know as to how do OS developers test their code ,as in- it could be really painful to make some changes to the code and then again recompile the entire kernel , make a new image and then boot from that in essence it would require - 1. Making changes 2. Compiling 3. Reflashing the kernel 4. Rebooting the machine (physical or virtual as the case may be) So I am pretty sure that this is not the way the work's done , so can i have the needed enlightenment as to how do OS developers go about making hacks /changes to the code and then testing the new build Regards Supratim Chakraborty about.me/borax12 ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: Regarding testing of OS Development specific Code
On Wed, Dec 12, 2012 at 5:28 PM, supratim chakraborty sup270...@gmail.comwrote: I searched on the internet for an apt answer but i couldn't find one so i thought this could be a newbie-friendly place to shoot the doubt I have developed an interest in OS development (kernel) and have successfully built/compiled/configured the kernel source but i would like to know as to how do OS developers test their code ,as in- it could be really painful to make some changes to the code and then again recompile the entire kernel , make a new image and then boot from that in essence it would require - 1. Making changes 2. Compiling 3. Reflashing the kernel 4. Rebooting the machine (physical or virtual as the case may be) So I am pretty sure that this is not the way the work's done , so can i have the needed enlightenment as to how do OS developers go about making hacks /changes to the code and then testing the new build Regards Supratim Chakraborty about.me/borax12 Linux Test suite is one place to test your Linux: http://ltp.sourceforge.net/ more from slashdot http://linux.slashdot.org/story/05/06/05/1426206/linux-kernel-gets-fully-automated-test kernel autotest http://autotest.github.com/ besides people make changes in one or two parts of kernel subsystem at a time and/or parts totally related and test it out in accordance to that subsystem. you can also use UML for testing. It is pretty good way to quickly get idea of basic functionality. For networkign you can use wireshark and all and what this guy has replied. http://stackoverflow.com/questions/3177338/how-is-linux-kernel-tested ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies -- Thank you Warm Regards Anuz ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: Find out function arguments value from stack pointer
在 2012-12-12,19:28,Manavendra Nath Manav mnm.ker...@gmail.com 写道: On Wed, Dec 12, 2012 at 4:38 PM, Fabio Pozzi pozzi.fa...@gmail.com 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? Arm does not use stack to pass parameters when parameters are less than 4, it uses registers r0 to r3 to pass parameters, and at the beginning of subroutine, r0 to r3 are not stored on stack. So it is complicated to find out parameters from stack as I know. -- Manavendra Nath Manav ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies