Skip to content
System Status: All systems are operational • Services are available and operational.
Click for detailed status

Debugging 🐛

In engineering, debugging is the process of finding the root cause, workarounds, and possible fixes for bugs.

Debugging on Euler

Debugging on Euler can be done using various tools and techniques. Here are some common methods:

Using gdb

gdb is a powerful debugger for C/C++ programs. You can use it to - Set breakpoints - Inspect variables - Step through code - Analyze core dumps - etc. To use gdb, you need to compile your program with debugging symbols. For example, compile your C/C++ code with the -g flag:

gcc -g -o my_program my_program.c
Then, you can run gdb on your program:
gdb ./my_program
or with Slurm by submitting a job:
sbatch --wrap="gdb --batch --eval-command=run --eval-command=bt --nw --args ./my_program"
Inside gdb, you can set breakpoints, run the program, and inspect variables. See the gdb documentation for more details on how to use it.

Using valgrind

valgrind is a tool for memory debugging, memory leak detection, and profiling. You can use it to find memory leaks, invalid memory accesses, and other memory-related issues. To use valgrind, run your program with it:

valgrind ./my_program
This will run your program under valgrind and report any memory issues it finds. You can also use valgrind with Slurm by submitting a job:
sbatch --wrap="valgrind --leak-check=full --track-origins=yes ./my_program"
For more information, see the valgrind documentation.

Using strace

strace is a diagnostic tool that monitors system calls made by a program and the signals it receives. It can be useful for debugging issues related to file I/O, network communication, and other system interactions. To use strace, run your program with it:

strace ./my_program
This will print a trace of all system calls made by your program. You can also use strace with Slurm by submitting a job:
sbatch --wrap="strace -o strace_output.txt ./my_program"
This will save the output to a file named strace_output.txt. For more information, see the strace documentation.

Debugging MPI programs

If you are debugging MPI programs, you can use mpirunwith the above tools. For example, to use gdb with an MPI program, you can run:

mpirun -np 4 gdb ./my_mpi_program
This will start gdb for each MPI process. You can also use valgrind or strace with MPI programs in a similar way.

The Open MPI library has a page on parallel debugging using Open MPI: https://www.open-mpi.org/faq/?category=debugging

Using pdb

If you are debugging Python programs, you can use the built-in pdb module. To use pdb, you can run your Python script with the -m pdb option:

python -m pdb my_script.py
This will start the Python debugger and allow you to set breakpoints, step through code, and inspect variables. You can also use pdb with Slurm by submitting a job:
sbatch --wrap="python -m pdb my_script.py"
For more information, see the pdb documentation.