Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
Fix issues with django and jinja2 exceptions with just-my-code turned…
Browse files Browse the repository at this point in the history
… on. Fixes #1181 (#1243)

* Fix issues with django and jinja2 exceptions with just-my-code turned on. Fixes #1181

* Modules don't have __qualname__.

* Fix test to do a step out.

* Fix test for Jython.
  • Loading branch information
fabioz authored and karthiknadig committed Mar 19, 2019
1 parent 1173a2b commit 6d2062b
Show file tree
Hide file tree
Showing 23 changed files with 2,225 additions and 1,897 deletions.
3,459 changes: 1,742 additions & 1,717 deletions src/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_cython.c

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_cython.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,9 @@ cdef class PyDBFrame:
or (step_cmd in (108, 109, 159, 160) and stop_frame is not frame)

if can_skip:
if plugin_manager is not None and main_debugger.has_plugin_line_breaks:
can_skip = not plugin_manager.can_not_skip(main_debugger, frame)
if plugin_manager is not None and (
main_debugger.has_plugin_line_breaks or main_debugger.has_plugin_exception_breaks):
can_skip = plugin_manager.can_skip(main_debugger, frame)

# CMD_STEP_OVER = 108, CMD_STEP_OVER_MY_CODE = 159
if can_skip and main_debugger.show_return_values and info.pydev_step_cmd in (108, 159) and frame.f_back is info.pydev_step_stop:
Expand Down
5 changes: 3 additions & 2 deletions src/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,9 @@ def trace_dispatch(self, frame, event, arg):
or (step_cmd in (108, 109, 159, 160) and stop_frame is not frame)

if can_skip:
if plugin_manager is not None and main_debugger.has_plugin_line_breaks:
can_skip = not plugin_manager.can_not_skip(main_debugger, frame)
if plugin_manager is not None and (
main_debugger.has_plugin_line_breaks or main_debugger.has_plugin_exception_breaks):
can_skip = plugin_manager.can_skip(main_debugger, frame)

# CMD_STEP_OVER = 108, CMD_STEP_OVER_MY_CODE = 159
if can_skip and main_debugger.show_return_values and info.pydev_step_cmd in (108, 159) and frame.f_back is info.pydev_step_stop:
Expand Down
16 changes: 13 additions & 3 deletions src/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_io.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from _pydevd_bundle import pydevd_constants
from _pydev_imps._pydev_saved_modules import threading

IS_PY3K = pydevd_constants.IS_PY3K

