##// END OF EJS Templates
Correct import for kernelmanager on Windows
Correct import for kernelmanager on Windows

File last commit:

r9399:16e26cab
r9487:2eaa847c
Show More
debugger.py
566 lines | 20.0 KiB | text/x-python | PythonLexer
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 # -*- coding: utf-8 -*-
"""
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:
Fernando Perez
Remove svn-style $Id marks from docstrings and Release imports....
r1853 http://www.python.org/2.2.3/license.html"""
fperez
Small fix in ultraTB, and fix autocall....
r88
#*****************************************************************************
#
vivainio
Add license notes, closes #203
r911 # This file is licensed under the PSF license.
fperez
Small fix in ultraTB, and fix autocall....
r88 #
# Copyright (C) 2001 Python Software Foundation, www.python.org
# Copyright (C) 2005-2006 Fernando Perez. <fperez@colorado.edu>
#
#
#*****************************************************************************
Matthias BUSSONNIER
use print function in module with `print >>`
r7817 from __future__ import print_function
fperez
Small fix in ultraTB, and fix autocall....
r88
fperez
Cosmetic cleanups: put all imports in a single line, and sort them...
r52 import bdb
Bradley M. Froehle
Maintain backwards compatibility in BdbQuit_excepthook.excepthook_ori.
r8679 import functools
fperez
Cosmetic cleanups: put all imports in a single line, and sort them...
r52 import linecache
import sys
Thomas Kluyver
Fix getting unicode lines in IPython.core.debugger.
r8324 from IPython.utils import PyColorize, ulinecache
Brian Granger
ipapi.py => core/ipapi.py and imports updated.
r2027 from IPython.core import ipapi
Thomas Kluyver
Remove unused imports
r9399 from IPython.utils import coloransi, io, py3compat
Brian Granger
excolors.py => core/excolors.py and updated import statements.
r2021 from IPython.core.excolors import exception_colors
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46
vivainio
Last set of Rocky's patches for pydb integration
r393 # See if we can use pydb.
has_pydb = False
fperez
- Added patches for better pydb and Emacs support....
r552 prompt = 'ipdb> '
vivainio
Added -pydb command line switch to enable pydb, pydb is now disabled as default
r922 #We have to check this directly from sys.argv, config struct not yet available
MinRK
re-enable pydb flag...
r5004 if '--pydb' in sys.argv:
Bernardo B. Marques
remove all trailling spaces
r4872 try:
vivainio
Added -pydb command line switch to enable pydb, pydb is now disabled as default
r922 import pydb
if hasattr(pydb.pydb, "runl") and pydb.version>'1.17':
# Version 1.17 is broken, and that's what ships with Ubuntu Edgy, so we
# better protect against it.
has_pydb = True
except ImportError:
Matthias BUSSONNIER
use print function in module with `print >>`
r7817 print("Pydb (http://bashdb.sourceforge.net/pydb/) does not seem to be available")
vivainio
Last set of Rocky's patches for pydb integration
r393
if has_pydb:
from pydb import Pdb as OldPdb
vivainio
Added -pydb command line switch to enable pydb, pydb is now disabled as default
r922 #print "Using pydb for %run -d and post-mortem" #dbg
fperez
- Added patches for better pydb and Emacs support....
r552 prompt = 'ipydb> '
vivainio
Last set of Rocky's patches for pydb integration
r393 else:
from pdb import Pdb as OldPdb
fperez
Add support for set_trace-like functionality, but with IPython's enhanced...
r506 # Allow the set_trace code to operate outside of an ipython instance, even if
# it does so with some limitations. The rest of this support is implemented in
# the Tracer constructor.
Bradley M. Froehle
Maintain backwards compatibility in BdbQuit_excepthook.excepthook_ori.
r8679 def BdbQuit_excepthook(et, ev, tb, excepthook=None):
"""Exception hook which handles `BdbQuit` exceptions.
All other exceptions are processed using the `excepthook`
parameter.
"""
fperez
Add support for set_trace-like functionality, but with IPython's enhanced...
r506 if et==bdb.BdbQuit:
Matthias BUSSONNIER
use print function in module with `print >>`
r7817 print('Exiting Debugger.')
Bradley M. Froehle
Maintain backwards compatibility in BdbQuit_excepthook.excepthook_ori.
r8679 elif excepthook is not None:
excepthook(et, ev, tb)
fperez
Add support for set_trace-like functionality, but with IPython's enhanced...
r506 else:
Bradley M. Froehle
Maintain backwards compatibility in BdbQuit_excepthook.excepthook_ori.
r8679 # Backwards compatibility. Raise deprecation warning?
jdh2358
Small Debugger fix seen only when using the code outside a running ipython instance
r615 BdbQuit_excepthook.excepthook_ori(et,ev,tb)
fperez
Add support for set_trace-like functionality, but with IPython's enhanced...
r506
MinRK
protect IPython from bad custom exception handlers...
r4991 def BdbQuit_IPython_excepthook(self,et,ev,tb,tb_offset=None):
Matthias BUSSONNIER
use print function in module with `print >>`
r7817 print('Exiting Debugger.')
fperez
Add support for set_trace-like functionality, but with IPython's enhanced...
r506
Brian Granger
Fixed the %debug magic.
r2290
fperez
Add support for set_trace-like functionality, but with IPython's enhanced...
r506 class Tracer(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.
"""
def __init__(self,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:
Brian Granger
Debugger.py => core/debugger.py and updated all imports.
r2015 from IPython.core.debugger import Tracer; debug_here = Tracer()
fperez
Add support for set_trace-like functionality, but with IPython's enhanced...
r506
... 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.
"""
try:
MinRK
fix IPython check in debugger.Tracer
r5003 ip = get_ipython()
except NameError:
fperez
Add support for set_trace-like functionality, but with IPython's enhanced...
r506 # Outside of ipython, we set our own exception hook manually
Bradley M. Froehle
Maintain backwards compatibility in BdbQuit_excepthook.excepthook_ori.
r8679 sys.excepthook = functools.partial(BdbQuit_excepthook,
excepthook=sys.excepthook)
fperez
Add support for set_trace-like functionality, but with IPython's enhanced...
r506 def_colors = 'NoColor'
try:
# Limited tab completion support
Brian Granger
ColorANSI.py -> utils/coloransi.py and all imports updated.
r2010 import readline
fperez
Add support for set_trace-like functionality, but with IPython's enhanced...
r506 readline.parse_and_bind('tab: complete')
except ImportError:
pass
else:
# In ipython, we use its custom exception handler mechanism
Brian Granger
Continuing a massive refactor of everything.
r2205 def_colors = ip.colors
Brian Granger
Fixed the %debug magic.
r2290 ip.set_custom_exc((bdb.BdbQuit,), BdbQuit_IPython_excepthook)
fperez
Add support for set_trace-like functionality, but with IPython's enhanced...
r506
if colors is None:
colors = def_colors
Fernando Perez
Raise repr limit for strings to 80 characters (from 30)....
r7083
# The stdlib debugger internally uses a modified repr from the `repr`
# module, that limits the length of printed strings to a hardcoded
# limit of 30 characters. That much trimming is too aggressive, let's
# at least raise that limit to 80 chars, which should be enough for
# most interactive uses.
try:
from repr import aRepr
aRepr.maxstring = 80
except:
# This is only a user-facing convenience, so any error we encounter
# here can be warned about but can be otherwise ignored. These
DamianHeard
Fixed infinite loop on exit in the event of where multiple debuggers have been attached an there is an uncaught exception. I am in the process of submitting a similar patch for ipdb.
r8678 # printouts will tell us about problems if this API changes
Fernando Perez
Raise repr limit for strings to 80 characters (from 30)....
r7083 import traceback
traceback.print_exc()
fperez
Add support for set_trace-like functionality, but with IPython's enhanced...
r506 self.debugger = Pdb(colors)
def __call__(self):
"""Starts an interactive debugger at the point where called.
This is similar to the pdb.set_trace() function from the std lib, but
using IPython's enhanced debugger."""
Bernardo B. Marques
remove all trailling spaces
r4872
fperez
Add support for set_trace-like functionality, but with IPython's enhanced...
r506 self.debugger.set_trace(sys._getframe().f_back)
Brian Granger
Fixed the %debug magic.
r2290
vivainio
Last set of Rocky's patches for pydb integration
r393 def decorate_fn_with_doc(new_fn, old_fn, additional_text=""):
"""Make new_fn have old_fn's doc string. This is particularly useful
Thomas Kluyver
Miscellaneous docs fixes
r9244 for the ``do_...`` commands that hook into the help system.
vivainio
Last set of Rocky's patches for pydb integration
r393 Adapted from from a comp.lang.python posting
by Duncan Booth."""
def wrapper(*args, **kw):
return new_fn(*args, **kw)
if old_fn.__doc__:
wrapper.__doc__ = old_fn.__doc__ + additional_text
return wrapper
Brian Granger
Fixed the %debug magic.
r2290
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 def _file_lines(fname):
"""Return the contents of a named file as a list of lines.
This function never raises an IOError exception: if the file can't be
read, it simply returns an empty list."""
try:
outfile = open(fname)
except IOError:
return []
else:
out = outfile.readlines()
outfile.close()
return out
Brian Granger
Fixed the %debug magic.
r2290
vivainio
Last set of Rocky's patches for pydb integration
r393 class Pdb(OldPdb):
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 """Modified Pdb class, does not load readline."""
fperez
- fix missing __file__ for scripts run via %run....
r122
Brian Granger
Fixed the %debug magic.
r2290 def __init__(self,color_scheme='NoColor',completekey=None,
stdin=None, stdout=None):
fperez
Apply Ville's patch, closes #87
r367
Brian Granger
Fixed the %debug magic.
r2290 # Parent constructor:
if has_pydb and completekey is None:
MinRK
io.Term.cin/out/err replaced by io.stdin/out/err...
r3800 OldPdb.__init__(self,stdin=stdin,stdout=io.stdout)
Brian Granger
Fixed the %debug magic.
r2290 else:
OldPdb.__init__(self,completekey,stdin,stdout)
Bernardo B. Marques
remove all trailling spaces
r4872
Brian Granger
Fixed the %debug magic.
r2290 self.prompt = prompt # The default prompt is '(Pdb)'
Bernardo B. Marques
remove all trailling spaces
r4872
Brian Granger
Fixed the %debug magic.
r2290 # IPython changes...
self.is_pydb = has_pydb
fperez
Apply Ville's patch, closes #87
r367
Brian Granger
Fixed the %debug magic.
r2290 self.shell = ipapi.get()
fperez
Apply Ville's patch, closes #87
r367
Brian Granger
Fixed the %debug magic.
r2290 if self.is_pydb:
fperez
Apply Ville's patch, closes #87
r367
Brian Granger
Moving and renaming in preparation of subclassing InteractiveShell....
r2760 # interactiveshell.py's ipalias seems to want pdb's checkline
Brian Granger
Fixed the %debug magic.
r2290 # which located in pydb.fn
import pydb.fns
self.checkline = lambda filename, lineno: \
pydb.fns.checkline(self, filename, lineno)
fperez
Apply Ville's patch, closes #87
r367
Brian Granger
Fixed the %debug magic.
r2290 self.curframe = None
self.do_restart = self.new_do_restart
fperez
Apply Ville's patch, closes #87
r367
Brian Granger
Fixed the %debug magic.
r2290 self.old_all_completions = self.shell.Completer.all_completions
self.shell.Completer.all_completions=self.all_completions
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46
Brian Granger
Fixed the %debug magic.
r2290 self.do_list = decorate_fn_with_doc(self.list_command_pydb,
OldPdb.do_list)
self.do_l = self.do_list
self.do_frame = decorate_fn_with_doc(self.new_do_frame,
OldPdb.do_frame)
fperez
- R. Bernstein's patches (minor reworks) to provide full syntax highlight in...
r553
Brian Granger
Fixed the %debug magic.
r2290 self.aliases = {}
fperez
- R. Bernstein's patches (minor reworks) to provide full syntax highlight in...
r553
Brian Granger
Fixed the %debug magic.
r2290 # Create color table: we copy the default one from the traceback
# module and add a few attributes needed for debugging
self.color_scheme_table = exception_colors()
fperez
Apply Ville's patch, closes #87
r367
Bernardo B. Marques
remove all trailling spaces
r4872 # shorthands
Brian Granger
Fixed the %debug magic.
r2290 C = coloransi.TermColors
cst = self.color_scheme_table
fperez
Apply Ville's patch, closes #87
r367
Brian Granger
Fixed the %debug magic.
r2290 cst['NoColor'].colors.breakpoint_enabled = C.NoColor
cst['NoColor'].colors.breakpoint_disabled = C.NoColor
fperez
Apply Ville's patch, closes #87
r367
Brian Granger
Fixed the %debug magic.
r2290 cst['Linux'].colors.breakpoint_enabled = C.LightRed
cst['Linux'].colors.breakpoint_disabled = C.Red
fperez
Apply Ville's patch, closes #87
r367
Brian Granger
Fixed the %debug magic.
r2290 cst['LightBG'].colors.breakpoint_enabled = C.LightRed
cst['LightBG'].colors.breakpoint_disabled = C.Red
fperez
Apply Ville's patch, closes #87
r367
Brian Granger
Fixed the %debug magic.
r2290 self.set_colors(color_scheme)
fperez
Apply Ville's patch, closes #87
r367
Brian Granger
Fixed the %debug magic.
r2290 # Add a python parser so we can syntax highlight source while
# debugging.
self.parser = PyColorize.Parser()
fperez
- R. Bernstein's patches (minor reworks) to provide full syntax highlight in...
r553
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 def set_colors(self, scheme):
"""Shorthand access to the color table scheme selector method."""
self.color_scheme_table.set_active_scheme(scheme)
def interaction(self, frame, traceback):
Brian Granger
Fixed the %debug magic.
r2290 self.shell.set_completer_frame(frame)
vivainio
Last set of Rocky's patches for pydb integration
r393 OldPdb.interaction(self, frame, traceback)
def new_do_up(self, arg):
OldPdb.do_up(self, arg)
Brian Granger
Fixed the %debug magic.
r2290 self.shell.set_completer_frame(self.curframe)
vivainio
Last set of Rocky's patches for pydb integration
r393 do_u = do_up = decorate_fn_with_doc(new_do_up, OldPdb.do_up)
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46
vivainio
Last set of Rocky's patches for pydb integration
r393 def new_do_down(self, arg):
OldPdb.do_down(self, arg)
Brian Granger
Fixed the %debug magic.
r2290 self.shell.set_completer_frame(self.curframe)
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46
vivainio
Last set of Rocky's patches for pydb integration
r393 do_d = do_down = decorate_fn_with_doc(new_do_down, OldPdb.do_down)
def new_do_frame(self, arg):
OldPdb.do_frame(self, arg)
Brian Granger
Fixed the %debug magic.
r2290 self.shell.set_completer_frame(self.curframe)
vivainio
Last set of Rocky's patches for pydb integration
r393
def new_do_quit(self, arg):
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
existence of old_all_completions checked in debugger exit
r465 if hasattr(self, 'old_all_completions'):
Brian Granger
Fixed the %debug magic.
r2290 self.shell.Completer.all_completions=self.old_all_completions
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
Last set of Rocky's patches for pydb integration
r393 return OldPdb.do_quit(self, arg)
do_q = do_quit = decorate_fn_with_doc(new_do_quit, OldPdb.do_quit)
def new_do_restart(self, arg):
"""Restart command. In the context of ipython this is exactly the same
thing as 'quit'."""
self.msg("Restart doesn't make sense here. Using 'quit' instead.")
return self.do_quit(arg)
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46
def postloop(self):
Brian Granger
Fixed the %debug magic.
r2290 self.shell.set_completer_frame(None)
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46
def print_stack_trace(self):
try:
for frame_lineno in self.stack:
self.print_stack_entry(frame_lineno, context = 5)
except KeyboardInterrupt:
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 pass
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46
def print_stack_entry(self,frame_lineno,prompt_prefix='\n-> ',
context = 3):
fperez
- Added patches for better pydb and Emacs support....
r552 #frame, lineno = frame_lineno
Matthias BUSSONNIER
use print function in module with `print >>`
r7817 print(self.format_stack_entry(frame_lineno, '', context), file=io.stdout)
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46
vds
synchronize with editor patch
r1241 # vds: >>
frame, lineno = frame_lineno
filename = frame.f_code.co_filename
Brian Granger
Fixed the %debug magic.
r2290 self.shell.hooks.synchronize_with_editor(filename, lineno, 0)
vds
synchronize with editor patch
r1241 # vds: <<
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 def format_stack_entry(self, frame_lineno, lprefix=': ', context = 3):
Thomas Kluyver
Fix getting unicode lines in IPython.core.debugger.
r8324 import repr
Bernardo B. Marques
remove all trailling spaces
r4872
fperez
- set the default value of autoedit_syntax to be false. Too many complaints....
r294 ret = []
Bernardo B. Marques
remove all trailling spaces
r4872
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 Colors = self.color_scheme_table.active_colors
ColorsNormal = Colors.Normal
Thomas Kluyver
Fix for going into the debugger with non-ascii filenames.
r8327 tpl_link = u'%s%%s%s' % (Colors.filenameEm, ColorsNormal)
tpl_call = u'%s%%s%s%%s%s' % (Colors.vName, Colors.valEm, ColorsNormal)
tpl_line = u'%%s%s%%s %s%%s' % (Colors.lineno, ColorsNormal)
tpl_line_em = u'%%s%s%%s %s%%s%s' % (Colors.linenoEm, Colors.line,
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 ColorsNormal)
Bernardo B. Marques
remove all trailling spaces
r4872
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 frame, lineno = frame_lineno
Bernardo B. Marques
remove all trailling spaces
r4872
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 return_value = ''
if '__return__' in frame.f_locals:
rv = frame.f_locals['__return__']
#return_value += '->'
return_value += repr.repr(rv) + '\n'
fperez
- set the default value of autoedit_syntax to be false. Too many complaints....
r294 ret.append(return_value)
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46
#s = filename + '(' + `lineno` + ')'
filename = self.canonic(frame.f_code.co_filename)
Thomas Kluyver
Fix for going into the debugger with non-ascii filenames.
r8327 link = tpl_link % py3compat.cast_unicode(filename)
Bernardo B. Marques
remove all trailling spaces
r4872
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 if frame.f_code.co_name:
func = frame.f_code.co_name
else:
func = "<lambda>"
Bernardo B. Marques
remove all trailling spaces
r4872
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 call = ''
Bernardo B. Marques
remove all trailling spaces
r4872 if func != '?':
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 if '__args__' in frame.f_locals:
args = repr.repr(frame.f_locals['__args__'])
else:
args = '()'
call = tpl_call % (func, args)
fperez
- set the default value of autoedit_syntax to be false. Too many complaints....
r294
# The level info should be generated in the same format pdb uses, to
# avoid breaking the pdbtrack functionality of python-mode in *emacs.
fperez
- Added patches for better pydb and Emacs support....
r552 if frame is self.curframe:
ret.append('> ')
else:
ret.append(' ')
Thomas Kluyver
Fix for going into the debugger with non-ascii filenames.
r8327 ret.append(u'%s(%s)%s\n' % (link,lineno,call))
Bernardo B. Marques
remove all trailling spaces
r4872
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 start = lineno - 1 - context//2
Thomas Kluyver
Fix getting unicode lines in IPython.core.debugger.
r8324 lines = ulinecache.getlines(filename)
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 start = min(start, len(lines) - context)
tcmulcahy
Update IPython/core/debugger.py...
r8895 start = max(start, 0)
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 lines = lines[start : start + context]
Bernardo B. Marques
remove all trailling spaces
r4872
fperez
- set the default value of autoedit_syntax to be false. Too many complaints....
r294 for i,line in enumerate(lines):
show_arrow = (start + 1 + i == lineno)
fperez
- Added patches for better pydb and Emacs support....
r552 linetpl = (frame is self.curframe or show_arrow) \
and tpl_line_em \
or tpl_line
ret.append(self.__format_line(linetpl, filename,
Thomas Kluyver
Fix getting unicode lines in IPython.core.debugger.
r8324 start + 1 + i, line,
fperez
- set the default value of autoedit_syntax to be false. Too many complaints....
r294 arrow = show_arrow) )
return ''.join(ret)
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46
def __format_line(self, tpl_line, filename, lineno, line, arrow = False):
bp_mark = ""
bp_mark_color = ""
fperez
- R. Bernstein's patches (minor reworks) to provide full syntax highlight in...
r553 scheme = self.color_scheme_table.active_scheme_name
new_line, err = self.parser.format2(line, 'str', scheme)
if not err: line = new_line
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 bp = None
if lineno in self.get_file_breaks(filename):
bps = self.get_breaks(filename, lineno)
bp = bps[-1]
Bernardo B. Marques
remove all trailling spaces
r4872
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 if bp:
Colors = self.color_scheme_table.active_colors
bp_mark = str(bp.number)
bp_mark_color = Colors.breakpoint_enabled
if not bp.enabled:
bp_mark_color = Colors.breakpoint_disabled
numbers_width = 7
if arrow:
# This is the line with the error
pad = numbers_width - len(str(lineno)) - len(bp_mark)
if pad >= 3:
marker = '-'*(pad-3) + '-> '
elif pad == 2:
marker = '> '
elif pad == 1:
marker = '>'
else:
marker = ''
num = '%s%s' % (marker, str(lineno))
line = tpl_line % (bp_mark_color + bp_mark, num, line)
else:
num = '%*s' % (numbers_width - len(bp_mark), str(lineno))
line = tpl_line % (bp_mark_color + bp_mark, num, line)
Bernardo B. Marques
remove all trailling spaces
r4872
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 return line
vivainio
Last set of Rocky's patches for pydb integration
r393 def list_command_pydb(self, arg):
"""List command to use if we have a newer pydb installed"""
filename, first, last = OldPdb.parse_list_cmd(self, arg)
if filename is not None:
self.print_list_lines(filename, first, last)
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
Last set of Rocky's patches for pydb integration
r393 def print_list_lines(self, filename, first, last):
"""The printing (as opposed to the parsing part of a 'list'
command."""
try:
Colors = self.color_scheme_table.active_colors
ColorsNormal = Colors.Normal
tpl_line = '%%s%s%%s %s%%s' % (Colors.lineno, ColorsNormal)
tpl_line_em = '%%s%s%%s %s%%s%s' % (Colors.linenoEm, Colors.line, ColorsNormal)
src = []
Jörgen Stenarson
fix for list pdb listcommand, broken for %run -d...
r8317 if filename == "<string>" and hasattr(self, "_exec_filename"):
Thomas Kluyver
Fix getting unicode lines in IPython.core.debugger.
r8324 filename = self._exec_filename
DamianHeard
Fixed infinite loop on exit in the event of where multiple debuggers have been attached an there is an uncaught exception. I am in the process of submitting a similar patch for ipdb.
r8678
vivainio
Last set of Rocky's patches for pydb integration
r393 for lineno in range(first, last+1):
Thomas Kluyver
Fix for going into the debugger with non-ascii filenames.
r8327 line = ulinecache.getline(filename, lineno)
vivainio
Last set of Rocky's patches for pydb integration
r393 if not line:
break
if lineno == self.curframe.f_lineno:
line = self.__format_line(tpl_line_em, filename, lineno, line, arrow = True)
else:
line = self.__format_line(tpl_line, filename, lineno, line, arrow = False)
src.append(line)
self.lineno = lineno
Matthias BUSSONNIER
use print function in module with `print >>`
r7817 print(''.join(src), file=io.stdout)
vivainio
Last set of Rocky's patches for pydb integration
r393
except KeyboardInterrupt:
pass
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 def do_list(self, arg):
self.lastcmd = 'list'
last = None
if arg:
try:
x = eval(arg, {}, {})
if type(x) == type(()):
first, last = x
first = int(first)
last = int(last)
if last < first:
# Assume it's a count
last = first + last
else:
first = max(1, int(x) - 5)
except:
Matthias BUSSONNIER
use print function in module with `print >>`
r7817 print('*** Error in argument:', repr(arg))
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 return
elif self.lineno is None:
first = max(1, self.curframe.f_lineno - 5)
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 else:
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 first = self.lineno + 1
if last is None:
last = first + 10
vivainio
Last set of Rocky's patches for pydb integration
r393 self.print_list_lines(self.curframe.f_code.co_filename, first, last)
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46
vds
synchronize with editor patch
r1241 # vds: >>
lineno = first
filename = self.curframe.f_code.co_filename
Brian Granger
Fixed the %debug magic.
r2290 self.shell.hooks.synchronize_with_editor(filename, lineno, 0)
vds
synchronize with editor patch
r1241 # vds: <<
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 do_l = do_list
vivainio
Last set of Rocky's patches for pydb integration
r393
def do_pdef(self, arg):
Bradley M. Froehle
Docs: replace 'definition header' with 'call signature'
r8707 """Print the call signature for any callable object.
Bradley M. Froehle
Clean up ipdb docstrings for namespace magics.
r8698
The debugger interface to %pdef"""
vivainio
Last set of Rocky's patches for pydb integration
r393 namespaces = [('Locals', self.curframe.f_locals),
('Globals', self.curframe.f_globals)]
Bradley M. Froehle
ipdb interface: look up magics by name and call them.
r7904 self.shell.find_line_magic('pdef')(arg, namespaces=namespaces)
vivainio
Last set of Rocky's patches for pydb integration
r393
def do_pdoc(self, arg):
Bradley M. Froehle
Clean up ipdb docstrings for namespace magics.
r8698 """Print the docstring for an object.
The debugger interface to %pdoc."""
vivainio
Last set of Rocky's patches for pydb integration
r393 namespaces = [('Locals', self.curframe.f_locals),
('Globals', self.curframe.f_globals)]
Bradley M. Froehle
ipdb interface: look up magics by name and call them.
r7904 self.shell.find_line_magic('pdoc')(arg, namespaces=namespaces)
vivainio
Last set of Rocky's patches for pydb integration
r393
Bradley M. Froehle
Add pfile command to ipdb.
r8699 def do_pfile(self, arg):
"""Print (or run through pager) the file where an object is defined.
The debugger interface to %pfile.
"""
namespaces = [('Locals', self.curframe.f_locals),
('Globals', self.curframe.f_globals)]
self.shell.find_line_magic('pfile')(arg, namespaces=namespaces)
vivainio
Last set of Rocky's patches for pydb integration
r393 def do_pinfo(self, arg):
Bradley M. Froehle
Clean up ipdb docstrings for namespace magics.
r8698 """Provide detailed information about an object.
The debugger interface to %pinfo, i.e., obj?."""
vivainio
Last set of Rocky's patches for pydb integration
r393 namespaces = [('Locals', self.curframe.f_locals),
('Globals', self.curframe.f_globals)]
Bradley M. Froehle
Split pinfo into pinfo, pinfo2....
r8701 self.shell.find_line_magic('pinfo')(arg, namespaces=namespaces)
def do_pinfo2(self, arg):
"""Provide extra detailed information about an object.
The debugger interface to %pinfo2, i.e., obj??."""
namespaces = [('Locals', self.curframe.f_locals),
('Globals', self.curframe.f_globals)]
self.shell.find_line_magic('pinfo2')(arg, namespaces=namespaces)
Fernando Perez
Fix debugging with breakpoints....
r2372
Bradley M. Froehle
Add psource command to ipdb.
r8700 def do_psource(self, arg):
"""Print (or run through pager) the source code for an object."""
namespaces = [('Locals', self.curframe.f_locals),
('Globals', self.curframe.f_globals)]
self.shell.find_line_magic('psource')(arg, namespaces=namespaces)
Fernando Perez
Fix debugging with breakpoints....
r2372 def checkline(self, 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.
"""
#######################################################################
# XXX Hack! Use python-2.5 compatible code for this call, because with
# all of our changes, we've drifted from the pdb api in 2.6. For now,
# changing:
#
#line = linecache.getline(filename, lineno, self.curframe.f_globals)
# to:
#
line = linecache.getline(filename, lineno)
#
# does the trick. But in reality, we need to fix this by reconciling
# our updates with the new Pdb APIs in Python 2.6.
#
# End hack. The rest of this method is copied verbatim from 2.6 pdb.py
#######################################################################
Bernardo B. Marques
remove all trailling spaces
r4872
Fernando Perez
Fix debugging with breakpoints....
r2372 if not line:
Matthias BUSSONNIER
use print function in module with `print >>`
r7817 print('End of file', file=self.stdout)
Fernando Perez
Fix debugging with breakpoints....
r2372 return 0
line = line.strip()
# Don't allow setting breakpoint at a blank line
if (not line or (line[0] == '#') or
(line[:3] == '"""') or line[:3] == "'''"):
Matthias BUSSONNIER
use print function in module with `print >>`
r7817 print('*** Blank or comment', file=self.stdout)
Fernando Perez
Fix debugging with breakpoints....
r2372 return 0
return lineno