Solved

GDB, how to know where your program failed

Posted on 2004-09-22
23
999 Views
Last Modified: 2008-03-03
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?
0
Comment
Question by:beside
  • 10
  • 8
  • 2
  • +3
23 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12124685
You must post your code.
0
 
LVL 86

Expert Comment

by:jkr
ID: 12124711
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
 

Author Comment

by:beside
ID: 12124714
can't I just use a debugger to find out more?
0
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 

Author Comment

by:beside
ID: 12124757
how to make that coredump?
0
 

Author Comment

by:beside
ID: 12124771
Oh I forgot it to compile using debug flag..
0
 
LVL 30

Expert Comment

by:Axter
ID: 12124842
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
 
LVL 86

Assisted Solution

by:jkr
jkr earned 30 total points
ID: 12124900
>> 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
 
LVL 30

Expert Comment

by:Axter
ID: 12125588
>>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
 

Author Comment

by:beside
ID: 12125631
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
 
LVL 30

Expert Comment

by:Axter
ID: 12126327
beside,
Have you try using the breakpoint method?

What OS are you working on?
0
 
LVL 23

Assisted Solution

by:brettmjohnson
brettmjohnson earned 20 total points
ID: 12126835
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
 

Author Comment

by:beside
ID: 12127141
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
 
LVL 11

Expert Comment

by:avizit
ID: 12129751
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
 

Author Comment

by:beside
ID: 12134959
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
 
LVL 30

Accepted Solution

by:
Axter earned 75 total points
ID: 12135119
>>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
 
LVL 30

Expert Comment

by:Axter
ID: 12135131
>>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
 

Author Comment

by:beside
ID: 12135158
thanx axter, will try, and report...
0
 

Author Comment

by:beside
ID: 12135203
(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
 
LVL 30

Expert Comment

by:Axter
ID: 12135325
What was the command line you use to start gdb?
0
 
LVL 30

Expert Comment

by:Axter
ID: 12135337
Also, is your code compiled as C++ or C?
Do you have *.cpp files,or *.c files?
0
 
LVL 30

Expert Comment

by:Axter
ID: 12135341
If _throw doesn't work, try jkr's suggestion, and put a breakpoint on raise
0
 

Author Comment

by:beside
ID: 12135394
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
 

Author Comment

by:beside
ID: 12147761
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

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question