我正在尝试运行一个测试程序以查看 gdb(回溯)如何显示调用堆栈。我有以下程序
#include<iostream>
#include<assert.h>
void fun2()
{
assert(0);
}
void fun1()
{
fun2();
}
int main()
{
fun1();
return 0;
}
然后我做了以下事情:
g++ -g dump.cpp -o out
./out
out: dump.cpp:16: void fun2(): Assertion `0' failed.
Abort (core dumped)
gdb out core.28149
(gdb) bt
No stack. //Why does it show no stack here
我原以为它会将调用堆栈显示为:
fun2
fun1
main
编辑:
我编辑了代码并编译为 g++ -g -O0 dump.cpp -o out
但我仍然没有堆栈
void fun2(int num)
{
int h=23;
if(h*num>100)
{
assert(0);
}
else
{
cout<<"Hello";
}
}
void fun1(int num)
{
{
fun2(num);
}
}
int main()
{
int num;
cin>>num;
fun1(num);
return 0;
}
汇编代码这次向我展示了 fun1、fun2(assert)、main 的单独代码。但我仍然在 gdb 中看到 No Stack
最佳答案
Reading symbols from /somepath here../tmp/out...done. "/somepath here/core.30117" is not a core dump: File format not recognized
您的核心转储已损坏。实际上它不是由 gdb 加载的,所以输入 bt
没有任何效果。
试着检查一下,这些命令应该给你一些关于核心转储的信息:
文件 core.28149
strings core.28149
关于c++ - GDB 显示无堆栈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41549590/