我正在实现一个用于 Python 开发的“断点”系统,该系统允许我调用一个函数,该函数本质上调用 pdb.set_trace();
我想要实现的一些功能需要我从代码控制 pdbwhile我在 set_trace 上下文中。
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();
在上面的例子中,我如何实现标记的注释#****
?
在该系统的其他部分,我想发出一个“up”命令,或两个连续的“up”命令,而不离开 pdb 会话(因此用户最终会出现 pdb 提示符,但在调用堆栈上上升两级)。
您可以调用较低级别的方法来更好地控制调试器:
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
您可以找到相关文档pdb
模块在这里:http://docs.python.org/library/pdb http://docs.python.org/library/pdb并为bdb
底层调试接口在这里:http://docs.python.org/library/bdb http://docs.python.org/library/bdb。您可能还想查看他们的源代码。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)