Solved

GDB, how to know where your program failed

Posted on 2004-09-22
23
995 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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. …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

747 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now