【问题标题】:Python (pdb) - Queueing up commands to executePython (pdb) - 排队执行命令
【发布时间】:2010-04-08 00:10:29
【问题描述】:

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

我想实现的一些功能需要我从代码中控制 pdb我在 set_trace 上下文中。

例子:

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();

在上面的例子中,我如何实现#****标记的cmets?

在这个系统的其他部分,我想在不离开 pdb 会话的情况下发出一个“up”命令,或两个连续的“up”命令(因此用户最终会在 pdb 提示符下,但在调用时会上升两个级别堆栈)。

【问题讨论】:

    标签: python debugging pdb


    【解决方案1】:

    您可以调用较低级别的方法来获得对调试器的更多控制:

    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/pdbbdb 低级调试接口的文档:http://docs.python.org/library/bdb。您可能还想查看他们的源代码。

    【讨论】:

      猜你喜欢
      • 2017-07-04
      • 1970-01-01
      • 2011-02-23
      • 1970-01-01
      • 2015-06-30
      • 1970-01-01
      • 1970-01-01
      • 2020-08-22
      • 2017-11-01
      相关资源
      最近更新 更多