IPython Documentation

Table Of Contents

Previous topic

core.crashhandler

Next topic

core.display

This Page

core.debugger

Module: core.debugger

Inheritance diagram for IPython.core.debugger:

Pdb debugger class.

Modified from the standard pdb.Pdb class to avoid including readline, so that the command line completion of other programs which include this isn’t damaged.

In the future, this class will be expanded with improvements over the standard pdb.

The code in this file is mainly lifted out of cmd.py in Python 2.2, with minor changes. Licensing should therefore be under the standard Python terms. For details on the PSF (Python Software Foundation) standard license, see:

http://www.python.org/2.2.3/license.html

Classes

Pdb

class IPython.core.debugger.Pdb(color_scheme='NoColor', completekey=None, stdin=None, stdout=None)

Bases: pdb.Pdb

Modified Pdb class, does not load readline.

__init__(color_scheme='NoColor', completekey=None, stdin=None, stdout=None)
bp_commands(frame)

Call every command that was set for the current active breakpoint (if there is one) Returns True if the normal interaction function must be called, False otherwise

break_anywhere(frame)
break_here(frame)
canonic(filename)
checkline(filename, lineno)

Check whether specified line seems to be executable.

Return lineno if it is, 0 if not (e.g. a docstring, comment, blank line or EOF). Warning: testing is not comprehensive.

clear_all_breaks()
clear_all_file_breaks(filename)
clear_bpbynumber(arg)
clear_break(filename, lineno)
cmdloop(intro=None)

Repeatedly issue a prompt, accept input, parse an initial prefix off the received input, and dispatch to action methods, passing them the remainder of the line as argument.

columnize(list, displaywidth=80)

Display a list of strings as a compact set of columns.

Each column is only as wide as necessary. Columns are separated by two spaces (one was not legible enough).

commands_resuming = ['do_continue', 'do_step', 'do_next', 'do_return', 'do_quit', 'do_jump']
complete(text, state)

Return the next possible completion for ‘text’.

If a command has not been entered, then complete against command list. Otherwise try to call complete_<command> to get list of completions.

complete_help(*args)
completedefault(*ignored)

Method called to complete an input line when no command-specific complete_*() method is available.

By default, it returns an empty list.

completenames(text, *ignored)
default(line)
defaultFile()

Produce a reasonable default.

dispatch_call(frame, arg)
dispatch_exception(frame, arg)
dispatch_line(frame)
dispatch_return(frame, arg)
displayhook(obj)

Custom displayhook for the exec in default(), which prevents assignment of the _ variable in the builtins.

do_EOF(arg)
do_a(arg)
do_alias(arg)
do_args(arg)
do_b(arg, temporary=0)
do_break(arg, temporary=0)
do_bt(arg)
do_c(arg)
do_cl(arg)

Three possibilities, tried in this order: clear -> clear all breaks, ask for confirmation clear file:lineno -> clear all breaks at file:lineno clear bpno bpno ... -> clear breakpoints by number

do_clear(arg)

Three possibilities, tried in this order: clear -> clear all breaks, ask for confirmation clear file:lineno -> clear all breaks at file:lineno clear bpno bpno ... -> clear breakpoints by number

do_commands(arg)

Defines a list of commands associated to a breakpoint Those commands will be executed whenever the breakpoint causes the program to stop execution.

do_condition(arg)
do_cont(arg)
do_continue(arg)
do_d(*args, **kw)
do_debug(arg)
do_disable(arg)
do_down(*args, **kw)
do_enable(arg)
do_exit(arg)
do_h(arg)
do_help(arg)
do_ignore(arg)

arg is bp number followed by ignore count.

do_j(arg)
do_jump(arg)
do_l(arg)
do_list(arg)
do_n(arg)
do_next(arg)
do_p(arg)
do_pdef(arg)

The debugger interface to magic_pdef

do_pdoc(arg)

The debugger interface to magic_pdoc

do_pinfo(arg)

The debugger equivalant of ?obj

do_pp(arg)
do_q(*args, **kw)
do_quit(*args, **kw)
do_r(arg)
do_restart(arg)

Restart program by raising an exception to be caught in the main debugger loop. If arguments were given, set them in sys.argv.

do_return(arg)
do_retval(arg)
do_run(arg)

Restart program by raising an exception to be caught in the main debugger loop. If arguments were given, set them in sys.argv.

do_rv(arg)
do_s(arg)
do_step(arg)
do_tbreak(arg)
do_u(*args, **kw)
do_unalias(arg)
do_unt(arg)
do_until(arg)
do_up(*args, **kw)
do_w(arg)
do_whatis(arg)
do_where(arg)
doc_header = 'Documented commands (type help <topic>):'
doc_leader = ''
emptyline()

Called when an empty line is entered in response to the prompt.

If this method is not overridden, it repeats the last nonempty command entered.

execRcLines()
forget()
format_stack_entry(frame_lineno, lprefix=': ', context=3)
get_all_breaks()
get_break(filename, lineno)
get_breaks(filename, lineno)
get_file_breaks(filename)
get_names()
get_stack(f, t)
handle_command_def(line)

