Search code examples
sessionsavegdbcommandbreakpoints

How to save gdb setup information inside gdb session?


We can use .gdbinit or a command file to start gdb with pre-set commands and macro definitions. But my case in:

I've started gdb and defined a few "breakpoints", "commands", "defines", how to save these debug session information into a file(either .gdbinit or commands file), by a gdb command? I don't wish to trace back gdb command history and copy-paste all those typings.

Does gdb support this? Thanks.


Solution

  • You can use GDB logging feature. Below said options are available in GDB documentation.

    https://sourceware.org/gdb/current/onlinedocs/gdb/Logging-Output.html#Logging-Output

    set logging on
               Enable logging. 
    set logging off
               Disable logging. 
    set logging file file
               Change the name of the current logfile. The default logfile is gdb.txt. 
    set logging overwrite [on|off]
               By default, gdb will append to the logfile. Set overwrite if you want set logging on to overwrite the logfile instead. 
    set logging redirect [on|off]
               By default, gdb output will go to both the terminal and the logfile. Set redirect if you want output to go only to the log file. 
    show logging
              Show the current values of the logging settings.