您可以使用以下命令设置保存的过去命令的数量 . 该命令描述为"Set the number of commands which gdb keeps in its history list. This defaults to the value of the environment variable GDBHISTSIZE, or to 256 if this variable is not set. Non-numeric values of GDBHISTSIZE are ignored. If size is unlimited or if GDBHISTSIZE is either a negative number or the empty string, then the number of commands gdb keeps in the history list is unlimited" .
set history size <size>
相关命令是 set history remove-duplicates <count> . 该命令描述为"Control the removal of duplicate history entries in the command history list. If count is non-zero, gdb will look back at the last count history entries and remove the first entry that is a duplicate of the current entry being added to the command history list. If count is unlimited then this lookbehind is unbounded. If count is 0, then removal of duplicate history entries is disabled" .
gdb$ show history
expansion: History expansion on command input is off.
filename: The filename in which to record the command history is "/home/xiao/.gdb_history".
save: Saving of the history record on exit is on.
size: The size of the command history is 100000000.
2 回答
简短回答:
echo 'set history save on' >> ~/.gdbinit && chmod 600 ~/.gdbinit
答案很长:
命令历史记录包含在GDB manual, 22.3 Command History中 . 创建文件
$HOME/.gdbinit
,将其权限更改为0600
,并添加以下内容:您可以使用以下命令设置保存的过去命令的数量 . 该命令描述为"Set the number of commands which gdb keeps in its history list. This defaults to the value of the environment variable GDBHISTSIZE, or to 256 if this variable is not set. Non-numeric values of GDBHISTSIZE are ignored. If size is unlimited or if GDBHISTSIZE is either a negative number or the empty string, then the number of commands gdb keeps in the history list is unlimited" .
相关命令是
set history remove-duplicates <count>
. 该命令描述为"Control the removal of duplicate history entries in the command history list. If count is non-zero, gdb will look back at the last count history entries and remove the first entry that is a duplicate of the current entry being added to the command history list. If count is unlimited then this lookbehind is unbounded. If count is 0, then removal of duplicate history entries is disabled" .默认情况下,gdb将历史记录保存到文件./.gdb_history in the current directory中 . 如果您希望命令历史记录不依赖于您所在的目录,还包括:
如果您仍遇到问题,请确保您的HISTSIZE环境变量数字合适 . 我的是空的,导致gdb的“历史大小”设置默认为0 .
添加
到我的〜/ .bashrc,一切都很膨胀
您可以通过执行(在gdb内部)“show history”来检查您的gdb历史记录设置:
来自docs: