Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
18e6e9c
Allow using sys.monitoring for bdb
gaogaotiantian Sep 25, 2024
b29aff5
Add basic line ignore
gaogaotiantian Sep 25, 2024
23601f3
Use setttrace as default backend for bdb
gaogaotiantian Sep 25, 2024
c9a92f6
📜🤖 Added by blurb_it.
blurb-it[bot] Sep 25, 2024
8955d78
Use settrace by default for pdb.Pdb, but use monitoring for all
gaogaotiantian Sep 26, 2024
6afc2e7
Only trigger events on thread calling start_trace
gaogaotiantian Oct 16, 2024
b595682
Use local events when possible
gaogaotiantian Oct 16, 2024
addf465
Merge branch 'main' into pdb-use-monitoring
gaogaotiantian Jan 19, 2025
70d5138
Fix ignore and condition of breakpoints
gaogaotiantian Feb 8, 2025
7c83425
Merge branch 'main' into pdb-use-monitoring
gaogaotiantian Feb 8, 2025
fe9971c
Address comments about backend
gaogaotiantian Feb 18, 2025
69a5030
Merge branch 'main' into pdb-use-monitoring
gaogaotiantian Feb 18, 2025
05cc3b0
We need BaseException to handle SystemExit case
gaogaotiantian Feb 18, 2025
e6bc287
Move default_backend to module level and provide utils
gaogaotiantian Feb 19, 2025
f0c1306
Do not need to pass trace_dispatch explicitly
gaogaotiantian Feb 19, 2025
a9b53ed
Add docs
gaogaotiantian Feb 19, 2025
9790085
Add version added
gaogaotiantian Feb 19, 2025
ea811f2
Add new functions to __all__
gaogaotiantian Feb 19, 2025
ad2179e
Merge branch 'main' into pdb-use-monitoring
gaogaotiantian Mar 7, 2025
e4ccd8a
Restart events after user line
gaogaotiantian Mar 7, 2025
d2c1f2e
Merge branch 'main' into pdb-use-monitoring
gaogaotiantian Mar 17, 2025
e9252ec
Remove blank line
gaogaotiantian Mar 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use local events when possible
  • Loading branch information
gaogaotiantian committed Jan 17, 2025
commit b59568262f593730f3e445015f244e931dc57d54
27 changes: 22 additions & 5 deletions Lib/bdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ class _MonitoringTracer:
E.INSTRUCTION: 'opcode',
}

GLOBAL_EVENTS = E.PY_START | E.PY_RESUME | E.PY_THROW | E.PY_UNWIND | E.RAISE
LOCAL_EVENTS = E.LINE | E.JUMP | E.PY_RETURN | E.PY_YIELD | E.STOP_ITERATION

def __init__(self):
self._tool_id = sys.monitoring.DEBUGGER_ID
self._name = 'bdbtracer'
self._tracefunc = None
self._disable_current_event = False
self._tracing_thread = None
self._enabled = False

def start_trace(self, tracefunc):
self._tracefunc = tracefunc
Expand All @@ -47,7 +51,7 @@ def start_trace(self, tracefunc):
if curr_tool is None:
sys.monitoring.use_tool_id(self._tool_id, self._name)
elif curr_tool == self._name:
sys.monitoring.set_events(self._tool_id, 0)
sys.monitoring.clear_tool_id(self._tool_id)
else:
raise ValueError('Another debugger is using the monitoring tool')
E = sys.monitoring.events
Expand All @@ -57,17 +61,18 @@ def start_trace(self, tracefunc):
sys.monitoring.register_callback(self._tool_id, event, callback)
if event != E.INSTRUCTION:
all_events |= event
self.check_trace_func()
self.check_trace_opcodes()
sys.monitoring.set_events(self._tool_id, all_events)
sys.monitoring.set_events(self._tool_id, self.GLOBAL_EVENTS)
self._enabled = True

def stop_trace(self):
self._enabled = False
self._tracing_thread = None
curr_tool = sys.monitoring.get_tool(self._tool_id)
if curr_tool != self._name:
return
for event in self.EVENT_CALLBACK_MAP.keys():
sys.monitoring.register_callback(self._tool_id, event, None)
sys.monitoring.set_events(self._tool_id, 0)
sys.monitoring.clear_tool_id(self._tool_id)
self.check_trace_opcodes()
sys.monitoring.free_tool_id(self._tool_id)

Expand All @@ -88,6 +93,8 @@ def wrapper(self, *args):
try:
frame = sys._getframe().f_back
ret = func(self, frame, *args)
if self._enabled and frame.f_trace:
self.check_trace_func()
if self._disable_current_event:
return sys.monitoring.DISABLE
else:
Expand All @@ -105,6 +112,8 @@ def call_callback(self, frame, code, *args):
local_tracefunc = self._tracefunc(frame, 'call', None)
if local_tracefunc is not None:
frame.f_trace = local_tracefunc
if self._enabled:
sys.monitoring.set_local_events(self._tool_id, code, self.LOCAL_EVENTS)

@callback_wrapper
def return_callback(self, frame, code, offset, retval):
Expand Down Expand Up @@ -163,6 +172,14 @@ def set_trace_opcodes(self, frame, trace_opcodes):
else:
sys.monitoring.set_local_events(self._tool_id, frame.f_code, 0)

def check_trace_func(self, frame=None):
if frame is None:
frame = sys._getframe().f_back
while frame is not None:
if frame.f_trace is not None:
sys.monitoring.set_local_events(self._tool_id, frame.f_code, self.LOCAL_EVENTS)
frame = frame.f_back

def _get_lineno(self, code, offset):
import dis
last_lineno = None
Expand Down