Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Pylinted and slightly better commented
  • Loading branch information
cactorium committed Jan 5, 2015
1 parent 3d3670b commit 22cae7e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/etc/gdb_rust_pretty_printing.py
Expand Up @@ -51,7 +51,7 @@ def rust_pretty_printer_lookup_function(val):
enum_member_count = len(enum_members)

if enum_member_count == 0:
return RustStructPrinter(val, false)
return RustStructPrinter(val, False)

if enum_member_count == 1:
first_variant_name = enum_members[0].name
Expand All @@ -60,7 +60,11 @@ def rust_pretty_printer_lookup_function(val):
return rust_pretty_printer_lookup_function(val[enum_members[0]])
else:
assert first_variant_name.startswith("RUST$ENCODED$ENUM$")
# This is a space-optimized enum
# This is a space-optimized enum.
# This means this enum has only two states, and Rust uses one of the
# fields somewhere in the struct to determine which of the two states
# it's in. The location of the field is encoded in the name as something
# like RUST$ENCODED$ENUM$(num$)*name_of_zero_state
last_separator_index = first_variant_name.rfind("$")
start_index = len("RUST$ENCODED$ENUM$")
disr_field_indices = first_variant_name[start_index :
Expand All @@ -76,7 +80,7 @@ def rust_pretty_printer_lookup_function(val):
# If the discriminant field is a fat pointer we have to consider the
# first word as the true discriminant
if discriminant.type.code == gdb.TYPE_CODE_STRUCT:
discriminant = discriminant[get_field_at_index(discriminant, 0)]
discriminant = discriminant[get_field_at_index(discriminant, 0)]

if discriminant == 0:
null_variant_name = first_variant_name[last_separator_index + 1:]
Expand Down
6 changes: 3 additions & 3 deletions src/etc/lldb_rust_formatters.py
Expand Up @@ -131,19 +131,19 @@ def print_enum_val(val, internal_dict):
try:
disr_field_indices = first_variant_name[start_index :
last_separator_index].split("$")
disr_field_indices = [int(index) for index in dis_field_indices]
disr_field_indices = [int(index) for index in disr_field_indices]
except:
return "<invalid enum encoding: %s>" % first_variant_name

# Read the discriminant
disr_val = val.GetChildAtIndex(0)
for index in disr_field_indices:
disr_val = disr_val.GetChildAtIndex(disr_field_index)
disr_val = disr_val.GetChildAtIndex(index)

# If the discriminant field is a fat pointer we have to consider the
# first word as the true discriminant
if disr_val.GetType().GetTypeClass() == lldb.eTypeClassStruct:
disr_val = disr_val.GetChildAtIndex(0)
disr_val = disr_val.GetChildAtIndex(0)

if disr_val.GetValueAsUnsigned() == 0:
# Null case: Print the name of the null-variant
Expand Down

0 comments on commit 22cae7e

Please sign in to comment.