Debugging a Core with DDD

When something goes badly wrong in a C program, things generally go south in one of two ways:

  1. If the programmer has been careful, the program will detect that something is wrong and abort itself
  2. If the programmer was lazy or the program has strayed into a bad place that was unanticipated, the operating system may terminate the program with a fault.

In either case, if you want to debug the problem, you need a core file. If your program aborts or faults and no core is produced, see Where’s my Core Dump? for help.

While it is possible to debug a core using gdb (see Debugging with GDB), I prefer to use a graphical debugger, the nearly as venerable ddd. In either case, you are in for a world of hurt if you have not built your program with debugger support. Please refer to the above post for details. Once you have a debuggable program and a core file, run ddd as follows:

ddd program-file core

DDD should open with one of the source files of the program showing up in the center pane, with an arrow pointing to the line where the fault (or abort) occurred. Sometimes, it won’t. For example, in the shot below, the main program file is displayed with no arrow. If you look in the bottom pane, you can see that the program died in raise, which is part of the C library.


Clicking Up in the DDD toolbar window will get you to the point in the program that triggered the call to raise. The first click told me that the program was in abort when it called raise. The next click showed me the error:


My program was intentionally aborting, because I had inverted the condition that was checking whether to abort if a value was not found. Removing the ~ from the line above the call to abort fixed it right up.


About jimbelton

I'm a software developer, and a writer of both fiction and non-fiction, and I blog about movies, books, and philosophy. My interest in religious philosophy and the search for the truth inspires much of my writing.
This entry was posted in c programming, tools and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s