Subsequent "list" commands in ipdb
Asked Answered
H

3

7

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?

Homager answered 17/6, 2013 at 0:15 Comment(1)
Interesting question! A simple demo: In [1]: raise Exception --------------------------------------------------------------------------- Exception Traceback (most recent call last) <ipython-input-1-fca2ab0ca76b> in <module>() ----> 1 raise Exception Exception: In [2]: %debug > <ipython-input-1-fca2ab0ca76b>(1)<module>() -1 raise Exception ipdb> l ----> 1 raise Exception ipdb> l ipdb> l Those last two list commands return nothing, just as the OP says.Enact
B
4

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.

Binate answered 17/6, 2013 at 2:40 Comment(3)
Thanks falsetru. Do you know what is the reasoning behind this? And is there any way to have a single alias that always shows the context around the current line. Having to look up the line with where and then typing l lineno is fine, but definitely not as easy as just typing just lHomager
reasoning: reading code below current line is more common.. (guess). I don't know any alias for where + l lineno. You can issue u, d, l commands consecutively. It's easier than where,l <lineno>, but does not work in top-most function.Binate
I observe that there rather than anyone suggesting fixing up pdb, workarounds are instead suggested. In the trepan3k and trepan2 debuggers, you can write an alias say 'u;d;l' for this, although existing commands to support this and could be extended more easily, if desired. As for pudb, I'll also mention that for GNU Emacs users there is a frontend to all of these debuggers: realgudMahone
M
1

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".

Mahone answered 3/7, 2015 at 2:18 Comment(1)
Scrolling is not always an option as printing a big object might take the previous output out of the scrollable area.Mccray
N
0

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

(pdb) l .

Nelan answered 9/2, 2023 at 9:30 Comment(3)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Environmentalist
It is not clear how this command answers the question. Please add more explanation, provide an example or link to the documentation.Belligerency
@AzharKhan The question describes wanting the l command in pdb to show the lines around the current breakpoint, and asks "how can I have it behave consistently as the first time". I provided the command that does that with an explanation. In this case I don't see how to be much clearer.Nelan

© 2022 - 2024 — McMap. All rights reserved.