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

C, C++, Python, Perl, Shell, etc.

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

Postby graudeejs » 13 Feb 2009, 16:34

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

I'm learning c/c++, tools tips&tricks welcomed here :D
User avatar
graudeejs
Style(9) Addict
 
Posts: 4591
Joined: 16 Nov 2008, 23:23
Location: Riga, Latvia

Postby vivek » 13 Feb 2009, 17:20

  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..
Neither in this world nor elsewhere is there any happiness in store for him who always doubts. If you enjoyed my answer please consider donating some money to FreeBSD foundation @ http://www.freebsdfoundation.org/
User avatar
vivek
Member
 
Posts: 809
Joined: 17 Nov 2008, 08:19
Location: Hyper Space

Postby gilinko » 13 Feb 2009, 17:33

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.
User avatar
gilinko
Member
 
Posts: 416
Joined: 18 Nov 2008, 06:02
Location: SV_se

Postby hydra » 13 Feb 2009, 19:06

C:
gdb, valgrind (hopefully an amd64 version will be out soon...), printf :)
hydra
Member
 
Posts: 272
Joined: 17 Nov 2008, 08:50
Location: Slovakia

Postby fonz » 13 Feb 2009, 20:39

killasmurf86 wrote: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
ΔS>0 ⇒ Entropy is here to stay.

"Lawyer" is just "liar" pronounced in a regional accent.
User avatar
fonz
Giant Locked
 
Posts: 2236
Joined: 16 Nov 2008, 16:32
Location: in dreamland, swooning over a woman I can't have

Postby graudeejs » 13 Feb 2009, 21:47

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


atm i do the same
User avatar
graudeejs
Style(9) Addict
 
Posts: 4591
Joined: 16 Nov 2008, 23:23
Location: Riga, Latvia

Postby fonz » 13 Feb 2009, 23:42

killasmurf86 wrote: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.
ΔS>0 ⇒ Entropy is here to stay.

"Lawyer" is just "liar" pronounced in a regional accent.
User avatar
fonz
Giant Locked
 
Posts: 2236
Joined: 16 Nov 2008, 16:32
Location: in dreamland, swooning over a woman I can't have

Postby trev » 16 Feb 2009, 10:11

fonz wrote: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 :)
trev
Member
 
Posts: 354
Joined: 31 Dec 2008, 06:41

Postby kamikaze » 17 Feb 2009, 12:26

I use gdb. But really only to read backtraces.
sysutils/bsdadminscripts: binary package maintenance, library integrity checking, ...
sysutils/automounter: [man=8]amd[/man] based automounting without HAL
contact: kamikaze@bsdforen.de

Disclaimer: My posts represent my perception. Errors and incompleteness are to be expected, I deny any responsibility to know everything.
User avatar
kamikaze
Member
 
Posts: 366
Joined: 17 Nov 2008, 07:34
Location: /earth/europe/germany

The easiest way to debug

Postby ligregni » 19 Feb 2009, 19:05

Code: Select all
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
Is UNIX hot enough for you? | [color="DarkRed"]FreeBSD[/color]
User avatar
ligregni
Junior Member
 
Posts: 18
Joined: 12 Feb 2009, 18:09
Location: Querétaro, Mexico

Postby dap » 19 Feb 2009, 21:52

There is a similar macro NDEBUG, which is standard (when defined, assert() calls are ignored).
:wq
User avatar
dap
Junior Member
 
Posts: 20
Joined: 16 Nov 2008, 23:01


Return to Userland Programming & Scripting

Who is online

Users browsing this forum: No registered users and 0 guests