bpo-35931: Gracefully handle SyntaxError in pdb debug command (GH-11782) · python/cpython@6f35219

@@ -1093,10 +1093,16 @@ def do_debug(self, arg):

10931093

sys.settrace(None)

10941094

globals = self.curframe.f_globals

10951095

locals = self.curframe_locals

1096+

try:

1097+

code = compile(arg, "<string>", "exec")

1098+

except SyntaxError:

1099+

exc_info = sys.exc_info()[:2]

1100+

self.error(traceback.format_exception_only(*exc_info)[-1].strip())

1101+

return

10961102

p = Pdb(self.completekey, self.stdin, self.stdout)

10971103

p.prompt = "(%s) " % self.prompt.strip()

10981104

self.message("ENTERING RECURSIVE DEBUGGER")

1099-

sys.call_tracing(p.run, (arg, globals, locals))

1105+

sys.call_tracing(p.run, (code, globals, locals))

11001106

self.message("LEAVING RECURSIVE DEBUGGER")

11011107

sys.settrace(self.trace_dispatch)

11021108

self.lastcmd = p.lastcmd