61

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?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
zenzic
  • 1,517
  • 2
  • 16
  • 25

4 Answers4

53

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.

Niko Föhr
  • 28,336
  • 10
  • 93
  • 96
Ghopper21
  • 10,287
  • 10
  • 63
  • 92
  • Simple and worked for me. This should be marked as the answer! – trinth Mar 19 '14 at 21:13
  • 2
    This command is super handy. To save time, you can add this to a `.pdbrc` file so you don't have to enter it each time (described [here](https://docs.python.org/3/library/pdb.html#debugger-commands)) – Cabbage soup Nov 17 '16 at 15:59
  • 1
    I couldn't do following to overwrite `alias l` => `alias l u;;d;;l` which enters into a loop – alper Jul 15 '20 at 16:40
47

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

Source: Python Bug tracker #4179

CoupleWavyLines
  • 4,523
  • 2
  • 19
  • 12
28

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.

plhn
  • 5,017
  • 4
  • 47
  • 47
21

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.

kojiro
  • 74,557
  • 19
  • 143
  • 201
  • I didn't think of using "where' to get back. It's less than ideal, but certainly better than nothing. Thanks! – zenzic Mar 02 '11 at 16:21