This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to implement a function which will give the address of the calling function during runtime.

I am working on a complex project written in C for 8051 arhitecture with Keil C. And unfortunately no real debugger. There are many functions called from various c files. Some times hundereds of different c file. I want to implement a function which will give me the address of the calling function during runtime. Is there a way to read the call stack to exctract the callig function address? If a can get the adress a can check it from .m51 file and can understand which function call is active.

func1(void)
{ func_test();
};

func2(void)
{ func_test();
};

func3(void)
{ func_test();
};

func_test(void)
{ int get_call_func_address;

get_call_func_address = ???????; printf("Calling function adress is %d", get_call_func_address);

//Do other things...

}

main()
{ func1(); func2(); func3();
}

Best regards
Saltuk Alakus

Parents
  • I think you need to explain why you think you need to do this?

    "If I can get the adress I can check it from .m51 file and can understand which function call is active."

    So you're talking about a debugging aid?

    So you should probably be looking into a uVision debug function, rather than trying to do this in your embedded code?
    See: http://www.keil.com/support/man/docs/uv3/uv3_debug_functions.htm

    Again, if you explained what you're actually trying to achieve, then people would be able to provide appropriate suggestions...

Reply
  • I think you need to explain why you think you need to do this?

    "If I can get the adress I can check it from .m51 file and can understand which function call is active."

    So you're talking about a debugging aid?

    So you should probably be looking into a uVision debug function, rather than trying to do this in your embedded code?
    See: http://www.keil.com/support/man/docs/uv3/uv3_debug_functions.htm

    Again, if you explained what you're actually trying to achieve, then people would be able to provide appropriate suggestions...

Children