Skip to content

Commit

Permalink
Describing volatile C++ datatypes (#597)
Browse files Browse the repository at this point in the history
  • Loading branch information
sevaa authored Feb 15, 2025
1 parent 3181eed commit 108e184
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions elftools/dwarf/datatype_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
cpp_symbols = dict(
pointer = "*",
reference = "&",
const = "const")
const = "const",
volatile = "volatile")

def describe_cpp_datatype(var_die):
return str(parse_cpp_datatype(var_die))
Expand All @@ -36,8 +37,8 @@ def parse_cpp_datatype(var_die):

mods = []
# Unlike readelf, dwarfdump doesn't chase typedefs
while type_die.tag in ('DW_TAG_const_type', 'DW_TAG_pointer_type', 'DW_TAG_reference_type'):
modifier = _strip_type_tag(type_die) # const/reference/pointer
while type_die.tag in ('DW_TAG_const_type', 'DW_TAG_volatile_type', 'DW_TAG_pointer_type', 'DW_TAG_reference_type'):
modifier = _strip_type_tag(type_die) # const/volatile/reference/pointer
mods.insert(0, modifier)
if not 'DW_AT_type' in type_die.attributes: # void* is encoded as a pointer to nothing
t.name = t.tag = "void"
Expand Down Expand Up @@ -145,9 +146,9 @@ def __str__(self):
mods = self.modifiers

parts = []
# Initial const applies to the var ifself, other consts apply to the pointee
if len(mods) and mods[0] == 'const':
parts.append("const")
# Initial const/volatile applies to the var ifself, other consts apply to the pointee
if len(mods) and mods[0] in ('const', 'volatile'):
parts.append(mods[0])
mods = mods[1:]

# ref->const in the end, const goes in front
Expand Down
Binary file not shown.

0 comments on commit 108e184

Please sign in to comment.