Commit ed6b98b2 authored by Georg Brandl's avatar Georg Brandl

Convert bdb.rst line endings to Unix style.

parent e5e79849
:mod:`bdb` --- Debugger framework :mod:`bdb` --- Debugger framework
================================= =================================
.. module:: bdb .. module:: bdb
:synopsis: Debugger framework. :synopsis: Debugger framework.
The :mod:`bdb` module handles basic debugger functions, like setting breakpoints The :mod:`bdb` module handles basic debugger functions, like setting breakpoints
or managing execution via the debugger. or managing execution via the debugger.
The following exception is defined: The following exception is defined:
.. exception:: BdbQuit .. exception:: BdbQuit
Exception raised by the :class:`Bdb` class for quitting the debugger. Exception raised by the :class:`Bdb` class for quitting the debugger.
The :mod:`bdb` module also defines two classes: The :mod:`bdb` module also defines two classes:
.. class:: Breakpoint(self, file, line[, temporary=0[, cond=None [, funcname=None]]]) .. class:: Breakpoint(self, file, line[, temporary=0[, cond=None [, funcname=None]]])
This class implements temporary breakpoints, ignore counts, disabling and This class implements temporary breakpoints, ignore counts, disabling and
(re-)enabling, and conditionals. (re-)enabling, and conditionals.
Breakpoints are indexed by number through a list called :attr:`bpbynumber` Breakpoints are indexed by number through a list called :attr:`bpbynumber`
and by ``(file, line)`` pairs through :attr:`bplist`. The former points to a and by ``(file, line)`` pairs through :attr:`bplist`. The former points to a
single instance of class :class:`Breakpoint`. The latter points to a list of single instance of class :class:`Breakpoint`. The latter points to a list of
such instances since there may be more than one breakpoint per line. such instances since there may be more than one breakpoint per line.
When creating a breakpoint, its associated filename should be in canonical When creating a breakpoint, its associated filename should be in canonical
form. If a *funcname* is defined, a breakpoint hit will be counted when the form. If a *funcname* is defined, a breakpoint hit will be counted when the
first line of that function is executed. A conditional breakpoint always first line of that function is executed. A conditional breakpoint always
counts a hit. counts a hit.
:class:`Breakpoint` instances have the following methods: :class:`Breakpoint` instances have the following methods:
.. method:: Breakpoint.deleteMe() .. method:: Breakpoint.deleteMe()
Delete the breakpoint from the list associated to a file/line. If it is the 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 last breakpoint in that position, it also deletes the entry for the
file/line. file/line.
.. method:: Breakpoint.enable() .. method:: Breakpoint.enable()
Mark the breakpoint as enabled. Mark the breakpoint as enabled.
.. method:: Breakpoint.disable() .. method:: Breakpoint.disable()
Mark the breakpoint as disabled. Mark the breakpoint as disabled.
.. method:: Breakpoint.bpprint([out]) .. method:: Breakpoint.bpprint([out])
Print all the information about the breakpoint: Print all the information about the breakpoint:
* The breakpoint number. * The breakpoint number.
* If it is temporary or not. * If it is temporary or not.
* Its file,line position. * Its file,line position.
* The condition that causes a break. * The condition that causes a break.
* If it must be ignored the next N times. * If it must be ignored the next N times.
* The breakpoint hit count. * The breakpoint hit count.
.. class:: Bdb() .. class:: Bdb()
The :class:`Bdb` acts as a generic Python debugger base class. The :class:`Bdb` acts as a generic Python debugger base class.
This class takes care of the details of the trace facility; a derived class This class takes care of the details of the trace facility; a derived class
should implement user interaction. The standard debugger class should implement user interaction. The standard debugger class
(:class:`pdb.Pdb`) is an example. (:class:`pdb.Pdb`) is an example.
The following methods of :class:`Bdb` normally don't need to be overridden. The following methods of :class:`Bdb` normally don't need to be overridden.
.. method:: Bdb.canonic(filename) .. method:: Bdb.canonic(filename)
Auxiliary method for getting a filename in a canonical form, that is, as a Auxiliary method for getting a filename in a canonical form, that is, as a
case-normalized (on case-insensitive filesystems) absolute path, stripped case-normalized (on case-insensitive filesystems) absolute path, stripped
of surrounding angle brackets. of surrounding angle brackets.
.. method:: Bdb.reset() .. method:: Bdb.reset()
Set the :attr:`botframe`, :attr:`stopframe`, :attr:`returnframe` and Set the :attr:`botframe`, :attr:`stopframe`, :attr:`returnframe` and
:attr:`quitting` attributes with values ready to start debugging. :attr:`quitting` attributes with values ready to start debugging.
.. method:: Bdb.trace_dispatch(frame, event, arg) .. method:: Bdb.trace_dispatch(frame, event, arg)
This function is installed as the trace function of debugged frames. Its 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). 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 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 type of event (passed as a string) that is about to be executed. *event* can
be one of the following: be one of the following:
* ``"line"``: A new line of code is going to be executed. * ``"line"``: A new line of code is going to be executed.
* ``"call"``: A function is about to be called, or another code block * ``"call"``: A function is about to be called, or another code block
entered. entered.
* ``"return"``: A function or other code block is about to return. * ``"return"``: A function or other code block is about to return.
* ``"exception"``: An exception has occurred. * ``"exception"``: An exception has occurred.
* ``"c_call"``: A C function is about to be called. * ``"c_call"``: A C function is about to be called.
* ``"c_return"``: A C function has returned. * ``"c_return"``: A C function has returned.
* ``"c_exception"``: A C function has thrown an exception. * ``"c_exception"``: A C function has thrown an exception.
For the Python events, specialized functions (see below) are called. For the For the Python events, specialized functions (see below) are called. For the
C events, no action is taken. C events, no action is taken.
The *arg* parameter depends on the previous event. The *arg* parameter depends on the previous event.
For more information on trace functions, see :ref:`debugger-hooks`. For more For more information on trace functions, see :ref:`debugger-hooks`. For more
information on code and frame objects, refer to :ref:`types`. information on code and frame objects, refer to :ref:`types`.
.. method:: Bdb.dispatch_line(frame) .. method:: Bdb.dispatch_line(frame)
If the debugger should stop on the current line, invoke the :meth:`user_line` If the debugger should stop on the current line, invoke the :meth:`user_line`
method (which should be overridden in subclasses). Raise a :exc:`BdbQuit` method (which should be overridden in subclasses). Raise a :exc:`BdbQuit`
exception if the :attr:`Bdb.quitting` flag is set (which can be set from exception if the :attr:`Bdb.quitting` flag is set (which can be set from
:meth:`user_line`). Return a reference to the :meth:`trace_dispatch` method :meth:`user_line`). Return a reference to the :meth:`trace_dispatch` method
for further tracing in that scope. for further tracing in that scope.
.. method:: Bdb.dispatch_call(frame, arg) .. method:: Bdb.dispatch_call(frame, arg)
If the debugger should stop on this function call, invoke the If the debugger should stop on this function call, invoke the
:meth:`user_call` method (which should be overridden in subclasses). Raise a :meth:`user_call` method (which should be overridden in subclasses). Raise a
:exc:`BdbQuit` exception if the :attr:`Bdb.quitting` flag is set (which can :exc:`BdbQuit` exception if the :attr:`Bdb.quitting` flag is set (which can
be set from :meth:`user_call`). Return a reference to the be set from :meth:`user_call`). Return a reference to the
:meth:`trace_dispatch` method for further tracing in that scope. :meth:`trace_dispatch` method for further tracing in that scope.
.. method:: Bdb.dispatch_return(frame, arg) .. method:: Bdb.dispatch_return(frame, arg)
If the debugger should stop on this function return, invoke the If the debugger should stop on this function return, invoke the
:meth:`user_return` method (which should be overridden in subclasses). Raise :meth:`user_return` method (which should be overridden in subclasses). Raise
a :exc:`BdbQuit` exception if the :attr:`Bdb.quitting` flag is set (which can a :exc:`BdbQuit` exception if the :attr:`Bdb.quitting` flag is set (which can
be set from :meth:`user_return`). Return a reference to the be set from :meth:`user_return`). Return a reference to the
:meth:`trace_dispatch` method for further tracing in that scope. :meth:`trace_dispatch` method for further tracing in that scope.
.. method:: Bdb.dispatch_exception(frame, arg) .. method:: Bdb.dispatch_exception(frame, arg)
If the debugger should stop at this exception, invokes the If the debugger should stop at this exception, invokes the
:meth:`user_exception` method (which should be overridden in subclasses). :meth:`user_exception` method (which should be overridden in subclasses).
Raise a :exc:`BdbQuit` exception if the :attr:`Bdb.quitting` flag is set Raise a :exc:`BdbQuit` exception if the :attr:`Bdb.quitting` flag is set
(which can be set from :meth:`user_exception`). Return a reference to the (which can be set from :meth:`user_exception`). Return a reference to the
:meth:`trace_dispatch` method for further tracing in that scope. :meth:`trace_dispatch` method for further tracing in that scope.
Normally derived classes don't override the following methods, but they may if Normally derived classes don't override the following methods, but they may if
they want to redefine the definition of stopping and breakpoints. they want to redefine the definition of stopping and breakpoints.
.. method:: Bdb.stop_here(frame) .. method:: Bdb.stop_here(frame)
This method checks if the *frame* is somewhere below :attr:`botframe` in the This method checks if the *frame* is somewhere below :attr:`botframe` in the
call stack. :attr:`botframe` is the frame in which debugging started. call stack. :attr:`botframe` is the frame in which debugging started.
.. method:: Bdb.break_here(frame) .. method:: Bdb.break_here(frame)
This method checks if there is a breakpoint in the filename and line This method checks if there is a breakpoint in the filename and line
belonging to *frame* or, at least, in the current function. If the belonging to *frame* or, at least, in the current function. If the
breakpoint is a temporary one, this method deletes it. breakpoint is a temporary one, this method deletes it.
.. method:: Bdb.break_anywhere(frame) .. method:: Bdb.break_anywhere(frame)
This method checks if there is a breakpoint in the filename of the current This method checks if there is a breakpoint in the filename of the current
frame. frame.
Derived classes should override these methods to gain control over debugger Derived classes should override these methods to gain control over debugger
operation. operation.
.. method:: Bdb.user_call(frame, argument_list) .. method:: Bdb.user_call(frame, argument_list)
This method is called from :meth:`dispatch_call` when there is the This method is called from :meth:`dispatch_call` when there is the
possibility that a break might be necessary anywhere inside the called possibility that a break might be necessary anywhere inside the called
function. function.
.. method:: Bdb.user_line(frame) .. method:: Bdb.user_line(frame)
This method is called from :meth:`dispatch_line` when either This method is called from :meth:`dispatch_line` when either
:meth:`stop_here` or :meth:`break_here` yields True. :meth:`stop_here` or :meth:`break_here` yields True.
.. method:: Bdb.user_return(frame, return_value) .. method:: Bdb.user_return(frame, return_value)
This method is called from :meth:`dispatch_return` when :meth:`stop_here` This method is called from :meth:`dispatch_return` when :meth:`stop_here`
yields True. yields True.
.. method:: Bdb.user_exception(frame, exc_info) .. method:: Bdb.user_exception(frame, exc_info)
This method is called from :meth:`dispatch_exception` when :meth:`stop_here` This method is called from :meth:`dispatch_exception` when :meth:`stop_here`
yields True. yields True.
.. method:: Bdb.do_clear(arg) .. method:: Bdb.do_clear(arg)
Handle how a breakpoint must be removed when it is a temporary one. Handle how a breakpoint must be removed when it is a temporary one.
This method must be implemented by derived classes. This method must be implemented by derived classes.
Derived classes and clients can call the following methods to affect the Derived classes and clients can call the following methods to affect the
stepping state. stepping state.
.. method:: Bdb.set_step() .. method:: Bdb.set_step()
Stop after one line of code. Stop after one line of code.
.. method:: Bdb.set_next(frame) .. method:: Bdb.set_next(frame)
Stop on the next line in or below the given frame. Stop on the next line in or below the given frame.
.. method:: Bdb.set_return(frame) .. method:: Bdb.set_return(frame)
Stop when returning from the given frame. Stop when returning from the given frame.
.. method:: Bdb.set_trace([frame]) .. method:: Bdb.set_trace([frame])
Start debugging from *frame*. If *frame* is not specified, debugging starts Start debugging from *frame*. If *frame* is not specified, debugging starts
from caller's frame. from caller's frame.
.. method:: Bdb.set_continue() .. method:: Bdb.set_continue()
Stop only at breakpoints or when finished. If there are no breakpoints, set Stop only at breakpoints or when finished. If there are no breakpoints, set
the system trace function to None. the system trace function to None.
.. method:: Bdb.set_quit() .. method:: Bdb.set_quit()
Set the :attr:`quitting` attribute to True. This raises :exc:`BdbQuit` in Set the :attr:`quitting` attribute to True. This raises :exc:`BdbQuit` in
the next call to one of the :meth:`dispatch_\*` methods. the next call to one of the :meth:`dispatch_\*` methods.
Derived classes and clients can call the following methods to manipulate Derived classes and clients can call the following methods to manipulate
breakpoints. These methods return a string containing an error message if breakpoints. These methods return a string containing an error message if
something went wrong, or ``None`` if all is well. something went wrong, or ``None`` if all is well.
.. method:: Bdb.set_break(filename, lineno[, temporary=0[, cond[, funcname]]]) .. method:: Bdb.set_break(filename, lineno[, temporary=0[, cond[, funcname]]])
Set a new breakpoint. If the *lineno* line doesn't exist for the *filename* Set a new breakpoint. If the *lineno* line doesn't exist for the *filename*
passed as argument, return an error message. The *filename* should be in passed as argument, return an error message. The *filename* should be in
canonical form, as described in the :meth:`canonic` method. canonical form, as described in the :meth:`canonic` method.
.. method:: Bdb.clear_break(filename, lineno) .. method:: Bdb.clear_break(filename, lineno)
Delete the breakpoints in *filename* and *lineno*. If none were set, an Delete the breakpoints in *filename* and *lineno*. If none were set, an
error message is returned. error message is returned.
.. method:: Bdb.clear_bpbynumber(arg) .. method:: Bdb.clear_bpbynumber(arg)
Delete the breakpoint which has the index *arg* in the Delete the breakpoint which has the index *arg* in the
:attr:`Breakpoint.bpbynumber`. If `arg` is not numeric or out of range, :attr:`Breakpoint.bpbynumber`. If `arg` is not numeric or out of range,
return an error message. return an error message.
.. method:: Bdb.clear_all_file_breaks(filename) .. method:: Bdb.clear_all_file_breaks(filename)
Delete all breakpoints in *filename*. If none were set, an error message is Delete all breakpoints in *filename*. If none were set, an error message is
returned. returned.
.. method:: Bdb.clear_all_breaks() .. method:: Bdb.clear_all_breaks()
Delete all existing breakpoints. Delete all existing breakpoints.
.. method:: Bdb.get_break(filename, lineno) .. method:: Bdb.get_break(filename, lineno)
Check if there is a breakpoint for *lineno* of *filename*. Check if there is a breakpoint for *lineno* of *filename*.
.. method:: Bdb.get_breaks(filename, lineno) .. method:: Bdb.get_breaks(filename, lineno)
Return all breakpoints for *lineno* in *filename*, or an empty list if none Return all breakpoints for *lineno* in *filename*, or an empty list if none
are set. are set.
.. method:: Bdb.get_file_breaks(filename) .. method:: Bdb.get_file_breaks(filename)
Return all breakpoints in *filename*, or an empty list if none are set. Return all breakpoints in *filename*, or an empty list if none are set.
.. method:: Bdb.get_all_breaks() .. method:: Bdb.get_all_breaks()
Return all breakpoints that are set. Return all breakpoints that are set.
Derived classes and clients can call the following methods to get a data Derived classes and clients can call the following methods to get a data
structure representing a stack trace. structure representing a stack trace.
.. method:: Bdb.get_stack(f, t) .. method:: Bdb.get_stack(f, t)
Get a list of records for a frame and all higher (calling) and lower frames, Get a list of records for a frame and all higher (calling) and lower frames,
and the size of the higher part. and the size of the higher part.
.. method:: Bdb.format_stack_entry(frame_lineno, [lprefix=': ']) .. method:: Bdb.format_stack_entry(frame_lineno, [lprefix=': '])
Return a string with information about a stack entry, identified by a Return a string with information about a stack entry, identified by a
``(frame, lineno)`` tuple: ``(frame, lineno)`` tuple:
* The canonical form of the filename which contains the frame. * The canonical form of the filename which contains the frame.
* The function name, or ``"<lambda>"``. * The function name, or ``"<lambda>"``.
* The input arguments. * The input arguments.
* The return value. * The return value.
* The line of code (if it exists). * The line of code (if it exists).
The following two methods can be called by clients to use a debugger to debug a The following two methods can be called by clients to use a debugger to debug a
statement, given as a string. statement, given as a string.
.. method:: Bdb.run(cmd, [globals, [locals]]) .. method:: Bdb.run(cmd, [globals, [locals]])
Debug a statement executed via the :keyword:`exec` statement. *globals* Debug a statement executed via the :keyword:`exec` statement. *globals*
defaults to :attr:`__main__.__dict__`, *locals* defaults to *globals*. defaults to :attr:`__main__.__dict__`, *locals* defaults to *globals*.
.. method:: Bdb.runeval(expr, [globals, [locals]]) .. method:: Bdb.runeval(expr, [globals, [locals]])
Debug an expression executed via the :func:`eval` function. *globals* and Debug an expression executed via the :func:`eval` function. *globals* and
*locals* have the same meaning as in :meth:`run`. *locals* have the same meaning as in :meth:`run`.
.. method:: Bdb.runctx(cmd, globals, locals) .. method:: Bdb.runctx(cmd, globals, locals)
For backwards compatibility. Calls the :meth:`run` method. For backwards compatibility. Calls the :meth:`run` method.
.. method:: Bdb.runcall(func, *args, **kwds) .. method:: Bdb.runcall(func, *args, **kwds)
Debug a single function call, and return its result. Debug a single function call, and return its result.
Finally, the module defines the following functions: Finally, the module defines the following functions:
.. function:: checkfuncname(b, frame) .. function:: checkfuncname(b, frame)
Check whether we should break here, depending on the way the breakpoint *b* Check whether we should break here, depending on the way the breakpoint *b*
was set. was set.
If it was set via line number, it checks if ``b.line`` is the same as the one If it was set via line number, it checks if ``b.line`` is the same as the one
in the frame also passed as argument. If the breakpoint was set via function in the frame also passed as argument. If the breakpoint was set via function
name, we have to check we are in the right frame (the right function) and if name, we have to check we are in the right frame (the right function) and if
we are in its first executable line. we are in its first executable line.
.. function:: effective(file, line, frame) .. function:: effective(file, line, frame)
Determine if there is an effective (active) breakpoint at this line of code. Determine if there is an effective (active) breakpoint at this line of code.
Return breakpoint number or 0 if none. Return breakpoint number or 0 if none.
Called only if we know there is a breakpoint at this location. Returns the Called only if we know there is a breakpoint at this location. Returns the
breakpoint that was triggered and a flag that indicates if it is ok to delete breakpoint that was triggered and a flag that indicates if it is ok to delete
a temporary breakpoint. a temporary breakpoint.
.. function:: set_trace() .. function:: set_trace()
Starts debugging with a :class:`Bdb` instance from caller's frame. Starts debugging with a :class:`Bdb` instance from caller's frame.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment