about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-07-13 20:42:55 +0000
committerbors <bors@rust-lang.org>2015-07-13 20:42:55 +0000
commit2533a85be4584a47818d4f381f29bbd6294e0fb0 (patch)
tree0ec96b4808e5010ccad8c3aa53c4cad4722d21c2
parent680053848928a94f933c5a453c031b458e9766e0 (diff)
parent6c701275b3a4583ccc43d23cdaea607ab2786217 (diff)
downloadrust-2533a85be4584a47818d4f381f29bbd6294e0fb0.tar.gz
rust-2533a85be4584a47818d4f381f29bbd6294e0fb0.zip
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
-rw-r--r--src/librustc_trans/back/link.rs3
-rw-r--r--src/librustc_trans/back/linker.rs21
2 files changed, 24 insertions, 0 deletions
diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs
index d24d8369751..d7849e8f555 100644
--- a/src/librustc_trans/back/link.rs
+++ b/src/librustc_trans/back/link.rs
@@ -954,6 +954,9 @@ fn link_args(cmd: &mut Linker,
     // Pass optimization flags down to the linker.
     cmd.optimize();
 
+    // Pass debuginfo flags down to the linker.
+    cmd.debuginfo();
+
     // We want to prevent the compiler from accidentally leaking in any system
     // libraries, so we explicitly ask gcc to not link to any libraries by
     // default. Note that this does not happen for windows because windows pulls
diff --git a/src/librustc_trans/back/linker.rs b/src/librustc_trans/back/linker.rs
index a272e7c4c8f..3a709955098 100644
--- a/src/librustc_trans/back/linker.rs
+++ b/src/librustc_trans/back/linker.rs
@@ -16,6 +16,7 @@ use std::fs;
 use back::archive;
 use session::Session;
 use session::config;
+use session::config::DebugInfoLevel::{NoDebugInfo, LimitedDebugInfo, FullDebugInfo};
 
 /// Linker abstraction used by back::link to build up the command to invoke a
 /// linker.
@@ -39,6 +40,7 @@ pub trait Linker {
     fn gc_sections(&mut self, is_dylib: bool);
     fn position_independent_executable(&mut self);
     fn optimize(&mut self);
+    fn debuginfo(&mut self);
     fn no_default_libraries(&mut self);
     fn build_dylib(&mut self, out_filename: &Path);
     fn args(&mut self, args: &[String]);
@@ -143,6 +145,10 @@ impl<'a> Linker for GnuLinker<'a> {
         }
     }
 
+    fn debuginfo(&mut self) {
+        // Don't do anything special here for GNU-style linkers.
+    }
+
     fn no_default_libraries(&mut self) {
         // Unfortunately right now passing -nodefaultlibs to gcc on windows
         // doesn't work so hot (in terms of native dependencies). This if
@@ -265,6 +271,21 @@ impl<'a> Linker for MsvcLinker<'a> {
     fn optimize(&mut self) {
         // Needs more investigation of `/OPT` arguments
     }
+
+    fn debuginfo(&mut self) {
+        match self.sess.opts.debuginfo {
+            NoDebugInfo => {
+                // Do nothing if debuginfo is disabled
+            },
+            LimitedDebugInfo |
+            FullDebugInfo    => {
+                // This will cause the Microsoft linker to generate a PDB file
+                // from the CodeView line tables in the object files.
+                self.cmd.arg("/DEBUG");
+            }
+        }
+    }
+
     fn whole_archives(&mut self) {
         // hints not supported?
     }