Breakpoint
Explore how to use breakpoints in the GNU debugger GDB to pause your C program at specific lines. Learn to inspect variables, step through code, and manage breakpoints by viewing, disabling, or deleting them. This lesson helps you identify uninitialized pointers and logical errors to improve your debugging skills in C programming.
The print command in GDB prints out the value of a variable that’s defined in the current stack.
We’ll continue to use the go.c file from the previous lesson, as a reference for this lesson. We’ll try to print the s variable (which is supposed to be a character buffer).
Let’s first, however, define a breakpoint.
Inserting a breakpoint
A breakpoint is a flag that will stop the program at a specific line of code. Let’s insert a breakpoint on line 9 of our code. This means the program will stop before executing that line of code and leave us in GDB. We use the GDB command break to insert a breakpoint and then the run command to run the program:
Now (gdb) prompt is waiting for input and we are stopped just short ...