python中pdb的中断控制

520次阅读
没有评论

python中pdb的中断控制

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电脑。

神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2022-07-03发表,共计1098字。
新手QQ群:570568346,欢迎进群讨论 Python51学习
天启|企业级代理IP免费测试>>>>>>>>神龙|纯净稳定代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试