在pdb中如何重置列表(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.
这个“继续上一个列表”的功能真不错,但怎么把它关掉呢?
5 个回答
31
虽然有点晚,但希望对你有帮助。在pdb中,可以创建一个别名(你可以把它添加到你的.pdbrc文件中,这样每次都能用到):
alias ll u;;d;;l
然后每当你输入 ll
时,pdb就会从当前位置列出信息。它的工作原理是先向上查找调用记录,然后再向下查找,这样就会把'l'重置为从当前位置开始显示。(如果你在调用记录的最上面,这个方法就不管用了。)
4
你可以通过一种叫做猴子补丁的方式来实现你想要的功能。比如,这里有一个完整的脚本,它为pdb(Python调试器)添加了一个“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
命令进行猴子补丁,使它不保留行号历史记录。
补充:这里就是这样的一个补丁:
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