Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Nov 11, 2023
1 parent 3a8a6d3 commit 59b9505
Showing 1 changed file with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
_global_notify_skipped_step_in_lock = ForkSafeLock()


def notify_skipped_step_in_because_of_filters(py_db, frame):
def _notify_skipped_step_in_because_of_filters(py_db, frame):
global _global_notify_skipped_step_in

with _global_notify_skipped_step_in_lock:
Expand Down Expand Up @@ -93,7 +93,7 @@ def initialize_can_create_dummy_thread(self, code):

# In these cases we cannot create a dummy thread (an actual
# thread will be created later or tracing will already be set).
if basename == 'threading' and co_name in ('__bootstrap', '_bootstrap', '__bootstrap_inner', '_bootstrap_inner'):
if basename == 'threading':
self.can_create_dummy_thread = False
elif basename == 'pydev_monkey' and co_name == '__call__':
self.can_create_dummy_thread = False
Expand Down Expand Up @@ -157,7 +157,7 @@ def __init__(self):
self.filtered_out: Optional[bool] = None


def get_thread_info(code: Optional[CodeType], create: bool) -> Optional[ThreadInfo]:
def _get_thread_info(code: Optional[CodeType], create: bool) -> Optional[ThreadInfo]:
'''
Provides thread-related info.
Expand Down Expand Up @@ -289,13 +289,13 @@ def get_func_code_info(code_obj) -> FuncCodeInfo:
return func_code_info


def enable_line_tracing(code):
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)


def enable_return_tracing(code):
def _enable_return_tracing(code):
print('enable return tracing', code)
events = monitor.get_local_events(DEBUGGER_ID, code)
monitor.set_local_events(DEBUGGER_ID, code, events | monitor.events.PY_RETURN)
Expand All @@ -320,13 +320,13 @@ def _enable_code_tracing(thread, code, frame):
return monitor.DISABLE

if func_code_info.breakpoint_found:
enable_line_tracing(code)
_enable_line_tracing(code)
elif py_db.has_plugin_line_breaks or py_db.has_plugin_exception_breaks:
can_skip = py_db.plugin.can_skip(py_db, frame)

if not can_skip:
if py_db.has_plugin_line_breaks:
enable_line_tracing(code)
_enable_line_tracing(code)

# if py_db.has_plugin_exception_breaks:
# enable_exception_tracing(code)
Expand All @@ -342,17 +342,17 @@ def _enable_code_tracing(thread, code, frame):

if step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE, CMD_STEP_INTO_COROUTINE, CMD_SMART_STEP_INTO):
# Stepping (must have line tracing enabled).
enable_line_tracing(code)
_enable_line_tracing(code)

elif step_cmd in (CMD_STEP_RETURN, CMD_STEP_RETURN_MY_CODE) and _is_same_frame(info, info.pydev_step_stop, frame):
enable_return_tracing(code)
_enable_return_tracing(code)

elif step_cmd in (CMD_STEP_OVER, CMD_STEP_OVER_MY_CODE):
if _is_same_frame(info, info.pydev_step_stop, frame):
enable_line_tracing(code)
_enable_line_tracing(code)
elif py_db.show_return_values and _is_same_frame(info, info.pydev_step_stop, frame.f_back):
# Show return values on step over.
enable_return_tracing(code)
_enable_return_tracing(code)
#
# if py_db.break_on_caught_exceptions or py_db.break_on_user_uncaught_exceptions or py_db.has_plugin_exception_breaks:
# enable_exception_tracing(code)
Expand All @@ -365,7 +365,7 @@ def _return_event(code, instruction, retval):
try:
thread_info = _thread_local_info.thread_info
except:
thread_info = get_thread_info(code, True)
thread_info = _get_thread_info(code, True)
if thread_info is None:
return

Expand Down Expand Up @@ -432,15 +432,15 @@ def _stop_on_return(py_db, thread_info, info, step_cmd, frame, retval):


def _line_event(code, line):
print('line event', code, line)
# print('line event', code, line)

# 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(code, True)
thread_info = _get_thread_info(code, True)
if thread_info is None:
return

Expand Down Expand Up @@ -469,7 +469,7 @@ def _line_event(code, line):
if func_code_info.filtered_out is None: # i.e.: needs to be calculated
if py_db.apply_files_filter(frame, func_code_info.abs_path_filename, False):
if is_stepping and info.pydev_original_step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE) and not _global_notify_skipped_step_in:
notify_skipped_step_in_because_of_filters(py_db, frame)
_notify_skipped_step_in_because_of_filters(py_db, frame)

# A little gotcha, sometimes when we're stepping in we have to stop in a
# return event showing the back frame as the current frame, so, we need
Expand All @@ -488,6 +488,8 @@ def _line_event(code, line):
else:
func_code_info.filtered_out = False

# print('line event', info, id(info), thread_info.thread.name)
# print('line event', info.pydev_state, line, threading.current_thread(), code)
# If we reached here, it was not filtered out.
bp = None
stop = False
Expand Down Expand Up @@ -654,7 +656,7 @@ def _start_method(code, instruction_offset):
try:
thread_info = _thread_local_info.thread_info
except:
thread_info = get_thread_info(code, True)
thread_info = _get_thread_info(code, True)
if thread_info is None:
return

Expand All @@ -672,8 +674,8 @@ def _start_method(code, instruction_offset):


def start_monitoring(all_threads=False):
print('start monitoring, all_threads=', all_threads)
if all_threads:
print('start monitoring, all_threads=', all_threads)
DEBUGGER_ID = monitor.DEBUGGER_ID
if not monitor.get_tool(DEBUGGER_ID):
monitor.use_tool_id(DEBUGGER_ID, 'pydevd')
Expand All @@ -698,15 +700,17 @@ def start_monitoring(all_threads=False):
thread_info = _thread_local_info.thread_info
except:
# code=None means we can already get the threading.current_thread.
thread_info = get_thread_info(code=None, create=True)
thread_info = _get_thread_info(code=None, create=True)
if thread_info is None:
print('start monitoring, thread=', None)
return
thread_info.trace = True
print('start monitoring, thread=', thread_info.thread)
thread_info.trace = True


def stop_monitoring(all_threads=False):
print('stop monitoring, all_threads=', all_threads)
if all_threads:
print('stop monitoring, all_threads=', all_threads)
if monitor.get_tool(monitor.DEBUGGER_ID) == 'pydevd':
monitor.set_events(monitor.DEBUGGER_ID, 0)
monitor.register_callback(DEBUGGER_ID, monitor.events.PY_START, None)
Expand All @@ -719,10 +723,11 @@ def stop_monitoring(all_threads=False):
thread_info = _thread_local_info.thread_info
except:
# code=None means we can already get the threading.current_thread.
thread_info = get_thread_info(code=None, create=False)
thread_info = _get_thread_info(code=None, create=False)
if thread_info is None:
return
thread_info.trace = False
print('stop monitoring, thread=', thread_info.thread)
thread_info.trace = False


def restart_events():
Expand Down

0 comments on commit 59b9505

Please sign in to comment.