From 8b7d0c04c412acf06d73c9b9c8623319f804b062 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 30 Jan 2016 22:30:19 -0800 Subject: [PATCH] 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 --- src/librustc_trans/trans/debuginfo/mod.rs | 7 ++++++ src/test/run-pass/backtrace-debuginfo.rs | 28 +++++++++-------------- src/test/run-pass/backtrace.rs | 18 +++++++-------- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/librustc_trans/trans/debuginfo/mod.rs b/src/librustc_trans/trans/debuginfo/mod.rs index 5e11a50be2273..f0b48ddd5c388 100644 --- a/src/librustc_trans/trans/debuginfo/mod.rs +++ b/src/librustc_trans/trans/debuginfo/mod.rs @@ -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 _, diff --git a/src/test/run-pass/backtrace-debuginfo.rs b/src/test/run-pass/backtrace-debuginfo.rs index a8eade34cbcdd..8b2b26948824f 100644 --- a/src/test/run-pass/backtrace-debuginfo.rs +++ b/src/test/run-pass/backtrace-debuginfo.rs @@ -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),*) => ({ diff --git a/src/test/run-pass/backtrace.rs b/src/test/run-pass/backtrace.rs index 5d65f9eb2be0f..3fb52f8c8b4dc 100644 --- a/src/test/run-pass/backtrace.rs +++ b/src/test/run-pass/backtrace.rs @@ -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 = 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() {}