Auto merge of #38753 - philipc:debuginfo-union, r=petrochenkov

Add pretty printing of unions in debuggers

Fixes #37479
This commit is contained in:
bors 2017-01-01 16:41:29 +00:00
commit 7b659cfdbc
3 changed files with 15 additions and 10 deletions

View file

@ -45,6 +45,7 @@ TYPE_KIND_SINGLETON_ENUM = 13
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"
@ -188,15 +189,18 @@ class Type(object):
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):

View file

@ -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,
@ -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 = ""

View file

@ -9,7 +9,6 @@
// except according to those terms.
// min-lldb-version: 310
// ignore-macos FIXME(#37479)
// compile-flags:-g
@ -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)]