Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Nov 18, 2023
1 parent 2f89940 commit c037d03
Showing 1 changed file with 89 additions and 7 deletions.
96 changes: 89 additions & 7 deletions _pydevd_sys_monitoring/pydevd_sys_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
from _pydevd_bundle import pydevd_dont_trace
from _pydevd_bundle.pydevd_additional_thread_info import _set_additional_thread_info_lock, PyDBAdditionalThreadInfo
from _pydevd_bundle.pydevd_constants import GlobalDebuggerHolder, ForkSafeLock, \
PYDEVD_IPYTHON_CONTEXT, EXCEPTION_TYPE_USER_UNHANDLED
PYDEVD_IPYTHON_CONTEXT, EXCEPTION_TYPE_USER_UNHANDLED, RETURN_VALUES_DICT
from pydevd_file_utils import NORM_PATHS_AND_BASE_CONTAINER, \
get_abs_path_real_path_and_base_from_file, \
get_abs_path_real_path_and_base_from_frame
from _pydevd_bundle.pydevd_trace_dispatch import should_stop_on_exception, handle_exception
from _pydevd_bundle.pydevd_constants import EXCEPTION_TYPE_HANDLED
from _pydevd_bundle.pydevd_trace_dispatch import is_unhandled_exception
from _pydevd_bundle.pydevd_breakpoints import stop_on_unhandled_exception
from _pydevd_bundle.pydevd_utils import get_clsname_for_code

if hasattr(sys, 'monitoring'):
DEBUGGER_ID = sys.monitoring.DEBUGGER_ID
Expand Down Expand Up @@ -576,6 +577,66 @@ def _raise_event(code, instruction, exc):
return


# IFDEF CYTHON
# cdef get_func_name(frame):
# cdef str func_name
# ELSE
def get_func_name(frame):
# ENDIF
code_obj = frame.f_code
func_name = code_obj.co_name
try:
cls_name = get_clsname_for_code(code_obj, frame)
if cls_name is not None:
return "%s.%s" % (cls_name, func_name)
else:
return func_name
except:
pydev_log.exception()
return func_name


# IFDEF CYTHON
# cdef _show_return_values(frame, arg):
# ELSE
def _show_return_values(frame, arg):
# ENDIF
try:
try:
f_locals_back = getattr(frame.f_back, "f_locals", None)
if f_locals_back is not None:
return_values_dict = f_locals_back.get(RETURN_VALUES_DICT, None)
if return_values_dict is None:
return_values_dict = {}
f_locals_back[RETURN_VALUES_DICT] = return_values_dict
name = get_func_name(frame)
return_values_dict[name] = arg
except:
pydev_log.exception()
finally:
f_locals_back = None


# IFDEF CYTHON
# cdef _remove_return_values(py_db, frame):
# ELSE
def _remove_return_values(py_db, frame):
# ENDIF
try:
try:
# Showing return values was turned off, we should remove them from locals dict.
# The values can be in the current frame or in the back one
frame.f_locals.pop(RETURN_VALUES_DICT, None)

f_locals_back = getattr(frame.f_back, "f_locals", None)
if f_locals_back is not None:
f_locals_back.pop(RETURN_VALUES_DICT, None)
except:
pydev_log.exception()
finally:
f_locals_back = None


def _return_event(code, instruction, retval):
try:
thread_info = _thread_local_info.thread_info
Expand Down Expand Up @@ -603,20 +664,39 @@ def _return_event(code, instruction, retval):
frame = sys._getframe(1)

step_cmd = info.pydev_step_cmd
if step_cmd in (CMD_STEP_RETURN, CMD_STEP_RETURN_MY_CODE) and _is_same_frame(info, info.pydev_step_stop, frame):
_stop_on_return(py_db, thread_info, info, step_cmd, frame, retval)
return
stop_frame = info.pydev_step_stop
stop = False
if step_cmd in (CMD_STEP_RETURN, CMD_STEP_RETURN_MY_CODE) and _is_same_frame(info, stop_frame, frame):
stop = True

if step_cmd in (CMD_STEP_OVER, CMD_STEP_OVER_MY_CODE) and _is_same_frame(info, info.pydev_step_stop, frame):
elif step_cmd in (CMD_STEP_OVER, CMD_STEP_OVER_MY_CODE) and _is_same_frame(info, stop_frame, frame):
# This isn't in the sys.settrace version: on a step over, if we return and the return is valid, show
# as a step return instead of going back to step into mode (but if the back frame is not valid, then
# go to step into mode).
f_back = frame.f_back
if f_back is not None:
back_func_code_info = get_func_code_info(f_back.f_code)
if back_func_code_info is not None and not back_func_code_info.always_skip_code and not back_func_code_info.filtered_out:
_stop_on_return(py_db, thread_info, info, step_cmd, frame, retval)
return
stop = True
if stop:
if py_db.show_return_values:
_show_return_values(frame, retval)

_stop_on_return(py_db, thread_info, info, step_cmd, frame, retval)
return

if py_db.show_return_values:
if (
(info.pydev_step_cmd in (CMD_STEP_OVER, CMD_STEP_OVER_MY_CODE, CMD_SMART_STEP_INTO) and (_is_same_frame(info, stop_frame, frame.f_back))) or
(info.pydev_step_cmd in (CMD_STEP_RETURN, CMD_STEP_RETURN_MY_CODE) and (info, _is_same_frame(stop_frame, frame))) or
(info.pydev_step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_COROUTINE)) or
(
info.pydev_step_cmd == CMD_STEP_INTO_MY_CODE
and frame.f_back is not None
and not py_db.apply_files_filter(frame.f_back, frame.f_back.f_code.co_filename, True)
)
):
_show_return_values(frame, retval)

if step_cmd in (CMD_STEP_OVER, CMD_STEP_RETURN, CMD_STEP_OVER_MY_CODE, CMD_STEP_RETURN_MY_CODE, CMD_SMART_STEP_INTO):
# If we are in single step mode and something causes us to exit the current frame, we need to make sure we break
Expand All @@ -633,6 +713,8 @@ def _return_event(code, instruction, retval):
info.pydev_step_cmd = CMD_STEP_INTO_MY_CODE
info.pydev_step_stop = None
_enable_code_tracing_for_frame_and_parents(thread_info, stop_frame.f_back)
if py_db.show_return_values:
_show_return_values(frame, retval)


def _enable_code_tracing_for_frame_and_parents(thread_info, frame):
Expand Down

0 comments on commit c037d03

Please sign in to comment.