如何找到调用函数的名称? [英] How do I find the name of the calling function?
问题描述
我一直在使用PRETTY_FUNCTION来输出当前的函数名,但是我已经重新实现了一些函数,并想知道哪些函数调用它们。
在C ++中如何获取调用例程的函数名?
这里有两个选项:
-
如果这不是你正在寻找的,那么你可以试试 libunwind ,但它将涉及更多的工作。
You can get a full stacktrace (including the name, module, and offset of the calling function) with recent versions of glibc with the GNU backtrace functions. See my answer here for the details. This is probably the easiest thing.
If that isn't exactly what you're looking for, then you might try libunwind, but it's going to involve more work.
请注意,这不是静态的(如PRETTY_FUNCTION);你实际上必须走栈来找出你叫什么功能。所以这不是在普通调试printfs中真正值得做的事情。如果您想进行更严重的调试或分析,那么这可能对您有用。
I have been using PRETTY_FUNCTION to output the current function name, however I have reimplemented some functions and would like to find out which functions are calling them.
In C++ how can I get the function name of the calling routine?
Here are two options:
Keep in mind that this isn't something you can know statically (as with PRETTY_FUNCTION); you actually have to walk the stack to figure out what function called you. So this isn't something that's really worth doing in ordinary debug printfs. If you want to do more serious debugging or analysis, though, then this might be useful for you.
这篇关于如何找到调用函数的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!