7.5. Setting Breakpoints

Setting a New Breakpoint

To set a new breakpoint at a certain line, run the following command:
break [file_name:]line_number
You can also set a breakpoint on a certain function:
break [file_name:]function_name

Example 7.5. Setting a New Breakpoint

Assuming that you have compiled the fibonacci.c file listed in Example 7.1, “Compiling a C Program With Debugging Information” with debugging information, you can set a new breakpoint at line 10 by running the following command:
(gdb) break 10
Breakpoint 1 at 0x4004e5: file fibonacci.c, line 10.

Listing Breakpoints

To display a list of currently set breakpoints, run the following command:
info breakpoints

Example 7.6. Listing Breakpoints

Assuming that you have followed the instructions in Example 7.5, “Setting a New Breakpoint”, you can display the list of currently set breakpoints by running the following command:
(gdb) info breakpoints
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x00000000004004e5 in main at fibonacci.c:10

Deleting Existing Breakpoints

To delete a breakpoint that is set at a certain line, run the following command:
clear line_number
Similarly, to delete a breakpoint that is set on a certain function, run:
clear function_name

Example 7.7. Deleting an Existing Breakpoint

Assuming that you have compiled the fibonacci.c file listed in Example 7.1, “Compiling a C Program With Debugging Information” with debugging information, you can set a new breakpoint at line 7 by running the following command:
(gdb) break 7
Breakpoint 2 at 0x4004e3: file fibonacci.c, line 7.
To remove this breakpoint, type:
(gdb) clear 7
Deleted breakpoint 2