在pdb中保存命令历史记录

vko*_*ori 12 python debugging

有没有办法跨会话保存pdb(python调试器)命令历史记录?另外,我可以指定历史长度吗?

这类似于如何使gdb保存命令历史记录的问题?但是对于pdb而不是gdb.

-非常感谢

irr*_*rom 12

这篇文章.可以在pdb中保存历史记录.默认情况下,pdb不读取多行.所以所有功能都需要在一条线上.

在〜/ .pdbrc中:

import atexit
import os
import readline

historyPath = os.path.expanduser("~/.pyhistory")

def save_history(historyPath=historyPath): import readline; readline.write_history_file(historyPath)

if os.path.exists(historyPath): readline.read_history_file(historyPath)

atexit.register(save_history, historyPath=historyPath)
Run Code Online (Sandbox Code Playgroud)


ole*_*enb 6

注意:这只是用python 2测试的.

致谢:https://wiki.python.org/moin/PdbRcIdea

pdb使用readline,因此我们可以指示readline保存历史记录:

.pdbrc

# NB: This file only works with single-line statements
import os
execfile(os.path.expanduser("~/.pdbrc.py"))
Run Code Online (Sandbox Code Playgroud)

.pdbrc.py

def _pdbrc_init():
    # Save history across sessions
    import readline
    histfile = ".pdb-pyhist"
    try:
        readline.read_history_file(histfile)
    except IOError:
        pass
    import atexit
    atexit.register(readline.write_history_file, histfile)
    readline.set_history_length(500)

_pdbrc_init()
del _pdbrc_init
Run Code Online (Sandbox Code Playgroud)