diff --git a/python/helpers/pydev/_pydevd_bundle/pydevd_constants.py b/python/helpers/pydev/_pydevd_bundle/pydevd_constants.py index 9516c1455f9b..fcc06feeaa61 100644 --- a/python/helpers/pydev/_pydevd_bundle/pydevd_constants.py +++ b/python/helpers/pydev/_pydevd_bundle/pydevd_constants.py @@ -37,6 +37,8 @@ except AttributeError: #the communication slower -- as the variables are being gathered lazily in the latest version of eclipse, #this value was raised from 200 to 1000. MAXIMUM_VARIABLE_REPRESENTATION_SIZE = 1000 +# Prefix for saving functions return values in locals +RETURN_VALUES_PREFIX = '__pydevd_ret_val_' import os diff --git a/python/helpers/pydev/_pydevd_bundle/pydevd_frame.py b/python/helpers/pydev/_pydevd_bundle/pydevd_frame.py index c17f32a5210d..def345f0f4db 100644 --- a/python/helpers/pydev/_pydevd_bundle/pydevd_frame.py +++ b/python/helpers/pydev/_pydevd_bundle/pydevd_frame.py @@ -11,7 +11,7 @@ from _pydevd_bundle.pydevd_breakpoints import get_exception_breakpoint from _pydevd_bundle.pydevd_comm import CMD_STEP_CAUGHT_EXCEPTION, CMD_STEP_RETURN, CMD_STEP_OVER, CMD_SET_BREAK, \ CMD_STEP_INTO, CMD_SMART_STEP_INTO, CMD_RUN_TO_LINE, CMD_SET_NEXT_STATEMENT, CMD_STEP_INTO_MY_CODE from _pydevd_bundle.pydevd_constants import STATE_SUSPEND, dict_contains, get_thread_id, STATE_RUN, dict_iter_values, IS_PY3K, \ - dict_keys, dict_pop + dict_keys, dict_pop, RETURN_VALUES_PREFIX from _pydevd_bundle.pydevd_dont_trace_files import DONT_TRACE, PYDEV_FILE from _pydevd_bundle.pydevd_frame_utils import add_exception_to_frame, just_raised from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame @@ -266,18 +266,25 @@ class PyDBFrame: # No longer cdef because object was dying when only a reference thread = None def manage_return_values(self, main_debugger, frame, event, arg): - if main_debugger.show_return_values: - if event == "return" and hasattr(frame, "f_code") and hasattr(frame.f_code, "co_name"): - name = frame.f_code.co_name - if hasattr(frame, "f_back") and hasattr(frame.f_back, "f_locals"): - frame.f_back.f_locals["__pydevd_ret_val" + name] = arg - elif main_debugger.remove_return_values_flag: - # show return values was turned off, we should remove them from locals dict - if hasattr(frame, "f_back") and hasattr(frame.f_back, "f_locals"): - for var_name in dict_keys(frame.f_back.f_locals): - if var_name.startswith("__pydevd_ret_val"): + try: + if main_debugger.show_return_values: + if event == "return" and hasattr(frame, "f_code") and hasattr(frame.f_code, "co_name"): + name = frame.f_code.co_name + if hasattr(frame, "f_back") and hasattr(frame.f_back, "f_locals"): + frame.f_back.f_locals[RETURN_VALUES_PREFIX + name] = arg + elif main_debugger.remove_return_values_flag: + # show return values was turned off, we should remove them from locals dict + for var_name in dict_keys(frame.f_locals): + if var_name.startswith(RETURN_VALUES_PREFIX): dict_pop(frame.f_back.f_locals, var_name) + if hasattr(frame, "f_back") and hasattr(frame.f_back, "f_locals"): + for var_name in dict_keys(frame.f_back.f_locals): + if var_name.startswith(RETURN_VALUES_PREFIX): + dict_pop(frame.f_back.f_locals, var_name) + main_debugger.remove_return_values_flag = False + except: main_debugger.remove_return_values_flag = False + traceback.print_exc() # IFDEF CYTHON # def trace_dispatch(self, frame, str event, arg): diff --git a/python/helpers/pydev/_pydevd_bundle/pydevd_xml.py b/python/helpers/pydev/_pydevd_bundle/pydevd_xml.py index 47a2180474ae..263047cfa085 100644 --- a/python/helpers/pydev/_pydevd_bundle/pydevd_xml.py +++ b/python/helpers/pydev/_pydevd_bundle/pydevd_xml.py @@ -239,8 +239,8 @@ def var_to_xml(val, name, doTrim=True, additionalInXml=''): except: pass - if name.startswith("__pydevd_ret_val"): - name = name.split("__pydevd_ret_val")[1] + if name.startswith(RETURN_VALUES_PREFIX): + name = name.split(RETURN_VALUES_PREFIX)[1] xmlRetVal = ' isRetVal="True"' else: xmlRetVal = '' diff --git a/python/pydevSrc/com/jetbrains/python/debugger/PyDebugValue.java b/python/pydevSrc/com/jetbrains/python/debugger/PyDebugValue.java index 7bb5b5b79d09..b2a23241e35e 100644 --- a/python/pydevSrc/com/jetbrains/python/debugger/PyDebugValue.java +++ b/python/pydevSrc/com/jetbrains/python/debugger/PyDebugValue.java @@ -19,6 +19,8 @@ public class PyDebugValue extends XNamedValue { private static final Logger LOG = Logger.getInstance("#com.jetbrains.python.pydev.PyDebugValue"); public static final int MAX_VALUE = 256; + public static final String RETURN_VALUES_PREFIX = "__pydevd_ret_val_"; + private String myTempName = null; private final String myType; private final String myTypeQualifier; diff --git a/python/src/com/jetbrains/python/debugger/PyDebugProcess.java b/python/src/com/jetbrains/python/debugger/PyDebugProcess.java index 23f3f6f12021..bf3626166629 100644 --- a/python/src/com/jetbrains/python/debugger/PyDebugProcess.java +++ b/python/src/com/jetbrains/python/debugger/PyDebugProcess.java @@ -608,7 +608,11 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr @Override public XValueChildrenList loadVariable(final PyDebugValue var) throws PyDebuggerException { final PyStackFrame frame = currentFrame(); - return myDebugger.loadVariable(frame.getThreadId(), frame.getFrameId(), var); + PyDebugValue debugValue = var; + if (var.isReturnedVal()) { + debugValue = var.setName(PyDebugValue.RETURN_VALUES_PREFIX + var.getName()); + } + return myDebugger.loadVariable(frame.getThreadId(), frame.getFrameId(), debugValue); } @Override