what do you use to debug C/C++?

  1. gdb - The GNU Debugger.
  2. Nemiver is a standalone graphical C and C++ debugger that integrates well in the GNOME desktop environment.
  3. Valgrind is a programming tool for memory debugging, memory leak detection, and profiling
  4. DDD GUI for gdb and others.
  5. dbx another gdb like tool.

I also recommend - "The Art of Debugging with GDB, DDD, and Eclipse (No Starch Press, September 2008, 280 pp, ISBN 9781593271749)" book. It has lots of info which I wasn't aware of..
 
Personally I prefer the larger IDE's. I started coding both C and java in Eclipse but have since then moved to Netbeans as I find the UI a bit more responsive than Eclipse. Both of these has a built in debugger, editor etc(as they are IDE's). My personal opinion is that module management(extra programming language support etc) is a bit better in NetBeans than Eclipse.

A book that have had good use of is "Practical C Programming" from O'Reilly, as you always do something stupid and totally obvious once you have found the error.
 
killasmurf86 said:
What kind of tools do you use to debug c/c++ code?

Gdb when I really need it, although I tend to debug the old-fahioned way using printf(C)/cout(C++)/System.out.printf(java) statements.

I know it's kinda bad practice but I tend to only turn to a proper debugger (which for me would be gdb) when I really really need it pretty badly.

In fact, another practice is breaking down your code into small chunks (e.g. functions with clear and cut purpose) and writing tests for all those chunks, as well as keeping track of pre-/postconditions and loop invariants. I'm often too lazy for this, but if you can bring up the discipline it really helps.

Alphons
 
killasmurf86 said:
atm i do the same

I remember it was easy in the old days when I used Borland C or Borland Pascal. Their builtin debugger was pretty easy to use (*) so it would have been kinda silly not to use it. But since I started coding on UNIX boxes with vi(m) and gcc it's pretty much been the printf() method except for some odd cases where I really needed to use an actual debugger.

But then again, I'm too lazy to properly document pre-/postconditions and loop invariants. Plus that I find all those comments somewhat cluttering. That is in fact what I dislike most about javadoc. In itself it's a great idea but all those comments drive me nuts at times. When I'm coding in Java it occasionally occurs to me that I'm writing more comments than actual code :OOO (edit: ditto in terms of thinking time)

Alphons

Ad (*): Actually, so was their entire IDE. You could do pretty much anything with just a simple key combo. Those old Borland products were the only IDEs I've ever found usable and I haven't used any IDEs since I discovered UNIX a little over 10 years ago.
 
fonz said:
I remember it was easy in the old days when I used Borland C or Borland Pascal. Their builtin debugger was pretty easy to use (*) so it would have been kinda silly not to use it. But since I started coding on UNIX boxes with vi(m) and gcc it's pretty much been the printf() method except for some odd cases where I really needed to use an actual debugger.

+1 ('cept Zortech C, Borland Delphi :)
 
The easiest way to debug

Code:
main ()
{
#ifdef DEBUG
 printf("It reached checkpoint A");
#endif

 return 0;
}

gcc -DDEBUG c.c

I know it is too primitive, but it works for me (I wanna learn to use the gdb mentioned above.

Greetings from Mexico

Sergio Ligregni
 
There is a similar macro NDEBUG, which is standard (when defined, assert() calls are ignored).
 
Back
Top