Programming Parallel Computers 2019

Help with debugging

GDB quick start

We will use MF1 here as an example. One part of its test suite is a small program called mf-test which will call mf function with some small inputs. Let us compile it with debug options and open it in the debugger, using GDB with its text user interface:

$ make clean
$ make DEBUG=1
$ gdb -tui mf-test

Then use command b to set a breakpoint in function mf and start the program with command r; it will execute until it reaches function mf:

(gdb) b mf
Breakpoint 1 at ...: file, line ...
(gdb) r
Starting program: .../mf-test
Breakpoint 1 ...

You should have a split-screen text user interface, with the upper half of the screen showing your source code and the lower half showing the GDB console. You can scroll the source code with arrow keys; highlighting shows which line will be executed next. You can now e.g. execute code line by line with command n:

(gdb) n
(gdb) n

At any point you can also show the contents of any variable with command p:

(gdb) p ny
... = 1
(gdb) p in[0]
... = 0

We can continue execution until we reach the breakpoint again with c:

(gdb) c

Breakpoint 1 ...

Other highly useful commands include bt for showing the stack backtrace (who called us), and q for quitting GDB. See the manual for more information; the split-screen text user interface is documented in section TUI.