如何让 gdb 保存命令历史? [英] How can I make gdb save the command history?

查看:21
本文介绍了如何让 gdb 保存命令历史?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置 gdb 以保存命令历史记录?当开始一个新的 gdb 会话时,我想使用向上箭头键来访问以前会话的命令.

How can I set up gdb so that it saves the command history? When starting a new gdb session I'd like to use the arrow up keys to access the commands of the previous sessions.

推荐答案

Short answer: echo 'set history save on' >>~/.gdbinit &&chmod 600 ~/.gdbinit

Short answer: echo 'set history save on' >> ~/.gdbinit && chmod 600 ~/.gdbinit

长答案:

GDB 手册,22.3 命令历史中介绍了命令历史记录.创建文件$HOME/.gdbinit,修改权限为0600,添加如下内容:

Command history is covered in the GDB manual, 22.3 Command History. Create a file $HOME/.gdbinit, change its permissions to 0600, and add the following content:

set history save on

您可以设置使用以下命令保存的过去命令的数量.该命令被描述为 设置 gdb 保留在其历史列表中的命令数.默认为环境变量 GDBHISTSIZE 的值,如果未设置此变量,则为 256.GDBHISTSIZE 的非数字值是忽略.如果大小是无限制的,或者如果 GDBHISTSIZE 是负数或空字符串,那么 gdb 保留在历史列表中的命令数量是无限制的".

You can set the number of past commands saved with the following. The command is described as "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 .该命令被描述为控制删除命令历史列表中重复的历史条目.如果计数不为零,gdb 将回顾最后一个计数历史条目并删除第一个与历史条目重复的条目.当前条目被添加到命令历史列表中.如果计数是无限制的,那么此后视是无界的.如果计数为 0,则禁用重复历史条目的删除".

A related command is set history remove-duplicates <count>. The command is described as "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".

set history remove-duplicates <count>

默认情况下,gdb 将历史记录保存到文件 ./.gdb_history 当前目录.如果您希望命令历史记录不依赖于您所在的目录,还包括:

By default, gdb saves the history into the file ./.gdb_history in the current directory. If you want your command history not to depend on the directory you are in, also include:

set history filename ~/.gdb_history

这篇关于如何让 gdb 保存命令历史?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