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

问题描述 投票:32回答:5

来自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.

“继续上一个上市”功能非常好,但是你怎么把它关掉?

python pdb
5个回答
4
投票

你可以monkey patch它为你想要的行为。例如,这是一个完整的脚本,它向pdb添加“reset_list”或“rl”命令:

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

25
投票

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

alias ll u;;d;;l

然后每当你输入ll时,pdb将从当前位置列出。它的工作方式是向上移动堆栈然后向下移动堆栈,重置“l”以显示当前位置。 (如果您位于堆栈跟踪的顶部,则无效。)


6
投票

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

import epdb
epdb.serve()

5
投票

我认为没有办法将其关掉。这让我感到非常恼火,一旦我查看pdb源代码,看看是否有未记录的语法,但我没有找到。

确实需要一种语法,即“列出当前执行指针附近的行”。


2
投票

试试这个。

(pdb) l .

也许你总是可以输入点。

© www.soinside.com 2019 - 2024. All rights reserved.