bdb
— 调试器框架
¶
源代码: Lib/bdb.py
bdb
模块处理基本调试器功能,像:设置断点 (或凭借调试器管理执行)。
定义了以下异常:
此类实现临时断点、忽略计数、禁用和 (重新) 启用及条件。
是通过数字索引断点透过列表称为
bpbynumber
和通过
(file, line)
对透过
bplist
。前者指向单实例化的类
Breakpoint
。后者指向这种实例的列表,由于每行可能有多个断点。
当创建断点时,关联
file name
应该是典型形式。若
funcname
有定义,断点
hit
会计数当执行该函数的第一行时。
conditional
断点始终计数
hit
.
Breakpoint
实例具有下列方法:
从文件/行关联列表删除断点。若它是该位置的最后一个断点,还会删除文件/行条目。
将断点标记为启用。
将断点标记为禁用。
返回具有断点所有有关信息的字符串,好的格式:
断点编号。
临时状态 (删除或保持)。
文件/行位置。
中断条件。
忽略次数。
命中次数。
3.2 版新增。
打印输出的
bpformat()
到文件
out
,或若它为
None
,到标准输出。
Breakpoint
实例拥有下列属性:
文件名对于
Breakpoint
.
行号对于
Breakpoint
在
file
.
True 若
Breakpoint
在 (file, line) 是临时的。
条件为估算
Breakpoint
在 (file, line)。
函数名称定义是否
Breakpoint
被命中当进入函数时。
True 若
Breakpoint
被启用。
数字索引对于单实例
Breakpoint
.
字典对于
Breakpoint
实例索引通过 (
file
,
line
) 元组。
次数为忽略
Breakpoint
.
Count of the number of times a
Breakpoint
has been hit.
Bdb
类充当一般 Python 调试器基类。
此类负责跟踪设施细节;派生类应实现用户交互。标准调试器类 (
pdb.Pdb
) 是范例。
skip
argument, if given, must be an iterable of glob-style module name patterns. The debugger will not step into frames that originate in a module that matches one of these patterns. Whether a frame is considered to originate in a certain module is determined by the
__name__
in the frame globals.
3.1 版新增: skip 自变量。
下列方法对于
Bdb
通常不需要覆写。
返回典型形式的 filename .
For real file names, the canonical form is an operating-system-dependent,
case-normalized
absolute path
。
filename
with angle brackets, such as
"<stdin>"
generated in interactive mode, is returned unchanged.
设置
botframe
,
stopframe
,
returnframe
and
quitting
属性采用准备开始调试的值。
This function is installed as the trace function of debugged frames. Its return value is the new trace function (in most cases, that is, itself).
The default implementation decides how to dispatch a frame, depending on the type of event (passed as a string) that is about to be executed. event can be one of the following:
"line"
: A new line of code is going to be executed.
"call"
: A function is about to be called, or another code block entered.
"return"
: A function or other code block is about to return.
"exception"
: An exception has occurred.
"c_call"
: A C function is about to be called.
"c_return"
: A C function has returned.
"c_exception"
: A C function has raised an exception.
For the Python events, specialized functions (see below) are called. For the C events, no action is taken.
arg 参数从属先前事件。
见文档编制为
sys.settrace()
for more information on the trace function. For more information on code and frame objects, refer to
标准类型层次结构
.
If the debugger should stop on the current line, invoke the
user_line()
方法 (应在子类中覆写)。引发
BdbQuit
异常若
Bdb.quitting
flag is set (which can be set from
user_line()
). Return a reference to the
trace_dispatch()
method for further tracing in that scope.
If the debugger should stop on this function call, invoke the
user_call()
方法 (应在子类中覆写)。引发
BdbQuit
异常若
Bdb.quitting
flag is set (which can be set from
user_call()
). Return a reference to the
trace_dispatch()
method for further tracing in that scope.
若调试器应在此函数返回时停止,援引
user_return()
方法 (应在子类中覆写)。引发
BdbQuit
异常若
Bdb.quitting
flag is set (which can be set from
user_return()
). Return a reference to the
trace_dispatch()
method for further tracing in that scope.
若调试器应在此异常处停止,援引
user_exception()
方法 (应在子类中覆写)。引发
BdbQuit
异常若
Bdb.quitting
flag is set (which can be set from
user_exception()
). Return a reference to the
trace_dispatch()
method for further tracing in that scope.
Normally derived classes don’t override the following methods, but they may if they want to redefine the definition of stopping and breakpoints.
返回 True 若 module_name 匹配任何跳过模式。
返回 True 若 frame is below the starting frame in the stack.
返回 True 若此行存在有效断点。
Check whether a line or function breakpoint exists and is in effect. Delete temporary breakpoints based on information from
effective()
.
Return True if any breakpoint exists for frame ’s filename.
派生类应该覆写这些方法,以获得对调试器操作的控制。
被调用从
dispatch_call()
若中断可能在调用函数内停止。
被调用从
dispatch_line()
当
stop_here()
or
break_here()
返回
True
.
被调用从
dispatch_return()
当
stop_here()
返回
True
.
被调用从
dispatch_exception()
当
stop_here()
返回
True
.
Handle how a breakpoint must be removed when it is a temporary one.
此方法必须由派生类实现。
Derived classes and clients can call the following methods to affect the stepping state.
停止在 1 行代码后。
Stop on the next line in or below the given frame.
Stop when returning from the given frame.
Stop when the line with the lineno greater than the current one is reached or when returning from current frame.
Start debugging from frame 。若 frame is not specified, debugging starts from caller’s frame.
Stop only at breakpoints or when finished. If there are no breakpoints, set the system trace function to
None
.
设置
quitting
属性为
True
。这引发
BdbQuit
in the next call to one of the
dispatch_*()
方法。
Derived classes and clients can call the following methods to manipulate breakpoints. These methods return a string containing an error message if something went wrong, or
None
if all is well.
设置新断点。若
lineno
line doesn’t exist for the
filename
passed as argument, return an error message. The
filename
should be in canonical form, as described in the
canonic()
方法。
Delete the breakpoints in filename and lineno 。若设为 None,返回错误消息。
Delete the breakpoint which has the index
arg
在
Breakpoint.bpbynumber
。若
arg
is not numeric or out of range, return an error message.
删除所有断点在 filename 。若设为 None,返回错误消息。
删除所有现有断点。若设为 None,返回错误消息。
Return a breakpoint specified by the given number. If
arg
is a string, it will be converted to a number. If
arg
is a non-numeric string, if the given breakpoint never existed or has been deleted, a
ValueError
被引发。
3.2 版新增。
Return True if there is a breakpoint for lineno in filename .
Return all breakpoints for lineno in filename , or an empty list if none are set.
Return all breakpoints in filename , or an empty list if none are set.
返回设置的所有断点。
Derived classes and clients can call the following methods to get a data structure representing a stack trace.
Return a list of (frame, lineno) tuples in a stack trace, and a size.
The most recently called frame is last in the list. The size is the number of frames below the frame where the debugger was invoked.
Return a string with information about a stack entry, which is a
(frame, lineno)
tuple. The return string contains:
包含帧的典型文件名。
函数名称或
"<lambda>"
.
输入自变量。
返回值。
代码行 (若它存在)。
The following two methods can be called by clients to use a debugger to debug a statement , given as a string.
调试执行语句凭借
exec()
函数。
globals
默认为
__main__.__dict__
,
locals
默认为
globals
.
Debug an expression executed via the
eval()
函数。
globals
and
locals
拥有相同含义如在
run()
.
Debug a single function call, and return its result.
Finally, the module defines the following functions:
Return True if we should break here, depending on the way the
Breakpoint
b
was set.
If it was set via line number, it checks if
b.line
is the same as the one in
frame
. If the breakpoint was set via
function name
, we have to check we are in the right
frame
(the right function) and if we are on its first executable line.
返回
(active breakpoint, delete temporary flag)
or
(None, None)
as the breakpoint to act upon.
active breakpoint
is the first entry in
bplist
for the (
file
,
line
) (which must exist) that is
enabled
, for which
checkfuncname()
is True, and that has neither a False
condition
nor positive
ignore
count. The
flag
, meaning that a temporary breakpoint should be deleted, is False only when the
cond
cannot be evaluated (in which case,
ignore
count is ignored).
If no such entry exists, then (None, None) is returned.