bdb
— Debugger framework¶
Source code: Lib/bdb.py
The bdb
module handles basic debugger functions, like setting breakpoints
or managing execution via the debugger.
The following exception is defined:
The bdb
module also defines two classes:
- class bdb.Breakpoint(self, file, line, temporary=False, cond=None, funcname=None)¶
This class implements temporary breakpoints, ignore counts, disabling and (re-)enabling, and conditionals.
Breakpoints are indexed by number through a list called
bpbynumber
and by(file, line)
pairs throughbplist
. The former points to a single instance of classBreakpoint
. The latter points to a list of such instances since there may be more than one breakpoint per line.When creating a breakpoint, its associated
file name
should be in canonical form. If afuncname
is defined, a breakpointhit
will be counted when the first line of that function is executed. Aconditional
breakpoint always counts ahit
.Breakpoint
instances have the following methods:- deleteMe()¶
Delete the breakpoint from the list associated to a file/line. If it is the last breakpoint in that position, it also deletes the entry for the file/line.
- enable()¶
Mark the breakpoint as enabled.
- disable()¶
Mark the breakpoint as disabled.
- bpformat()¶
Return a string with all the information about the breakpoint, nicely formatted:
Breakpoint number.
Temporary status (del or keep).
File/line position.
Break condition.
Number of times to ignore.
Number of times hit.
Added in version 3.2.
- bpprint(out=None)¶
Print the output of
bpformat()
to the file out, or if it isNone
, to standard output.
Breakpoint
instances have the following attributes:- file¶
File name of the
Breakpoint
.
- line¶
Line number of the
Breakpoint
withinfile
.
- temporary¶
True
if aBreakpoint
at (file, line) is temporary.
- cond¶
Condition for evaluating a
Breakpoint
at (file, line).
- funcname¶
Function name that defines whether a
Breakpoint
is hit upon entering the function.
- enabled¶
True
ifBreakpoint
is enabled.
- bpbynumber¶
Numeric index for a single instance of a
Breakpoint
.
- bplist¶
Dictionary of
Breakpoint
instances indexed by (file
,line
) tuples.
- ignore¶
Number of times to ignore a
Breakpoint
.
- hits¶
Count of the number of times a
Breakpoint
has been hit.
- class bdb.Bdb(skip=None)¶
The
Bdb
class acts as a generic Python debugger base class.This class takes care of the details of the trace facility; a derived class should implement user interaction. The standard debugger class (
pdb.Pdb
) is an example.The 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.Changed in version 3.1: Added the skip parameter.
The following methods of
Bdb
normally don’t need to be overridden.- canonic(filename)¶
Return canonical form of filename.
For real file names, the canonical form is an operating-system-dependent,
case-normalized
absolute path
. A filename with angle brackets, such as"<stdin>"
generated in interactive mode, is returned unchanged.
- reset()¶
Set the
botframe
,stopframe
,returnframe
andquitting
attributes with values ready to start debugging.
- trace_dispatch(frame, event, arg)¶
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.
The arg parameter depends on the previous event.
See the documentation for
sys.settrace()
for more information on the trace function. For more information on code and frame objects, refer to The standard type hierarchy.
- dispatch_line(frame)¶
If the debugger should stop on the current line, invoke the
user_line()
method (which should be overridden in subclasses). Raise aBdbQuit
exception if thequitting
flag is set (which can be set fromuser_line()
). Return a reference to thetrace_dispatch()
method for further tracing in that scope.
- dispatch_call(frame, arg)¶
If the debugger should stop on this function call, invoke the
user_call()
method (which should be overridden in subclasses). Raise aBdbQuit
exception if thequitting
flag is set (which can be set fromuser_call()
). Return a reference to thetrace_dispatch()
method for further tracing in that scope.
- dispatch_return(frame, arg)¶
If the debugger should stop on this function return, invoke the
user_return()
method (which should be overridden in subclasses). Raise aBdbQuit
exception if thequitting
flag is set (which can be set fromuser_return()
). Return a reference to thetrace_dispatch()
method for further tracing in that scope.
- dispatch_exception(frame, arg)¶
If the debugger should stop at this exception, invokes the
user_exception()
method (which should be overridden in subclasses). Raise a