Skip to content

Commit 886ff4f

Browse files
committed
lldb: Fix pretty printer for nullable-opt enums with fat pointers.
1 parent 3a325c6 commit 886ff4f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/etc/lldb_rust_formatters.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,14 @@ def print_enum_val(val, internal_dict):
138138
return "<invalid enum encoding: %s>" % first_variant_name
139139

140140
# Read the discriminant
141-
disr_val = val.GetChildAtIndex(0).GetChildAtIndex(disr_field_index).GetValueAsUnsigned()
141+
disr_val = val.GetChildAtIndex(0).GetChildAtIndex(disr_field_index)
142142

143-
if disr_val == 0:
143+
# If the discriminant field is a fat pointer we have to consider the
144+
# first word as the true discriminant
145+
if disr_val.GetType().GetTypeClass() == lldb.eTypeClassStruct:
146+
disr_val = disr_val.GetChildAtIndex(0)
147+
148+
if disr_val.GetValueAsUnsigned() == 0:
144149
# Null case: Print the name of the null-variant
145150
null_variant_name = first_variant_name[last_separator_index + 1:]
146151
return null_variant_name

src/test/debuginfo/option-like-enum.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@
6161
// lldb-command:print void_droid
6262
// lldb-check:[...]$5 = Void
6363

64+
// lldb-command:print some_str
65+
// lldb-check:[...]$6 = Some(&str { data_ptr: [...], length: 3 })
66+
67+
// lldb-command:print none_str
68+
// lldb-check:[...]$7 = None
69+
6470

6571
// If a struct has exactly two variants, one of them is empty, and the other one
6672
// contains a non-nullable pointer, then this value is used as the discriminator.
@@ -96,6 +102,9 @@ struct NamedFieldsRepr<'a> {
96102

97103
fn main() {
98104

105+
let some_str: Option<&'static str> = Some("abc");
106+
let none_str: Option<&'static str> = None;
107+
99108
let some: Option<&u32> = Some(unsafe { std::mem::transmute(0x12345678u) });
100109
let none: Option<&u32> = None;
101110

0 commit comments

Comments
 (0)