Python(pdb) - 排队执行命令 [英] Python (pdb) - Queueing up commands to execute
问题描述
我想实现的一些功能需要我从代码控制pdb,而我在一个set_trace上下文中。
示例:
disableList = []
def断点(name = None):
def d():
disableList.append(name)
#****
#issue'run'命令到pdb所以用户
#does不必键入'c'
#****
如果disableList中的名称:
返回
打印使用d()禁用断点,'c'继续
pdb.set_trace();
在上面的例子中,如何实现由# ****
?
在本系统的其他部分,我想发出一个up命令,或者两个连续的up '命令,而不用离开pdb会话(所以用户在pdb提示符处结束,但是调用堆栈上的两个级别)。
p>您可以调用较低级别的方法来获得对调试器的更多控制:
def debug():
import pdb
import sys
#设置调试器
debugger = pdb.Pdb()
debugger.reset()
#
debugger.do_where(None)#运行where命令
#调用交互式调试提示符
users_frame = sys._getframe()。f_back#frame用户调用`debug()`
debugger.interaction(users_frame,None)
如果__name__ =='__main__':
打印1
调试()
打印2
您可以找到 pdb
module here: http://docs.python .org / library / pdb 以及 bdb
底层调试界面: http://docs.python.org/library/bdb 。您可能还想查看他们的源代码。
I am implementing a "breakpoint" system for use in my Python development that will allow me to call a function that, in essence, calls pdb.set_trace();
Some of the functionality that I would like to implement requires me to control pdb from code while I am within a set_trace context.
Example:
disableList = []
def breakpoint(name=None):
def d():
disableList.append(name)
#****
#issue 'run' command to pdb so user
#does not have to type 'c'
#****
if name in disableList:
return
print "Use d() to disable breakpoint, 'c' to continue"
pdb.set_trace();
In the above example, how do I implement the comments demarked by the #****
?
In other parts of this system, I would like to issue an 'up' command, or two sequential 'up' commands without leaving the pdb session (so the user ends up at a pdb prompt but up two levels on the call stack).
You could invoke lower-level methods to get more control over the debugger:
def debug():
import pdb
import sys
# set up the debugger
debugger = pdb.Pdb()
debugger.reset()
# your custom stuff here
debugger.do_where(None) # run the "where" command
# invoke the interactive debugging prompt
users_frame = sys._getframe().f_back # frame where the user invoked `debug()`
debugger.interaction(users_frame, None)
if __name__ == '__main__':
print 1
debug()
print 2
You can find documentation for the pdb
module here: http://docs.python.org/library/pdb and for the bdb
lower-level debugging interface here: http://docs.python.org/library/bdb. You may also want to look at their source code.
这篇关于Python(pdb) - 排队执行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!