c - 需要在C语言中编写运行程序的调用堆栈

标签 c

我需要在正在运行的程序(C语言)的日志文件中打印调用堆栈,因为我需要检查流程, 我必须将跟踪发送到其他环境,但无法调试,有没有办法在 C 中做到这一点。

最佳答案

如果平台是linux(我也相信OSX),你可以使用backtracebacktrace_symbols来实现你想要的。

根据backtrace的注释部分

The symbol names may be unavailable without the use of special linker options. For systems using the GNU linker, it is necessary to use the -rdynamic linker option. Note that names of "static" functions are not exposed, and won't be available in the backtrace.

关于c - 需要在C语言中编写运行程序的调用堆栈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15150005/

相关文章:

c - 操作数如何提升

c - 在 C 中后/前递减 char 变量时这里发生了什么

c - 使用 qsort 对 c 中分配的字符数组进行排序

c - C 中的格式化矩阵

c - 程序崩溃?

c++ - Eclipse C/C++ 控制台行为异常

c - 我对多重性问题的 C 解决方案太慢了,需要建议

c - 字符串终止符 '\0' 与整数常量 0 的值如何相同?

C 运行时库第 2 部分

c - 在 C 中为指针分配特定的内存位置