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?

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 26 comments so far... add one
CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
26 comments… add one
  • Melmacian Feb 24, 2009 @ 18:35


  • Kevin Feb 24, 2009 @ 19:39

    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 Feb 24, 2009 @ 20:19

    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 Feb 24, 2009 @ 21:10

    Eclipse is a good option for Java.

  • paul Feb 24, 2009 @ 22:11

    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 Feb 24, 2009 @ 22:14

    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 Feb 24, 2009 @ 22:15

    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 Feb 25, 2009 @ 2:38

    netbeans … ^^

  • Guy Feb 25, 2009 @ 6:31

    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 Feb 25, 2009 @ 7:05

    print and strace

  • mhernandez Feb 25, 2009 @ 8:06

    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 Feb 25, 2009 @ 11:11

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

  • Gili Feb 25, 2009 @ 12:51

    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 Feb 25, 2009 @ 16:00

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

  • Nikolodeon Feb 25, 2009 @ 16:06

    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.


  • Chris Gottbrath Feb 25, 2009 @ 20:47

    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.

    Chris Gotbrath

  • Mike Feb 26, 2009 @ 1:38

    conventiona way… printf, got more control of it

  • Chris Gottbrath Feb 26, 2009 @ 20:37

    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.

    Chris Gottbrath

  • Steve Parker Feb 26, 2009 @ 23:05

    I tend to use a combination of printf and valgrind.

  • Joshua Zhu Mar 5, 2009 @ 4:17

    I use GNU Emacs (gud mode) + syslog.

  • Lakshmipathi.G Mar 12, 2009 @ 10:37

    I use strace and printf for my open source projects.

    And very rarely use gdb, Nemiver.

  • rima Mar 13, 2009 @ 4:38

    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


    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 Dec 16, 2009 @ 10:38

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

  • Kalyani Sep 10, 2012 @ 7:23

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

  • Andrei Apr 23, 2013 @ 8:37

    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 Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum