##// END OF EJS Templates
fix uncaught `BdbQuit` exceptions on ipdb `exit`...
fix uncaught `BdbQuit` exceptions on ipdb `exit` - `BdbQuit` is now handled in the top-most scope of `InteractiveShell.run_code`. This ensures that `BdbQuit` is correctly handled but can still do its job of breaking out of all user code/loops/further breakpoint requests. Hopefully will work better than previous attempts, which put the `BdqQuit` handling in `Pdb.set_trace` - fixes: - jupyterlab/jupyterlab#12501 - refs: - ipython/ipython#876 - ipython/ipython#1273 - ipython/ipython#4474 - ipython/ipython#5306 - ipython/ipython#9731 - ipython/ipython#9942 - ipython/ipython#9950 - ipython/ipython#10006 - ipython/ipython#12378

File last commit:

r27658:fc235985
r27658:fc235985
Show More
debugger.py
999 lines | 32.6 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.
Matthias Bussonnier
Allow decorator frames to be marked as skippable....
r26810
This is an extension to PDB which adds a number of new features.
Note that there is also the `IPython.terminal.debugger` class which provides UI
improvements.
We also strongly recommend to use this via the `ipdb` package, which provides
extra configuration options.
Matthias Bussonnier
Apply suggestions from code review...
r26811 Among other things, this subclass of PDB:
- supports many IPython magics like pdef/psource
- hide frames in tracebacks based on `__tracebackhide__`
- allows to skip frames based on `__debuggerskip__`
Matthias Bussonnier
Allow decorator frames to be marked as skippable....
r26810
The skipping and hiding frames are configurable via the `skip_predicates`
command.
By default, frames from readonly files will be hidden, frames containing
``__tracebackhide__=True`` will be hidden.
Frames containing ``__debuggerskip__`` will be stepped over, frames who's parent
frames value of ``__debuggerskip__`` is ``True`` will be skipped.
Matthias Bussonnier
Expand and Fix PDB skip....
r26824 >>> def helpers_helper():
... pass
...
... def helper_1():
Matthias Bussonnier
Allow decorator frames to be marked as skippable....
r26810 ... print("don't step in me")
Matthias Bussonnier
Expand and Fix PDB skip....
r26824 ... helpers_helpers() # will be stepped over unless breakpoint set.
Matthias Bussonnier
Allow decorator frames to be marked as skippable....
r26810 ...
...
... def helper_2():
... print("in me neither")
...
Matthias Bussonnier
Apply suggestions from code review...
r26811 One can define a decorator that wraps a function between the two helpers:
Matthias Bussonnier
Allow decorator frames to be marked as skippable....
r26810
>>> def pdb_skipped_decorator(function):
...
...
... def wrapped_fn(*args, **kwargs):
... __debuggerskip__ = True
... helper_1()
... __debuggerskip__ = False
... result = function(*args, **kwargs)
... __debuggerskip__ = True
... helper_2()
Matthias Bussonnier
Expand and Fix PDB skip....
r26824 ... # setting __debuggerskip__ to False again is not necessary
Matthias Bussonnier
Allow decorator frames to be marked as skippable....
r26810 ... return result
...
... return wrapped_fn
When decorating a function, ipdb will directly step into ``bar()`` by
default:
>>> @foo_decorator
... def bar(x, y):
... return x * y
You can toggle the behavior with
ipdb> skip_predicates debuggerskip false
or configure it in your ``.pdbrc``
Dimitri Papadopoulos
Typos found by codespell
r26875 License
-------
Matthias Bussonnier
Allow decorator frames to be marked as skippable....
r26810
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 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.
Matthias Bussonnier
Allow decorator frames to be marked as skippable....
r26810 The original 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:
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
Thomas Kluyver
Fix some broken links in the docs
r23220 https://docs.python.org/2/license.html
Matthias Bussonnier
Allow decorator frames to be marked as skippable....
r26810
All the changes since then are under the same license as IPython.
Thomas Kluyver
Fix some broken links in the docs
r23220 """
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>
#
#
#*****************************************************************************
Victor Ramirez
Longlist display code with syntax-highlighted. Close #4093
r21395 import inspect
Srinivas Reddy Thatiparthy
move ulinecache.getlines function call to linecache.getlines()
r23116 import linecache
fperez
Cosmetic cleanups: put all imports in a single line, and sort them...
r52 import sys
Antony Lee
Simplify debugger classes....
r22687 import warnings
Corey McCandless
strip indentation from imported docstrings
r24092 import re
Matthias Bussonnier
Implement more predicates to skip frames in debugger....
r26540 import os
fperez
Cosmetic cleanups: put all imports in a single line, and sort them...
r52
MinRK
Don't rely on `get_ipython` in builtins in library code
r10580 from IPython import get_ipython
Srinivas Reddy Thatiparthy
move ulinecache.getlines function call to linecache.getlines()
r23116 from IPython.utils import PyColorize
Thomas Kluyver
Deprecate io.{stdout,stderr} and shell.{write,write_err}...
r22192 from IPython.utils import coloransi, py3compat
Brian Granger
excolors.py => core/excolors.py and updated import statements.
r2021 from IPython.core.excolors import exception_colors
Matthias Bussonnier
Reuse CLI in between pdb prompts...
r22390
Nikita Kniazev
Fix unintentional skipping of module level doctests...
r26873 # skip module docstests
__skip_doctest__ = True
Matthias Bussonnier
Use python-prompt-toolkit for ipdb....
r22383
fperez
- Added patches for better pydb and Emacs support....
r552 prompt = 'ipdb> '
Matthias Bussonnier
Remove Pydb integration as Pydb is unmaintained and not ion PyPI...
r22359
Blazej Michalik
ipdb: fix formatting in core.debugger
r26325 # We have to check this directly from sys.argv, config struct not yet available
Matthias Bussonnier
Remove Pydb integration as Pydb is unmaintained and not ion PyPI...
r22359 from pdb import Pdb as OldPdb
vivainio
Last set of Rocky's patches for pydb integration
r393
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.
Matthias Bussonnier
Refactor simplify and share common function.
r22083
Matthias Bussonnier
Allow decorator frames to be marked as skippable....
r26810 DEBUGGERSKIP = "__debuggerskip__"
Blazej Michalik
ipdb: fix formatting in core.debugger
r26325
Matthias Bussonnier
Refactor simplify and share common function.
r22083 def make_arrow(pad):
"""generate the leading arrow in front of traceback or debugger"""
if pad >= 2:
return '-'*(pad-2) + '> '
elif pad == 1:
return '>'
return ''
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.
"""
Matthias Bussonnier
Remove many deprecation and bump traitlets to 5+...
r27272 raise ValueError(
"`BdbQuit_excepthook` is deprecated since version 5.1",
)
fperez
Add support for set_trace-like functionality, but with IPython's enhanced...
r506
Antony Lee
Simplify debugger classes....
r22687
Blazej Michalik
ipdb: fix formatting in core.debugger
r26325 def BdbQuit_IPython_excepthook(self, et, ev, tb, tb_offset=None):
Matthias Bussonnier
Remove many deprecation and bump traitlets to 5+...
r27272 raise ValueError(
Antony Lee
Simplify debugger classes....
r22687 "`BdbQuit_IPython_excepthook` is deprecated since version 5.1",
Matthias Bussonnier
Sprinkle deprecation warnings stacklevel in the debugger....
r22994 DeprecationWarning, stacklevel=2)
fperez
Add support for set_trace-like functionality, but with IPython's enhanced...
r506
Brian Granger
Fixed the %debug magic.
r2290
Matthias Bussonnier
Use raw string when invalid escape sequence present....
r24451 RGX_EXTRA_INDENT = re.compile(r'(?<=\n)\s+')
Corey McCandless
move regex definition for readability
r24093
Corey McCandless
strip indentation from imported docstrings
r24092 def strip_indentation(multiline_string):
return RGX_EXTRA_INDENT.sub('', multiline_string)
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__:
Corey McCandless
strip indentation from imported docstrings
r24092 wrapper.__doc__ = strip_indentation(old_fn.__doc__) + additional_text
vivainio
Last set of Rocky's patches for pydb integration
r393 return wrapper
Brian Granger
Fixed the %debug magic.
r2290
Thomas Kluyver
Revert debugger 'smart command mode'...
r23003 class Pdb(OldPdb):
Matthias Bussonnier
Make clearer and simpler how to user prompt-toolkit PDB...
r22724 """Modified Pdb class, does not load readline.
Thomas Kluyver
Fix typo
r22731 for a standalone version that uses prompt_toolkit, see
Matthias Bussonnier
Make clearer and simpler how to user prompt-toolkit PDB...
r22724 `IPython.terminal.debugger.TerminalPdb` and
`IPython.terminal.debugger.set_trace()`
Matthias Bussonnier
Document how to change the default predicates for the debugger....
r26566
This debugger can hide and skip frames that are tagged according to some predicates.
See the `skip_predicates` commands.
Matthias Bussonnier
Make clearer and simpler how to user prompt-toolkit PDB...
r22724 """
fperez
- fix missing __file__ for scripts run via %run....
r122
Matthias Bussonnier
Allow decorator frames to be marked as skippable....
r26810 default_predicates = {
"tbhide": True,
"readonly": False,
"ipython_internal": True,
"debuggerskip": True,
}
Matthias Bussonnier
Document how to change the default predicates for the debugger....
r26566
Matthias Bussonnier
Remove deprecated debugger chunks.
r27225 def __init__(self, completekey=None, stdin=None, stdout=None, context=5, **kwargs):
Terry Davis
Add docstring for core.debugger.Pdb
r25173 """Create a new IPython debugger.
Blazej Michalik
ipdb: fix formatting in core.debugger
r26325
Matthias Bussonnier
Document how to change the default predicates for the debugger....
r26566 Parameters
----------
completekey : default None
Passed to pdb.Pdb.
stdin : default None
Passed to pdb.Pdb.
stdout : default None
Passed to pdb.Pdb.
context : int
Number of lines of source code context to show when
Terry Davis
Add docstring for core.debugger.Pdb
r25173 displaying stacktrace information.
Matthias Bussonnier
Document how to change the default predicates for the debugger....
r26566 **kwargs
Passed to pdb.Pdb.
Notes
-----
The possibilities are python version dependent, see the python
docs for more info.
Terry Davis
Add docstring for core.debugger.Pdb
r25173 """
fperez
Apply Ville's patch, closes #87
r367
Brian Granger
Fixed the %debug magic.
r2290 # Parent constructor:
JamshedVesuna
Added user defined context for Pdb
r21876 try:
Antony Lee
Simplify debugger classes....
r22687 self.context = int(context)
JamshedVesuna
Added user defined context for Pdb
r21876 if self.context <= 0:
raise ValueError("Context must be a positive integer")
Ram Rachum
Fix exception causes in debugger.py
r25824 except (TypeError, ValueError) as e:
raise ValueError("Context must be a positive integer") from e
Terry Davis
add whitespace
r25176
Terry Davis
Add **kwargs to Pdb and pass into base class.
r25172 # `kwargs` ensures full compatibility with stdlib's `pdb.Pdb`.
OldPdb.__init__(self, completekey, stdin, stdout, **kwargs)
Bernardo B. Marques
remove all trailling spaces
r4872
Brian Granger
Fixed the %debug magic.
r2290 # IPython changes...
MinRK
don't use deprecated ipapi.get...
r10581 self.shell = get_ipython()
fperez
Apply Ville's patch, closes #87
r367
Puneeth Chaganti
Get Tracer working after ipapi.get replaced with get_ipython...
r11114 if self.shell is None:
mbyt
restore sys.modules["__main__"] in the debugger...
r22907 save_main = sys.modules['__main__']
Puneeth Chaganti
Get Tracer working after ipapi.get replaced with get_ipython...
r11114 # No IPython instance running, we must create one
from IPython.terminal.interactiveshell import \
TerminalInteractiveShell
self.shell = TerminalInteractiveShell.instance()
mbyt
restore sys.modules["__main__"] in the debugger...
r22907 # needed by any code which calls __import__("__main__") after
# the debugger was entered. See also #9941.
Blazej Michalik
Darken terminal.debugger and core.debugger
r26328 sys.modules["__main__"] = save_main
Puneeth Chaganti
Get Tracer working after ipapi.get replaced with get_ipython...
r11114
Matthias Bussonnier
Remove deprecated debugger chunks.
r27225
color_scheme = self.shell.colors
Antony Lee
Simplify debugger classes....
r22687
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
Gábor Luk
Color the prompt...
r21692 cst['NoColor'].colors.prompt = C.NoColor
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
Gábor Luk
Color the prompt...
r21692 cst['Linux'].colors.prompt = C.Green
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
Gábor Luk
Color the prompt...
r21692 cst['LightBG'].colors.prompt = C.Blue
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
Matthias Bussonnier
Make everyone happy with a neutral colortheme by default.
r22609 cst['Neutral'].colors.prompt = C.Blue
cst['Neutral'].colors.breakpoint_enabled = C.LightRed
cst['Neutral'].colors.breakpoint_disabled = C.Red
Brian Granger
Fixed the %debug magic.
r2290 # Add a python parser so we can syntax highlight source while
# debugging.
Matthias Bussonnier
Start refactoring handling of color....
r22911 self.parser = PyColorize.Parser(style=color_scheme)
self.set_colors(color_scheme)
fperez
- R. Bernstein's patches (minor reworks) to provide full syntax highlight in...
r553
Thomas Kluyver
Wrap colour sequences in debugger prompt in marker bytes...
r22094 # Set the prompt - the default prompt is '(Pdb)'
Matthias Bussonnier
Use python-prompt-toolkit for ipdb....
r22383 self.prompt = prompt
Matthias Bussonnier
Implement understanding on __tracebackhide__...
r25839 self.skip_hidden = True
Matthias Bussonnier
Backport PR #13000: Allow to control if reporting hidden frames
r26573 self.report_skipped = True
Gábor Luk
Color the prompt...
r21692
Matthias Bussonnier
Implement more predicates to skip frames in debugger....
r26540 # list of predicates we use to skip frames
Matthias Bussonnier
Document how to change the default predicates for the debugger....
r26566 self._predicates = self.default_predicates
Matthias Bussonnier
Implement more predicates to skip frames in debugger....
r26540
Matthias Bussonnier
Allow decorator frames to be marked as skippable....
r26810 #
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)
Matthias Bussonnier
Start refactoring handling of color....
r22911 self.parser.style = scheme
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46
Matthias Bussonnier
Mark initial frame as not hidden.
r26135 def set_trace(self, frame=None):
if frame is None:
frame = sys._getframe().f_back
self.initial_frame = frame
return super().set_trace(frame)
Matthias Bussonnier
Implement understanding on __tracebackhide__...
r25839
Matthias Bussonnier
Implement more predicates to skip frames in debugger....
r26540 def _hidden_predicate(self, frame):
"""
Given a frame return whether it it should be hidden or not by IPython.
"""
if self._predicates["readonly"]:
fname = frame.f_code.co_filename
# we need to check for file existence and interactively define
# function would otherwise appear as RO.
if os.path.isfile(fname) and not os.access(fname, os.W_OK):
return True
if self._predicates["tbhide"]:
if frame in (self.curframe, getattr(self, "initial_frame", None)):
return False
Quentin Peter
f_locals might not have get
r27017 frame_locals = self._get_frame_locals(frame)
if "__tracebackhide__" not in frame_locals:
return False
return frame_locals["__tracebackhide__"]
Matthias Bussonnier
Implement more predicates to skip frames in debugger....
r26540 return False
Matthias Bussonnier
Implement understanding on __tracebackhide__...
r25839 def hidden_frames(self, stack):
"""
Matthias Bussonnier
Always display last frame when show tracebacks with hidden frames....
r26053 Given an index in the stack return whether it should be skipped.
Matthias Bussonnier
Implement understanding on __tracebackhide__...
r25839
This is used in up/down and where to skip frames.
"""
Quentin Peter
avoid calling .f_locals on the current frame...
r25895 # The f_locals dictionary is updated from the actual frame
# locals whenever the .f_locals accessor is called, so we
# avoid calling it here to preserve self.curframe_locals.
Dimitri Papadopoulos
Typos found by codespell
r26875 # Furthermore, there is no good reason to hide the current frame.
Matthias Bussonnier
Implement more predicates to skip frames in debugger....
r26540 ip_hide = [self._hidden_predicate(s[0]) for s in stack]
Matthias Bussonnier
Implement understanding on __tracebackhide__...
r25839 ip_start = [i for i, s in enumerate(ip_hide) if s == "__ipython_bottom__"]
Matthias Bussonnier
Implement more predicates to skip frames in debugger....
r26540 if ip_start and self._predicates["ipython_internal"]:
Matthias Bussonnier
Implement understanding on __tracebackhide__...
r25839 ip_hide = [h if i > ip_start[0] else True for (i, h) in enumerate(ip_hide)]
return ip_hide
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 def interaction(self, frame, traceback):
Thomas Kluyver
Remove readline code from debugger machinery
r22385 try:
OldPdb.interaction(self, frame, traceback)
except KeyboardInterrupt:
Matthias Bussonnier
Implement understanding on __tracebackhide__...
r25839 self.stdout.write("\n" + self.shell.get_exception_only())
vivainio
Last set of Rocky's patches for pydb integration
r393
Blazej Michalik
ipdb: accept question mark(s) suffixes
r26327 def precmd(self, line):
"""Perform useful escapes on the command before it is executed."""
Blazej Michalik
Darken terminal.debugger and core.debugger
r26328 if line.endswith("??"):
line = "pinfo2 " + line[:-2]
elif line.endswith("?"):
line = "pinfo " + line[:-1]
Blazej Michalik
ipdb: accept question mark(s) suffixes
r26327
line = super().precmd(line)
return line
vivainio
Last set of Rocky's patches for pydb integration
r393 def new_do_frame(self, arg):
OldPdb.do_frame(self, arg)
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'):
Blazej Michalik
ipdb: fix formatting in core.debugger
r26325 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
JamshedVesuna
Added user defined context for Pdb
r21876 def print_stack_trace(self, context=None):
Matthias Bussonnier
Implement understanding on __tracebackhide__...
r25839 Colors = self.color_scheme_table.active_colors
ColorsNormal = Colors.Normal
JamshedVesuna
Added user defined context for Pdb
r21876 if context is None:
context = self.context
try:
Blazej Michalik
ipdb: fix formatting in core.debugger
r26325 context = int(context)
JamshedVesuna
Added user defined context for Pdb
r21876 if context <= 0:
raise ValueError("Context must be a positive integer")
Ram Rachum
Fix exception causes in debugger.py
r25824 except (TypeError, ValueError) as e:
raise ValueError("Context must be a positive integer") from e
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 try:
Matthias Bussonnier
Implement understanding on __tracebackhide__...
r25839 skipped = 0
for hidden, frame_lineno in zip(self.hidden_frames(self.stack), self.stack):
if hidden and self.skip_hidden:
skipped += 1
continue
if skipped:
print(
f"{Colors.excName} [... skipping {skipped} hidden frame(s)]{ColorsNormal}\n"
)
skipped = 0
JamshedVesuna
Added user defined context for Pdb
r21876 self.print_stack_entry(frame_lineno, context=context)
Matthias Bussonnier
Implement understanding on __tracebackhide__...
r25839 if skipped:
print(
f"{Colors.excName} [... skipping {skipped} hidden frame(s)]{ColorsNormal}\n"
)
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 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
Maor Kleinberger
redirected output from core debugger to correct stdout
r25083 def print_stack_entry(self, frame_lineno, prompt_prefix='\n-> ',
JamshedVesuna
Added user defined context for Pdb
r21876 context=None):
if context is None:
context = self.context
try:
Blazej Michalik
ipdb: fix formatting in core.debugger
r26325 context = int(context)
JamshedVesuna
Added user defined context for Pdb
r21876 if context <= 0:
raise ValueError("Context must be a positive integer")
Ram Rachum
Fix exception causes in debugger.py
r25824 except (TypeError, ValueError) as e:
raise ValueError("Context must be a positive integer") from e
Maor Kleinberger
redirected output from core debugger to correct stdout
r25083 print(self.format_stack_entry(frame_lineno, '', context), file=self.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: <<
Matthias Bussonnier
Don't access current_frame f_locals...
r26584 def _get_frame_locals(self, frame):
""" "
Dimitri Papadopoulos
Typos found by codespell
r26875 Accessing f_local of current frame reset the namespace, so we want to avoid
that or the following can happen
Matthias Bussonnier
Don't access current_frame f_locals...
r26584
ipdb> foo
"old"
ipdb> foo = "new"
ipdb> foo
"new"
ipdb> where
ipdb> foo
"old"
So if frame is self.current_frame we instead return self.curframe_locals
"""
if frame is self.curframe:
return self.curframe_locals
else:
return frame.f_locals
JamshedVesuna
Added user defined context for Pdb
r21876 def format_stack_entry(self, frame_lineno, lprefix=': ', context=None):
if context is None:
context = self.context
try:
Blazej Michalik
ipdb: fix formatting in core.debugger
r26325 context = int(context)
JamshedVesuna
Added user defined context for Pdb
r21876 if context <= 0:
Maor Kleinberger
redirected output from core debugger to correct stdout
r25083 print("Context must be a positive integer", file=self.stdout)
JamshedVesuna
Added user defined context for Pdb
r21876 except (TypeError, ValueError):
Maor Kleinberger
redirected output from core debugger to correct stdout
r25083 print("Context must be a positive integer", file=self.stdout)
Terry Davis
Remove clearly marked python 2 imports.
r25516
import reprlib
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
Blazej Michalik
Darken terminal.debugger and core.debugger
r26328 tpl_link = "%s%%s%s" % (Colors.filenameEm, ColorsNormal)
tpl_call = "%s%%s%s%%s%s" % (Colors.vName, Colors.valEm, ColorsNormal)
tpl_line = "%%s%s%%s %s%%s" % (Colors.lineno, ColorsNormal)
tpl_line_em = "%%s%s%%s %s%%s%s" % (Colors.linenoEm, Colors.line, 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 = ''
Matthias Bussonnier
Don't access current_frame f_locals...
r26584 loc_frame = self._get_frame_locals(frame)
if "__return__" in loc_frame:
rv = loc_frame["__return__"]
# return_value += '->'
return_value += reprlib.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
Matthias Bussonnier
Don't access current_frame f_locals...
r26584 call = ""
if func != "?":
if "__args__" in loc_frame:
args = reprlib.repr(loc_frame["__args__"])
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 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:
Blazej Michalik
Darken terminal.debugger and core.debugger
r26328 ret.append(" ")
ret.append("%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
Srinivas Reddy Thatiparthy
move ulinecache.getlines function call to linecache.getlines()
r23116 lines = linecache.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
Blazej Michalik
ipdb: fix formatting in core.debugger
r26325 for i, line in enumerate(lines):
Blazej Michalik
Darken terminal.debugger and core.debugger
r26328 show_arrow = start + 1 + i == lineno
linetpl = (frame is self.curframe or show_arrow) and tpl_line_em or tpl_line
ret.append(
self.__format_line(
linetpl, filename, start + 1 + i, line, arrow=show_arrow
)
)
return "".join(ret)
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46
Blazej Michalik
ipdb: fix formatting in core.debugger
r26325 def __format_line(self, tpl_line, filename, lineno, line, arrow=False):
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 bp_mark = ""
bp_mark_color = ""
Matthias Bussonnier
Start refactoring handling of color....
r22911 new_line, err = self.parser.format2(line, 'str')
if not err:
line = new_line
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 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)
Matthias Bussonnier
Refactor simplify and share common function.
r22083 num = '%s%s' % (make_arrow(pad), str(lineno))
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 else:
num = '%*s' % (numbers_width - len(bp_mark), str(lineno))
Bernardo B. Marques
remove all trailling spaces
r4872
Matthias Bussonnier
Refactor simplify and share common function.
r22083 return tpl_line % (bp_mark_color + bp_mark, num, line)
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):
Srinivas Reddy Thatiparthy
move ulinecache.getlines function call to linecache.getlines()
r23116 line = linecache.getline(filename, lineno)
vivainio
Last set of Rocky's patches for pydb integration
r393 if not line:
break
if lineno == self.curframe.f_lineno:
Blazej Michalik
Darken terminal.debugger and core.debugger
r26328 line = self.__format_line(
tpl_line_em, filename, lineno, line, arrow=True
)
vivainio
Last set of Rocky's patches for pydb integration
r393 else:
Blazej Michalik
Darken terminal.debugger and core.debugger
r26328 line = self.__format_line(
tpl_line, filename, lineno, line, arrow=False
)
vivainio
Last set of Rocky's patches for pydb integration
r393
src.append(line)
self.lineno = lineno
Maor Kleinberger
redirected output from core debugger to correct stdout
r25083 print(''.join(src), file=self.stdout)
vivainio
Last set of Rocky's patches for pydb integration
r393
except KeyboardInterrupt:
pass
Matthias Bussonnier
Implement more predicates to skip frames in debugger....
r26540 def do_skip_predicates(self, args):
"""
Turn on/off individual predicates as to whether a frame should be hidden/skip.
The global option to skip (or not) hidden frames is set with skip_hidden
To change the value of a predicate
skip_predicates key [true|false]
Call without arguments to see the current values.
Matthias Bussonnier
Document how to change the default predicates for the debugger....
r26566 To permanently change the value of an option add the corresponding
command to your ``~/.pdbrc`` file. If you are programmatically using the
Pdb instance you can also change the ``default_predicates`` class
attribute.
Matthias Bussonnier
Implement more predicates to skip frames in debugger....
r26540 """
if not args.strip():
print("current predicates:")
for (p, v) in self._predicates.items():
print(" ", p, ":", v)
return
type_value = args.strip().split(" ")
if len(type_value) != 2:
Matthias Bussonnier
improve error message
r26542 print(
f"Usage: skip_predicates <type> <value>, with <type> one of {set(self._predicates.keys())}"
)
Matthias Bussonnier
Implement more predicates to skip frames in debugger....
r26540 return
type_, value = type_value
if type_ not in self._predicates:
print(f"{type_!r} not in {set(self._predicates.keys())}")
return
if value.lower() not in ("true", "yes", "1", "no", "false", "0"):
print(
Matthias Bussonnier
improve error message
r26542 f"{value!r} is invalid - use one of ('true', 'yes', '1', 'no', 'false', '0')"
Matthias Bussonnier
Implement more predicates to skip frames in debugger....
r26540 )
return
self._predicates[type_] = value.lower() in ("true", "yes", "1")
if not any(self._predicates.values()):
print(
"Warning, all predicates set to False, skip_hidden may not have any effects."
)
Matthias Bussonnier
Implement understanding on __tracebackhide__...
r25839 def do_skip_hidden(self, arg):
"""
Change whether or not we should skip frames with the
__tracebackhide__ attribute.
"""
Matthias Bussonnier
Implement more predicates to skip frames in debugger....
r26540 if not arg.strip():
print(
f"skip_hidden = {self.skip_hidden}, use 'yes','no', 'true', or 'false' to change."
)
elif arg.strip().lower() in ("true", "yes"):
Matthias Bussonnier
Implement understanding on __tracebackhide__...
r25839 self.skip_hidden = True
elif arg.strip().lower() in ("false", "no"):
self.skip_hidden = False
Matthias Bussonnier
Implement more predicates to skip frames in debugger....
r26540 if not any(self._predicates.values()):
print(
"Warning, all predicates set to False, skip_hidden may not have any effects."
)
Matthias Bussonnier
Implement understanding on __tracebackhide__...
r25839
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 def do_list(self, arg):
Thomas Kluyver
Add docstrings for debugger commands...
r23488 """Print lines of code from the current stack frame
"""
fperez
- Fairly significant changes to include Vivian's patches for improved pdb...
r46 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:
Maor Kleinberger
redirected output from core debugger to correct stdout
r25083 print('*** Error in argument:', repr(arg), file=self.stdout)
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
Victor Ramirez
Longlist display code with syntax-highlighted. Close #4093
r21395 def getsourcelines(self, obj):
lines, lineno = inspect.findsource(obj)
Matthias Bussonnier
Don't access current_frame f_locals...
r26584 if inspect.isframe(obj) and obj.f_globals is self._get_frame_locals(obj):
Victor Ramirez
Longlist display code with syntax-highlighted. Close #4093
r21395 # must be a module frame: do not try to cut a block out of it
return lines, 1
elif inspect.ismodule(obj):
return lines, 1
return inspect.getblock(lines[lineno:]), lineno+1
def do_longlist(self, arg):
Thomas Kluyver
Add docstrings for debugger commands...
r23488 """Print lines of code from the current stack frame.
Shows more lines than 'list' does.
"""
Victor Ramirez
Longlist display code with syntax-highlighted. Close #4093
r21395 self.lastcmd = 'longlist'
try:
lines, lineno = self.getsourcelines(self.curframe)
except OSError as err:
self.error(err)
return
last = lineno + len(lines)
self.print_list_lines(self.curframe.f_code.co_filename, lineno, last)
do_ll = do_longlist
Segev Finer
Make recursive pdb properly invoke IPython's enhanced pdb...
r23823 def do_debug(self, arg):
"""debug code
Enter a recursive debugger that steps through the code
argument (which is an arbitrary expression or statement to be
executed in the current environment).
"""
Quentin Peter
Fix settrace for recursive debugger
r26149 trace_function = sys.gettrace()
Segev Finer
Make recursive pdb properly invoke IPython's enhanced pdb...
r23823 sys.settrace(None)
globals = self.curframe.f_globals
locals = self.curframe_locals
p = self.__class__(completekey=self.completekey,
stdin=self.stdin, stdout=self.stdout)
p.use_rawinput = self.use_rawinput
p.prompt = "(%s) " % self.prompt.strip()
self.message("ENTERING RECURSIVE DEBUGGER")
sys.call_tracing(p.run, (arg, globals, locals))
self.message("LEAVING RECURSIVE DEBUGGER")
Quentin Peter
Fix settrace for recursive debugger
r26149 sys.settrace(trace_function)
Segev Finer
Make recursive pdb properly invoke IPython's enhanced pdb...
r23823 self.lastcmd = p.lastcmd
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"""
Matthias Bussonnier
reformat with darker
r26170 namespaces = [
("Locals", self.curframe_locals),
("Globals", self.curframe.f_globals),
]
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."""
Matthias Bussonnier
reformat with darker
r26170 namespaces = [
("Locals", self.curframe_locals),
("Globals", self.curframe.f_globals),
]
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.
"""
Matthias Bussonnier
reformat with darker
r26170 namespaces = [
("Locals", self.curframe_locals),
("Globals", self.curframe.f_globals),
]
self.shell.find_line_magic("pfile")(arg, namespaces=namespaces)
Bradley M. Froehle
Add pfile command to ipdb.
r8699
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?."""
Matthias Bussonnier
reformat with darker
r26170 namespaces = [
("Locals", self.curframe_locals),
("Globals", self.curframe.f_globals),
]
self.shell.find_line_magic("pinfo")(arg, namespaces=namespaces)
Bradley M. Froehle
Split pinfo into pinfo, pinfo2....
r8701
def do_pinfo2(self, arg):
"""Provide extra detailed information about an object.
The debugger interface to %pinfo2, i.e., obj??."""
Matthias Bussonnier
reformat with darker
r26170 namespaces = [
("Locals", self.curframe_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."""
Matthias Bussonnier
reformat with darker
r26170 namespaces = [
("Locals", self.curframe_locals),
("Globals", self.curframe.f_globals),
]
self.shell.find_line_magic("psource")(arg, namespaces=namespaces)
JamshedVesuna
Added user defined context for Pdb
r21876
Paul Ivanov
remove sys_version for Python 3...
r22959 def do_where(self, arg):
"""w(here)
Print a stack trace, with the most recent frame at the bottom.
An arrow indicates the "current frame", which determines the
context of most commands. 'bt' is an alias for this command.
Take a number as argument as an (optional) number of context line to
print"""
if arg:
Quentin Peter
Catch ValueError...
r25620 try:
context = int(arg)
Quentin Peter
use self.error
r25622 except ValueError as err:
self.error(err)
Quentin Peter
Catch ValueError...
r25620 return
Paul Ivanov
remove sys_version for Python 3...
r22959 self.print_stack_trace(context)
else:
self.print_stack_trace()
JamshedVesuna
Added user defined context for Pdb
r21876
Paul Ivanov
remove sys_version for Python 3...
r22959 do_w = do_where
tillahoffmann
Add set_trace to core debugger.
r22871
Matthias Bussonnier
Allow decorator frames to be marked as skippable....
r26810 def break_anywhere(self, frame):
"""
_stop_in_decorator_internals is overly restrictive, as we may still want
to trace function calls, so we need to also update break_anywhere so
that is we don't `stop_here`, because of debugger skip, we may still
stop at any point inside the function
"""
Matthias Bussonnier
Expand and Fix PDB skip....
r26824
sup = super().break_anywhere(frame)
if sup:
return sup
Matthias Bussonnier
Allow decorator frames to be marked as skippable....
r26810 if self._predicates["debuggerskip"]:
if DEBUGGERSKIP in frame.f_code.co_varnames:
return True
if frame.f_back and self._get_frame_locals(frame.f_back).get(DEBUGGERSKIP):
return True
Matthias Bussonnier
Expand and Fix PDB skip....
r26824 return False
Matthias Bussonnier
Allow decorator frames to be marked as skippable....
r26810
def _is_in_decorator_internal_and_should_skip(self, frame):
"""
Utility to tell us whether we are in a decorator internal and should stop.
"""
Matthias Bussonnier
Apply suggestions from code review...
r26811 # if we are disabled don't skip
Matthias Bussonnier
Allow decorator frames to be marked as skippable....
r26810 if not self._predicates["debuggerskip"]:
return False
# if frame is tagged, skip by default.
if DEBUGGERSKIP in frame.f_code.co_varnames:
return True
Matthias Bussonnier
Expand and Fix PDB skip....
r26824 # if one of the parent frame value set to True skip as well.
cframe = frame
while getattr(cframe, "f_back", None):
cframe = cframe.f_back
if self._get_frame_locals(cframe).get(DEBUGGERSKIP):
return True
Matthias Bussonnier
Allow decorator frames to be marked as skippable....
r26810
return False
Matthias Bussonnier
Implement understanding on __tracebackhide__...
r25839 def stop_here(self, frame):
Matthias Bussonnier
Allow decorator frames to be marked as skippable....
r26810
if self._is_in_decorator_internal_and_should_skip(frame) is True:
return False
Matthias Bussonnier
Implement understanding on __tracebackhide__...
r25839 hidden = False
if self.skip_hidden:
Matthias Bussonnier
Implement more predicates to skip frames in debugger....
r26540 hidden = self._hidden_predicate(frame)
Matthias Bussonnier
Implement understanding on __tracebackhide__...
r25839 if hidden:
Matthias Bussonnier
Backport PR #13000: Allow to control if reporting hidden frames
r26573 if self.report_skipped:
Colors = self.color_scheme_table.active_colors
ColorsNormal = Colors.Normal
print(
f"{Colors.excName} [... skipped 1 hidden frame]{ColorsNormal}\n"
)
Matthias Bussonnier
Implement understanding on __tracebackhide__...
r25839 return super().stop_here(frame)
def do_up(self, arg):
"""u(p) [count]
Move the current frame count (default one) levels up in the
stack trace (to an older frame).
Will skip hidden frames.
"""
Blazej Michalik
ipdb: fix formatting in core.debugger
r26325 # modified version of upstream that skips
Matthias Bussonnier
Implement more predicates to skip frames in debugger....
r26540 # frames with __tracebackhide__
Matthias Bussonnier
Implement understanding on __tracebackhide__...
r25839 if self.curindex == 0:
self.error("Oldest frame")
return
try:
count = int(arg or 1)
except ValueError:
self.error("Invalid frame count (%s)" % arg)
return
skipped = 0
if count < 0:
_newframe = 0
else:
counter = 0
hidden_frames = self.hidden_frames(self.stack)
for i in range(self.curindex - 1, -1, -1):
if hidden_frames[i] and self.skip_hidden:
skipped += 1
continue
counter += 1
if counter >= count:
break
else:
Dimitri Papadopoulos
Typos found by codespell
r26875 # if no break occurred.
Matthias Bussonnier
Always display last frame when show tracebacks with hidden frames....
r26053 self.error(
"all frames above hidden, use `skip_hidden False` to get get into those."
)
Matthias Bussonnier
Implement understanding on __tracebackhide__...
r25839 return
Colors = self.color_scheme_table.active_colors
ColorsNormal = Colors.Normal
_newframe = i
self._select_frame(_newframe)
if skipped:
print(
f"{Colors.excName} [... skipped {skipped} hidden frame(s)]{ColorsNormal}\n"
)
def do_down(self, arg):
"""d(own) [count]
Move the current frame count (default one) levels down in the
stack trace (to a newer frame).
Will skip hidden frames.
"""
if self.curindex + 1 == len(self.stack):
self.error("Newest frame")
return
try:
count = int(arg or 1)
except ValueError:
self.error("Invalid frame count (%s)" % arg)
return
if count < 0:
_newframe = len(self.stack) - 1
else:
counter = 0
skipped = 0
hidden_frames = self.hidden_frames(self.stack)
for i in range(self.curindex + 1, len(self.stack)):
if hidden_frames[i] and self.skip_hidden:
skipped += 1
continue
counter += 1
if counter >= count:
break
else:
Matthias Bussonnier
Always display last frame when show tracebacks with hidden frames....
r26053 self.error(
Dimitri Papadopoulos
Typos found by codespell
r26875 "all frames below hidden, use `skip_hidden False` to get get into those."
Matthias Bussonnier
Always display last frame when show tracebacks with hidden frames....
r26053 )
Matthias Bussonnier
Implement understanding on __tracebackhide__...
r25839 return
Colors = self.color_scheme_table.active_colors
ColorsNormal = Colors.Normal
if skipped:
print(
f"{Colors.excName} [... skipped {skipped} hidden frame(s)]{ColorsNormal}\n"
)
_newframe = i
self._select_frame(_newframe)
do_d = do_down
do_u = do_up
tillahoffmann
Add set_trace to core debugger.
r22871
Blazej Michalik
ipdb: ada "context" command
r26339 def do_context(self, context):
"""context number_of_lines
Set the number of lines of source code to show when displaying
stacktrace information.
"""
try:
new_context = int(context)
if new_context <= 0:
raise ValueError()
Blazej Michalik
ipdb: fix ULE when running 'context' without argument
r26357 self.context = new_context
Blazej Michalik
ipdb: ada "context" command
r26339 except ValueError:
self.error("The 'context' command requires a positive integer argument.")
Itamar Turner-Trauring
A maybe better-working interruptible Pdb. Also make separate class so we don't...
r25649 class InterruptiblePdb(Pdb):
"""Version of debugger where KeyboardInterrupt exits the debugger altogether."""
Matthias Bussonnier
Allow decorator frames to be marked as skippable....
r26810 def cmdloop(self, intro=None):
Itamar Turner-Trauring
A maybe better-working interruptible Pdb. Also make separate class so we don't...
r25649 """Wrap cmdloop() such that KeyboardInterrupt stops the debugger."""
try:
Matthias Bussonnier
Allow decorator frames to be marked as skippable....
r26810 return OldPdb.cmdloop(self, intro=intro)
Itamar Turner-Trauring
A maybe better-working interruptible Pdb. Also make separate class so we don't...
r25649 except KeyboardInterrupt:
self.stop_here = lambda frame: False
self.do_quit("")
sys.settrace(None)
self.quitting = False
raise
Itamar Turner-Trauring
Fix built-in and standard library pdb (🙈) so they are interruptible from Jupyter.
r25568 def _cmdloop(self):
while True:
try:
# keyboard interrupts allow for an easy way to cancel
# the current command, so allow them during interactive input
self.allow_kbdint = True
self.cmdloop()
self.allow_kbdint = False
break
except KeyboardInterrupt:
Itamar Turner-Trauring
A maybe better-working interruptible Pdb. Also make separate class so we don't...
r25649 self.message('--KeyboardInterrupt--')
Itamar Turner-Trauring
Fix built-in and standard library pdb (🙈) so they are interruptible from Jupyter.
r25568 raise
tillahoffmann
Add set_trace to core debugger.
r22871
tillahoffmann
Remove condition from set_trace.
r22872 def set_trace(frame=None):
"""
Start debugging from `frame`.
If frame is not specified, debugging starts from caller's frame.
"""
tillahoffmann
Fix unused frame variable.
r22873 Pdb().set_trace(frame or sys._getframe().f_back)