Monte
Posts: 1
Joined: Fri Oct 06, 2017 9:25 am

gdb stack trace from core

Thu Jun 14, 2018 2:12 pm

Hi,

I can't view a thread's stack in gdb when debugging a core. Perhaps I am not building correctly.

Here is a small program to demonstrate what I'm seeing. After a few recursive calls, mydiv() will divide by zero and generate a core file.

Code: Select all

    1: void mydiv( int d )
    2: {
    3:   int i = 10 / d;
    4:   mydiv( d-1 );
    5: }
    6: 
    7: int main( int argc, char * argv[] )
    8: {
    9:   mydiv( 3 );
   10:   return 0;
   11: }
bt works when I use gdb to actively debug the binary.

Code: Select all

(gdb) cont
Continuing.

Program received signal SIGFPE, Arithmetic exception.
__GI_raise (sig=<optimized out>) at ../sysdeps/unix/sysv/linux/raise.c:51
51      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  __GI_raise (sig=<optimized out>) at ../sysdeps/unix/sysv/linux/raise.c:51
#1  0x76dbe1fc in __aeabi_ldiv0 () from /lib/arm-linux-gnueabihf/libgcc_s.so.1
#2  0x00010558 in mydiv (d=0) at tester.c:3
#3  0x00010570 in mydiv (d=1) at tester.c:4
#4  0x00010570 in mydiv (d=2) at tester.c:4
#5  0x00010570 in mydiv (d=3) at tester.c:4
#6  0x00010598 in main (argc=1, argv=0x7efff2e4) at tester.c:9

I really need it to work on a core.

Code: Select all

(gdb) core core.3926
[New LWP 3926]
Core was generated by `./tester'.
Program terminated with signal SIGFPE, Arithmetic exception.
#0  0x76c3c45c in ?? ()
(gdb) bt
#0  0x76c3c45c in ?? ()
#1  0xfffffffe in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
Here is my makefile.

Code: Select all

# makefile

CC=g++
CFLAGS=-c -g -O0 -Wno-write-strings

all: tester

tester.o: tester.c
        $(CC) $(CFLAGS) $< -o [email protected]

tester: tester.o
        $(CC)  $^  -o [email protected]

clean:
        rm -f tester.o
        rm -f tester
Miscellaneous:
$ uname -a
Linux pi3 4.14.30-v7+ #1102 SMP Mon Mar 26 16:45:49 BST 2018 armv7l GNU/Linux
$ gcc -v
. . .
gcc version 6.3.0 20170516 (Raspbian 6.3.0-18+rpi1+deb9u1)


Thanks in advance for any pointers.

Monte

Heater
Posts: 9840
Joined: Tue Jul 17, 2012 3:02 pm

Re: gdb stack trace from core

Thu Jun 14, 2018 2:56 pm

I have never used GDB to debug core dumps from runaway recursive algorithms. But it looks like it is working fine. It says:

"Backtrace stopped: previous frame identical to this frame (corrupt stack?)"

I guess the stack frame is the same, same as the previous recursive call that is.

I presume you are debugging with optimizations turned off when compiling, "-O0".

jahboater
Posts: 2931
Joined: Wed Feb 04, 2015 6:38 pm

Re: gdb stack trace from core

Thu Jun 14, 2018 3:29 pm

I use these options. Not sure if all this is still needed ....

-g -Og -ggdb -fno-omit-frame-pointer -gcolumn-info

-Og .......

Code: Select all

-Og Optimize debugging experience.  -Og enables optimizations that do not interfere with
     debugging. It should be the optimization level of choice for the standard edit-
     compile-debug cycle, offering a reasonable level of optimization while maintaining
     fast compilation and a good debugging experience.

ericcooper
Posts: 110
Joined: Sat Apr 08, 2017 6:23 pm

Re: gdb stack trace from core

Thu Jun 14, 2018 3:41 pm

That program compiles fine with gcc (you don't need g++). When I compile it with just "gcc -g", gdb correctly prints the stack trace from the core dump.

Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 6 guests