Skip to content

debuginfo: Improve commandline option handling for debuginfo #12816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 35 additions & 25 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using unwrap(), this may be better expressed with a match where the None case returns NoDebugInfo. Could you also put the {} in instead was {} in backticks? (just to be clear what the user input was)

Additionally, having ~str as a pattern will likely be going away, so it may be easier to go ahead and remove it for now (matching on Some("0") instead for example)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll do that. The code in question was pretty much literally copied from --opt-level handling directly above it. I'll adapt this too...

};

let addl_lib_search_paths = matches.opt_strs("L").map(|s| {
Expand Down Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion src/test/debug-info/issue7712.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/test/debug-info/limited-debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// ignore-android: FIXME(#10381)

// compile-flags:-g1
// compile-flags:--debuginfo=1

// Make sure functions have proper names
// debugger:info functions
Expand Down