Skip to content

Commit 22cae7e

Browse files
committed
Pylinted and slightly better commented
1 parent 3d3670b commit 22cae7e

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/etc/gdb_rust_pretty_printing.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def rust_pretty_printer_lookup_function(val):
5151
enum_member_count = len(enum_members)
5252

5353
if enum_member_count == 0:
54-
return RustStructPrinter(val, false)
54+
return RustStructPrinter(val, False)
5555

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

8185
if discriminant == 0:
8286
null_variant_name = first_variant_name[last_separator_index + 1:]

src/etc/lldb_rust_formatters.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,19 @@ def print_enum_val(val, internal_dict):
131131
try:
132132
disr_field_indices = first_variant_name[start_index :
133133
last_separator_index].split("$")
134-
disr_field_indices = [int(index) for index in dis_field_indices]
134+
disr_field_indices = [int(index) for index in disr_field_indices]
135135
except:
136136
return "<invalid enum encoding: %s>" % first_variant_name
137137

138138
# Read the discriminant
139139
disr_val = val.GetChildAtIndex(0)
140140
for index in disr_field_indices:
141-
disr_val = disr_val.GetChildAtIndex(disr_field_index)
141+
disr_val = disr_val.GetChildAtIndex(index)
142142

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

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

0 commit comments

Comments
 (0)