trans: Inform LLVM we want CodeView on MSVC

This mirrors the behavior of `clang-cl.exe` by adding a `CodeView` global
variable when emitting debug information. This should in turn help stack traces
that are generated when code is compiled with debuginfo enabled.

Closes #28133
This commit is contained in:
Alex Crichton 2016-01-30 22:30:19 -08:00
parent 449e8bf304
commit 8b7d0c04c4
3 changed files with 26 additions and 27 deletions

View File

@ -200,6 +200,13 @@ pub fn finalize(cx: &CrateContext) {
2)
}
// Indicate that we want CodeView debug information on MSVC
if cx.sess().target.target.options.is_like_msvc {
llvm::LLVMRustAddModuleFlag(cx.llmod(),
"CodeView\0".as_ptr() as *const _,
1)
}
// Prevent bitcode readers from deleting the debug info.
let ptr = "Debug Info Version\0".as_ptr();
llvm::LLVMRustAddModuleFlag(cx.llmod(), ptr as *const _,

View File

@ -14,6 +14,7 @@
// seemingly completely unrelated change.
// Unfortunately, LLVM has no "disable" option for this, so we have to set
// "enable" to 0 instead.
// compile-flags:-g -Cllvm-args=-enable-tail-merge=0
// ignore-pretty as this critically relies on line numbers
@ -27,30 +28,23 @@ macro_rules! pos {
() => ((file!(), line!()))
}
#[cfg(all(unix,
not(target_os = "macos"),
not(target_os = "ios"),
not(target_os = "android"),
not(all(target_os = "linux", target_arch = "arm"))))]
macro_rules! dump_and_die {
($($pos:expr),*) => ({
// FIXME(#18285): we cannot include the current position because
// the macro span takes over the last frame's file/line.
dump_filelines(&[$($pos),*]);
panic!();
if cfg!(target_os = "macos") ||
cfg!(target_os = "ios") ||
cfg!(target_os = "android") ||
cfg!(all(target_os = "linux", target_arch = "arm")) ||
cfg!(all(windows, target_env = "gnu")) {
// skip these platforms as this support isn't implemented yet.
} else {
dump_filelines(&[$($pos),*]);
panic!();
}
})
}
// this does not work on Windows, Android, OSX or iOS
#[cfg(not(all(unix,
not(target_os = "macos"),
not(target_os = "ios"),
not(target_os = "android"),
not(all(target_os = "linux", target_arch = "arm")))))]
macro_rules! dump_and_die {
($($pos:expr),*) => ({ let _ = [$($pos),*]; })
}
// we can't use a function as it will alter the backtrace
macro_rules! check {
($counter:expr; $($pos:expr),*) => ({

View File

@ -10,12 +10,11 @@
// no-pretty-expanded FIXME #15189
// ignore-android FIXME #17520
// ignore-msvc FIXME #28133
// compile-flags:-g
use std::env;
use std::process::{Command, Stdio};
use std::str;
use std::ops::{Drop, FnMut, FnOnce};
#[inline(never)]
fn foo() {
@ -52,7 +51,7 @@ fn runtest(me: &str) {
let out = p.wait_with_output().unwrap();
assert!(!out.status.success());
let s = str::from_utf8(&out.stderr).unwrap();
assert!(s.contains("stack backtrace") && s.contains("foo::h"),
assert!(s.contains("stack backtrace") && s.contains(" - foo"),
"bad output: {}", s);
// Make sure the stack trace is *not* printed
@ -62,7 +61,7 @@ fn runtest(me: &str) {
let out = p.wait_with_output().unwrap();
assert!(!out.status.success());
let s = str::from_utf8(&out.stderr).unwrap();
assert!(!s.contains("stack backtrace") && !s.contains("foo::h"),
assert!(!s.contains("stack backtrace") && !s.contains(" - foo"),
"bad output2: {}", s);
// Make sure a stack trace is printed
@ -72,7 +71,7 @@ fn runtest(me: &str) {
let s = str::from_utf8(&out.stderr).unwrap();
// loosened the following from double::h to double:: due to
// spurious failures on mac, 32bit, optimized
assert!(s.contains("stack backtrace") && s.contains("double::"),
assert!(s.contains("stack backtrace") && s.contains(" - double"),
"bad output3: {}", s);
// Make sure a stack trace isn't printed too many times
@ -89,8 +88,11 @@ fn runtest(me: &str) {
"bad output4: {}", s);
}
#[cfg(not(all(windows, target_arch = "x86")))]
fn main() {
if cfg!(windows) && cfg!(target_arch = "x86") && cfg!(target_env = "gnu") {
return
}
let args: Vec<String> = env::args().collect();
if args.len() >= 2 && args[1] == "fail" {
foo();
@ -100,7 +102,3 @@ fn main() {
runtest(&args[0]);
}
}
// See issue 28218
#[cfg(all(windows, target_arch = "x86"))]
fn main() {}