Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Jan 20, 2024
1 parent c93aab2 commit b791ae7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 53 deletions.
82 changes: 42 additions & 40 deletions _pydevd_sys_monitoring/pydevd_sys_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,8 @@ def _get_func_code_info(code_obj, frame_or_depth) -> FuncCodeInfo:
def _enable_line_tracing(code):
# print('enable line tracing', code)
events = monitor.get_local_events(DEBUGGER_ID, code)
monitor.set_local_events(DEBUGGER_ID, code, events | monitor.events.LINE | monitor.events.JUMP)
# monitor.set_local_events(DEBUGGER_ID, code, events | monitor.events.LINE | monitor.events.JUMP)
monitor.set_local_events(DEBUGGER_ID, code, events | monitor.events.LINE)


def _enable_return_tracing(code):
Expand Down Expand Up @@ -999,44 +1000,45 @@ def _plugin_stepping(py_db, step_cmd, event, frame, thread_info):


def _jump_event(code, from_offset, to_offset):

# A bunch of things have to be repeated especially because in the sys.monitoring
# everything is global, yet, when we start tracing something for stepping that
# needs to be per-thread.
try:
thread_info = _thread_local_info.thread_info
except:
thread_info = _get_thread_info(True, 1)
if thread_info is None:
return

py_db: object = GlobalDebuggerHolder.global_dbg
if py_db is None or py_db.pydb_disposed:
return monitor.DISABLE

if not thread_info.trace or thread_info.thread._is_stopped:
# For thread-related stuff we can't disable the code tracing because other
# threads may still want it...
return

func_code_info: FuncCodeInfo = _get_func_code_info(code, 1)
if func_code_info.always_skip_code or func_code_info.always_filtered_out:
return monitor.DISABLE

# Same logic as "sys_trace_jump_func" in https://github.com/python/cpython/blob/main/Python/legacy_tracing.c
# if to_offset > from_offset:
return monitor.DISABLE

# # A bunch of things have to be repeated especially because in the sys.monitoring
# # everything is global, yet, when we start tracing something for stepping that
# # needs to be per-thread.
# try:
# thread_info = _thread_local_info.thread_info
# except:
# thread_info = _get_thread_info(True, 1)
# if thread_info is None:
# return
#
# py_db: object = GlobalDebuggerHolder.global_dbg
# if py_db is None or py_db.pydb_disposed:
# return monitor.DISABLE
#
from_line = func_code_info.get_line_of_offset(from_offset)
to_line = func_code_info.get_line_of_offset(to_offset)
# print('jump event', code.co_name, 'from line', from_line, 'to line', to_line)

if from_line != to_line:
return monitor.DISABLE

# We know the frame depth.
frame = _getframe(1)
return _internal_line_event(func_code_info, frame, frame.f_lineno)
# if not thread_info.trace or thread_info.thread._is_stopped:
# # For thread-related stuff we can't disable the code tracing because other
# # threads may still want it...
# return
#
# func_code_info: FuncCodeInfo = _get_func_code_info(code, 1)
# if func_code_info.always_skip_code or func_code_info.always_filtered_out:
# return monitor.DISABLE
#
# # Same logic as "sys_trace_jump_func" in https://github.com/python/cpython/blob/main/Python/legacy_tracing.c
# # if to_offset > from_offset:
# # return monitor.DISABLE
# #
# from_line = func_code_info.get_line_of_offset(from_offset)
# to_line = func_code_info.get_line_of_offset(to_offset)
# # print('jump event', code.co_name, 'from line', from_line, 'to line', to_line)
#
# if from_line != to_line:
# return monitor.DISABLE
#
# # We know the frame depth.
# frame = _getframe(1)
# return _internal_line_event(func_code_info, frame, frame.f_lineno)


