One method is to walk the call stack yet as how to do this is dependant on the system you are using. glibc gives you a
backtrace, windows has StackWalk64, then there is __builtin_return_address and __builtin_frame_address.
edit:
What are you trying to achieve here is this for debugging information of say the allocation point or is this something completely different?