Troskyvs
Troskyvs

Reputation: 8047

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.

Upvotes: 1

Views: 2080

Answers (2)

Tom Tromey
Tom Tromey

Reputation: 22539

You can do this partially from gdb, but otherwise you're a bit on your own.

The thing you can do is save breakpoints. It's easy:

(gdb) save breakpoints /tmp/whatever-file

Unfortunately there currently isn't a way to save a define -- there's a gdb bug for this.

One thing you can do in this case is use show user to find your command, then cut-and-paste it into a file. Or maybe it's possible to implement the hypothetical save user from Python.

Upvotes: 0

Pavan Chandaka
Pavan Chandaka

Reputation: 12761

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.

Upvotes: 1

Related Questions