17from .startup
import in_gdb_thread
18from .server
import client_bool_capability
19from abc
import ABC, abstractmethod
20from collections
import defaultdict
21from contextlib
import contextmanager
36gdb.events.cont.connect(clear_vars)
47 """Temporarily apply the DAP ValueFormat.
49 This returns a new context manager that applies the given DAP
50 ValueFormat object globally, then restores gdb's state when finished."""
51 if value_format
is not None and "hex" in value_format
and value_format[
"hex"]:
57 """Represent a variable or a scope.
59 This class is just a base class, some methods must be implemented in
62 The 'ref' field can be used as the variablesReference in the protocol.
67 """Create a new variable reference with the given name.
69 NAME is a string or None. None means this does not have a
70 name, e.g., the result of expression evaluation."""
73 all_variables.append(self)
74 self.
ref = len(all_variables)
80 """Return a dictionary that describes this object for DAP.
82 The resulting object is a starting point that can be filled in
83 further. See the Scope or Variable types in the spec"""
85 if self.
name is not None:
86 result[
"name"] = str(self.
name)
91 """Return True if this object has children."""
95 """Reset any cached information about the children of this object."""
108 """Fetch one child of this variable.
110 INDEX is the index of the child to fetch.
111 This should return a tuple of the form (NAME, VALUE), where
112 NAME is the name of the variable, and VALUE is a gdb.Value."""
117 """Return the number of children of this variable."""
140 """Fetch children of this variable.
142 START is the starting index.
143 COUNT is the number to return, with 0 meaning return all.
144 Returns an iterable of some kind."""
149 for idx
in range(start, start + count):
160 """Find a child of this variable, given its name.
162 Returns the value of the child, or throws if not found."""
168 raise Exception(
"no variable named '" + name +
"'")
172 """Concrete subclass of BaseReference that handles gdb.Value."""
174 def __init__(self, name, value, result_name="value"):
177 NAME is the name of this reference, see superclass.
178 VALUE is a gdb.Value that holds the value.
179 RESULT_NAME can be used to change how the simple string result
180 is emitted in the result dictionary."""
197 """Assign VALUE to this object and update."""
202 return hasattr(self.
printer,
"children")
216 if self.
count is None:
220 if isinstance(self.
printer, gdb.ValuePrinter)
and hasattr(
223 num_children = self.
printer.num_children()
224 if num_children
is None:
226 self.
count = num_children
233 if num_children
is not None:
235 hasattr(self.
printer,
"display_hint")
236 and self.
printer.display_hint() ==
"array"
238 result[
"indexedVariables"] = num_children
240 result[
"namedVariables"] = num_children
241 if client_bool_capability(
"supportsMemoryReferences"):
246 if self.
value.type.strip_typedefs().code == gdb.TYPE_CODE_PTR:
247 result[
"memoryReference"] = hex(int(self.
value))
248 if client_bool_capability(
"supportsVariableType"):
249 result[
"type"] = str(self.
value.type)
254 if isinstance(self.
printer, gdb.ValuePrinter)
and hasattr(
257 (name, val) = self.
printer.child(idx)
262 if not isinstance(val, gdb.Value):
269 """Given a variable reference, return the corresponding variable object."""
273 if ref < 0
or ref > len(all_variables):
274 raise Exception(
"invalid variablesReference")
275 return all_variables[ref]
_compute_name(self, name)
find_child_by_name(self, name)
fetch_children(self, start, count)
fetch_one_child(self, index)
fetch_one_child(self, idx)
__init__(self, name, value, result_name="value")
std::string to_string(cooked_index_flag flags)
apply_format(value_format)
with_parameter(name, value)