about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Woerister <michaelwoerister@posteo>2014-03-10 20:13:19 +0100
committerMichael Woerister <michaelwoerister@posteo>2014-03-11 18:15:35 +0100
commit3ea50f0e36ea518e94dd4d3ec0e0be69e05e1358 (patch)
tree7d46efccab3c97fc0c1ad598f937b126662e348e
parenta0f20f09fde77fb7330b1a67918744149dca3318 (diff)
downloadrust-3ea50f0e36ea518e94dd4d3ec0e0be69e05e1358.tar.gz
rust-3ea50f0e36ea518e94dd4d3ec0e0be69e05e1358.zip
debuginfo: Improve commandline option handling for debuginfo (fixes #12811)
The `-g` flag does not take an argument anymore while the argument to `--debuginfo` becomes mandatory. This change makes it possible again to run the compiler like this:

`rustc -g ./file.rs`

This did not work before because `./file.rs` was misinterpreted as the argument to `-g`. In order to get limited debuginfo, one now has to use `--debuginfo=1`.
-rw-r--r--src/librustc/driver/driver.rs60
-rw-r--r--src/test/debug-info/issue7712.rs2
-rw-r--r--src/test/debug-info/lexical-scope-in-parameterless-closure.rs2
-rw-r--r--src/test/debug-info/limited-debuginfo.rs2
4 files changed, 38 insertions, 28 deletions
diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs
index 2a92ef496c7..331677cf955 100644
--- a/src/librustc/driver/driver.rs
+++ b/src/librustc/driver/driver.rs
@@ -39,9 +39,7 @@ use std::os;
 use std::vec_ng::Vec;
 use std::vec_ng;
 use collections::HashMap;
-use getopts::{optopt, optmulti, optflag, optflagopt, opt};
-use MaybeHasArg = getopts::Maybe;
-use OccurOptional = getopts::Optional;
+use getopts::{optopt, optmulti, optflag, optflagopt};
 use getopts;
 use syntax::ast;
 use syntax::abi;
@@ -866,29 +864,41 @@ pub fn build_session_options(matches: &getopts::Matches)
             }
             Default
         } else if matches.opt_present("opt-level") {
-            match matches.opt_str("opt-level").unwrap() {
-              ~"0" => No,
-              ~"1" => Less,
-              ~"2" => Default,
-              ~"3" => Aggressive,
-              _ => {
-                early_error("optimization level needs to be between 0-3")
-              }
+            match matches.opt_str("opt-level").as_ref().map(|s| s.as_slice()) {
+                None      |
+                Some("0") => No,
+                Some("1") => Less,
+                Some("2") => Default,
+                Some("3") => Aggressive,
+                Some(arg) => {
+                    early_error(format!("optimization level needs to be between 0-3 \
+                                        (instead was `{}`)", arg));
+                }
             }
-        } else { No }
+        } else {
+            No
+        }
     };
     let gc = debugging_opts & session::GC != 0;
 
-    let debuginfo = match matches.opt_default("debuginfo", "2") {
-        Some(level) => {
-            match level {
-                ~"0" => NoDebugInfo,
-                ~"1" => LimitedDebugInfo,
-                ~"2" => FullDebugInfo,
-                _    => early_error("debug info level needs to be between 0-2")
+    let debuginfo = if matches.opt_present("g") {
+        if matches.opt_present("debuginfo") {
+            early_error("-g and --debuginfo both provided");
+        }
+        FullDebugInfo
+    } else if matches.opt_present("debuginfo") {
+        match matches.opt_str("debuginfo").as_ref().map(|s| s.as_slice()) {
+            Some("0") => NoDebugInfo,
+            Some("1") => LimitedDebugInfo,
+            None      |
+            Some("2") => FullDebugInfo,
+            Some(arg) => {
+                early_error(format!("optimization level needs to be between 0-3 \
+                                    (instead was `{}`)", arg));
             }
         }
-        None => NoDebugInfo
+    } else {
+        NoDebugInfo
     };
 
     let addl_lib_search_paths = matches.opt_strs("L").map(|s| {
@@ -1045,11 +1055,11 @@ pub fn optgroups() -> Vec<getopts::OptGroup> {
   optflag("", "crate-file-name", "Output the file(s) that would be written if compilation \
           continued and exit"),
   optflag("",  "ls",  "List the symbols defined by a library crate"),
-  opt("g",  "debuginfo",  "Emit DWARF debug info to the objects created:
-       0 = no debug info,
-       1 = line-tables only (for stacktraces),
-       2 = full debug info with variable, argument and type information",
-      "LEVEL", MaybeHasArg, OccurOptional),
+  optflag("g",  "",  "Equivalent to --debuginfo=2"),
+  optopt("",  "debuginfo",  "Emit DWARF debug info to the objects created:
+         0 = no debug info,
+         1 = line-tables only (for stacktraces and breakpoints),
+         2 = full debug info with variable and type information (same as -g)", "LEVEL"),
   optflag("", "no-trans", "Run all passes except translation; no output"),
   optflag("", "no-analysis", "Parse and expand the output, but run no analysis or produce output"),
   optflag("O", "", "Equivalent to --opt-level=2"),
diff --git a/src/test/debug-info/issue7712.rs b/src/test/debug-info/issue7712.rs
index af9b84085e3..8308afce08e 100644
--- a/src/test/debug-info/issue7712.rs
+++ b/src/test/debug-info/issue7712.rs
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// compile-flags:-g1
+// compile-flags:--debuginfo=1
 
 pub trait TraitWithDefaultMethod {
     fn method(self) {
diff --git a/src/test/debug-info/lexical-scope-in-parameterless-closure.rs b/src/test/debug-info/lexical-scope-in-parameterless-closure.rs
index ec2c80034d2..fd0a156b454 100644
--- a/src/test/debug-info/lexical-scope-in-parameterless-closure.rs
+++ b/src/test/debug-info/lexical-scope-in-parameterless-closure.rs
@@ -10,7 +10,7 @@
 
 // ignore-android: FIXME(#10381)
 
-// compile-flags:-g1
+// compile-flags:--debuginfo=1
 // debugger:run
 
 // Nothing to do here really, just make sure it compiles. See issue #8513.
diff --git a/src/test/debug-info/limited-debuginfo.rs b/src/test/debug-info/limited-debuginfo.rs
index ccf1506a565..f1e413e5e92 100644
--- a/src/test/debug-info/limited-debuginfo.rs
+++ b/src/test/debug-info/limited-debuginfo.rs
@@ -10,7 +10,7 @@
 
 // ignore-android: FIXME(#10381)
 
-// compile-flags:-g1
+// compile-flags:--debuginfo=1
 
 // Make sure functions have proper names
 // debugger:info functions