|
2 | 2 | import logging |
3 | 3 | import posixpath |
4 | 4 | import struct |
| 5 | +import typing |
5 | 6 | from collections import defaultdict |
6 | 7 | from typing import Any, Callable, Generator |
7 | 8 |
|
@@ -292,14 +293,7 @@ def visit_typedef(self, die: DWARFDie) -> None: |
292 | 293 | self._set(die, typedef) |
293 | 294 |
|
294 | 295 | def visit_class_type(self, die: DWARFDie) -> None: |
295 | | - if die.find("DW_AT_signature"): |
296 | | - sig = die.resolve_type_unit_reference() |
297 | | - self.visit(sig) |
298 | | - cls = copy.copy(self._get(sig)) |
299 | | - else: |
300 | | - cls = Class(name=die.short_name) |
301 | | - |
302 | | - self._handle_struct(die, cls) |
| 296 | + self._handle_struct(die, Class) |
303 | 297 |
|
304 | 298 | def visit_enumeration_type(self, die: DWARFDie) -> None: |
305 | 299 | if die.find("DW_AT_signature"): |
@@ -343,24 +337,10 @@ def visit_enumeration_type(self, die: DWARFDie) -> None: |
343 | 337 | self._set(die, enum) |
344 | 338 |
|
345 | 339 | def visit_union_type(self, die: DWARFDie) -> None: |
346 | | - if die.find("DW_AT_signature"): |
347 | | - sig = die.resolve_type_unit_reference() |
348 | | - self.visit(sig) |
349 | | - union = copy.copy(self._get(sig)) |
350 | | - else: |
351 | | - union = Union(name=die.short_name) |
352 | | - |
353 | | - self._handle_struct(die, union) |
| 340 | + self._handle_struct(die, Union) |
354 | 341 |
|
355 | 342 | def visit_structure_type(self, die: DWARFDie) -> None: |
356 | | - if die.find("DW_AT_signature"): |
357 | | - sig = die.resolve_type_unit_reference() |
358 | | - self.visit(sig) |
359 | | - struct = copy.copy(self._get(sig)) |
360 | | - else: |
361 | | - struct = Struct(name=die.short_name) |
362 | | - |
363 | | - self._handle_struct(die, struct) |
| 343 | + self._handle_struct(die, Struct) |
364 | 344 |
|
365 | 345 | def visit_variable(self, die: DWARFDie) -> None: |
366 | 346 | self._handle_attribute(die) |
@@ -828,7 +808,17 @@ def _handle_attribute(self, die: DWARFDie) -> None: |
828 | 808 |
|
829 | 809 | self._set(die, variable) |
830 | 810 |
|
831 | | - def _handle_struct(self, die: DWARFDie, struct: Struct) -> None: |
| 811 | + def _handle_struct(self, die: DWARFDie, ty: typing.Type[Class | Struct | Union]) -> None: |
| 812 | + signature = die.find("DW_AT_signature") |
| 813 | + if signature is not None: |
| 814 | + signature = die.resolve_type_unit_reference() |
| 815 | + self.visit(signature) |
| 816 | + declaration = self._get(signature) |
| 817 | + assert declaration is not None, "Expected valid declaration" |
| 818 | + struct = copy.deepcopy(declaration) |
| 819 | + else: |
| 820 | + struct: Class | Struct | Union = ty(name=die.short_name) |
| 821 | + |
832 | 822 | class_name = struct.name.split("<", maxsplit=1)[0] if struct.name else None |
833 | 823 | access = AccessAttribute.PRIVATE if isinstance(struct, Class) else AccessAttribute.PUBLIC |
834 | 824 |
|
|
0 commit comments