Skip to content

Commit 56a5f31

Browse files
committed
Fixed GDB pretty printer to work on enums correctly
1 parent 5773bde commit 56a5f31

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/etc/gdb_rust_pretty_printing.py

100644100755
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,16 @@ def rust_pretty_printer_lookup_function(val):
6262
assert first_variant_name.startswith("RUST$ENCODED$ENUM$")
6363
# This is a space-optimized enum
6464
last_separator_index = first_variant_name.rfind("$")
65-
second_last_separator_index = first_variant_name.rfind("$", 0, last_separator_index)
66-
disr_field_index = first_variant_name[second_last_separator_index + 1 :
65+
start_index = len("RUST$ENCODED$ENUM")
66+
disr_field_indices = first_variant_name[start_index + 1 :
6767
last_separator_index]
68-
disr_field_index = int(disr_field_index)
68+
disr_field_indices = [int(index) for index in disr_field_indices.split("$")]
6969

7070
sole_variant_val = val[enum_members[0]]
71-
disr_field = get_field_at_index(sole_variant_val, disr_field_index)
72-
discriminant = sole_variant_val[disr_field]
71+
discriminant = sole_variant_val
72+
for disr_field_index in disr_field_indices:
73+
disr_field = get_field_at_index(discriminant, disr_field_index)
74+
discriminant = discriminant[disr_field]
7375

7476
# If the discriminant field is a fat pointer we have to consider the
7577
# first word as the true discriminant
@@ -234,4 +236,5 @@ def get_field_at_index(val, index):
234236
for field in val.type.fields():
235237
if i == index:
236238
return field
239+
i += 1
237240
return None

0 commit comments

Comments
 (0)