Getting GDB to save a list of breakpoints

后端 未结 11 1102
终归单人心
终归单人心 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:42

    This answer is outdated. GDB now supports saving directly. See this answer.

    You can use logging:

    (gdb) b main
    Breakpoint 1 at 0x8049329
    (gdb) info break
    Num     Type           Disp Enb Address    What
    1       breakpoint     keep y   0x08049329 <main+16>
    (gdb) set logging file breaks.txt
    (gdb) set logging on
    Copying output to breaks.txt.
    (gdb) info break
    Num     Type           Disp Enb Address    What
    1       breakpoint     keep y   0x08049329 <main+16>
    (gdb) q
    

    The file breaks.txt now contains:

    Num     Type           Disp Enb Address    What
    1       breakpoint     keep y   0x08049329 <main+16>
    

    Writing an AWK script that transforms that into a format useful for the .gdbinit or a --command file is easy. Or you may even make the script emit separate --eval-command's to the GDB command line...

    Adding this small macro to .gdbinit will help you do it:

    # Call with dump_breaks file.txt
    define dump_breaks
        set logging file $arg0
        set logging redirect on
        set logging on
        info breakpoints
        set logging off
        set logging redirect off
    end
    
    0 讨论(0)
  • 2020-12-04 05:44

    warning: Current output protocol does not support redirection

    I also get this error/warning in GDB when trying to enable logging in TUI mode. However, the logging seems to work when in "non-TUI" mode. So I leave TUI mode whenever I want to log something. (Toggle back and forth into TUI mode with Ctrl + X, Ctrl + A).

    Here's how I work:

    1. start GDB (in normal mode)
    2. enable logging: set logging on - now it should not complain.
    3. toggle back/forth to TUI mode and do GDB stuff
    4. whenever I want to log something (like a huge backtrace dump) - toggle to normal mode
    0 讨论(0)
  • 2020-12-04 05:45

    As of GDB 7.2 (2011-08-23) you can now use the save breakpoints command.

    save breakpoints <filename>
      Save all current breakpoint definitions to a file suitable for use
      in a later debugging session.  To read the saved breakpoint
      definitions, use the `source' command.
    

    Use source <filename> to restore the saved breakpoints from the file.

    0 讨论(0)
  • 2020-12-04 05:49

    Any other ideas? I have got

    warning: Current output protocol does not support redirection
    

    after

    set logging on
    

    EDIT:

    I know that question is "how to save a list of breakpoints", however I just discovered, that with GDB we can simply set "saved in file" breakpoints by

    gdb> source breakpoints.txt
    

    where breakpoints.txt is a file like this:

    break main.cpp:25
    break engine.cpp:465
    break wheel.cpp:57
    
    0 讨论(0)
  • 2020-12-04 05:55

    An extension to anon's extension to Johannes' answer:

    .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
    
    define brestore
      source brestore.gdb
    end
    document brestore
      restore breakpoints saved by bsave
    end
    

    With brestore you can then restore the breakpoints saved with bsave.

    0 讨论(0)
  • 2020-12-04 05:58

    Put the following in ~/.gdbinit to define bsave and brestore as GDB commands to save- and restore breakpoints.

    define bsave
        save breakpoints ~/.breakpoints
    end
    
    define brestore
       source ~/.breakpoints
    end
    
    0 讨论(0)
提交回复
热议问题