gh-128991: Release the enter frame reference within bdb callback (#128992)
* Release the enter frame reference within bdb callback * 📜🤖 Added by blurb_it. --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
This commit is contained in:
parent
e8092e5cdc
commit
61b35f74aa
68
Lib/bdb.py
68
Lib/bdb.py
@ -4,6 +4,7 @@ import fnmatch
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import weakref
|
import weakref
|
||||||
|
from contextlib import contextmanager
|
||||||
from inspect import CO_GENERATOR, CO_COROUTINE, CO_ASYNC_GENERATOR
|
from inspect import CO_GENERATOR, CO_COROUTINE, CO_ASYNC_GENERATOR
|
||||||
|
|
||||||
__all__ = ["BdbQuit", "Bdb", "Breakpoint"]
|
__all__ = ["BdbQuit", "Bdb", "Breakpoint"]
|
||||||
@ -65,6 +66,12 @@ class Bdb:
|
|||||||
self.botframe = None
|
self.botframe = None
|
||||||
self._set_stopinfo(None, None)
|
self._set_stopinfo(None, None)
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def set_enterframe(self, frame):
|
||||||
|
self.enterframe = frame
|
||||||
|
yield
|
||||||
|
self.enterframe = None
|
||||||
|
|
||||||
def trace_dispatch(self, frame, event, arg):
|
def trace_dispatch(self, frame, event, arg):
|
||||||
"""Dispatch a trace function for debugged frames based on the event.
|
"""Dispatch a trace function for debugged frames based on the event.
|
||||||
|
|
||||||
@ -90,28 +97,27 @@ class Bdb:
|
|||||||
The arg parameter depends on the previous event.
|
The arg parameter depends on the previous event.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.enterframe = frame
|
with self.set_enterframe(frame):
|
||||||
|
if self.quitting:
|
||||||
if self.quitting:
|
return # None
|
||||||
return # None
|
if event == 'line':
|
||||||
if event == 'line':
|
return self.dispatch_line(frame)
|
||||||
return self.dispatch_line(frame)
|
if event == 'call':
|
||||||
if event == 'call':
|
return self.dispatch_call(frame, arg)
|
||||||
return self.dispatch_call(frame, arg)
|
if event == 'return':
|
||||||
if event == 'return':
|
return self.dispatch_return(frame, arg)
|
||||||
return self.dispatch_return(frame, arg)
|
if event == 'exception':
|
||||||
if event == 'exception':
|
return self.dispatch_exception(frame, arg)
|
||||||
return self.dispatch_exception(frame, arg)
|
if event == 'c_call':
|
||||||
if event == 'c_call':
|
return self.trace_dispatch
|
||||||
|
if event == 'c_exception':
|
||||||
|
return self.trace_dispatch
|
||||||
|
if event == 'c_return':
|
||||||
|
return self.trace_dispatch
|
||||||
|
if event == 'opcode':
|
||||||
|
return self.dispatch_opcode(frame, arg)
|
||||||
|
print('bdb.Bdb.dispatch: unknown debugging event:', repr(event))
|
||||||
return self.trace_dispatch
|
return self.trace_dispatch
|
||||||
if event == 'c_exception':
|
|
||||||
return self.trace_dispatch
|
|
||||||
if event == 'c_return':
|
|
||||||
return self.trace_dispatch
|
|
||||||
if event == 'opcode':
|
|
||||||
return self.dispatch_opcode(frame, arg)
|
|
||||||
print('bdb.Bdb.dispatch: unknown debugging event:', repr(event))
|
|
||||||
return self.trace_dispatch
|
|
||||||
|
|
||||||
def dispatch_line(self, frame):
|
def dispatch_line(self, frame):
|
||||||
"""Invoke user function and return trace function for line event.
|
"""Invoke user function and return trace function for line event.
|
||||||
@ -395,16 +401,15 @@ class Bdb:
|
|||||||
if frame is None:
|
if frame is None:
|
||||||
frame = sys._getframe().f_back
|
frame = sys._getframe().f_back
|
||||||
self.reset()
|
self.reset()
|
||||||
self.enterframe = frame
|
with self.set_enterframe(frame):
|
||||||
while frame:
|
while frame:
|
||||||
frame.f_trace = self.trace_dispatch
|
frame.f_trace = self.trace_dispatch
|
||||||
self.botframe = frame
|
self.botframe = frame
|
||||||
self.frame_trace_lines_opcodes[frame] = (frame.f_trace_lines, frame.f_trace_opcodes)
|
self.frame_trace_lines_opcodes[frame] = (frame.f_trace_lines, frame.f_trace_opcodes)
|
||||||
# We need f_trace_lines == True for the debugger to work
|
# We need f_trace_lines == True for the debugger to work
|
||||||
frame.f_trace_lines = True
|
frame.f_trace_lines = True
|
||||||
frame = frame.f_back
|
frame = frame.f_back
|
||||||
self.set_stepinstr()
|
self.set_stepinstr()
|
||||||
self.enterframe = None
|
|
||||||
sys.settrace(self.trace_dispatch)
|
sys.settrace(self.trace_dispatch)
|
||||||
|
|
||||||
def set_continue(self):
|
def set_continue(self):
|
||||||
@ -424,7 +429,6 @@ class Bdb:
|
|||||||
for frame, (trace_lines, trace_opcodes) in self.frame_trace_lines_opcodes.items():
|
for frame, (trace_lines, trace_opcodes) in self.frame_trace_lines_opcodes.items():
|
||||||
frame.f_trace_lines, frame.f_trace_opcodes = trace_lines, trace_opcodes
|
frame.f_trace_lines, frame.f_trace_opcodes = trace_lines, trace_opcodes
|
||||||
self.frame_trace_lines_opcodes = {}
|
self.frame_trace_lines_opcodes = {}
|
||||||
self.enterframe = None
|
|
||||||
|
|
||||||
def set_quit(self):
|
def set_quit(self):
|
||||||
"""Set quitting attribute to True.
|
"""Set quitting attribute to True.
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
Release the enter frame reference within :mod:`bdb` callback
|
Loading…
x
Reference in New Issue
Block a user