python中pdb的中断控制

2025-12-01 0 17,580

1、根据用户输入的调试命令,pdb在跟踪frame的每一步时都会进行中断控制,决定下一步是否中断,中断到哪一行。

2、stop_here是中断控制的主要方法。

中断控制是指在输入不同的调试命令后,代码可以执行到正确的位置,等待用户输入。例如,输入s控制台应该在下一个运行frame的代码处停止,输出c需要运行到下一个中断点。在sys.settrace的每一步跟踪中,中断控制是调试运行的核心逻辑。

实例

def stop_here(self, frame):
        # (CT) stopframe may now also be None, see dispatch_call.
        # (CT) the former test for None is therefore removed from here.
        if self.skip and 
               self.is_skipped_module(frame.f_globals.get('__name__')):
            return False
 
 
        # next
        if frame is self.stopframe:
            # stoplineno >= 0 means: stop at line >= the stoplineno
            # stoplineno -1 means: don't stop at all
            if self.stoplineno == -1:
                return False
            return frame.f_lineno >= self.stoplineno
 
 
        # step:当前只要追溯到botframe,就等待执行。
        while frame is not None and frame is not self.stopframe:
            if frame is self.botframe:
                return True
            frame = frame.f_back
        return False

以上就是python中pdb的中断控制,希望对大家有所帮助。更多Python学习指路:python基础教程

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:以上部本文内容由互联网用户自发贡献,本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。投诉邮箱:3758217903@qq.com

ZhiUp资源网 python基础 python中pdb的中断控制 https://www.zhiup.top/706.html

相关