Skip to content

Commit

Permalink
lldb: Fix pretty printer for nullable-opt enums with fat pointers.
Browse files Browse the repository at this point in the history
  • Loading branch information
luqmana committed Dec 2, 2014
1 parent 3a325c6 commit 886ff4f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/etc/lldb_rust_formatters.py
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/test/debuginfo/option-like-enum.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 886ff4f

Please sign in to comment.