Skip to content

Commit 8895399

Browse files
committed
Add limited support for synthetic items
1 parent d11cd4a commit 8895399

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ This already supports a wide array of features available in the Natvis system:
4242
- `ArrayItems` is supported for the simple case (`Size` and `ValuePointer`)
4343
- `IndexListItems` including `$i` parameters
4444
- `ExpandedItem`
45+
- Limited support for `Synthetic`. Only the display string part is supported since synthetic items are not possible
46+
with the current GDB API
4547

4648
## Known issues
4749
- The expression parser does not support all syntax elements yet

src/natvis.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,13 @@ def __init__(self, condition: str, expression: str):
187187
self.condition = condition
188188

189189

190+
class ExpandSynthetic(ExpandElement):
191+
192+
def __init__(self, type: 'NatvisType') -> None:
193+
super().__init__()
194+
self.type = type
195+
196+
190197
class NatvisType:
191198
expand_items: List[ExpandElement]
192199

@@ -239,6 +246,10 @@ def _parse_expanded_item(self, element):
239246
expr = element.text.lstrip().rstrip()
240247
self.expand_items.append(ExpandExpandedItem(element.get("Condition", None), expr))
241248

249+
def _parse_synthetic_item(self, element):
250+
parsed = NatvisType(element)
251+
self.expand_items.append(ExpandSynthetic(parsed))
252+
242253
def _process_expand(self, element):
243254
for child in element:
244255
if child.tag == "Item":
@@ -249,6 +260,8 @@ def _process_expand(self, element):
249260
self._parse_array_items_element(child)
250261
elif child.tag == "ExpandedItem":
251262
self._parse_expanded_item(child)
263+
elif child.tag == "Synthetic":
264+
self._parse_synthetic_item(child)
252265

253266
def typename_matches(self, typename: templates.TemplateType, template_args: List[str] = None) -> bool:
254267
if template_args is None:
@@ -288,6 +301,8 @@ def enumerate_expressions(self) -> Iterator[Tuple[str, bool]]:
288301
if expand.condition is not None:
289302
yield expand.condition, True
290303
yield expand.expression, True
304+
elif isinstance(expand, ExpandSynthetic):
305+
yield from expand.type.enumerate_expressions()
291306

292307

293308
def remove_namespace(doc, namespace):

src/printer.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ def _get_value(self, expression, convert_func=None, **kwargs: str):
8282
def display_hint(self):
8383
return 'string'
8484

85-
def to_string(self):
86-
for string in self.type.display_parsers:
85+
def _get_natvis_type_display_string(self, t: natvis.NatvisType):
86+
for string in t.display_parsers:
8787
if self.check_condition(string.condition):
8888
display_args = []
8989
for code in string.parser.code_parts:
@@ -98,6 +98,9 @@ def to_string(self):
9898

9999
return "No visualizer available"
100100

101+
def to_string(self):
102+
return self._get_natvis_type_display_string(self.type)
103+
101104
def children(self):
102105
yield "[display string]", gdb.Value(self.to_string()).cast(gdb.lookup_type("char").pointer())
103106

@@ -113,6 +116,11 @@ def children(self):
113116
yield from self._expand_array_items(item)
114117
elif isinstance(item, natvis.ExpandExpandedItem):
115118
yield from self._expand_expanded_item(item)
119+
elif isinstance(item, natvis.ExpandSynthetic):
120+
yield from self._expand_synthetic_item(item)
121+
122+
def _expand_synthetic_item(self, item: natvis.ExpandSynthetic):
123+
yield str(item.type.template_type), self._get_natvis_type_display_string(item.type)
116124

117125
def _expand_expanded_item(self, item: natvis.ExpandExpandedItem):
118126
if self.check_condition(item.condition):

0 commit comments

Comments
 (0)