enable persistent history in gdb

Friends. I have been using GDB for more than two decades and have been annoyed by the fact that, unlike the shell, it doesn’t keep a persistent history.

Of course, it has always been able to do that, but history saving is just not on by default. So do yourself a favor and turn it on by pasting this into your terminal:

mkdir -p ~/.config/gdb
mkdir -p ~/.cache/gdb
echo 'set history filename ~/.cache/gdb/history' >> ~/.config/gdb/gdbinit
echo 'set history save on' >> ~/.config/gdb/gdbinit
echo 'set history size unlimited' >> ~/.config/gdb/gdbinit

You are welcome!

One response

  1. Jan Alexander Steffens says:

    You could also use a line ‘shell mkdir -p -m 0700 ~/.cache/gdb’ in your gdbinit to ensure the cache directory exists.

    Might be helpful if you’re using a mechanism to place the config file but not necessarily the cache dir, or if ~/.cache gets pruned.