How can we know the caller function's name?

后端 未结 10 1607
北海茫月
北海茫月 2020-12-02 10:26

In the C language, __FUNCTION__ can be used to get the current function\'s name. But if I define a function named a() and it is called

10条回答
  •  渐次进展
    2020-12-02 11:21

    Refer: https://www.gnu.org/software/libc/manual/html_node/Backtraces.html

    A backtrace is a list of the function calls that are currently active in a thread. The usual way to inspect a backtrace of a program is to use an external debugger such as gdb. However, sometimes it is useful to obtain a backtrace programmatically from within a program, e.g., for the purposes of logging or diagnostics.

    The header file execinfo.h declares three functions that obtain and manipulate backtraces of the current thread.

提交回复
热议问题