c++ - 如何使用堆栈跟踪来确定崩溃原因?

标签 c++ crash stack interpreter root-framework

我了解堆栈跟踪背后的“大想法”,但是实际上如何使用堆栈跟踪来确定崩溃的原因呢?例如,我正在编码一个c++宏,而我的解释器吐出了以下堆栈跟踪:

>  *** Break *** illegal instruction
> 
> 
> 
> =========================================================== There was a crash. This is the entire stack trace of all threads:
> ===========================================================
> #0  0x00007fb64ef29bbc in waitpid () from /lib64/libc.so.6
> #1  0x00007fb64eea7ea2 in do_system () from /lib64/libc.so.6
> #2  0x00007fb64ffb3d84 in TUnixSystem::StackTrace (this=0x98e960) at /cvmfs/myusername/trunk/centos7/source/root-6.16.00/core/unix/src/TUnixSystem.cxx:2413
> #3  0x00007fb64ffb64bc in TUnixSystem::DispatchSignals (this=0x98e960, sig=kSigIllegalInstruction) at
> /cvmfs/myusername/trunk/centos7/source/root-6.16.00/core/unix/src/TUnixSystem.cxx:3644
> #4  <signal handler called>
> #5  0x00007fb65057f54a in ?? ()
> #6  0x000000000146e4ec in ?? ()
> #7  0x000000000028dc9d in ?? ()
> #8  0x0028dcf80146e51c in ?? ()
> #9  0x00007ffd08a37890 in ?? ()
> #10 0x0000000000051b93 in ?? ()
> #11 0x000000000000a372 in ?? ()
> #12 0x0000a3e900051c01 in ?? ()
> #13 0x000000000000146e in ?? ()
> #14 0x00007ffd08a3788f in ?? ()
> #15 0x0000000000000000 in ?? ()
> ===========================================================
> 
> 
> The lines below might hint at the cause of the crash. You may get help
> by asking at the ROOT forum http://root.cern.ch/forum Only if you are
> really convinced it is a bug in ROOT then please submit a report at
> http://root.cern.ch/bugs Please post the ENTIRE stack trace from above
> as an attachment in addition to anything else that might help us
> fixing this issue.
> ===========================================================
> #5  0x00007fb65057f54a in ?? ()
> #6  0x000000000146e4ec in ?? ()
> #7  0x000000000028dc9d in ?? ()
> #8  0x0028dcf80146e51c in ?? ()
> #9  0x00007ffd08a37890 in ?? ()
> #10 0x0000000000051b93 in ?? ()
> #11 0x000000000000a372 in ?? ()
> #12 0x0000a3e900051c01 in ?? ()
> #13 0x000000000000146e in ?? ()
> #14 0x00007ffd08a3788f in ?? ()
> #15 0x0000000000000000 in ?? ()
> ===========================================================

最佳答案

堆栈跟踪背后的想法是查看崩溃时谁在 call 谁。因此,您可以检查产生故障的函数,并查看其调用方式。
您在示例中看到的是函数的地址,当然,如果堆栈由于某种原因而损坏,您也可能会找到无效的地址。
要查看更多有用的信息,您应该使用调试信息来编译代码,这样您不仅会看到地址,而且还会看到函数的名称。
例如,在gcc中,您可以使用-g来启用调试信息,即:

gcc -g test.c -o test
这是'test.c'错误代码的示例:
void foo()
{
    int a=1/0;
}
void foo1()
{
    foo();
}
void foo2()
{
    foo1();
}
void foo3()
{
    foo2();
}

int main()
{
    foo3();
};

这是它产生的回溯(在gdb中运行,信息可用,因为我使用-g标志进行编译)
#0  0x0000000000401101 in foo () at test.c:3
#1  0x0000000000401117 in foo1 () at test.c:7
#2  0x0000000000401128 in foo2 () at test.c:11
#3  0x0000000000401139 in foo3 () at test.c:15
#4  0x000000000040114a in main () at test.c:20

关于c++ - 如何使用堆栈跟踪来确定崩溃原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63333109/

相关文章:

c++ - 在读取 udp 之前查找 sockaddr 信息

c++ - 使用 "mask"分割图像

c++ - 获取 std::wstring 的子字符串

google-maps - 移动Safari崩溃(内存不足)

c - 缓冲区溢出错误变量改变值

c++ - 嵌套类的值初始化

ios - 由于供应配置文件过期,是否有可能获得崩溃日志?

c++ - 从 View Controller 中调用 C++ 类会崩溃

c - 栈溢出成变量困惑(计算机安全)

c - 像 v8 这样的 JIT 编译器如何构建其内存(即堆栈、堆、代码和数据)?