Re: How can i read the stack frames of running process?
On Oct 17, 3:56 pm, harshal <harshalsh...@gmail.com> wrote:
> Hi all,
>
> Can we read the stack frame's of the current process.
> as we know that whenever a function call is made in c new functions
> stack frame
> is created and pushed on to the stack. and when the function returns
> it is popped out from the stack. i want to know the caller functions
> name.
>
> i mean i want something like this
>
> int a()
> {
> printf("File = %s\n",__FILE__);
> /* i want to print the callers name over here. something like this
> printf("Caller function = %s\n",__CALLER_FUN__); it should print
> b*/
> return 0;
>
> }
>
> int b()
> {
> a();
> return 0;
>
> }
>
> int main()
> {
> b();
>
> }
>
> if there is any way please tell me.
>
You can try something as below :
( This is just a rough idea for you . )
You need to know the register that has the address of the current
frame info.
and that address is normally saved to the frame by the called
function.
Create a LIFO list with this info
a) address of the calling function frame
b) return address
c) parameter list
Every function call should add a frame to the list.
Every return from function will delete the frame.
So, if you know the register that has the address of the current frame
info and the
value at that register, then you can make it up on your own.
Also , Many ways are dependent on parsing through the assembly files
and MAP files .
Karthik Balaguru
|