From 7f56e6ee6c249dd664d54120e09faa30e5207320 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 9 Nov 2020 03:49:53 +0100 Subject: [PATCH] bpo-36388: fix Pdb.do_debug to not trace itself --- Lib/pdb.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index d7d957159458be..8e78e6caa45590 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1094,7 +1094,9 @@ def do_debug(self, arg): argument (which is an arbitrary expression or statement to be executed in the current environment). """ - sys.settrace(None) + orig_trace = sys.gettrace() + if orig_trace: + sys.settrace(None) globals = self.curframe.f_globals locals = self.curframe_locals p = Pdb(self.completekey, self.stdin, self.stdout) @@ -1106,7 +1108,8 @@ def do_debug(self, arg): exc_info = sys.exc_info()[:2] self.error(traceback.format_exception_only(*exc_info)[-1].strip()) self.message("LEAVING RECURSIVE DEBUGGER") - sys.settrace(self.trace_dispatch) + if orig_trace: + sys.settrace(orig_trace) self.lastcmd = p.lastcmd complete_debug = _complete_expression