c++ - GDB 显示无堆栈

标签 c++ gdb

我正在尝试运行一个测试程序以查看 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/

相关文章:

c++ - QKeyEvent 处理非拉丁布局

c++ - Matlab 和 c++ 矩阵乘积 : same input, 不同的输出

c++ - 在链表的第 n 个位置插入节点(无法理解我的代码)

debugging - 无法在GDB的Rust程序中获得 `main`的当前行

gdb - 如何使 gdb 日志记录命令像 windbg 一样?

gdb - 获取返回地址GDB

c++ - 是否可以删除子函数中的对象?

c++ - 我怎样才能避免菱形继承(钻石问题)?

c - 段错误 - 无效的自由未解决 - C

debugging - GDB 在调试和程序输入之间切换