Getting to Know your Debugger

(work in progress - ideas welcome!)

What is my Debugger

On Linux, this is most likely to be gdb (now that Intel have dropped idb).

Serial Debugging

  1. compile with -g (and usually with -O0 to turn off any optimisations)
  2. start the debugger for the given executable, e.g. gdb ./a.out
  3. within the debugger you can either run or if you wish to pass arguments you use run arg1 arg2 for example
  4. if there's a memory issue, then gdb will halt at the bad line. if there's no issues it will continue until completion or until you CNTL-C and enter a gdb command

Debugging OpenMP

  1. compile with -g (and usually with -O0 to turn off any optimisations) and the OpenMP compilation flag e.g. -fopenmp
  2. set the number of OpenMP threads e.g. export OMP_NUM_THREADS=2
  3. start the debugger for the given executable, e.g. gdb ./a.out
  4. within the debugger you can either run or if you wish to pass arguments you use run arg1 arg2 for example
  5. if there's a memory issue, then gdb will halt at the bad line on the first thread that has a problem. if there's no issues it will continue until completion or until you CNTL-C and enter a gdb command

Debugging MPI

  1. compile with -g (and usually with -O0 to turn off any optimisations) for your favored MPI installation e.g. mpiicc -g -O0
  2. we need to use mpirun -np N (for N processes) and for this to launch a terminal, e.g. xterm in which we can then start the debugger for the given executable. That is we will have a command line akin to
    mpirun -np N xterm -e gdb ./a.out
  3. within the debugger in each terminal you can either run or if you wish to pass arguments you use run arg1 arg2 for example
  4. if there's a memory issue, then gdb will halt at the bad line on the first process that has a problem. if there's no issues it will continue until completion or until you CNTL-C and enter a gdb command

Useful gdb commands

print VAR what VAR quit

quit the debugger (may be needed on each thread and each process)

run run (or continue to run) the executable
step [N] step one line [or N lines]
list [N] list from current point in source file [or from line N]
print the current value of the variable VAR
output the type of variable VAR
break set a breakpoint (i.e. when re-run the debugger will stop at this point)
watch EXP stop execution when expression EXP changes
help CMD give the help information for command CMD