Skip to content

Add pretty printing of unions in debuggers #38753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that while I think this should be fixed for macos, I've only tested for linux with llvm 3.9.

// 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