Save command history in pdb

Is there a way to keep pdb (python debugger) command history in sessions? Also, can you specify the length of the story?

This seems like a question. How do I get gdb to keep the command history? however for pdb instead of gdb.

-Many thanks

+6
source share
4 answers

Note. This is checked only with python 2.

Credits: https://wiki.python.org/moin/PdbRcIdea

pdb uses readline, so we can instruct readline to save history:

.pdbrc

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

.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 
+5
source

See this post. You can save the history in pdb. By default, pdb does not read multiple lines. Thus, all functions must be on the same line.

In ~ / .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) 
+2
source

I do not believe that there is a way with "stock" pdb. But I wrote a replacement debugger that does this.

just install Pycopia from source: http://code.google.com/p/pycopia/source/checkout and this is in pycopia.debugger.

+1
source

Source: https://habr.com/ru/post/914302/


All Articles