GDB, how to know where your program failed

I have such a situation:

I run a program to debug, and get

Program received signal SIGABRT, Aborted.
0x4012cee9 in raise () from /lib/tls/libc.so.6

I know there is bug in my prog. But how to find out where? after wich command in my prog it gets SIGABRT?
besideAsked:
Who is Participating?
 
AxterCommented:
>>Previous frame inner to this frame (corrupt stack?)(gdb)

As I stated in my previous comments, it has been my experience that if you try to get stack data after a crash, you loose stack data.

I highly recommend you try putting the breakpoint on _throw, and then run the program.

When the program hits the breakpoint, you can then look at your stack, and better identify your crash point.

Try above method, and post your stack, if you still have problems.
0
 
Jaime OlivaresSoftware ArchitectCommented:
You must post your code.
0
 
jkrCommented:
If you have a coredump, just start gdb with that file and it'll take you straight to the line where it failed:

gdb <corefile>
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
besideAuthor Commented:
can't I just use a debugger to find out more?
0
 
besideAuthor Commented:
how to make that coredump?
0
 
besideAuthor Commented:
Oh I forgot it to compile using debug flag..
0
 
AxterCommented:
try putting a breakpoint on _throw.  When a throw is made in any catch statement, you'll hit the breakpoint, and the stack will still be available.

Remember its "_throw" with an underscore.
0
 
jkrCommented:
>> try putting a breakpoint on _throw

That would make sense if the SIGABRT came from lbstdc++.o, but not from libc.o. 'raise()' might be the better place :o)
0
 
AxterCommented:
>>That would make sense if the SIGABRT came from lbstdc++.o, but not from libc.o. 'raise()'
>>might be the better place :o)

That might work, but I've had problems with gdb/gnu in that if you put the break point at the crash position, you loose the stack information.

Where-as if you put the break point at _throw, you still have the stack available.
0
 
besideAuthor Commented:
jkr you just noticed that I can give core dump to gdb, but how to make that my program reproduce core dump on SIGABRT, because now, it gives me no core dump.. It would be very helpfull if there would be core dump, because It's relly difficult to reproduce this error in my programe.
0
 
AxterCommented:
beside,
Have you try using the breakpoint method?

What OS are you working on?
0
 
brettmjohnsonCommented:
Make sure your program was compiled with debugging symbols by
supplying the  -g  switch to gcc at compile time.

Load your program into gdb to start debugging:  'gdb  myprogram'

Start running the program within the debugger:  'r myprograms_command_line_args'

When the program faults, it automatically breaks into the debugger.
However, we notice that the point of failure is within the standard C library.
The most common cause of this is incorrect arguments supplied to a library routine.

You can find out who called the library routine by examining the call stack:  'where'

You can use the 'up' and 'down' commands to navigate up the call stack frames
and examine the calling code and the data passed.

0
 
besideAuthor Commented:
yes, I got a point how to find out bug, no I just waiting when i accours, because it's very difficult to catch...
0
 
avizitCommented:
coredump are not produced if you set
coredumpsize to 0  ..so maybe you can check your login files of your shell if it is being set to zero

more information here
http://www.unixguide.net/hp/faq/8.5.shtml
0
 
besideAuthor Commented:
here I have everything what I could get from debuger and core file, but this is something mistical for me... could you explain.. here is information:

root@isdn:~/server_new# gdb isdn_server core
GNU gdb 6.1-debian
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-linux"...Using host libthread_db library "/lib/tls/libthread_db.so.1".

