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



## graudeejs (Feb 13, 2009)

What kind of tools do you use to debug c/c++ code?

I'm learning c/c++, tools tips&tricks welcomed here


----------



## vivek (Feb 13, 2009)

gdb - The GNU Debugger.

Nemiver is a standalone graphical C and C++ debugger that integrates well in the GNOME desktop environment.

Valgrind is a programming tool for memory debugging, memory leak detection, and profiling

DDD GUI for gdb and others.

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..


----------



## gilinko (Feb 13, 2009)

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.


----------



## hydra (Feb 13, 2009)

C:
gdb, valgrind (hopefully an amd64 version will be out soon...), printf


----------



## fonz (Feb 13, 2009)

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


----------



## graudeejs (Feb 13, 2009)

fonz said:
			
		

> although I tend to debug the old-fahioned way using printf(C)/cout(C++)/System.out.printf(java) statements.



atm i do the same


----------



## fonz (Feb 13, 2009)

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.


----------



## trev (Feb 16, 2009)

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


----------



## kamikaze (Feb 17, 2009)

I use gdb. But really only to read backtraces.


----------



## ligregni (Feb 19, 2009)

*The easiest way to debug*


```
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


----------



## dap (Feb 19, 2009)

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


----------

