From fd4a15ce717d6bc0a4b27c1883a149cf3d417af4 2017-01-12 12:29:59 From: Thomas Kluyver Date: 2017-01-12 12:29:59 Subject: [PATCH] Backport PR #9947: Add set_trace to core debugger. This PR adds a `set_trace` method to `IPython.core.debugger` to mirror the functionality of `IPython.terminal.debugger`. See 9940 for a discussion. Signed-off-by: Thomas Kluyver --- 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)