How do I list the current line in python PDB?

zenzic picture zenzic · Mar 2, 2011 · Viewed 13.5k times · Source

In the perl debugger, if you repeatedly list segments of code taking you away from the current line, you can return to the current line by entering the command . (dot).

I have not been able to find anything comparable using the python PDB module. If I list myself away from the current line and want to view it again, it seems I have to either remember the line number that was currently executing (unlikely for me) or execute a statement (often undesirable).

Am I missing something?

Answer

Ghopper21 picture Ghopper21 · Aug 7, 2012

Late but hopefully still helpful. Make the following alias:

alias ll u;;d;;l

Then whenever you type ll, pdb will list from the current position. It works by going up the stack and then down the stack, which resets 'l' to show from the current position. (This won't work if you are at the top of the stack trace.)

Tip: Permanent alias

To make the alias permanent, add the line into your .pdbrc-file in the user home directory (~/.pdbrc). This works with both pdb and ipdb.