Reputation: 3631
I would like to run a set of python commands from a file in the PDB debugger. Related to this, can I set up a file that is automatically run when PDB starts?
Upvotes: 0
Views: 346
Reputation: 454
Pdb contained a bug previously that made this not possible
This has been fixed for python 3.13 and appears to be back ported to 3.11 and 3.12 per the discussion on this pull request
https://github.com/python/cpython/issues/90095#issuecomment-1989517207
Upvotes: 0
Reputation: 304127
make a subclass of pdb.Pdb
and put a call to your extra stuff in the __init__
alternatively
pdb.Pdb() looks for a .pdbrc
file, so you may be able to put your stuff in there
# Read $HOME/.pdbrc and ./.pdbrc
self.rcLines = []
if 'HOME' in os.environ:
envHome = os.environ['HOME']
try:
rcFile = open(os.path.join(envHome, ".pdbrc"))
except IOError:
pass
else:
for line in rcFile.readlines():
self.rcLines.append(line)
rcFile.close()
try:
rcFile = open(".pdbrc")
except IOError:
pass
else:
for line in rcFile.readlines():
self.rcLines.append(line)
rcFile.close()
Upvotes: 1