1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Userland Programming and Scripting' started by graudeejs, Feb 13, 2009.

  1. graudeejs

    graudeejs Member

    Messages:
    4,594
    Likes Received:
    0
    What kind of tools do you use to debug c/c++ code?

    I'm learning c/c++, tools tips&tricks welcomed here :D
     
  2. vivek

    vivek New Member

    Messages:
    809
    Likes Received:
    0
    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..
     
  3. gilinko

    gilinko New Member

    Messages:
    416
    Likes Received:
    0
    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.
     
  4. hydra

    hydra New Member

    Messages:
    272
    Likes Received:
    0
    C:
    gdb, valgrind (hopefully an amd64 version will be out soon...), printf :)
     
  5. fonz

    fonz Moderator Staff Member Moderator

    Messages:
    2,435
    Likes Received:
    5
    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
     
  6. graudeejs

    graudeejs Member

    Messages:
    4,594
    Likes Received:
    0
    atm i do the same
     
  7. fonz

    fonz Moderator Staff Member Moderator

    Messages:
    2,435
    Likes Received:
    5
    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.
     
  8. trev

    trev New Member

    Messages:
    364
    Likes Received:
    0
    +1 ('cept Zortech C, Borland Delphi :)
     
  9. kamikaze

    kamikaze New Member

    Messages:
    366
    Likes Received:
    0
    I use gdb. But really only to read backtraces.
     
  10. ligregni

    ligregni New Member

    Messages:
    18
    Likes Received:
    0
    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
     
  11. dap

    dap New Member

    Messages:
    20
    Likes Received:
    0
    There is a similar macro NDEBUG, which is standard (when defined, assert() calls are ignored).