Skip to content

Commit e15fd40

Browse files
debuginfo: Expose limited debuginfo in command line options
1 parent 1938e87 commit e15fd40

File tree

4 files changed

+69
-54
lines changed

4 files changed

+69
-54
lines changed

src/libgetopts/lib.rs

+19
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,25 @@ pub fn optmulti(short_name: &str, long_name: &str, desc: &str, hint: &str) -> Op
455455
}
456456
}
457457

458+
/// Create a generic option group, stating all parameters explicitly
459+
pub fn opt(short_name: &str,
460+
long_name: &str,
461+
desc: &str,
462+
hint: &str,
463+
hasarg: HasArg,
464+
occur: Occur) -> OptGroup {
465+
let len = short_name.len();
466+
assert!(len == 1 || len == 0);
467+
OptGroup {
468+
short_name: short_name.to_owned(),
469+
long_name: long_name.to_owned(),
470+
hint: hint.to_owned(),
471+
desc: desc.to_owned(),
472+
hasarg: hasarg,
473+
occur: occur
474+
}
475+
}
476+
458477
impl Fail_ {
459478
/// Convert a `Fail_` enum into an error string.
460479
pub fn to_err_msg(self) -> ~str {

src/librustc/driver/driver.rs

+48-52
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
use back::link;
1313
use back::{arm, x86, x86_64, mips};
14-
use driver::session::{Aggressive, CrateTypeExecutable, FullDebugInfo, NoDebugInfo};
14+
use driver::session::{Aggressive, CrateTypeExecutable, FullDebugInfo, LimitedDebugInfo,
15+
NoDebugInfo};
1516
use driver::session::{Session, Session_, No, Less, Default};
1617
use driver::session;
1718
use front;
@@ -38,7 +39,9 @@ use std::vec;
3839
use std::vec_ng::Vec;
3940
use std::vec_ng;
4041
use collections::{HashMap, HashSet};
41-
use getopts::{optopt, optmulti, optflag, optflagopt};
42+
use getopts::{optopt, optmulti, optflag, optflagopt, opt};
43+
use MaybeHasArg = getopts::Maybe;
44+
use OccurOptional = getopts::Optional;
4245
use getopts;
4346
use syntax::ast;
4447
use syntax::abi;
@@ -865,10 +868,17 @@ pub fn build_session_options(matches: &getopts::Matches)
865868
} else { No }
866869
};
867870
let gc = debugging_opts & session::GC != 0;
868-
let debuginfo = if matches.opt_present("g") || matches.opt_present("debuginfo") {
869-
FullDebugInfo
870-
} else {
871-
NoDebugInfo
871+
872+
let debuginfo = match matches.opt_default("debuginfo", "2") {
873+
Some(level) => {
874+
match level {
875+
~"0" => NoDebugInfo,
876+
~"1" => LimitedDebugInfo,
877+
~"2" => FullDebugInfo,
878+
_ => early_error("debug info level needs to be between 0-2")
879+
}
880+
}
881+
None => NoDebugInfo
872882
};
873883

874884
let addl_lib_search_paths = matches.opt_strs("L").map(|s| {
@@ -1016,61 +1026,47 @@ pub fn optgroups() -> ~[getopts::OptGroup] {
10161026
optflag("h", "help", "Display this message"),
10171027
optmulti("", "cfg", "Configure the compilation environment", "SPEC"),
10181028
optmulti("L", "", "Add a directory to the library search path", "PATH"),
1019-
optmulti("", "crate-type", "Comma separated list of types of crates for the \
1020-
compiler to emit",
1029+
optmulti("", "crate-type", "Comma separated list of types of crates for the compiler to emit",
10211030
"[bin|lib|rlib|dylib|staticlib]"),
1022-
optmulti("", "emit", "Comma separated list of types of output for the compiler
1023-
to emit",
1031+
optmulti("", "emit", "Comma separated list of types of output for the compiler to emit",
10241032
"[asm|bc|ir|obj|link]"),
10251033
optflag("", "crate-id", "Output the crate id and exit"),
10261034
optflag("", "crate-name", "Output the crate name and exit"),
10271035
optflag("", "crate-file-name", "Output the file(s) that would be written if compilation \
10281036
continued and exit"),
10291037
optflag("", "ls", "List the symbols defined by a library crate"),
1030-
optflag("g", "debuginfo", "Emit DWARF debug info to the objects created"),
1031-
optflag("", "no-trans",
1032-
"Run all passes except translation; no output"),
1033-
optflag("", "no-analysis",
1034-
"Parse and expand the output, but run no analysis or produce \
1035-
output"),
1036-
optflag("O", "", "Equivalent to --opt-level=2"),
1037-
optopt("o", "", "Write output to <filename>", "FILENAME"),
1038-
optopt("", "opt-level",
1039-
"Optimize with possible levels 0-3", "LEVEL"),
1040-
optopt( "", "out-dir",
1041-
"Write output to compiler-chosen filename
1042-
in <dir>", "DIR"),
1043-
optflag("", "parse-only",
1044-
"Parse only; do not compile, assemble, or link"),
1038+
opt("g", "debuginfo", "Emit DWARF debug info to the objects created:
1039+
0 = no debug info,
1040+
1 = line-tables only (for stacktraces),
1041+
2 = full debug info with variable, argument and type information",
1042+
"LEVEL", MaybeHasArg, OccurOptional),
1043+
optflag("", "no-trans", "Run all passes except translation; no output"),
1044+
optflag("", "no-analysis", "Parse and expand the output, but run no analysis or produce output"),
1045+
optflag("O", "", "Equivalent to --opt-level=2"),
1046+
optopt("o", "", "Write output to <filename>", "FILENAME"),
1047+
optopt("", "opt-level", "Optimize with possible levels 0-3", "LEVEL"),
1048+
optopt( "", "out-dir", "Write output to compiler-chosen filename in <dir>", "DIR"),
1049+
optflag("", "parse-only", "Parse only; do not compile, assemble, or link"),
10451050
optflagopt("", "pretty",
1046-
"Pretty-print the input instead of compiling;
1047-
valid types are: normal (un-annotated source),
1048-
expanded (crates expanded),
1049-
typed (crates expanded, with type annotations),
1050-
or identified (fully parenthesized,
1051-
AST nodes and blocks with IDs)", "TYPE"),
1052-
optflagopt("", "dep-info",
1053-
"Output dependency info to <filename> after compiling", "FILENAME"),
1054-
optopt("", "sysroot",
1055-
"Override the system root", "PATH"),
1051+
"Pretty-print the input instead of compiling;
1052+
valid types are: normal (un-annotated source),
1053+
expanded (crates expanded),
1054+
typed (crates expanded, with type annotations),
1055+
or identified (fully parenthesized,
1056+
AST nodes and blocks with IDs)", "TYPE"),
1057+
optflagopt("", "dep-info", "Output dependency info to <filename> after compiling", "FILENAME"),
1058+
optopt("", "sysroot", "Override the system root", "PATH"),
10561059
optflag("", "test", "Build a test harness"),
1057-
optopt("", "target",
1058-
"Target triple cpu-manufacturer-kernel[-os]
1059-
to compile for (see chapter 3.4 of http://www.sourceware.org/autobook/
1060-
for details)", "TRIPLE"),
1061-
optmulti("W", "warn",
1062-
"Set lint warnings", "OPT"),
1063-
optmulti("A", "allow",
1064-
"Set lint allowed", "OPT"),
1065-
optmulti("D", "deny",
1066-
"Set lint denied", "OPT"),
1067-
optmulti("F", "forbid",
1068-
"Set lint forbidden", "OPT"),
1069-
optmulti("C", "codegen",
1070-
"Set a codegen option", "OPT[=VALUE]"),
1071-
optmulti("Z", "", "Set internal debugging options", "FLAG"),
1072-
optflag( "v", "version",
1073-
"Print version info and exit"),
1060+
optopt("", "target", "Target triple cpu-manufacturer-kernel[-os]
1061+
to compile for (see chapter 3.4 of http://www.sourceware.org/autobook/
1062+
for details)", "TRIPLE"),
1063+
optmulti("W", "warn", "Set lint warnings", "OPT"),
1064+
optmulti("A", "allow", "Set lint allowed", "OPT"),
1065+
optmulti("D", "deny", "Set lint denied", "OPT"),
1066+
optmulti("F", "forbid", "Set lint forbidden", "OPT"),
1067+
optmulti("C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
1068+
optmulti("Z", "", "Set internal debugging options", "FLAG"),
1069+
optflag( "v", "version", "Print version info and exit"),
10741070
]
10751071
}
10761072

src/test/debug-info/issue7712.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// compile-flags:-g
11+
// compile-flags:-g1
1212

1313
pub trait TraitWithDefaultMethod {
1414
fn method(self) {

src/test/debug-info/lexical-scope-in-parameterless-closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// ignore-android: FIXME(#10381)
1212

13-
// compile-flags:-g
13+
// compile-flags:-g1
1414
// debugger:run
1515

1616
// Nothing to do here really, just make sure it compiles. See issue #8513.

0 commit comments

Comments
 (0)