The CSF2 has been replaced by the CSF3 - please use that system! This documentation may be out of date. Please read the CSF3 documentation instead. To display this old CSF2 page click here. |
gdb (GNU Debugger)
Overview
Typically a debugger is used to execute a program and pause under certain conditions (e.g. at specific line numbers) to examine the state of the program, e.g. to look at values associated with program variables. Using the debugger it is possible to step through execution of the program, line by line.
Restrictions on use
GDB can be used to debug programs written in C/C++, Fortran and some other languages, see GDB documentation for more information. With Fortran it may be necessary to refer to some variables with a trailing underscore.
Debugging sessions should use the interactive queue, do not run the debugger on the login node.
Set up procedure
Before using GDB a program must be compiled with the appropriate flag, e.g. -g
for the Intel and GNU compilers. Note: the -g
flag may change the default level of optimisation, check the compiler documentation for further information.
Running the application
A tutorial on gdb debugging is beyond the scope of this page. A tutorial can be found at http://www.unknownroad.com/rtfm/gdbtut/gdbtoc.html.
The commands below show you how to start gdb correctly on the CSF. Please do not debug large complex programs on the login node.
Debugging is an interactive process – you will usually want to enter commands in the debugger to step through your code, executing those instructions as you do so, check the value of variables, set breakpoints in the code etc. Hence you should use the interactive queue, using the SGE command qrsh as shown below.
Debugging a Serial Program
To debug your serial executable (located in the current directory)
qrsh -cwd -V -l inter -l short gdb ./my_program.exe
and wait to connect to a remote node before using GDB. In GDB, entering r
will run your executable in the debugger. Enter q
to quit GDB and return to the log in node.
Debugging an MPI Program
The following method can be used for small MPI jobs (a couple of cores). Running parallel jobs interactively is not normally permitted due to the small number of cores available for interactive use. We recommend using 2 cores to initially test your MPI code.
The command below will open two xterm
windows in which gdb will be running. You can enter commands in to both instances of gdb in each window. Your MPI processes will be being debugged by gdb in each window. Ensure you have the MPI modulefile loaded that you used when compiling the application.
qrsh -cwd -V -l inter -l short -pe smp.pe 2 mpirun -n 2 xterm -e gdb ./my_mpi_program.exe
You will need to enter r
in both xterm
windows for the application to start working as normal inside the debugger.
Further info
Further information, including the GDB user manual, can be found here.
Updates
None at this time.