我怎么知道哪个函数或文件,哪一行调用了一个函数
How can I know which function or file and which line called a function?
例如
void MyFunction()
{
printf( "This function is called by %s in file %s on line $i.n", func, file, line ); // Where func, file and lines should be replaced
}
int main()
{
MyFunction();
return 0;
}
在Linux上,您可以使用backtrace来转储堆栈:
backtrace() returns a backtrace for the calling program, in the array pointed to by buffer. A backtrace is the series of currently active function calls for the program. Each item in the array pointed to by buffer is of type void *, and is the return address from the corresponding stack frame. The size argument specifies the maximum number of addresses that can be stored in buffer. If the backtrace is larger than size, then the addresses corresponding to the size most recent function calls are returned; to obtain the complete backtrace, make sure that buffer and size are large enough.
相关文章:
- 如何使用运算符在同一行中多次调用函数
- uncrustify:如何将多行 C 函数调用的参数组合到一行上?
- 使用更改此变量的函数在同一行中打印引用变量
- Ofstream一直给我函数的最后一行,而不是显示所有内容
- C++将函数指针放入一行的映射中
- C++ 两个函数除了一行之外执行相同的操作
- 将地址返回到 2D 数组中的一行值的函数
- 无法理解代码的特定片段:这是一个函数,只是一行还是什么
- 线程1:EXC_BAD_ACCESS错误,此错误在第一行的CPP文件中的句柄函数中出现
- 当两个函数位于一行中时,堆栈框架的样子
- 如何将具有多行代码的内联函数视为一行?
- 为什么这个函数从不超出第一行
- 无法弄清楚为什么只从文件中读取一行矩阵以及为什么我无法将 2D 数组传递给函数
- clang format函数和错误检查在同一行
- 从函数结果中分配 std::shared_ptr 的一行是什么?
- 当const在另一行处的const时,doxygen parse const成员函数不正确
- 为什么在同一行上有 2 个函数调用时跳过函数调用
- 在文件中返回一行的函数
- getline函数只读取第一行
- Std::sort函函数一行