Skip to content

Commit

Permalink
Show globals, group variables and show all dir() variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Apr 17, 2020
1 parent ade162b commit 05ffe6d
Show file tree
Hide file tree
Showing 19 changed files with 606 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,7 @@ def getVariable(self, attributes):
if val_dict is None:
val_dict = {}

keys = val_dict.keys()
for k in keys:
for k, val in dict_iter_items(val_dict):
val = val_dict[k]
evaluate_full_value = pydevd_xml.should_evaluate_full_value(val)
xml.write(pydevd_vars.var_to_xml(val, k, evaluate_full_value=evaluate_full_value))
Expand Down
18 changes: 18 additions & 0 deletions src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from _pydevd_bundle.pydevd_collect_bytecode_info import code_to_bytecode_representation
import itertools
import linecache
from _pydevd_bundle.pydevd_utils import DAPGrouper

try:
import dis
Expand Down Expand Up @@ -65,6 +66,19 @@ def iterate():

class PyDevdAPI(object):

class VariablePresentation(object):

def __init__(self, special='group', function='group', class_='group', protected='inline'):
self._presentation = {
DAPGrouper.SCOPE_SPECIAL_VARS: special,
DAPGrouper.SCOPE_FUNCTION_VARS: function,
DAPGrouper.SCOPE_CLASS_VARS: class_,
DAPGrouper.SCOPE_PROTECTED_VARS: protected,
}

def get_presentation(self, scope):
return self._presentation[scope]

def run(self, py_db):
py_db.ready_to_run = True

Expand Down Expand Up @@ -840,6 +854,10 @@ def set_source_mapping(self, py_db, source_filename, mapping):
self.reapply_breakpoints(py_db)
return ''

def set_variable_presentation(self, py_db, variable_presentation):
assert isinstance(variable_presentation, self.VariablePresentation)
py_db.variable_presentation = variable_presentation

def get_ppid(self):
'''
Provides the parent pid (even for older versions of Python on Windows).
Expand Down
14 changes: 12 additions & 2 deletions src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
import sys
import traceback
from _pydevd_bundle.pydevd_utils import quote_smart as quote, compare_object_attrs_key, \
notify_about_gevent_if_needed, isinstance_checked
notify_about_gevent_if_needed, isinstance_checked, ScopeRequest
from _pydev_bundle import pydev_log
from _pydev_bundle.pydev_log import exception as pydev_log_exception
from _pydev_bundle import _pydev_completer
Expand Down Expand Up @@ -729,6 +729,11 @@ def internal_get_variable_json(py_db, request):
'''
arguments = request.arguments # : :type arguments: VariablesArguments
variables_reference = arguments.variablesReference
scope = None
if isinstance_checked(variables_reference, ScopeRequest):
scope = variables_reference
variables_reference = variables_reference.variable_reference

fmt = arguments.format
if hasattr(fmt, 'to_dict'):
fmt = fmt.to_dict()
Expand All @@ -739,7 +744,7 @@ def internal_get_variable_json(py_db, request):
except KeyError:
pass
else:
for child_var in variable.get_children_variables(fmt=fmt):
for child_var in variable.get_children_variables(fmt=fmt, scope=scope):
variables.append(child_var.get_var_data(fmt=fmt))

body = VariablesResponseBody(variables)
Expand Down Expand Up @@ -844,6 +849,11 @@ def internal_change_variable_json(py_db, request):
# : :type arguments: SetVariableArguments
arguments = request.arguments
variables_reference = arguments.variablesReference
scope = None
if isinstance_checked(variables_reference, ScopeRequest):
scope = variables_reference
variables_reference = variables_reference.variable_reference

fmt = arguments.format
if hasattr(fmt, 'to_dict'):
fmt = fmt.to_dict()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
except NameError:
int_types = (int,)

# types does not include a MethodWrapperType
try:
MethodWrapperType = type([].__str__)
except:
MethodWrapperType = None

import sys # Note: the sys import must be here anyways (others depend on it)

