乐闻世界logo
搜索文章和话题

How to get GDB to save a list of breakpoints

1个答案

1

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:

  1. Set breakpoints: First, set breakpoints in your code. For example:

    bash
    (gdb) break main (gdb) break myFunction
  2. Save breakpoints: Use the save breakpoints command to save all breakpoints to a file. For example:

    bash
    (gdb) save breakpoints breakpoints.txt

    This saves all currently set breakpoints to the breakpoints.txt file.

  3. Exit GDB: After completing debugging, you can exit GDB normally:

    bash
    (gdb) quit
  4. 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.

2024年6月29日 12:07 回复

你的答案