anurag86
anurag86

Reputation: 209

GDB shows No stack

I am trying to run a test program to see how gdb (backtrace) shows the call stack. 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

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. But still I see No Stack in gdb

Upvotes: 6

Views: 27418

Answers (4)

Andrei
Andrei

Reputation: 884

In my case, gdb showed No stack. due to permission issues, when I tried attaching to process. To check if that's the case I used sudo:

sudo gdb -p <PID>

Upvotes: 0

Rajendra
Rajendra

Reputation: 1770

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

Upvotes: 0

ks1322
ks1322

Reputation: 35708

Reading symbols from /somepath here../tmp/out...done. "/somepath here/core.30117" is not a core dump: File format not recognized

Your core dump is somehow corrupted. Actually it was not loaded by gdb so typing bt has no effect.

Try to examine it, these command should give you some info about core dump:

  • file core.28149
  • strings core.28149

Upvotes: 3

Bathsheba
Bathsheba

Reputation: 234635

There's no reason why gcc wouldn't optimise your program to

int main()
{
    assert(0);
}

To remove all doubt, check the generated assembly.

Upvotes: 1

Related Questions