Breakpoint

Learn about breakpoints and how they are useful for debugging by executing a code line by line.

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 the GDB debugger. We use the GDB command break to insert a breakpoint, and then the run command to run the program:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy