How do I list the current line in python PDB?

PythonPdb

Python Problem Overview


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?

Python Solutions


Solution 1 - Python

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.

Solution 2 - Python

In Python 3.2 and higher, you can use list . to reset the list location.

Source: Python Bug tracker #4179

Solution 3 - Python

This question is 7 years old now..

If there’s anyone who are curious about this problem, just use the dot

(pdb) l .

This now works.

Solution 4 - Python

Well, I don't think there's a command similar to . in perl debugger, but you can always find the current line using the where / w command. That will show you both the current (contextual) frame as well as the most recent frame, which I believe is where the debugger was triggered.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionzenzicView Question on Stackoverflow
Solution 1 - PythonGhopper21View Answer on Stackoverflow
Solution 2 - PythonCoupleWavyLinesView Answer on Stackoverflow
Solution 3 - PythonplhnView Answer on Stackoverflow
Solution 4 - PythonkojiroView Answer on Stackoverflow