In GDB, you can use the save breakpoints command to save the current breakpoint settings to a file. This way, when you launch GDB again, you can reload these breakpoints using the source command.
Steps:
-
Set breakpoints: First, set breakpoints in your code. For example:
bash(gdb) break main (gdb) break myFunction -
Save breakpoints: Use the
save breakpointscommand to save all breakpoints to a file. For example:bash(gdb) save breakpoints breakpoints.txtThis saves all currently set breakpoints to the
breakpoints.txtfile. -
Exit GDB: After completing debugging, you can exit GDB normally:
bash(gdb) quit -
Reload breakpoints: When you launch GDB again, you can reload the previously saved breakpoints using the following command:
bash(gdb) source breakpoints.txt
Example:
Suppose you are debugging a program named example.c. You might have set breakpoints in the functions main and processData. At the end of the debugging session, you used save breakpoints to save these breakpoints, and in your next session, you reload them using the source command.
This method saves time, especially when working with large projects or frequently debugging the same code locations.