4

I usually debug in console gdb and now I'm trying to move to Emacs. In my ~/.gdbinit I have the following lines setting up history:

# save history of unlimited size, write always to ~/.gdb_history
set history save on
set history size unlimited
set history filename ~/.gdb_history

And in console gdb history works perfectly. show history result there:

(gdb) show history
+show history
expansion:  History expansion on command input is off.
filename:  The filename in which to record the command history is "/home/ars/.
gdb_history".
save:  Saving of the history record on exit is on.
size:  The size of the command history is 10000000.

If you wonder, history size is 10000000 instead of unlimited because I have $HISTSIZE=10000000.

In Emacs, I successfully search for old commands from ~/.gdb_history with comint-history-isearch-backward-regexp. However, the problem is that commands entered while debugging from Emacs are not appended to ~/.gdb_history. I can still search through them in the current session, i.e. they are saved somewhere in memory, but they will not be written to the file and as a consequence I don't see them in the following sessions.

While GDB starts inside Emacs, I see that the config is read:

...
+set history save on
+set history size unlimited
+set history filename ~/.gdb_history
...

And show history output there is exactly the same like in console GDB:

show history
+show history 
expansion:  History expansion on command input is off.
filename:  The filename in which to record the command history is "/home/ars/.gdb_history".
save:  Saving of the history record on exit is on.
size:  The size of the command history is 10000000.
(gdb) +info break

I start gdb with command like (gdb "gdb -i=mi $PROGTODEBUG") and finish debugging with quit, typed manually or via C-d. Then I kill the buffer with kill-this-buffer and exit Emacs. GNU Emacs version is 25.1.

1
  • Thanks for the edit. It looks like this is an interaction between server command and history, and may be a bug.
    – icarus
    Nov 25, 2016 at 1:55

1 Answer 1

1

Try:

(add-hook 'kill-buffer-hook 'comint-write-input-ring)

For some reason gdb, as one of the comint modes, does not do this by default.

Note: gdb gud buffer has to be killed.

By default tt is not enough to just 'quit' from gdb session. You really need to kill comint (gdb) buffer. You can correct this behavior so, when you quit gdb session ('q' or 'quit'), then gud session buffer will be closed and windows configuration will be restored, by using:

(setq gdb-restore-window-configuration-after-quit t)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.