Skip to content

Commit

Permalink
Auto merge of rust-lang#38753 - philipc:debuginfo-union, r=petrochenkov
Browse files Browse the repository at this point in the history
Add pretty printing of unions in debuggers

Fixes rust-lang#37479
  • Loading branch information
bors committed Jan 1, 2017
2 parents ac5cd3b + 1765a3f commit 7b659cf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
16 changes: 10 additions & 6 deletions src/etc/debugger_pretty_printers_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
TYPE_KIND_CSTYLE_ENUM = 14
TYPE_KIND_PTR = 15
TYPE_KIND_FIXED_SIZE_VEC = 16
TYPE_KIND_REGULAR_UNION = 17

ENCODED_ENUM_PREFIX = "RUST$ENCODED$ENUM$"
ENUM_DISR_FIELD_NAME = "RUST$ENUM$DISR"
Expand Down Expand Up @@ -188,15 +189,18 @@ def __classify_union(self):
union_member_count = len(union_members)
if union_member_count == 0:
return TYPE_KIND_EMPTY
elif union_member_count == 1:
first_variant_name = union_members[0].name
if first_variant_name is None:

first_variant_name = union_members[0].name
if first_variant_name is None:
if union_member_count == 1:
return TYPE_KIND_SINGLETON_ENUM
else:
assert first_variant_name.startswith(ENCODED_ENUM_PREFIX)
return TYPE_KIND_COMPRESSED_ENUM
return TYPE_KIND_REGULAR_ENUM
elif first_variant_name.startswith(ENCODED_ENUM_PREFIX):
assert union_member_count == 1
return TYPE_KIND_COMPRESSED_ENUM
else:
return TYPE_KIND_REGULAR_ENUM
return TYPE_KIND_REGULAR_UNION


def __conforms_to_field_layout(self, expected_fields):
Expand Down
4 changes: 3 additions & 1 deletion src/etc/lldb_rust_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def print_val(lldb_val, internal_dict):
type_kind = val.type.get_type_kind()

if (type_kind == rustpp.TYPE_KIND_REGULAR_STRUCT or
type_kind == rustpp.TYPE_KIND_REGULAR_UNION or
type_kind == rustpp.TYPE_KIND_EMPTY):
return print_struct_val(val,
internal_dict,
Expand Down Expand Up @@ -175,7 +176,8 @@ def print_struct_val(val, internal_dict, omit_first_field, omit_type_name, is_tu
Prints a struct, tuple, or tuple struct value with Rust syntax.
Ignores any fields before field_start_index.
"""
assert val.type.get_dwarf_type_kind() == rustpp.DWARF_TYPE_CODE_STRUCT
assert (val.type.get_dwarf_type_kind() == rustpp.DWARF_TYPE_CODE_STRUCT or
val.type.get_dwarf_type_kind() == rustpp.DWARF_TYPE_CODE_UNION)

if omit_type_name:
type_name = ""
Expand Down
5 changes: 2 additions & 3 deletions src/test/debuginfo/union-smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.

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

// compile-flags:-g

Expand All @@ -27,9 +26,9 @@

// lldb-command:run
// lldb-command:print u
// lldb-check:[...]$0 = { a = ('\x02', '\x02') b = 514 }
// lldb-check:[...]$0 = U { a: ('\x02', '\x02'), b: 514 }
// lldb-command:print union_smoke::SU
// lldb-check:[...]$1 = 257
// lldb-check:[...]$1 = U { a: ('\x01', '\x01'), b: 257 }

#![allow(unused)]
#![feature(omit_gdb_pretty_printer_section)]
Expand Down

0 comments on commit 7b659cf

Please sign in to comment.