Getting GDB to save a list of breakpoints

后端 未结 11 1103
终归单人心
终归单人心 2020-12-04 05:32

OK, info break lists the breakpoints, but not in a format that would work well with reusing them using the --command as in this question. Does GDB have a method for

相关标签:
11条回答
  • 2020-12-04 05:59

    The problem is that setting a breakpoint is context sensitive. What if you have two static functions named foo?

    If you are already debugging one of the modules that defines foo, then GDB will assume you meant that one. But if you just dump "break foo" into a file and then read that file at start-up, it will not be clear which function foo you mean.

    0 讨论(0)
  • 2020-12-04 06:03

    Perhaps this:

    save breakpoints [filename]

    0 讨论(0)
  • 2020-12-04 06:03

    I found the following addition to a previous answer useful to save/load the breakpoints to a specific file.

    • Save breakpoints: bsave {filename}
    • Load breakpoints: bload {filename}

    As in the previous answer, add the following code to the file ~/.gdbinit

    # Save breakpoints to a file
    define bsave
        if $argc != 1
            help bsave
        else
        save breakpoints $arg0
        end
    end
    document bsave
    Saves all current defined breakpoints to the defined file in the PWD
    Usage: bsave <filename>
    end
    
    # Loads breakpoints from a file
    define bload
        if $argc != 1
            help bload
        else
            source $arg0
        end
    end
    document bload
    Loads all breakpoints from the defined file in the PWD
    Usage: bload <filename>
    end
    
    0 讨论(0)
  • 2020-12-04 06:07

    Put your GDB commands and breakpoints in a .gdbinit file just as you might type them at the gdb> prompt, and GDB will automatically load and run them on startup. This is a per-directory file, so you can have different files for different projects.

    0 讨论(0)
  • 2020-12-04 06:09

    Extension to the answer from Johannes: you could automatically reformat the output of info break into a valid GDB command file:

    .gdbinit:
    
    define bsave
       shell rm -f brestore.txt
       set logging file brestore.txt
       set logging on
       info break
       set logging off
       # Reformat on-the-fly to a valid gdb command file
       shell perl -n -e 'print "break $1\n" if /^\d+.+?(\S+)$/g' brestore.txt > brestore.gdb
    end
    document bsave
      store actual breakpoints
    end
    

    Afterwards you have a valid commandfile in brestore.gdb.

    This worked for me when the application is compiled with -g.

    I also successfully tested it with GDB v6.8 on Ubuntu 9.10 (Karmic Koala).

    0 讨论(0)
提交回复
热议问题