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 8.5. Setting a New Breakpoint
Assuming that you have compiled the
fibonacci.c file listed in Example 8.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:
infobreakpoints
Example 8.6. Listing Breakpoints
Assuming that you have followed the instructions in Example 8.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:10Deleting Existing Breakpoints
To delete a breakpoint that is set at a certain line, run the following command:
clearline_number
Similarly, to delete a breakpoint that is set on a certain function, run:
clearfunction_name
You can also delete all breakpoints at once. To do so, run the
clear command with no additional arguments:
clearExample 8.7. Deleting an Existing Breakpoint
Assuming that you have compiled the
fibonacci.c file listed in Example 8.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