Expand All @@ -20,16 +21,25 @@ def __init__(self, original, new_redirect, wrap_buffer=False):
Whether to create a buffer attribute (needed to mimick python 3 s
tdout/stderr which has a buffer to write binary data).
'''
self._lock = threading.RLock()
self._writing = False
self._redirect_to = (original, new_redirect)
if wrap_buffer and hasattr(original, 'buffer'):
self.buffer = IORedirector(original.buffer, new_redirect.buffer, False)

def write(self, s):
# Note that writing to the original stream may fail for some reasons
# (such as trying to write something that's not a string or having it closed).
for r in self._redirect_to:
if hasattr(r, 'write'):
r.write(s)
with self._lock:
if self._writing:
return
self._writing = True
try:
for r in self._redirect_to:
if hasattr(r, 'write'):
r.write(s)
finally:
self._writing = False

def isatty(self):
for r in self._redirect_to:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
from _pydev_bundle.pydev_is_thread_alive import is_thread_alive
from _pydev_bundle.pydev_override import overrides
from _pydevd_bundle._debug_adapter import pydevd_schema
from _pydevd_bundle.pydevd_comm_constants import CMD_THREAD_CREATE, CMD_RETURN, CMD_MODULE_EVENT
from _pydevd_bundle.pydevd_comm_constants import CMD_THREAD_CREATE, CMD_RETURN, CMD_MODULE_EVENT, \
CMD_WRITE_TO_CONSOLE
from _pydevd_bundle.pydevd_constants import get_thread_id, dict_values
from _pydevd_bundle.pydevd_net_command import NetCommand
from _pydevd_bundle.pydevd_net_command_factory_xml import NetCommandFactory
from _pydevd_bundle.pydevd_utils import get_non_pydevd_threads
from _pydev_imps._pydev_saved_modules import threading
from _pydevd_bundle._debug_adapter.pydevd_schema import ModuleEvent, ModuleEventBody, Module
from _pydevd_bundle._debug_adapter.pydevd_schema import ModuleEvent, ModuleEventBody, Module, \
OutputEventBody, OutputEvent
from functools import partial
import itertools
import pydevd_file_utils
Expand Down Expand Up @@ -178,17 +180,16 @@ def make_get_thread_stack_message(self, py_db, seq, thread_id, topmost_frame, fm
py_db, topmost_frame, frame_id_to_lineno
):

module_name = frame.f_globals.get('__qualname__', '')
if not module_name:
module_name = frame.f_globals.get('__name__', '')
module_name = frame.f_globals.get('__name__', '')

module_events.extend(self.modules_manager.track_module(filename_in_utf8, module_name, frame))

presentation_hint = None
if not py_db.in_project_scope(filename_in_utf8):
if py_db.get_use_libraries_filter():
continue
presentation_hint = 'subtle'
if not getattr(frame, 'IS_PLUGIN_FRAME', False): # Never filter out plugin frames!
if not py_db.in_project_scope(filename_in_utf8):
if py_db.get_use_libraries_filter():
continue
presentation_hint = 'subtle'

formatted_name = self._format_frame_name(fmt, method_name, module_name, lineno, filename_in_utf8)
frames.append(pydevd_schema.StackFrame(
Expand All @@ -209,3 +210,10 @@ def make_get_thread_stack_message(self, py_db, seq, thread_id, topmost_frame, fm
command='stackTrace',
body=pydevd_schema.StackTraceResponseBody(stackFrames=frames, totalFrames=len(frames)))
return NetCommand(CMD_RETURN, 0, response.to_dict(), is_json=True)

@overrides(NetCommandFactory.make_io_message)
def make_io_message(self, v, ctx):
category = 'stdout' if int(ctx) == 1 else 'stderr'
body = OutputEventBody(v, category)
event = OutputEvent(body)
return NetCommand(CMD_WRITE_TO_CONSOLE, 0, event.to_dict(), is_json=True)
19 changes: 10 additions & 9 deletions src/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class DefaultResolver:
def resolve(self, var, attribute):
return getattr(var, attribute)

def get_contents_debug_adapter_protocol(self, obj, fmt={}):
def get_contents_debug_adapter_protocol(self, obj, fmt=None):
if MethodWrapperType:
dct, used___dict__ = self._get_py_dictionary(obj)
else:
Expand Down Expand Up @@ -260,17 +260,18 @@ def resolve(self, dict, key):

raise UnableToResolveVariableException()

def key_to_str(self, key, fmt={}):
if fmt.get('hex', False):
safe_repr = SafeRepr()
safe_repr.convert_to_hex = True
return safe_repr(key)
def key_to_str(self, key, fmt=None):
if fmt is not None:
if fmt.get('hex', False):
safe_repr = SafeRepr()
safe_repr.convert_to_hex = True
return safe_repr(key)
return '%r' % (key,)

def init_dict(self):
return {}

def get_contents_debug_adapter_protocol(self, dct, fmt={}):
def get_contents_debug_adapter_protocol(self, dct, fmt=None):
'''
This method is to be used in the case where the variables are all saved by its id (and as
such don't need to have the `resolve` method called later on, so, keys don't need to
Expand All @@ -286,7 +287,7 @@ def get_contents_debug_adapter_protocol(self, dct, fmt={}):
for key, val in dict_iter_items(dct):
i += 1
key_as_str = self.key_to_str(key, fmt)
eval_key_str = self.key_to_str(key) # do not format the key
eval_key_str = self.key_to_str(key) # do not format the key
ret.append((key_as_str, val, '[%s]' % (eval_key_str,)))
if i > MAX_ITEMS_TO_HANDLE:
ret.append((TOO_LARGE_ATTR, TOO_LARGE_MSG))
Expand Down Expand Up @@ -342,7 +343,7 @@ def resolve(self, var, attribute):
except:
return getattr(var, attribute)

def get_contents_debug_adapter_protocol(self, lst, fmt={}):
def get_contents_debug_adapter_protocol(self, lst, fmt=None):
'''
This method is to be used in the case where the variables are all saved by its id (and as
such don't need to have the `resolve` method called later on, so, keys don't need to
Expand Down
4 changes: 2 additions & 2 deletions src/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_trace_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def get_breakpoints(plugin, pydb):
return None


def can_not_skip(plugin, pydb, frame):
return False
def can_skip(plugin, pydb, frame):
return True


def has_exception_breaks(plugin):
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ cdef PyObject * get_bytecode_while_frame_eval(PyFrameObject * frame_obj, int exc
# print('get_bytecode_while_frame_eval always skip', func_code_info.always_skip_code)
if not func_code_info.always_skip_code:

if main_debugger.has_plugin_line_breaks:
can_skip = not main_debugger.plugin.can_not_skip(main_debugger, <object> frame_obj)
if main_debugger.has_plugin_line_breaks or main_debugger.has_plugin_exception_breaks:
can_skip = main_debugger.plugin.can_skip(main_debugger, <object> frame_obj)

if not can_skip:
# if DEBUG:
Expand Down
Loading

0 comments on commit 6d2062b

Please sign in to comment.