about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/etc/lldb_rust_formatters.py9
-rw-r--r--src/test/debuginfo/option-like-enum.rs9
2 files changed, 16 insertions, 2 deletions
diff --git a/src/etc/lldb_rust_formatters.py b/src/etc/lldb_rust_formatters.py
index 7924d63c8e0..f4f1a5121d1 100644
--- a/src/etc/lldb_rust_formatters.py
+++ b/src/etc/lldb_rust_formatters.py
@@ -138,9 +138,14 @@ def print_enum_val(val, internal_dict):
         return "<invalid enum encoding: %s>" % first_variant_name
 
       # Read the discriminant
-      disr_val = val.GetChildAtIndex(0).GetChildAtIndex(disr_field_index).GetValueAsUnsigned()
+      disr_val = val.GetChildAtIndex(0).GetChildAtIndex(disr_field_index)
 
-      if disr_val == 0:
+      # If the discriminant field is a fat pointer we have to consider the
+      # first word as the true discriminant
+      if disr_val.GetType().GetTypeClass() == lldb.eTypeClassStruct:
+          disr_val = disr_val.GetChildAtIndex(0)
+
+      if disr_val.GetValueAsUnsigned() == 0:
         # Null case: Print the name of the null-variant
         null_variant_name = first_variant_name[last_separator_index + 1:]
         return null_variant_name
diff --git a/src/test/debuginfo/option-like-enum.rs b/src/test/debuginfo/option-like-enum.rs
index 11c594bac59..333a430e351 100644
--- a/src/test/debuginfo/option-like-enum.rs
+++ b/src/test/debuginfo/option-like-enum.rs
@@ -61,6 +61,12 @@
 // lldb-command:print void_droid
 // lldb-check:[...]$5 = Void
 
+// lldb-command:print some_str
+// lldb-check:[...]$6 = Some(&str { data_ptr: [...], length: 3 })
+
+// lldb-command:print none_str
+// lldb-check:[...]$7 = None
+
 
 // If a struct has exactly two variants, one of them is empty, and the other one
 // contains a non-nullable pointer, then this value is used as the discriminator.
@@ -96,6 +102,9 @@ struct NamedFieldsRepr<'a> {
 
 fn main() {
 
+    let some_str: Option<&'static str> = Some("abc");
+    let none_str: Option<&'static str> = None;
+
     let some: Option<&u32> = Some(unsafe { std::mem::transmute(0x12345678u) });
     let none: Option<&u32> = None;