Skip to content

Commit 50df6b9

Browse files
committed
Auto merge of #31319 - alexcrichton:msvc-backtraces, r=michaelwoerister
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
2 parents a992241 + 8b7d0c0 commit 50df6b9

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

src/librustc_trans/trans/debuginfo/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ pub fn finalize(cx: &CrateContext) {
200200
2)
201201
}
202202

203+
// Indicate that we want CodeView debug information on MSVC
204+
if cx.sess().target.target.options.is_like_msvc {
205+
llvm::LLVMRustAddModuleFlag(cx.llmod(),
206+
"CodeView\0".as_ptr() as *const _,
207+
1)
208+
}
209+
203210
// Prevent bitcode readers from deleting the debug info.
204211
let ptr = "Debug Info Version\0".as_ptr();
205212
llvm::LLVMRustAddModuleFlag(cx.llmod(), ptr as *const _,

src/test/run-pass/backtrace-debuginfo.rs

+11-17
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// seemingly completely unrelated change.
1515
// Unfortunately, LLVM has no "disable" option for this, so we have to set
1616
// "enable" to 0 instead.
17+
1718
// compile-flags:-g -Cllvm-args=-enable-tail-merge=0
1819
// ignore-pretty as this critically relies on line numbers
1920

@@ -27,30 +28,23 @@ macro_rules! pos {
2728
() => ((file!(), line!()))
2829
}
2930

30-
#[cfg(all(unix,
31-
not(target_os = "macos"),
32-
not(target_os = "ios"),
33-
not(target_os = "android"),
34-
not(all(target_os = "linux", target_arch = "arm"))))]
3531
macro_rules! dump_and_die {
3632
($($pos:expr),*) => ({
3733
// FIXME(#18285): we cannot include the current position because
3834
// the macro span takes over the last frame's file/line.
39-
dump_filelines(&[$($pos),*]);
40-
panic!();
35+
if cfg!(target_os = "macos") ||
36+
cfg!(target_os = "ios") ||
37+
cfg!(target_os = "android") ||
38+
cfg!(all(target_os = "linux", target_arch = "arm")) ||
39+
cfg!(all(windows, target_env = "gnu")) {
40+
// skip these platforms as this support isn't implemented yet.
41+
} else {
42+
dump_filelines(&[$($pos),*]);
43+
panic!();
44+
}
4145
})
4246
}
4347

44-
// this does not work on Windows, Android, OSX or iOS
45-
#[cfg(not(all(unix,
46-
not(target_os = "macos"),
47-
not(target_os = "ios"),
48-
not(target_os = "android"),
49-
not(all(target_os = "linux", target_arch = "arm")))))]
50-
macro_rules! dump_and_die {
51-
($($pos:expr),*) => ({ let _ = [$($pos),*]; })
52-
}
53-
5448
// we can't use a function as it will alter the backtrace
5549
macro_rules! check {
5650
($counter:expr; $($pos:expr),*) => ({

src/test/run-pass/backtrace.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010

1111
// no-pretty-expanded FIXME #15189
1212
// ignore-android FIXME #17520
13-
// ignore-msvc FIXME #28133
13+
// compile-flags:-g
1414

1515
use std::env;
1616
use std::process::{Command, Stdio};
1717
use std::str;
18-
use std::ops::{Drop, FnMut, FnOnce};
1918

2019
#[inline(never)]
2120
fn foo() {
@@ -52,7 +51,7 @@ fn runtest(me: &str) {
5251
let out = p.wait_with_output().unwrap();
5352
assert!(!out.status.success());
5453
let s = str::from_utf8(&out.stderr).unwrap();
55-
assert!(s.contains("stack backtrace") && s.contains("foo::h"),
54+
assert!(s.contains("stack backtrace") && s.contains(" - foo"),
5655
"bad output: {}", s);
5756

5857
// Make sure the stack trace is *not* printed
@@ -62,7 +61,7 @@ fn runtest(me: &str) {
6261
let out = p.wait_with_output().unwrap();
6362
assert!(!out.status.success());
6463
let s = str::from_utf8(&out.stderr).unwrap();
65-
assert!(!s.contains("stack backtrace") && !s.contains("foo::h"),
64+
assert!(!s.contains("stack backtrace") && !s.contains(" - foo"),
6665
"bad output2: {}", s);
6766

6867
// Make sure a stack trace is printed
@@ -72,7 +71,7 @@ fn runtest(me: &str) {
7271
let s = str::from_utf8(&out.stderr).unwrap();
7372
// loosened the following from double::h to double:: due to
7473
// spurious failures on mac, 32bit, optimized
75-
assert!(s.contains("stack backtrace") && s.contains("double::"),
74+
assert!(s.contains("stack backtrace") && s.contains(" - double"),
7675
"bad output3: {}", s);
7776

7877
// Make sure a stack trace isn't printed too many times
@@ -89,8 +88,11 @@ fn runtest(me: &str) {
8988
"bad output4: {}", s);
9089
}
9190

92-
#[cfg(not(all(windows, target_arch = "x86")))]
9391
fn main() {
92+
if cfg!(windows) && cfg!(target_arch = "x86") && cfg!(target_env = "gnu") {
93+
return
94+
}
95+
9496
let args: Vec<String> = env::args().collect();
9597
if args.len() >= 2 && args[1] == "fail" {
9698
foo();
@@ -100,7 +102,3 @@ fn main() {
100102
runtest(&args[0]);
101103
}
102104
}
103-
104-
// See issue 28218
105-
#[cfg(all(windows, target_arch = "x86"))]
106-
fn main() {}

0 commit comments

Comments
 (0)