简体   繁体   English

GDB显示无堆栈

[英]GDB shows No stack

I am trying to run a test program to see how gdb (backtrace) shows the call stack. 我试图运行一个测试程序,看看gdb(backtrace)如何显示调用堆栈。 I have the following program 我有以下程序

#include<iostream>
#include<assert.h>

void fun2()
{
        assert(0);
}
void fun1()
{
        fun2();
}
int main()
{
        fun1();
        return 0;
}

And i do the following: 我做了以下事情:

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

I was expecting it to show the call stack as : 我期待它将调用堆栈显示为:

fun2
fun1
main

Edit: I edited the code and compiled as g++ -g -O0 dump.cpp -o out 编辑:我编辑了代码并编译为g++ -g -O0 dump.cpp -o out

But still i have No Stack 但我仍然没有堆栈

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;
}

Assembly code shows me this time the separate code for fun1,fun2(assert),main. 汇编代码这次显示了fun1,fun2(assert),main的单独代码。 But still I see No Stack in gdb 但我仍然在gdb中看到没有堆栈

Reading symbols from /somepath here../tmp/out...done. 从/ somepath读取符号这里../tmp / out ...完成。 "/somepath here/core.30117" is not a core dump: File format not recognized “/ somepath here / core.30117”不是核心转储:文件格式无法识别

Your core dump is somehow corrupted. 你的核心转储以某种方式被破坏了。 Actually it was not loaded by gdb so typing bt has no effect. 实际上它没有被gdb加载所以输入bt没有效果。

Try to examine it, these command should give you some info about core dump: 尝试检查它,这些命令应该给你一些关于核心转储的信息:

  • file core.28149
  • strings core.28149

There's no reason why gcc wouldn't optimise your program to gcc没有理由不优化你的程序

int main()
{
    assert(0);
}

To remove all doubt, check the generated assembly. 要消除所有疑问,请检查生成的装配。

Try as below: 请尝试以下方式:

$ clang++ -g -O0 -o dump dump.cpp

$ ./dump
100
Assertion failed: (0), function fun2, file dump.cpp, line 9.
Abort trap (core dumped)

$ gdb --core dump.core
. . .
Core was generated by `dump'.
Program terminated with signal SIGABRT, Aborted.
#0  0x000000080149f6ca in ?? ()
(gdb) file dump
Reading symbols from dump...done.
(gdb) set solib-search-path "/lib:<path>/llvm/lib"
(gdb) bt
#0  0x000000080149f6ca in thr_kill () from /lib/libc.so.7
#1  0x0000000801574149 in abort () from /lib/libc.so.7
#2  0x0000000801556011 in __assert () from /lib/libc.so.7
#3  0x000000000040130a in fun2 (num=100) at dump.cpp:10
#4  0x0000000000401343 in fun1 (num=100) at dump.cpp:20
#5  0x000000000040137e in main () at dump.cpp:27

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM