在 pdb 中如何重置 list (l) 命令行计数?
来自 PDB
(Pdb) help l
l(ist) [first [,last]]
List source code for the current file.
Without arguments, list 11 lines around the current line
or continue the previous listing.
With one argument, list 11 lines starting at that line.
With two arguments, list the given range;
if the second argument is less than the first, it is a count.
“继续之前的列表”功能确实很好,但是如何关闭它呢?
From PDB
(Pdb) help l
l(ist) [first [,last]]
List source code for the current file.
Without arguments, list 11 lines around the current line
or continue the previous listing.
With one argument, list 11 lines starting at that line.
With two arguments, list the given range;
if the second argument is less than the first, it is a count.
The "continue the previous listing" feature is really nice, but how do you turn it off?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
迟到了,但希望仍然有帮助。在 pdb 中,创建以下别名(您可以将其添加到 .pdbrc 文件中,以便它始终可用):
然后,每当您键入
ll
时,pdb 都会从当前位置开始列出。它的工作原理是向上移动堆栈,然后向下移动堆栈,这会重置“l”以从当前位置开始显示。 (如果您位于堆栈跟踪的顶部,这将不起作用。)Late but hopefully still helpful. In pdb, make the following alias (which you can add to your .pdbrc file so it's always available):
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.)尝试这个。
(pdb) l .
也许您可以随时键入点。
附注
您可以考虑使用 pudb。对于 pdb 来说,这是一个很好的 UI,就像 gdbtui 之于 gdb 一样。
Try this.
(pdb) l .
Maybe you can always type the dot.
ps.
You may consider to use pudb. This is a nice UI to pdb what gdbtui is to gdb.
如果您使用 epdb 而不是 pdb,则可以使用“l”像在 pdb 中一样前进,但然后是“l”。返回到当前行号,“l-”向后浏览文件。您还可以使用until # 继续直到给定的行。 Epdb 还提供了许多其他的优点。需要远程调试吗?尝试使用
serve()
而不是set_trace()
,然后 telnet 输入(端口 8080 是默认端口)。If you use epdb instead of pdb, you can use "l" to go forward like in pdb, but then "l." goes back to the current line number, and "l-" goes backwards through the file. You can also use until # to continue until a given line. Epdb offers a bunch of other niceties too. Need to debug remotely? Try
serve()
instead ofset_trace()
and then telnet in (port 8080 is the default port).我认为没有办法将其关闭。有一次我去查看 pdb 源代码以查看是否存在未记录的语法,但我没有找到任何内容,这让我很恼火。
确实需要有一种语法来表示“列出当前执行指针附近的行”。
I don't think there is a way to turn it off. It's annoyed me enough that once I went looking in the pdb source to see if there was an undocumented syntax, but I didn't find any.
There really needs to be a syntax that means, "List the lines near the current execution pointer."
您可以猴子补丁它以获得您想要的行为。例如,下面是一个完整的脚本,它将“reset_list”或“rl”命令添加到 pdb:
可以想象,可以对标准
list
命令进行猴子修补,以不保留 lineno 历史记录。编辑:这是这样一个补丁:
You could monkey patch it for the behavior you want. For example, here is a full script which adds a "reset_list" or "rl" command to pdb:
One could conceivably monkey patch the standard
list
command to not retain the lineno history.edit: And here is such a patch: