≡ Menu

What Do You Use to Debug Linux / UNIX C/C++ Programs?

The purpose of a debugger is to allow you to see what is going on inside another program while it executes. It is useful to find out what another program was doing at the moment it crashed. I know most people will recommend GNU gdb, Nemiver, Valgrind or IDE such as Eclipse. I use gdb when it is really required; otherwise I debug the old fashioned way using printf() or cout statements.

I'm often too lazy for this, but gdb is used when really needed. I found Eclipse as a good alternative to debug programs. In the old days Borland C (Turbo C) was good enough for most of us. It was pretty slick and easy to use. However, UNIX / Linux is altogether different story with vi and gcc. What do you use to debug your C/C++/Java programs under UNIX like operating systems?

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 26 comments… add one }

  • Melmacian February 24, 2009, 6:35 pm

    Netbeans.

  • Kevin February 24, 2009, 7:39 pm

    Oh… I thought I was the only one on the planet that still preferred to use printf() and manual breakpoints and checkpoints and such.

    However, I’m probably one of the few old farts that would still rather use K&R C.

  • brian February 24, 2009, 8:19 pm

    I used to use plain old “print”, but I know that’s not the right way. I recently started learning python and have determined to myself that I will learn to develop with it in Eclipse with the Eclipse debugger. I’ve been doing this for too long to still be using print!

  • yoander February 24, 2009, 9:10 pm

    Eclipse is a good option for Java.

  • paul February 24, 2009, 10:11 pm

    What is wrong with using print?

    My personal observation is that people using a debugger tend to fix just *something*, but most often the underlying cause is neither found nor corrected.

    As an example, you expect an object to be passed to your method. The method is called several hundret times, and within one single call NULL is passed. It is hard to debug such things with a debugger (because it doesn’t happen always).

    For me print debugging leads to using loggers in hot spots. When I find adding myself a print a second time, I place an logger statement instead.

    When I make assumptions, (e.g NULL here, see example above) I add assert statements.
    Ofcourse loggers and asserts can also be used when you rely on an debugger instead, but many people often only do one thing.

    Last but not least, adding prints helps me to better understand control/dataflow logic. I don’t like hitting F5 (or whatever the hotkey is) over and over again, until I find the statement where my programm is doing something wrong.

    PS: I use a debugger when I have to programm non-function code, eg. OOP and need to know about several local or global states at a specific point in time.

  • paul February 24, 2009, 10:14 pm

    Me again:

    When I want to add a print, I really have to think about where to place it. I cannot fall into an automatism and just use my debugger. I have to use my brain and IMHO that is all programming is about.

    I feel sick whenever I see people starting their debugger in order to understand what a piece of code is doing. A debugger is a tool, nothing to abuse.

  • paul2 February 24, 2009, 10:15 pm

    Me again: (sorry for potential double post, just wondering where the second post went to)

    When I want to add a print, I really have to think about where to place it. I cannot fall into an automatism and just use my debugger. I have to use my brain and IMHO that is all programming is about.

    I feel sick whenever I see people starting their debugger in order to understand what a piece of code is doing. A debugger is a tool, nothing to abuse.

  • chika.tambun February 25, 2009, 2:38 am

    netbeans … ^^

  • Guy February 25, 2009, 6:31 am

    I use ddd (http://www.gnu.org/software/ddd). I find its ability to visualize complex data structures a very important feature thats is missing in other debuggers.

  • ble February 25, 2009, 7:05 am

    print and strace

  • mhernandez February 25, 2009, 8:06 am

    I usually combine traces with gdb. I commonly use a function which, when a DEBUG_FLAG is enabled prints the message, file and function name and line number. When I need to know the exact state of my program at some point, I use gdb (probably with conditional breakpoints). Then, when everything is ok, I turn out the flag and I get the nice robust program I was looking for (-:

  • Karl February 25, 2009, 11:11 am

    if youre coding c++, it is nearly impossible to find lost pointers without gdb…

  • Gili February 25, 2009, 12:51 pm

    defentialy a debuger.
    Using printf() and assertions is great if you have those already covering you complete code. Unfortunatly, while this is a good practice, it is not the case in many cases.
    If the application is more than trivial it is dificult to effectively add printf() etc’ when you need to debug.

  • Raj February 25, 2009, 4:00 pm

    I use ddd to debug my c and c++ programs. Its a good debugger and always helps me in solving the problems.

  • Nikolodeon February 25, 2009, 4:06 pm

    I think there’s not any “one fits all” debugger, almost every time i use gdb, but when i have to deb ug complex data structures, i use ddd; for memory leaks and lost pointers i found nothing better than memwatch (http://sourceforge.net/projects/memwatch/).

    Never marry with only one tool… there’s always a feature inside one that is missing on another one, IMHO.

    Greetings!

  • Chris Gottbrath February 25, 2009, 8:47 pm

    I am the product manager for a debugger vendor. Yes, that’s right there is a company out there that actually has managed to stay in business (for about 10 years) specializing in debugging on Linux/UNUX.

    I’d encourage you to check out TotalView. It is a professionally developed debugger for apps running on C/C++ and Fortran on Linux and other UNIX OSs. It is compiler agnostic and plays nicely with GDB, Intel, PGI, and others.

    It has some really nice C++ features like automatic translation of STL variables, and has world-class support for threads and processes (up to 16k of them, in recent tests on the linux powered BlueGene platform).

    It is _not_ based on GDB (unlike most of the other GUI debugging solutions you will find in UNIX-land). GDB is nice, but having a separate code-base lets us be bug orthogonal.. as a previous poster said “never marry yourself to a single tool”. Which is sensible advice.

    The best feature is something that we recently added via an add-on called ReplayEngine. WIth TV and RE you can step freely forwards and backwards through your code. So you can run to a crash and then work backwards from there to the error in your program.

    I understand that you might be skeptical. So I encourage you to check out the videos and download a free copy to try out (we offer a free 15 day evaluation period).

    Feel free to contact me at (fn).(ln)@totalviewtech(dot)com with feedback (good, bad, or ugly) or questions.

    Cheers,
    Chris Gotbrath

  • Mike February 26, 2009, 1:38 am

    conventiona way… printf, got more control of it

  • Chris Gottbrath February 26, 2009, 8:37 pm

    Ok, this is embarrasing. There are two typos in my post above. Somehow I managed to type UNIX as UNUX. More confusingly I somehow omitted a ‘t’ in my own last name. So if you want to send me an email please use chris(dot)gottbrath(at)totalviewtech(dot)com with two ‘t’s.

    Cheers,
    Chris Gottbrath

  • Steve Parker February 26, 2009, 11:05 pm

    I tend to use a combination of printf and valgrind.

  • Joshua Zhu March 5, 2009, 4:17 am

    I use GNU Emacs (gud mode) + syslog.

  • Lakshmipathi.G March 12, 2009, 10:37 am

    I use strace and printf for my open source projects.

    And very rarely use gdb, Nemiver.

  • rima March 13, 2009, 4:38 am

    hi i am relatively new to the world of C programming and m having a tough time debugging my programs. i mostly have to del with matirx related problem and one wrong dimension and thw whole program chrashes. i ma working on UNIX. can anybody give me an idea about the debugging tools available

  • Vijay May 8, 2009, 5:08 am

    Rima,

    just take the core and analyse it with gdb. It will give you the information where mess up has happened. In matrix kinda problems, usually its dimension issues. Not sure you may be needing some validation in your code.

  • Chethan December 16, 2009, 10:38 am

    i use ddd to debug, i visual entire memory thats y i use it

  • Kalyani September 10, 2012, 7:23 am

    How do i actually get to know the exact syntax error in the c program when the compiler gives error as ‘Segmentation fault’?

  • Andrei April 23, 2013, 8:37 am

    I use WiCon wireless console on my iPhone to see debug messages out of main screen and to control my programs runing by sound.

Leave a Comment