Skip to content
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

Embed MSVC .natvis files into .pdbs and mangle debuginfo for &str, *T, and [T]. #43221

Merged
merged 5 commits into from
Jul 28, 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
24 changes: 24 additions & 0 deletions src/etc/natvis/intrinsic.natvis
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="str">
<DisplayString>{data_ptr,[length]s8}</DisplayString>
<StringView>data_ptr,[length]s8</StringView>
<Expand>
<Item Name="[size]" ExcludeView="simple">length</Item>
<ArrayItems>
<Size>length</Size>
<ValuePointer>data_ptr</ValuePointer>
</ArrayItems>
</Expand>
</Type>
<Type Name="slice&lt;*&gt;">
<DisplayString>{{ length={length} }}</DisplayString>
<Expand>
<Item Name="[size]" ExcludeView="simple">length</Item>
<ArrayItems>
<Size>length</Size>
<ValuePointer>data_ptr</ValuePointer>
</ArrayItems>
</Expand>
</Type>
</AutoVisualizer>
4 changes: 2 additions & 2 deletions src/etc/natvis/liballoc.natvis
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
</Expand>
</Type>
<Type Name="alloc::string::String">
<DisplayString>{*(char**)this,[vec.len]}</DisplayString>
<StringView>*(char**)this,[vec.len]</StringView>
<DisplayString>{*(char**)this,[vec.len]s8}</DisplayString>
<StringView>*(char**)this,[vec.len]s8</StringView>
<Expand>
<Item Name="[size]" ExcludeView="simple">vec.len</Item>
<Item Name="[capacity]" ExcludeView="simple">vec.buf.cap</Item>
Expand Down
21 changes: 21 additions & 0 deletions src/librustc_trans/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,27 @@ impl<'a> Linker for MsvcLinker<'a> {
// This will cause the Microsoft linker to generate a PDB file
// from the CodeView line tables in the object files.
self.cmd.arg("/DEBUG");

// This will cause the Microsoft linker to embed .natvis info into the the PDB file
let sysroot = self.sess.sysroot();
let natvis_dir_path = sysroot.join("lib\\rustlib\\etc");
if let Ok(natvis_dir) = fs::read_dir(&natvis_dir_path) {
for entry in natvis_dir {
match entry {
Ok(entry) => {
let path = entry.path();
if path.extension() == Some("natvis".as_ref()) {
let mut arg = OsString::from("/NATVIS:");
arg.push(path);
self.cmd.arg(arg);
}
},
Err(err) => {
self.sess.warn(&format!("error enumerating natvis directory: {}", err));
},
}
}
}
}

// Currently the compiler doesn't use `dllexport` (an LLVM attribute) to
Expand Down
34 changes: 30 additions & 4 deletions src/librustc_trans/debuginfo/type_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
t: Ty<'tcx>,
qualified: bool,
output: &mut String) {
// When targeting MSVC, emit C++ style type names for compatability with
// .natvis visualizers (and perhaps other existing native debuggers?)
let cpp_like_names = cx.sess().target.target.options.is_like_msvc;

match t.sty {
ty::TyBool => output.push_str("bool"),
ty::TyChar => output.push_str("char"),
Expand All @@ -61,21 +65,33 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
output.push(')');
},
ty::TyRawPtr(ty::TypeAndMut { ty: inner_type, mutbl } ) => {
output.push('*');
if !cpp_like_names {
output.push('*');
}
match mutbl {
hir::MutImmutable => output.push_str("const "),
hir::MutMutable => output.push_str("mut "),
}

push_debuginfo_type_name(cx, inner_type, true, output);

if cpp_like_names {
output.push('*');
}
},
ty::TyRef(_, ty::TypeAndMut { ty: inner_type, mutbl }) => {
output.push('&');
if !cpp_like_names {
output.push('&');
}
if mutbl == hir::MutMutable {
output.push_str("mut ");
}

push_debuginfo_type_name(cx, inner_type, true, output);

if cpp_like_names {
output.push('*');
}
},
ty::TyArray(inner_type, len) => {
output.push('[');
Expand All @@ -84,9 +100,19 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
output.push(']');
},
ty::TySlice(inner_type) => {
output.push('[');
if cpp_like_names {
output.push_str("slice<");
} else {
output.push('[');
}

push_debuginfo_type_name(cx, inner_type, true, output);
output.push(']');

if cpp_like_names {
output.push('>');
} else {
output.push(']');
}
},
ty::TyDynamic(ref trait_data, ..) => {
if let Some(principal) = trait_data.principal() {
Expand Down