diff --git a/python/helpers/pydev/_pydev_bundle/pydev_monkey.py b/python/helpers/pydev/_pydev_bundle/pydev_monkey.py index 8586b4bf61eb..145dfdf53127 100644 --- a/python/helpers/pydev/_pydev_bundle/pydev_monkey.py +++ b/python/helpers/pydev/_pydev_bundle/pydev_monkey.py @@ -58,7 +58,7 @@ def _on_forked_process(): def _on_set_trace_for_new_thread(global_debugger): if global_debugger is not None: - global_debugger.SetTrace(global_debugger.trace_dispatch) + global_debugger.SetTrace(global_debugger.trace_dispatch, global_debugger.frame_eval_func) #=============================================================================== # Things related to monkey-patching diff --git a/python/helpers/pydev/_pydev_bundle/pydev_monkey_qt.py b/python/helpers/pydev/_pydev_bundle/pydev_monkey_qt.py index 37702481270b..78aebb6e6902 100644 --- a/python/helpers/pydev/_pydev_bundle/pydev_monkey_qt.py +++ b/python/helpers/pydev/_pydev_bundle/pydev_monkey_qt.py @@ -5,7 +5,7 @@ def set_trace_in_qt(): from _pydevd_bundle.pydevd_comm import get_global_debugger debugger = get_global_debugger() if debugger is not None: - pydevd_tracing.SetTrace(debugger.trace_dispatch) + pydevd_tracing.SetTrace(debugger.trace_dispatch, debugger.frame_eval_func) _patched_qt = False diff --git a/python/helpers/pydev/_pydevd_bundle/pydevd_tracing.py b/python/helpers/pydev/_pydevd_bundle/pydevd_tracing.py index 8027d585b97c..5fa041903492 100644 --- a/python/helpers/pydev/_pydevd_bundle/pydevd_tracing.py +++ b/python/helpers/pydev/_pydevd_bundle/pydevd_tracing.py @@ -66,7 +66,13 @@ def _internal_set_trace(tracing_func): if TracingFunctionHolder._original_tracing: TracingFunctionHolder._original_tracing(tracing_func) -def SetTrace(tracing_func): + +def SetTrace(tracing_func, frame_eval_func=None): + if tracing_func is not None and frame_eval_func is not None: + # There is no need to set tracing function if frame evaluation is available + frame_eval_func() + return + if TracingFunctionHolder._original_tracing is None: #This may happen before replace_sys_set_trace_func is called. sys.settrace(tracing_func) diff --git a/python/helpers/pydev/_pydevd_frame_eval/pydevd_frame_eval_main.py b/python/helpers/pydev/_pydevd_frame_eval/pydevd_frame_eval_main.py index e4cdf098a02d..d05bf3f50f18 100644 --- a/python/helpers/pydev/_pydevd_frame_eval/pydevd_frame_eval_main.py +++ b/python/helpers/pydev/_pydevd_frame_eval/pydevd_frame_eval_main.py @@ -11,7 +11,7 @@ stop_frame_eval = None if IS_PY36_OR_OLDER: try: - from _pydevd_frame_eval.pydevd_frame_evaluator import set_frame_eval, stop_frame_eval + from _pydevd_frame_eval.pydevd_frame_evaluator import frame_eval_func, stop_frame_eval except ImportError: from _pydev_bundle.pydev_monkey import log_error_once diff --git a/python/helpers/pydev/_pydevd_frame_eval/pydevd_frame_evaluator.pyx b/python/helpers/pydev/_pydevd_frame_eval/pydevd_frame_evaluator.pyx index f7367874c8a5..153db498331d 100644 --- a/python/helpers/pydev/_pydevd_frame_eval/pydevd_frame_evaluator.pyx +++ b/python/helpers/pydev/_pydevd_frame_eval/pydevd_frame_evaluator.pyx @@ -31,7 +31,7 @@ cdef PyObject*get_bytecode_while_frame_eval(PyFrameObject *frame, int exc): update_globals_dict( frame.f_globals) return _PyEval_EvalFrameDefault(frame, exc) -def set_frame_eval(): +def frame_eval_func(): cdef PyThreadState *state = PyThreadState_Get() state.interp.eval_frame = get_bytecode_while_frame_eval diff --git a/python/helpers/pydev/pydevd.py b/python/helpers/pydev/pydevd.py index 4919f0d4d568..252f24d5134e 100644 --- a/python/helpers/pydev/pydevd.py +++ b/python/helpers/pydev/pydevd.py @@ -36,7 +36,7 @@ from _pydevd_bundle.pydevd_custom_frames import CustomFramesContainer, custom_fr from _pydevd_bundle.pydevd_frame_utils import add_exception_to_frame from _pydevd_bundle.pydevd_kill_all_pydevd_threads import kill_all_pydev_threads from _pydevd_bundle.pydevd_trace_dispatch import trace_dispatch as _trace_dispatch -from _pydevd_frame_eval.pydevd_frame_eval_main import set_frame_eval, stop_frame_eval +from _pydevd_frame_eval.pydevd_frame_eval_main import frame_eval_func, stop_frame_eval from _pydevd_bundle.pydevd_utils import save_main_module from pydevd_concurrency_analyser.pydevd_concurrency_logger import ThreadingLogger, AsyncioLogger, send_message, cur_time from pydevd_concurrency_analyser.pydevd_thread_wrappers import wrap_threads @@ -868,13 +868,10 @@ class PyDB: def prepare_to_run(self): ''' Shared code to prepare debugging by installing traces and registering threads ''' - if set_frame_eval is None: - self.patch_threads() - pydevd_tracing.SetTrace(self.trace_dispatch) - else: - # There is no need to set tracing function if frame evaluation is available. Moreover, there is no need to patch thread - # functions, because frame evaluation function is set to all threads by default. - set_frame_eval() + self.patch_threads() + pydevd_tracing.SetTrace(self.trace_dispatch, self.frame_eval_func) + # There is no need to set tracing function if frame evaluation is available. Moreover, there is no need to patch thread + # functions, because frame evaluation function is set to all threads by default. PyDBCommandThread(self).start() if self.signature_factory is not None or self.thread_analyser is not None: @@ -883,6 +880,9 @@ class PyDB: def patch_threads(self): + if self.frame_eval_func is not None: + # There is no need to patch thread functions, because frame evaluation function is set to all threads by default. + return try: # not available in jython! import threading @@ -1008,6 +1008,7 @@ class PyDB: time.sleep(0.01) trace_dispatch = _trace_dispatch + frame_eval_func = frame_eval_func def set_debug(setup): setup['DEBUG_RECORD_SOCKET_READS'] = True @@ -1245,7 +1246,7 @@ def _locked_settrace( # note that we do that through pydevd_tracing.SetTrace so that the tracing # is not warned to the user! - pydevd_tracing.SetTrace(debugger.trace_dispatch) + pydevd_tracing.SetTrace(debugger.trace_dispatch, debugger.frame_eval_func) if not trace_only_current_thread: # Trace future threads? @@ -1278,7 +1279,7 @@ def _locked_settrace( additional_info = PyDBAdditionalThreadInfo() t.additional_info = additional_info - pydevd_tracing.SetTrace(debugger.trace_dispatch) + pydevd_tracing.SetTrace(debugger.trace_dispatch, debugger.frame_eval_func) if not trace_only_current_thread: # Trace future threads?