# Preload codecs to avoid imports to them later on which can potentially halt the debugger.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from _pydevd_bundle.pydevd_filtering import ExcludeFilter
from _pydevd_bundle.pydevd_json_debug_options import _extract_debug_options, DebugOptions
from _pydevd_bundle.pydevd_net_command import NetCommand
from _pydevd_bundle.pydevd_utils import convert_dap_log_message_to_expression
from _pydevd_bundle.pydevd_utils import convert_dap_log_message_to_expression, ScopeRequest
from _pydevd_bundle.pydevd_constants import (PY_IMPL_NAME, DebugInfoHolder, PY_VERSION_STR,
PY_IMPL_VERSION_STR, IS_64BIT_PROCESS)
from _pydevd_bundle.pydevd_trace_dispatch import USING_CYTHON
Expand Down Expand Up @@ -162,7 +162,7 @@ def on_request(py_db, request):
else:
if DebugInfoHolder.DEBUG_RECORD_SOCKET_READS and DebugInfoHolder.DEBUG_TRACE_LEVEL >= 1:
pydev_log.info('Process %s: %s\n' % (
request.__class__.__name__, json.dumps(request.to_dict(), indent=4, sort_keys=True),))
request.__class__.__name__, json.dumps(request.to_dict(update_ids_to_dap=True), indent=4, sort_keys=True),))

assert request.type == 'request'
method_name = 'on_%s_request' % (request.command.lower(),)
Expand Down Expand Up @@ -328,6 +328,33 @@ def _set_debug_options(self, py_db, args, start_reason):
terminate_child_processes = args.get('terminateChildProcesses', True)
self.api.set_terminate_child_processes(py_db, terminate_child_processes)

variable_presentation = args.get('variablePresentation', None)
if isinstance(variable_presentation, dict):

def get_variable_presentation(setting, default):
value = variable_presentation.get(setting, default)
if value not in ('group', 'inline', 'hide'):
pydev_log.info(
'The value set for "%s" (%s) in the variablePresentation is not valid. Valid values are: "group", "inline", "hide"' % (
setting, value,))
value = default

return value

default = get_variable_presentation('all', 'group')

special_presentation = get_variable_presentation('special', default)
function_presentation = get_variable_presentation('function', default)
class_presentation = get_variable_presentation('class', default)
protected_presentation = get_variable_presentation('protected', default)

self.api.set_variable_presentation(py_db, self.api.VariablePresentation(
special_presentation,
function_presentation,
class_presentation,
protected_presentation
))

exclude_filters = []

if rules is not None:
Expand Down Expand Up @@ -747,7 +774,10 @@ def on_scopes_request(self, py_db, request):
frame_id = request.arguments.frameId

variables_reference = frame_id
scopes = [Scope('Locals', int(variables_reference), False).to_dict()]
scopes = [
Scope('Locals', ScopeRequest(int(variables_reference), 'locals'), False),
Scope('Globals', ScopeRequest(int(variables_reference), 'globals'), False),
]
body = ScopesResponseBody(scopes)
scopes_response = pydevd_base_schema.build_response(request, kwargs={'body': body})
return NetCommand(CMD_RETURN, 0, scopes_response, is_json=True)
Expand Down Expand Up @@ -817,6 +847,9 @@ def on_variables_request(self, py_db, request):
arguments = request.arguments # : :type arguments: VariablesArguments
variables_reference = arguments.variablesReference

if isinstance(variables_reference, ScopeRequest):
variables_reference = variables_reference.variable_reference

thread_id = py_db.suspended_frames_manager.get_thread_id_for_variable_reference(
variables_reference)
if thread_id is not None:
Expand All @@ -835,6 +868,9 @@ def on_setvariable_request(self, py_db, request):
arguments = request.arguments # : :type arguments: SetVariableArguments
variables_reference = arguments.variablesReference

if isinstance(variables_reference, ScopeRequest):
variables_reference = variables_reference.variable_reference

if arguments.name.startswith('(return) '):
response = pydevd_base_schema.build_response(
request,
Expand Down
Loading

0 comments on commit 05ffe6d

Please sign in to comment.