Skip to content

Commit 1765a3f

Browse files
committed
Add pretty printing of unions in debuggers
Fixes #37479
1 parent 08babdb commit 1765a3f

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/etc/debugger_pretty_printers_common.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
TYPE_KIND_CSTYLE_ENUM = 14
4646
TYPE_KIND_PTR = 15
4747
TYPE_KIND_FIXED_SIZE_VEC = 16
48+
TYPE_KIND_REGULAR_UNION = 17
4849

4950
ENCODED_ENUM_PREFIX = "RUST$ENCODED$ENUM$"
5051
ENUM_DISR_FIELD_NAME = "RUST$ENUM$DISR"
@@ -188,15 +189,18 @@ def __classify_union(self):
188189
union_member_count = len(union_members)
189190
if union_member_count == 0:
190191
return TYPE_KIND_EMPTY
191-
elif union_member_count == 1:
192-
first_variant_name = union_members[0].name
193-
if first_variant_name is None:
192+
193+
first_variant_name = union_members[0].name
194+
if first_variant_name is None:
195+
if union_member_count == 1:
194196
return TYPE_KIND_SINGLETON_ENUM
195197
else:
196-
assert first_variant_name.startswith(ENCODED_ENUM_PREFIX)
197-
return TYPE_KIND_COMPRESSED_ENUM
198+
return TYPE_KIND_REGULAR_ENUM
199+
elif first_variant_name.startswith(ENCODED_ENUM_PREFIX):
200+
assert union_member_count == 1
201+
return TYPE_KIND_COMPRESSED_ENUM
198202
else:
199-
return TYPE_KIND_REGULAR_ENUM
203+
return TYPE_KIND_REGULAR_UNION
200204

201205

202206
def __conforms_to_field_layout(self, expected_fields):

src/etc/lldb_rust_formatters.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def print_val(lldb_val, internal_dict):
9090
type_kind = val.type.get_type_kind()
9191

9292
if (type_kind == rustpp.TYPE_KIND_REGULAR_STRUCT or
93+
type_kind == rustpp.TYPE_KIND_REGULAR_UNION or
9394
type_kind == rustpp.TYPE_KIND_EMPTY):
9495
return print_struct_val(val,
9596
internal_dict,
@@ -175,7 +176,8 @@ def print_struct_val(val, internal_dict, omit_first_field, omit_type_name, is_tu
175176
Prints a struct, tuple, or tuple struct value with Rust syntax.
176177
Ignores any fields before field_start_index.
177178
"""
178-
assert val.type.get_dwarf_type_kind() == rustpp.DWARF_TYPE_CODE_STRUCT
179+
assert (val.type.get_dwarf_type_kind() == rustpp.DWARF_TYPE_CODE_STRUCT or
180+
val.type.get_dwarf_type_kind() == rustpp.DWARF_TYPE_CODE_UNION)
179181

180182
if omit_type_name:
181183
type_name = ""

src/test/debuginfo/union-smoke.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
// min-lldb-version: 310
12-
// ignore-macos FIXME(#37479)
1312

1413
// compile-flags:-g
1514

@@ -27,9 +26,9 @@
2726

2827
// lldb-command:run
2928
// lldb-command:print u
30-
// lldb-check:[...]$0 = { a = ('\x02', '\x02') b = 514 }
29+
// lldb-check:[...]$0 = U { a: ('\x02', '\x02'), b: 514 }
3130
// lldb-command:print union_smoke::SU
32-
// lldb-check:[...]$1 = 257
31+
// lldb-check:[...]$1 = U { a: ('\x01', '\x01'), b: 257 }
3332

3433
#![allow(unused)]
3534
#![feature(omit_gdb_pretty_printer_section)]

0 commit comments

Comments
 (0)