def _line_event(code, line):
Expand Down Expand Up @@ -1368,7 +1370,7 @@ def stop_monitoring(all_threads=False):
monitor.register_callback(DEBUGGER_ID, monitor.events.PY_START, None)
monitor.register_callback(DEBUGGER_ID, monitor.events.PY_RESUME, None)
monitor.register_callback(DEBUGGER_ID, monitor.events.LINE, None)
monitor.register_callback(DEBUGGER_ID, monitor.events.JUMP, None)
# monitor.register_callback(DEBUGGER_ID, monitor.events.JUMP, None)
monitor.register_callback(DEBUGGER_ID, monitor.events.PY_RETURN, None)
monitor.register_callback(DEBUGGER_ID, monitor.events.RAISE, None)
monitor.free_tool_id(monitor.DEBUGGER_ID)
Expand Down Expand Up @@ -1456,14 +1458,14 @@ def update_monitor_events(suspend_requested: Optional[bool]=None) -> None:
monitor.register_callback(DEBUGGER_ID, monitor.events.PY_START, _start_method_event)
# monitor.register_callback(DEBUGGER_ID, monitor.events.PY_RESUME, _resume_method_event)
monitor.register_callback(DEBUGGER_ID, monitor.events.LINE, _line_event)
monitor.register_callback(DEBUGGER_ID, monitor.events.JUMP, _jump_event)
# monitor.register_callback(DEBUGGER_ID, monitor.events.JUMP, _jump_event)
monitor.register_callback(DEBUGGER_ID, monitor.events.PY_RETURN, _return_event)

else:
monitor.register_callback(DEBUGGER_ID, monitor.events.PY_START, None)
monitor.register_callback(DEBUGGER_ID, monitor.events.PY_RESUME, None)
monitor.register_callback(DEBUGGER_ID, monitor.events.LINE, None)
monitor.register_callback(DEBUGGER_ID, monitor.events.JUMP, None)
# monitor.register_callback(DEBUGGER_ID, monitor.events.JUMP, None)
monitor.register_callback(DEBUGGER_ID, monitor.events.PY_RETURN, None)

monitor.set_events(DEBUGGER_ID, required_events)
Expand Down
16 changes: 8 additions & 8 deletions pydevd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2053,14 +2053,14 @@ def do_wait_suspend(self, thread, frame, event, arg, exception_type=None): # @U

thread_id = get_current_thread_id(thread)

if DebugInfoHolder.DEBUG_TRACE_LEVEL >= 2:
pydev_log.debug('do_wait_suspend %s %s %s %s %s %s (%s)' % (frame.f_lineno, frame.f_code.co_name, frame.f_code.co_filename, event, arg, constant_to_str(thread.additional_info.pydev_step_cmd), constant_to_str(thread.additional_info.pydev_original_step_cmd)))
pydev_log.debug('--- internal stack ---')
_f = sys._getframe()
while _f is not None:
pydev_log.debug(' -> %s' % (_f))
_f = _f.f_back
pydev_log.debug('--- end internal stack ---')
# if DebugInfoHolder.DEBUG_TRACE_LEVEL >= 2:
# pydev_log.debug('do_wait_suspend %s %s %s %s %s %s (%s)' % (frame.f_lineno, frame.f_code.co_name, frame.f_code.co_filename, event, arg, constant_to_str(thread.additional_info.pydev_step_cmd), constant_to_str(thread.additional_info.pydev_original_step_cmd)))
# pydev_log.debug('--- internal stack ---')
# _f = sys._getframe()
# while _f is not None:
# pydev_log.debug(' -> %s' % (_f))
# _f = _f.f_back
# pydev_log.debug('--- end internal stack ---')

# Send the suspend message
message = thread.additional_info.pydev_message
Expand Down
5 changes: 0 additions & 5 deletions tests_python/test_debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -4489,11 +4489,6 @@ def test_frame_eval_mode_corner_case_04(case_setup):
hit = writer.wait_for_breakpoint_hit(line=line)
writer.write_run_thread(hit.thread_id)

if TODO_PY312:
for i in range(2):
hit = writer.wait_for_breakpoint_hit(line=line)
writer.write_run_thread(hit.thread_id)

writer.finished_ok = True


Expand Down

0 comments on commit b791ae7

Please sign in to comment.