Subsequent "list" commands in ipdb

Question:

I just noticed an odd behavior when using l (i.e. the list command) in ipdb. I think I have seen something similar with the Perl debugger in the past, but it still puzzles me.

The first time I inoke it shows corerectly ~10 lines of code around the current step (breakpoint). However, if I press it repeatedly, it does not show code around the current location anymore, but instead it shows code that comes below it.

Eventually list shows the final lines of the script, and if I press l again it doesn’t show anything anymore.

Why is this, and how can I have it behave consistently as the first time I invoke it?

Answers:

Many command line debuggers behave that way. (pdb, gdb, ipdb …).

If you want display current line again, specify the line number.

l 42

If you don’t know the current line number, issue where command.

Answered By: falsetru

The reason several list commands in most debuggers show different lines is for the simple reason that it doesn’t make a lot of sense to show the same source code lines over and over. Presumably you can scroll back to see what you saw before.

That said, let me say that if you are willing to use the trepan debugger, it does have the ability to show the same source code lines for where you are currently stopped using “list .”. To see lines before the last list, use “list -“.

You can also set how many lines you want to list by default using “set listsize”.

Answered By: rocky

This command in pdb always shows the source text around the debugger’s current line

(pdb) l .

Answered By: aphi
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.