Handles one command line during command list definition.

help_EOF()
help_a()
help_alias()
help_args()
help_b()
help_break()
help_bt()
help_c()
help_cl()
help_clear()
help_commands()
help_condition()
help_cont()
help_continue()
help_d()
help_debug()
help_disable()
help_down()
help_enable()
help_exec()
help_exit()
help_h()
help_help()
help_ignore()
help_j()
help_jump()
help_l()
help_list()
help_n()
help_next()
help_p()
help_pdb()
help_pp()
help_q()
help_quit()
help_r()
help_restart()
help_return()
help_run()
help_s()
help_step()
help_tbreak()
help_u()
help_unalias()
help_unt()
help_until()
help_up()
help_w()
help_whatis()
help_where()
identchars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'
interaction(frame, traceback)
intro = None
lastcmd = ''
lineinfo(identifier)
list_command_pydb(arg)

List command to use if we have a newer pydb installed

lookupmodule(filename)

Helper function for break/clear parsing – may be overridden.

lookupmodule() translates (possibly incomplete) file or module name into an absolute file name.

misc_header = 'Miscellaneous help topics:'
new_do_down(arg)
new_do_frame(arg)
new_do_quit(arg)
new_do_restart(arg)

Restart command. In the context of ipython this is exactly the same thing as ‘quit’.

new_do_up(arg)
nohelp = '*** No help on %s'
onecmd(line)

Interpret the argument as though it had been typed in response to the prompt.

Checks whether this line is typed at the normal prompt or in a breakpoint command list definition.

parseline(line)

Parse the line into a command name and a string containing the arguments. Returns a tuple containing (command, args, line). ‘command’ and ‘args’ may be None if the line couldn’t be parsed.

postcmd(stop, line)

Hook method executed just after a command dispatch is finished.

postloop()
precmd(line)

Handle alias expansion and ‘;;’ separator.

preloop()

Hook method executed once when the cmdloop() method is called.

print_list_lines(filename, first, last)

The printing (as opposed to the parsing part of a ‘list’ command.

print_stack_entry(frame_lineno, prompt_prefix='n-> ', context=3)
print_stack_trace()
print_topics(header, cmds, cmdlen, maxcol)
prompt = '(Cmd) '
reset()
ruler = '='
run(cmd, globals=None, locals=None)
runcall(func, *args, **kwds)
runctx(cmd, globals, locals)
runeval(expr, globals=None, locals=None)
set_break(filename, lineno, temporary=0, cond=None, funcname=None)
set_colors(scheme)

Shorthand access to the color table scheme selector method.

set_continue()
set_next(frame)

Stop on the next line in or below the given frame.

set_quit()
set_return(frame)

Stop when returning from the given frame.

set_step()

Stop after one line of code.

set_trace(frame=None)

Start debugging from frame.

If frame is not specified, debugging starts from caller’s frame.

set_until(frame)

Stop when the line with the line no greater than the current one is reached or when returning from current frame

setup(f, t)
stop_here(frame)
trace_dispatch(frame, event, arg)
undoc_header = 'Undocumented commands:'
use_rawinput = 1
user_call(frame, argument_list)

This method is called when there is the remote possibility that we ever need to stop in this function.

user_exception(frame, exc_info)

This function is called if an exception occurs, but only if we are to stop at or just below this level.

user_line(frame)

This function is called when we stop or break at this line.

user_return(frame, return_value)

This function is called when a return trap is set here.

Tracer

class IPython.core.debugger.Tracer(colors=None)

Bases: object

Class for local debugging, similar to pdb.set_trace.

Instances of this class, when called, behave like pdb.set_trace, but providing IPython’s enhanced capabilities.

This is implemented as a class which must be initialized in your own code and not as a standalone function because we need to detect at runtime whether IPython is already active or not. That detection is done in the constructor, ensuring that this code plays nicely with a running IPython, while functioning acceptably (though with limitations) if outside of it.

__init__(colors=None)

Create a local debugger instance.

Parameters :
  • colors (None): a string containing the name of the color scheme to

use, it must be one of IPython’s valid color schemes. If not given, the function will default to the current IPython scheme when running inside IPython, and to ‘NoColor’ otherwise.

Usage example:

from IPython.core.debugger import Tracer; debug_here = Tracer()

... later in your code debug_here() # -> will open up the debugger at that point.

Once the debugger activates, you can use all of its regular commands to step through code, set breakpoints, etc. See the pdb documentation from the Python standard library for usage details.

Functions

IPython.core.debugger.BdbQuit_IPython_excepthook(self, et, ev, tb)
IPython.core.debugger.BdbQuit_excepthook(et, ev, tb)
IPython.core.debugger.decorate_fn_with_doc(new_fn, old_fn, additional_text='')

Make new_fn have old_fn’s doc string. This is particularly useful for the do_... commands that hook into the help system. Adapted from from a comp.lang.python posting by Duncan Booth.