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

查看:24
本文介绍了如何让 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.

推荐答案

简答: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 <count>.该命令描述为 控制命令历史列表中重复历史条目的删除.如果 count 不为零,gdb 将回顾最后的计数历史条目并删除第一个与当前条目被添加到命令历史列表中.如果 count 是无限的,那么这个lookbehind 是无限的.如果 count 是 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天全站免登陆