Skip to content

Commit 2533a85

Browse files
committed
Auto merge of #26993 - michaelwoerister:msvc-debuginfo, r=alexcrichton
This PR will enable RUSTC to generate PDB debuginfo files when targeting the MSVC toolchain. Mind that these are not full featured PDB files -- they just contain line tables, so you can get proper backtraces and step through your code, but variable values can't be inspected. We are just levering (LLVM's current support)[http://clang.llvm.org/docs/MSVCCompatibility.html] for creating Windows debuginfo. When LLVM's support gets better, we should benefit from that too without much effort. I also wanted to include some kind of auto test with this PR but I could not get the `rmake` tests to work properly when targeting MSVC. EDIT: Closes #19533
2 parents 6800538 + 6c70127 commit 2533a85

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/librustc_trans/back/link.rs

+3
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,9 @@ fn link_args(cmd: &mut Linker,
954954
// Pass optimization flags down to the linker.
955955
cmd.optimize();
956956

957+
// Pass debuginfo flags down to the linker.
958+
cmd.debuginfo();
959+
957960
// We want to prevent the compiler from accidentally leaking in any system
958961
// libraries, so we explicitly ask gcc to not link to any libraries by
959962
// default. Note that this does not happen for windows because windows pulls

src/librustc_trans/back/linker.rs

+21
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::fs;
1616
use back::archive;
1717
use session::Session;
1818
use session::config;
19+
use session::config::DebugInfoLevel::{NoDebugInfo, LimitedDebugInfo, FullDebugInfo};
1920

2021
/// Linker abstraction used by back::link to build up the command to invoke a
2122
/// linker.
@@ -39,6 +40,7 @@ pub trait Linker {
3940
fn gc_sections(&mut self, is_dylib: bool);
4041
fn position_independent_executable(&mut self);
4142
fn optimize(&mut self);
43+
fn debuginfo(&mut self);
4244
fn no_default_libraries(&mut self);
4345
fn build_dylib(&mut self, out_filename: &Path);
4446
fn args(&mut self, args: &[String]);
@@ -143,6 +145,10 @@ impl<'a> Linker for GnuLinker<'a> {
143145
}
144146
}
145147

148+
fn debuginfo(&mut self) {
149+
// Don't do anything special here for GNU-style linkers.
150+
}
151+
146152
fn no_default_libraries(&mut self) {
147153
// Unfortunately right now passing -nodefaultlibs to gcc on windows
148154
// doesn't work so hot (in terms of native dependencies). This if
@@ -265,6 +271,21 @@ impl<'a> Linker for MsvcLinker<'a> {
265271
fn optimize(&mut self) {
266272
// Needs more investigation of `/OPT` arguments
267273
}
274+
275+
fn debuginfo(&mut self) {
276+
match self.sess.opts.debuginfo {
277+
NoDebugInfo => {
278+
// Do nothing if debuginfo is disabled
279+
},
280+
LimitedDebugInfo |
281+
FullDebugInfo => {
282+
// This will cause the Microsoft linker to generate a PDB file
283+
// from the CodeView line tables in the object files.
284+
self.cmd.arg("/DEBUG");
285+
}
286+
}
287+
}
288+
268289
fn whole_archives(&mut self) {
269290
// hints not supported?
270291
}

0 commit comments

Comments
 (0)