Skip to content

debuginfo: Better type description of unsized vectors and LLDB test case #21519

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 2 commits into from
Jan 25, 2015
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
26 changes: 14 additions & 12 deletions src/librustc_trans/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ use session::config::{self, FullDebugInfo, LimitedDebugInfo, NoDebugInfo};
use util::nodemap::{DefIdMap, NodeMap, FnvHashMap, FnvHashSet};
use util::ppaux;

use libc::c_uint;
use libc::{c_uint, c_longlong};
use std::ffi::CString;
use std::cell::{Cell, RefCell};
use std::ptr;
Expand Down Expand Up @@ -2764,7 +2764,7 @@ fn create_struct_stub(cx: &CrateContext,
fn fixed_vec_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
unique_type_id: UniqueTypeId,
element_type: Ty<'tcx>,
len: uint,
len: Option<u64>,
span: Span)
-> MetadataCreationResult {
let element_type_metadata = type_metadata(cx, element_type, span);
Expand All @@ -2774,18 +2774,20 @@ fn fixed_vec_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let element_llvm_type = type_of::type_of(cx, element_type);
let (element_type_size, element_type_align) = size_and_align_of(cx, element_llvm_type);

let (array_size_in_bytes, upper_bound) = match len {
Some(len) => (element_type_size * len, len as c_longlong),
None => (0, -1)
};

let subrange = unsafe {
llvm::LLVMDIBuilderGetOrCreateSubrange(
DIB(cx),
0,
len as i64)
llvm::LLVMDIBuilderGetOrCreateSubrange(DIB(cx), 0, upper_bound)
};

let subscripts = create_DIArray(DIB(cx), &[subrange]);
let metadata = unsafe {
llvm::LLVMDIBuilderCreateArrayType(
DIB(cx),
bytes_to_bits(element_type_size * (len as u64)),
bytes_to_bits(array_size_in_bytes),
bytes_to_bits(element_type_align),
element_type_metadata,
subscripts)
Expand Down Expand Up @@ -2991,12 +2993,12 @@ fn type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
ty::ty_enum(def_id, _) => {
prepare_enum_metadata(cx, t, def_id, unique_type_id, usage_site_span).finalize(cx)
}
ty::ty_vec(typ, Some(len)) => {
fixed_vec_metadata(cx, unique_type_id, typ, len, usage_site_span)
ty::ty_vec(typ, len) => {
fixed_vec_metadata(cx, unique_type_id, typ, len.map(|x| x as u64), usage_site_span)
}
ty::ty_str => {
fixed_vec_metadata(cx, unique_type_id, cx.tcx().types.i8, None, usage_site_span)
}
// FIXME Can we do better than this for unsized vec/str fields?
ty::ty_vec(typ, None) => fixed_vec_metadata(cx, unique_type_id, typ, 0, usage_site_span),
ty::ty_str => fixed_vec_metadata(cx, unique_type_id, cx.tcx().types.i8, 0, usage_site_span),
ty::ty_trait(..) => {
MetadataCreationResult::new(
trait_pointer_metadata(cx, t, None, unique_type_id),
Expand Down
34 changes: 34 additions & 0 deletions src/test/debuginfo/option-like-enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
// gdb-command:print void_droid_gdb->internals
// gdb-check:$6 = (isize *) 0x0

// gdb-command:print nested_non_zero_yep
// gdb-check:$7 = {RUST$ENCODED$ENUM$1$2$Nope = {10.5, {a = 10, b = 20, c = [...]}}}

// gdb-command:print nested_non_zero_nope
// gdb-check:$8 = {RUST$ENCODED$ENUM$1$2$Nope = {[...], {a = [...], b = [...], c = 0x0}}}

// gdb-command:continue


Expand Down Expand Up @@ -67,6 +73,12 @@
// lldb-command:print none_str
// lldb-check:[...]$7 = None

// lldb-command:print nested_non_zero_yep
// lldb-check:[...]$8 = Yep(10.5, NestedNonZeroField { a: 10, b: 20, c: &[...] })

// lldb-command:print nested_non_zero_nope
// lldb-check:[...]$9 = Nope


#![omit_gdb_pretty_printer_section]

Expand Down Expand Up @@ -102,6 +114,17 @@ struct NamedFieldsRepr<'a> {
internals: &'a isize
}

struct NestedNonZeroField<'a> {
a: u16,
b: u32,
c: &'a char,
}

enum NestedNonZero<'a> {
Yep(f64, NestedNonZeroField<'a>),
Nope
}

fn main() {

let some_str: Option<&'static str> = Some("abc");
Expand All @@ -124,6 +147,17 @@ fn main() {
let void_droid = NamedFields::Void;
let void_droid_gdb: &NamedFieldsRepr = unsafe { std::mem::transmute(&NamedFields::Void) };

let x = 'x';
let nested_non_zero_yep = NestedNonZero::Yep(
10.5,
NestedNonZeroField {
a: 10,
b: 20,
c: &x
});

let nested_non_zero_nope = NestedNonZero::Nope;

zzz(); // #break
}

Expand Down