我需要在正在运行的程序(C语言)的日志文件中打印调用堆栈,因为我需要检查流程, 我必须将跟踪发送到其他环境,但无法调试,有没有办法在 C 中做到这一点。
最佳答案
如果平台是linux(我也相信OSX),你可以使用backtrace和 backtrace_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/