0

I know that one can use func to get the current function name statically.

Get called function name as string

But if I want to get the function that calls this function, it has to be done dynamically.

Is there a way to do so in C (without adding an arugment to the current function that pass the caller function name)?

I don't want to dramatically slow down the execution of the program. So gdb is not an option?

dladdr may be useful for shared library. I'd like something for statically compiled executable as well.

http://man7.org/linux/man-pages/man3/dladdr.3.html

EDIT:

Things like this are not helpful. If want to get the caller function name for each callee, it will require editing for each function, which is not a scalable solution.

How can we know the caller function's name?

Thanks.

user1424739
  • 11,937
  • 17
  • 63
  • 152
  • 1
    Possible duplicate of [How can we know the caller function's name?](https://stackoverflow.com/questions/16100090/how-can-we-know-the-caller-functions-name) – aschepler Jan 27 '19 at 23:10
  • Edited. Please remove the close vote. – user1424739 Jan 27 '19 at 23:14
  • `I don't want to dramatically slow down the execution of the program.` and `without adding an argument to the current function that pass the caller function name` makes this pretty much impossible. – Patrick Roberts Jan 27 '19 at 23:21
  • There is no portable way to do this in C without adding arguments or similar. But notice that question also has some answers describing non-portable ways to do it on Linux and Windows. – aschepler Jan 27 '19 at 23:51
  • I don't think they answer my question. But there are many answers, I may miss some. If you think a particular answer can answer my question in a non-portable way, could please point it specifically? – user1424739 Jan 28 '19 at 01:53

0 Answers0