Show Table of Contents
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_nameExample 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:
infobreakpoints
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:10Deleting 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_nameExample 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
Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.