Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python(pdb)-将要执行的命令排队_Python_Debugging_Pdb - Fatal编程技术网

Python(pdb)-将要执行的命令排队

Python(pdb)-将要执行的命令排队,python,debugging,pdb,Python,Debugging,Pdb,我正在实现一个用于Python开发的“断点”系统,它允许我调用一个函数,该函数本质上调用pdb.set_trace() 我想要实现的一些功能要求我在set_跟踪上下文中从代码控制pdb 例如: disableList = [] def breakpoint(name=None): def d(): disableList.append(name) #**** #issue 'run' command to pdb so user

我正在实现一个用于Python开发的“断点”系统,它允许我调用一个函数,该函数本质上调用pdb.set_trace()

我想要实现的一些功能要求我在set_跟踪上下文中从代码控制pdb

例如:

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();
在上面的示例中,如何实现由
#**
标记的注释


在该系统的其他部分中,我希望在不离开pdb会话的情况下发出一个“up”命令,或两个连续的“up”命令(因此用户在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
模块的文档,也可以在此处找到
bdb
低级调试接口的文档:。您可能还想看看他们的源代码