diff --git a/IPython/core/debugger.py b/IPython/core/debugger.py index 591e4c3..47bc92f 100644 --- a/IPython/core/debugger.py +++ b/IPython/core/debugger.py @@ -621,3 +621,12 @@ class Pdb(OldPdb, object): self.print_stack_trace() do_w = do_where + + +def set_trace(frame=None): + """ + Start debugging from `frame`. + + If frame is not specified, debugging starts from caller's frame. + """ + Pdb().set_trace(frame or sys._getframe().f_back) diff --git a/IPython/terminal/debugger.py b/IPython/terminal/debugger.py index 36dda89..9c8997d 100644 --- a/IPython/terminal/debugger.py +++ b/IPython/terminal/debugger.py @@ -7,6 +7,8 @@ from prompt_toolkit.token import Token from prompt_toolkit.shortcuts import create_prompt_application from prompt_toolkit.interface import CommandLineInterface from prompt_toolkit.enums import EditingMode +import sys + class TerminalPdb(Pdb): def __init__(self, *args, **kwargs): @@ -72,6 +74,12 @@ class TerminalPdb(Pdb): except Exception: raise -def set_trace(): - TerminalPdb().set_trace() + +def set_trace(frame=None): + """ + Start debugging from `frame`. + + If frame is not specified, debugging starts from caller's frame. + """ + TerminalPdb().set_trace(frame or sys._getframe().f_back)