debuging C++ apps in Linux

Red Squirrel

No Lifer
May 24, 2003
70,662
13,833
126
www.anyf.ca
What are some good tools to use for debugging C++ apps in Linux?

I want to be able to get stack traces, line numbers, etc when my program crashes. C# is really good for this, but I'm sure the same can be done in C++/Linux. If possible I'd even like to have it built right into my app, but if it can also be done by running an external app that will do. I know valgrind is one, but does not quite do the line number thing, and I find it changes the crash behavior of my program. Like normally my program crashes but with valgrind it never crashes. It's a huge multi threaded app so i need to be able to trace at which point its crashing.
 

Brett

Senior member
Oct 15, 1999
377
0
76
GNU Project Debugger (GDB), is the one I'm familiar with. Take a look at it.

-Brett
 

Red Squirrel

No Lifer
May 24, 2003
70,662
13,833
126
www.anyf.ca
That app is pure heaven. Playing with it now. Ok, maybe not pure, I'm sure God has a even better place setup for us - where we don't even have to worry about debugging since everything is perfect. :p

Code:
#0  0x08057904 in std::_Bit_reference::operator bool (this=0xb757d300)
    at /usr/lib/gcc/i386-redhat-linux/4.1.0/../../../../include/c++/4.1.0/bits/stl_bvector.h:80
#1  0x08058208 in RSlib::RSarraylist<bool>::Retrieve (this=0x8060344, pos=0)
    at ../_headers/common.h:910
#2  0x08058292 in RSlib::BitStream::ReadVarInt (this=0x8060344, pos=0, bits=8)
    at ../_headers/common.h:1229
#3  0x0805844d in RSlib::BitStream::PopVarInt (this=0x8060344, amt=1)
    at ../_headers/common.h:1303
#4  0x0805848b in RSlib::BitStream::PopInt8 (this=0x8060344)
    at ../_headers/common.h:1312
#5  0x08052b01 in uocli::InGamePacketHandler (info=0x8060320)
    at includes/handlers.h:246
#6  0x08052ba1 in uocli::PacketQueueReader (info=0x8060320)
    at includes/packetreader.h:48
#7  0x08052bd0 in PacketQueueReaderThread (data=0x0) at uocli.cpp:83
#8  0x00a81433 in start_thread () from /lib/libpthread.so.0
#9  0x009cda1e in clone () from /lib/libc.so.6
(gdb)

Beauty, it even shows the parameters that were sent to each function. Now to find my bug, but at least it brings me much much closer to the answer. Seems to be quite a lot of options I've yet to play with so far.

What are the most common ones normally used? Seems to be quite an intuitive app. I'll be able to use this in conjunction with valgrind, as valgrind is still nice for detecting mem leaks.