Core was generated by `./isdn_server'.
Program terminated with signal 6, Aborted.

warning: current_sos: Can't read pathname for load map: Input/output error

Reading symbols from /usr/lib/libstdc++.so.5...done.
Loaded symbols for /usr/lib/libstdc++.so.5
Reading symbols from /lib/tls/libm.so.6...done.
Loaded symbols for /lib/tls/libm.so.6
Reading symbols from /lib/libgcc_s.so.1...done.
Loaded symbols for /lib/libgcc_s.so.1
Reading symbols from /lib/tls/libc.so.6...done.
Loaded symbols for /lib/tls/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
Reading symbols from /lib/tls/libnss_files.so.2...done.
Loaded symbols for /lib/tls/libnss_files.so.2
#0  0x4012cee9 in raise () from /lib/tls/libc.so.6
(gdb) where
#0  0x4012cee9 in raise () from /lib/tls/libc.so.6
#1  0x4023aedc in ?? () from /lib/tls/libc.so.6
#2  0x0804c518 in ?? ()
#3  0x4012e781 in abort () from /lib/tls/libc.so.6
#4  0x00000000 in ?? ()
#5  0x00000020 in ?? ()
#6  0x00000000 in ?? ()
#7  0x00000000 in ?? ()
#8  0x00000000 in ?? ()
#9  0x00000000 in ?? ()
#10 0x00000000 in ?? ()
#11 0x00000000 in ?? ()
#12 0x00000000 in ?? ()
#13 0x00000000 in ?? ()
#14 0x00000000 in ?? ()
#15 0x00000000 in ?? ()
#16 0x00000000 in ?? ()
#17 0x00000000 in ?? ()
#18 0x00000000 in ?? ()
#19 0x00000000 in ?? ()
#20 0x00000000 in ?? ()
#21 0x00000000 in ?? ()
#22 0x00000000 in ?? ()
#23 0x00000000 in ?? ()
#24 0x00000000 in ?? ()
#25 0x00000000 in ?? ()
#26 0x00000000 in ?? ()
#27 0x00000000 in ?? ()
#28 0x00000000 in ?? ()
#29 0x00000000 in ?? ()
#30 0x00000000 in ?? ()
#31 0x00000000 in ?? ()
#32 0x00000000 in ?? ()
#33 0x00000000 in ?? ()
#34 0x00000000 in ?? ()
---Type <return> to continue, or q <return> to quit---
#35 0x00000000 in ?? ()
#36 0x00000000 in ?? ()
#37 0x00000000 in ?? ()
#38 0x00000000 in ?? ()
#39 0x00000000 in ?? ()
#40 0x09844246 in ?? ()
#41 0xbfffdb30 in ?? ()
#42 0x40017a08 in ?? ()
#43 0x401187f8 in __libc_start_main () from /lib/tls/libc.so.6
#44 0x00000000 in ?? ()
#45 0xbfffdb50 in ?? ()
#46 0x40017a08 in ?? ()
#47 0x4000ba16 in _dl_map_object_deps () from /lib/ld-linux.so.2
Previous frame inner to this frame (corrupt stack?)
(gdb)

I compile program as follow:

/usr/bin/g++ -ansi -pedantic -Wall -g -DDEBUG -o isdn_server -L.  main.cpp analyzeisdn.cpp callcard.cpp isdnmessage.cpp socketcon.cpp

And by the way, what this meens when I load core file.
warning: current_sos: Can't read pathname for load map: Input/output error
0
 
AxterCommented:
>>As I stated in my previous comments, it has been my experience that if you try to get stack data after a crash,
>>you loose stack data.

FYI:  Above comment is just referring to gdb, and not other debuggers.
0
 
besideAuthor Commented:
thanx axter, will try, and report...
0
 
besideAuthor Commented:
(gdb) b _throw
Function "_throw" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (_throw) pending.

if I did correctly? or something here is wrong that it could not file _throw?
0
 
AxterCommented:
What was the command line you use to start gdb?
0
 
AxterCommented:
Also, is your code compiled as C++ or C?
Do you have *.cpp files,or *.c files?
0
 
AxterCommented:
If _throw doesn't work, try jkr's suggestion, and put a breakpoint on raise
0
 
besideAuthor Commented:
command line to start gdb is:
gdb isdn_server
(gdb) set follow-fork-mode child
(gdb) b _throw
(gdb) run

my code is compiled as C++, I have .cpp files
0
 
besideAuthor Commented:
I think I found problem in my program (without using debuger), but thanx for suggestions, know I'm more reliable on debuging program with gdb.

Thank you all.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.