[英]Interactively watch code in python debugger pdb
Is is possible to watch the code being executed line by line interactively in python debugger pdb
? 是否可以在python调试器pdb
以交互方式逐行查看正在执行的代码?
For example in gdb
one can press ^x + ^a and it brings up a code window. 例如,在gdb
可以按^ x + ^ a并显示代码窗口。
I know I can see a bit of code using list
but is there a gdb
like option? 我知道我可以看到使用list
的一些代码但是有一个类似gdb
选项吗?
Not out of the box, but you can add Cmd.preloop()
and Cmd.precmd()
hooks of the pdb.Pdb
command subclass in a .pdbrc
file in your home directory, then drive a text editor to show the text. 未开箱的,但您可以添加Cmd.preloop()
和Cmd.precmd()
中的钩pdb.Pdb
命令子在.pdbrc
在你的主目录文件,然后开车一个文本编辑器来显示文本。
This is the approach used by the PdbSublimeTextSupport and PdbTextMateSupport packages. 这是PdbSublimeTextSupport和PdbTextMateSupport包使用的方法。
These packages simply read the current location from the Cmd
subclass; 这些包只是从Cmd
子类中读取当前位置; self.stack[self.curindex]
contains the current frame and line number, for example. self.stack[self.curindex]
包含当前帧和行号。
PdbSublimeTextSupport
does: PdbSublimeTextSupport
做:
def launch(self):
frame, lineno = self.stack[self.curindex]
filename = self.canonic(frame.f_code.co_filename)
if exists(filename):
command = 'subl -b "%s:%d"' % (filename, lineno)
os.system(command)
def preloop(self):
launch(self)
def precmd(self, line):
launch(self)
return line
and the Sublime Text editor opens filename
at line lineno
. 并且Sublime Text编辑器在line lineno
处打开filename
。
You can reference the bdb
documentation (the bedrock on which PDB is built), together with the bdb.py
and pdb.py
source code, but the above example should be enough to drive just about any method of displaying the current source code lines. 您可以引用bdb
文档 (构建PDB的基础)以及bdb.py
和pdb.py
源代码,但上面的示例应该足以驱动任何显示当前源代码行的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.