python中pdb的中断控制

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基础教程

发表回复