Skip to content

Data Display Debugger

DDD stands for 'Data Display Debugger'. It is a GUI front end of GDB, the GNU debugger. The main advantage of DDD over GDB is that DDD offers a GUI. In this tutorial, we will learn about

  • setting and removing breakpoints
  • tracing through programs
  • examining data at various points in execution.

Starting DDD

Since DDD is a graphical debugger, you will either need to SSH with X forwarding or use OnDemand.

SSH with X

If you want to debug from a dev node, first make sure that you SSH using the -X option. You can then start DDD using ddd which will open a DDD window on your computer:

1
2
3
$ ssh -X user@hpcc.msu.edu
$ ssh dev-amd20  # only the first ssh needs -X
$ ddd

If you would like to run your debugging job interactively on a compute node, please see the instructions for running an interactive graphical application.

OnDemand

You can also use DDD in your browser through OnDemand. Log in using your MSU credentials on the OnDemand site. Then from the Jobs menu, select Interactive Desktop. Once your job starts, you can open your Interactive Desktop and choose "Data Display Debugger" from the Applications menu under Programming.

The DDD interface

When you start DDD, you will see a DDD window like this:

A DDD window. A small C program is loaded in the source window near the top of the main window. Below that is a dump of that program's assembler code is in the machine code window, and a blank GDB console is below that.

The DDD window consists of 4 sections:

  • data window
  • source window
  • machine code window
  • GDB console

You can show/hide each of them in View menu.

You can customize the DDD environment in Edit → Preferences menu.

For example, to display line numbers in source window, under Edit → Preferences → Source, check 'Display Source Line Numbers'.

Opening a program

To use DDD, we need a program to debug. Let's use the following code.

debug_ex.c
1
2
3
4
5
6
7
8
9
#include <stdio.h>

int main(int argc, char** argv){
  for(int i = 0; i < 10; i++){
    int j = i*i;
    printf("%d ", j);
  }
  printf("\n");
}

First, you need to compile this code with -g option to include the debug symbols. Run this on the command line:

1
gcc -g debug_ex.c -o debug_ex

Now, to open this in DDD, you can either select it in the File → Open Program menu or you can run DDD with this executable from the command line like

1
ddd debug_ex

Even though you open an executable such as debug_ex, DDD will show the source file name such as debug_ex.c.

Setting breakpoints

Breakpoints stop your program in the middle of running to examine the current state of variables and data structures. You can continue from where you set the breakpoint to finish program execution.

To set a breakpoint, double click to the left of the source line in the source window. A STOP icon will appear next to it.

Click Run at the top of the window to start execution or type run in the GDB console. A green arrow will appear as soon as you hit the breakpoint.

The same DDD window from before with a STOP sign next to line 6 in the source code indicating a break point. An arrow is next to line 7 indicating this is the next line to be run. The equivalent instruction in the machine code window also has an arrow pointing towards it.

The breakpoints you set can be deleted or disabled by right-clicking on the line with the breakpoint and choosing either the "Disable Breakpoint" or "Delete Breakpoint" options.

In order to set breakpoints in other files (i.e., not in the main() function), choose the "Open Source" option from the File menu of DDD. The file dialog should appear.

The example in the figure above has a breakpoint at line 6. The program runs to the line number 5 and waits your input. You can run the code a line by line with 'next' command (by either clicking the button at the top of the screen or typing next into the GDB console).

To see a variable's value, type print <variable_name> in the GDB console. For example, print i will show the value of the variable i. You can also right click the variable in the source code choose Print <variable_name>.

To go to the next break point, click Cont button or type cont on GDB console.

When you find bugs, edit your source code in your editor of choice and recompile the code. Reload the new source code into DDD using the Source menu: Source → Reload Source.

Common commands

DDD offers command buttons, but you can also type commands directly on GDB console.

command Description
help help documentation for topics and commands
help breakpoint Lists help information about breakpoints
break sets breakpoint
break line_number Sets breakpoint at a line number
break function_name Sets breakpoint at the begining of function name
enable, disable, delete/clear Enable, disable, or delete one or more breakpoints.
disable 3 Disables breakpoint number 3
clear line_number Clears breakpoint at line_number
delete 3 Deletes breakpoint number 3
delete Deletes all beakpoints
run Starts program running from the begining.
continue (or cont) Continues execution from the current line to the next breakpoint
step (or s) Execute next line(s) of program
step Executes one line of a program
step number Executes next number of lines of program
next (or n) Like step, but treats a function as a single line.
next Execute the next line
next number Executes next number of lines of program
until line_number Executes program until line number
quit quit DDD
list Lists program source code
condition Conditional breakpoints
print Display program values, results of expressions
whatis List type of an expression
whatis j Shows data type of expression j
info Get information
info locals Shows local variables in current stack frame
info args Shows the argument variable of current stack frame
info break Show breakpoints
set Change values of variables, memory, registers
set x = 123*y Set variable x's value to 123*y

Examining data

While the program is running, you may want to examine the contents of variables. You can do this by right-clicking on a variable name in the DDD window.

Upon right-clicking, select "Display". If you want to display the value of a pointer, use the "Display*" menu item.

The same DDD window from before with two boxes in a data section above the source code. The first box is labeled j and has a value of 4 below it and the second box is labeled i and has the value 3 below it. The i variable is highlighted in the source code.

Right-clicking on a variable name offers other capabilities such as Print, Lookup, What Is (showing the data type), Break, and Clear.

Instead of right-clicking, you can peek at memory contents also. To do that, click Data → Memory.

Some useful resources