
1、根据用户输入的调试命令,pdb在跟踪frame的每一步时都会中断控制,决定下一步是否中断,哪一行中断。
2、stop_here是中断控制的主要方法。
中断控制是指在输入不同的调试命令后,代码可以执行到正确的位置,等待用户输入。例如,输入S控制台应停止在下一个运行frame的代码中,输出C需要运行到下一个中断点。在sys.在settrace的每一步跟踪中,中断控制是调试操作的核心逻辑。
实例
defstop_here(self,frame):
#(CT)stopframemaynowalsobeNone,seedispatch_call.
#(CT)theformertestforNoneisthereforeremovedfromhere.
ifself.skipand\
self.is_skipped_module(frame.f_globals.get('__name__')):
returnFalse
#next
ifframeisself.stopframe:
#stoplineno>=0means:stopatline>=thestoplineno
#stoplineno-1means:don'tstopatall
ifself.stoplineno==-1:
returnFalse
returnframe.f_lineno>=self.stoplineno
#step:现在只要追溯到botframe,等待执行。
whileframeisnotNoneandframeisnotself.stopframe:
ifframeisself.botframe:
returnTrue
frame=frame.f_back
returnFalse以上是python中pdb的中断控制,希望对大家有所帮助。更多Python学习指导:python基础教程
本文教程操作环境:windows7系统Python 3.9.1,DELL G3电脑。