我正在尝试运行一个测试程序,以查看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中仍然看不到堆栈。
core.28149
是为out
二进制文件生成的吗?file core.28149
的输出是什么? - ks1322Reading symbols from /somepath here../tmp/out...done. "/somepath here/core.30117" is not a core dump: File format not recognized
。这很奇怪,因为那确实是core dump,因为在程序崩溃后那是唯一生成的文件。 - anurag86file /somepath here/core.30117
这个 shell 命令输出的类型是什么? - Mark Plotnick