在 pdb 中如何重置 list (l) 命令行计数?

发布于 2024-08-02 05:18:54 字数 412 浏览 4 评论 0原文

来自 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

琴流音 2024-08-09 05:18:54

迟到了,但希望仍然有帮助。在 pdb 中,创建以下别名(您可以将其添加到 .pdbrc 文件中,以便它始终可用):

alias ll u;;d;;l

然后,每当您键入 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):

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

如此安好 2024-08-09 05:18:54

尝试这个。

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

云淡风轻 2024-08-09 05:18:54

如果您使用 epdb 而不是 pdb,则可以使用“l”像在 pdb 中一样前进,但然后是“l”。返回到当前行号,“l-”向后浏览文件。您还可以使用until # 继续直到给定的行。 Epdb 还提供了许多其他的优点。需要远程调试吗?尝试使用 serve() 而不是 set_trace(),然后 telnet 输入(端口 8080 是默认端口)。

import epdb
epdb.serve()

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 of set_trace() and then telnet in (port 8080 is the default port).

import epdb
epdb.serve()
未央 2024-08-09 05:18:54

我认为没有办法将其关闭。有一次我去查看 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."

蓝颜夕 2024-08-09 05:18:54

您可以猴子补丁它以获得您想要的行为。例如,下面是一个完整的脚本,它将“reset_list”或“rl”命令添加到 pdb:

import pdb

def Pdb_reset_list(self, arg):
    self.lineno = None
    print >>self.stdout, "Reset list position."
pdb.Pdb.do_reset = Pdb_reset_list
pdb.Pdb.do_rl = Pdb_reset_list

a = 1
b = 2

pdb.set_trace()

print a, b

可以想象,可以对标准 list 命令进行猴子修补,以不保留 lineno 历史记录。

编辑:这是这样一个补丁:

import pdb
Pdb = pdb.Pdb

Pdb._do_list = Pdb.do_list
def pdb_list_wrapper(self, arg):
    if arg.strip().lower() in ('r', 'reset', 'c', 'current'):
        self.lineno = None
        arg = ''
    self._do_list(arg)
Pdb.do_list = Pdb.do_l = pdb_list_wrapper

a = 1
b = 2

pdb.set_trace()

print a, b

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:

import pdb

def Pdb_reset_list(self, arg):
    self.lineno = None
    print >>self.stdout, "Reset list position."
pdb.Pdb.do_reset = Pdb_reset_list
pdb.Pdb.do_rl = Pdb_reset_list

a = 1
b = 2

pdb.set_trace()

print a, b

One could conceivably monkey patch the standard list command to not retain the lineno history.

edit: And here is such a patch:

import pdb
Pdb = pdb.Pdb

Pdb._do_list = Pdb.do_list
def pdb_list_wrapper(self, arg):
    if arg.strip().lower() in ('r', 'reset', 'c', 'current'):
        self.lineno = None
        arg = ''
    self._do_list(arg)
Pdb.do_list = Pdb.do_l = pdb_list_wrapper

a = 1
b = 2

pdb.set_trace()

print a, b
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文