Skip to content

Commit 14c6207

Browse files
committed
auto merge of #12714 : michaelwoerister/rust/limited-debuginfo, r=alexcrichton
This PR brings back limited debuginfo which allows for nice backtraces and breakpoints, but omits any info about variables and types. The `-g` and `--debuginfo` command line options have been extended to take an optional argument: `-g0` means no debug info. `-g1` means line-tables only. `-g2` means full debug info. Specifying `-g` without argument is equivalent to `-g2`. Fixes #12280
2 parents 2fba2fe + a5b4d94 commit 14c6207

File tree

13 files changed

+155
-72
lines changed

13 files changed

+155
-72
lines changed

src/libgetopts/lib.rs

Lines changed: 19 additions & 0 deletions
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/back/link.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use back::archive::{Archive, METADATA_FILENAME};
1212
use back::rpath;
1313
use back::svh::Svh;
1414
use driver::driver::{CrateTranslation, OutputFilenames};
15-
use driver::session::Session;
15+
use driver::session::{NoDebugInfo, Session};
1616
use driver::session;
1717
use lib::llvm::llvm;
1818
use lib::llvm::ModuleRef;
@@ -92,7 +92,7 @@ pub mod write {
9292
use back::link::{OutputTypeExe, OutputTypeLlvmAssembly};
9393
use back::link::{OutputTypeObject};
9494
use driver::driver::{CrateTranslation, OutputFilenames};
95-
use driver::session::Session;
95+
use driver::session::{NoDebugInfo, Session};
9696
use driver::session;
9797
use lib::llvm::llvm;
9898
use lib::llvm::{ModuleRef, TargetMachineRef, PassManagerRef};
@@ -148,7 +148,7 @@ pub mod write {
148148

149149
// FIXME: #11906: Omitting frame pointers breaks retrieving the value of a parameter.
150150
// FIXME: #11954: mac64 unwinding may not work with fp elim
151-
let no_fp_elim = sess.opts.debuginfo ||
151+
let no_fp_elim = (sess.opts.debuginfo != NoDebugInfo) ||
152152
(sess.targ_cfg.os == abi::OsMacos &&
153153
sess.targ_cfg.arch == abi::X86_64);
154154

@@ -1052,7 +1052,7 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
10521052

10531053
// On OSX, debuggers need this utility to get run to do some munging of
10541054
// the symbols
1055-
if sess.targ_cfg.os == abi::OsMacos && sess.opts.debuginfo {
1055+
if sess.targ_cfg.os == abi::OsMacos && (sess.opts.debuginfo != NoDebugInfo) {
10561056
// FIXME (#9639): This needs to handle non-utf8 paths
10571057
match Process::status("dsymutil",
10581058
[out_filename.as_str().unwrap().to_owned()]) {

src/librustc/driver/driver.rs

Lines changed: 49 additions & 49 deletions
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};
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,7 +868,18 @@ pub fn build_session_options(matches: &getopts::Matches)
865868
} else { No }
866869
};
867870
let gc = debugging_opts & session::GC != 0;
868-
let debuginfo = matches.opt_present("g") || matches.opt_present("debuginfo");
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
882+
};
869883

870884
let addl_lib_search_paths = matches.opt_strs("L").map(|s| {
871885
Path::new(s.as_slice())
@@ -1012,61 +1026,47 @@ pub fn optgroups() -> ~[getopts::OptGroup] {
10121026
optflag("h", "help", "Display this message"),
10131027
optmulti("", "cfg", "Configure the compilation environment", "SPEC"),
10141028
optmulti("L", "", "Add a directory to the library search path", "PATH"),
1015-
optmulti("", "crate-type", "Comma separated list of types of crates for the \
1016-
compiler to emit",
1029+
optmulti("", "crate-type", "Comma separated list of types of crates for the compiler to emit",
10171030
"[bin|lib|rlib|dylib|staticlib]"),
1018-
optmulti("", "emit", "Comma separated list of types of output for the compiler
1019-
to emit",
1031+
optmulti("", "emit", "Comma separated list of types of output for the compiler to emit",
10201032
"[asm|bc|ir|obj|link]"),
10211033
optflag("", "crate-id", "Output the crate id and exit"),
10221034
optflag("", "crate-name", "Output the crate name and exit"),
10231035
optflag("", "crate-file-name", "Output the file(s) that would be written if compilation \
10241036
continued and exit"),
10251037
optflag("", "ls", "List the symbols defined by a library crate"),
1026-
optflag("g", "debuginfo", "Emit DWARF debug info to the objects created"),
1027-
optflag("", "no-trans",
1028-
"Run all passes except translation; no output"),
1029-
optflag("", "no-analysis",
1030-
"Parse and expand the output, but run no analysis or produce \
1031-
output"),
1032-
optflag("O", "", "Equivalent to --opt-level=2"),
1033-
optopt("o", "", "Write output to <filename>", "FILENAME"),
1034-
optopt("", "opt-level",
1035-
"Optimize with possible levels 0-3", "LEVEL"),
1036-
optopt( "", "out-dir",
1037-
"Write output to compiler-chosen filename
1038-
in <dir>", "DIR"),
1039-
optflag("", "parse-only",
1040-
"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"),
10411050
optflagopt("", "pretty",
1042-
"Pretty-print the input instead of compiling;
1043-
valid types are: normal (un-annotated source),
1044-
expanded (crates expanded),
1045-
typed (crates expanded, with type annotations),
1046-
or identified (fully parenthesized,
1047-
AST nodes and blocks with IDs)", "TYPE"),
1048-
optflagopt("", "dep-info",
1049-
"Output dependency info to <filename> after compiling", "FILENAME"),
1050-
optopt("", "sysroot",
1051-
"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"),
10521059
optflag("", "test", "Build a test harness"),
1053-
optopt("", "target",
1054-
"Target triple cpu-manufacturer-kernel[-os]
1055-
to compile for (see chapter 3.4 of http://www.sourceware.org/autobook/
1056-
for details)", "TRIPLE"),
1057-
optmulti("W", "warn",
1058-
"Set lint warnings", "OPT"),
1059-
optmulti("A", "allow",
1060-
"Set lint allowed", "OPT"),
1061-
optmulti("D", "deny",
1062-
"Set lint denied", "OPT"),
1063-
optmulti("F", "forbid",
1064-
"Set lint forbidden", "OPT"),
1065-
optmulti("C", "codegen",
1066-
"Set a codegen option", "OPT[=VALUE]"),
1067-
optmulti("Z", "", "Set internal debugging options", "FLAG"),
1068-
optflag( "v", "version",
1069-
"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"),
10701070
]
10711071
}
10721072

src/librustc/driver/session.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ pub enum OptLevel {
114114
Aggressive // -O3
115115
}
116116

117+
#[deriving(Clone, Eq)]
118+
pub enum DebugInfoLevel {
119+
NoDebugInfo,
120+
LimitedDebugInfo,
121+
FullDebugInfo,
122+
}
123+
117124
#[deriving(Clone)]
118125
pub struct Options {
119126
// The crate config requested for the session, which may be combined
@@ -122,7 +129,7 @@ pub struct Options {
122129

123130
gc: bool,
124131
optimize: OptLevel,
125-
debuginfo: bool,
132+
debuginfo: DebugInfoLevel,
126133
lint_opts: ~[(lint::Lint, lint::level)],
127134
output_types: ~[back::link::OutputType],
128135
// This was mutable for rustpkg, which updates search paths based on the
@@ -314,7 +321,7 @@ pub fn basic_options() -> @Options {
314321
crate_types: ~[],
315322
gc: false,
316323
optimize: No,
317-
debuginfo: false,
324+
debuginfo: NoDebugInfo,
318325
lint_opts: ~[],
319326
output_types: ~[],
320327
addl_lib_search_paths: @RefCell::new(HashSet::new()),

src/librustc/middle/trans/_match.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
#[allow(non_camel_case_types)];
196196

197197
use back::abi;
198+
use driver::session::FullDebugInfo;
198199
use lib::llvm::{llvm, ValueRef, BasicBlockRef};
199200
use middle::const_eval;
200201
use middle::borrowck::root_map_key;
@@ -1393,7 +1394,7 @@ fn insert_lllocals<'a>(bcx: &'a Block<'a>,
13931394
llmap.get().insert(binding_info.id, datum);
13941395
}
13951396

1396-
if bcx.sess().opts.debuginfo {
1397+
if bcx.sess().opts.debuginfo == FullDebugInfo {
13971398
debuginfo::create_match_binding_metadata(bcx,
13981399
ident,
13991400
binding_info.id,
@@ -2052,7 +2053,7 @@ pub fn store_arg<'a>(mut bcx: &'a Block<'a>,
20522053
// like `x: T`
20532054
let arg_ty = node_id_type(bcx, pat.id);
20542055
if type_of::arg_is_indirect(bcx.ccx(), arg_ty)
2055-
&& !bcx.ccx().sess.opts.debuginfo {
2056+
&& bcx.ccx().sess.opts.debuginfo != FullDebugInfo {
20562057
// Don't copy an indirect argument to an alloca, the caller
20572058
// already put it in a temporary alloca and gave it up, unless
20582059
// we emit extra-debug-info, which requires local allocas :(.

src/librustc/middle/trans/base.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
use back::link::{mangle_exported_name};
2929
use back::{link, abi};
3030
use driver::session;
31-
use driver::session::Session;
31+
use driver::session::{Session, NoDebugInfo, FullDebugInfo};
3232
use driver::driver::OutputFilenames;
3333
use driver::driver::{CrateAnalysis, CrateTranslation};
3434
use lib::llvm::{ModuleRef, ValueRef, BasicBlockRef};
@@ -1367,7 +1367,7 @@ fn copy_args_to_allocas<'a>(fcx: &FunctionContext<'a>,
13671367

13681368
bcx = _match::store_arg(bcx, args[i].pat, arg_datum, arg_scope_id);
13691369

1370-
if fcx.ccx.sess.opts.debuginfo {
1370+
if fcx.ccx.sess.opts.debuginfo == FullDebugInfo {
13711371
debuginfo::create_argument_metadata(bcx, &args[i]);
13721372
}
13731373
}
@@ -2678,7 +2678,7 @@ pub fn trans_crate(sess: session::Session,
26782678
}
26792679
26802680
glue::emit_tydescs(ccx);
2681-
if ccx.sess.opts.debuginfo {
2681+
if ccx.sess.opts.debuginfo != NoDebugInfo {
26822682
debuginfo::finalize(ccx);
26832683
}
26842684

src/librustc/middle/trans/closure.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use back::abi;
1313
use back::link::mangle_internal_name_by_path_and_seq;
14+
use driver::session::FullDebugInfo;
1415
use lib::llvm::ValueRef;
1516
use middle::moves;
1617
use middle::trans::base::*;
@@ -299,7 +300,7 @@ fn load_environment<'a>(bcx: &'a Block<'a>, cdata_ty: ty::t,
299300

300301
// Store the pointer to closure data in an alloca for debug info because that's what the
301302
// llvm.dbg.declare intrinsic expects
302-
let env_pointer_alloca = if bcx.ccx().sess.opts.debuginfo {
303+
let env_pointer_alloca = if bcx.ccx().sess.opts.debuginfo == FullDebugInfo {
303304
let alloc = alloc_ty(bcx, ty::mk_mut_ptr(bcx.tcx(), cdata_ty), "__debuginfo_env_ptr");
304305
Store(bcx, llcdata, alloc);
305306
Some(alloc)

src/librustc/middle/trans/context.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
use driver::session;
13+
use driver::session::NoDebugInfo;
1314
use lib::llvm::{ContextRef, ModuleRef, ValueRef};
1415
use lib::llvm::{llvm, TargetData, TypeNames};
1516
use lib::llvm::mk_target_data;
@@ -151,7 +152,7 @@ impl CrateContext {
151152
let tn = TypeNames::new();
152153

153154
let mut intrinsics = base::declare_intrinsics(llmod);
154-
if sess.opts.debuginfo {
155+
if sess.opts.debuginfo != NoDebugInfo {
155156
base::declare_dbg_intrinsics(llmod, &mut intrinsics);
156157
}
157158
let int_type = Type::int(targ_cfg.arch);
@@ -165,7 +166,7 @@ impl CrateContext {
165166
tn.associate_type("str_slice", &str_slice_ty);
166167

167168
let (crate_map_name, crate_map) = decl_crate_map(sess, link_meta.clone(), llmod);
168-
let dbg_cx = if sess.opts.debuginfo {
169+
let dbg_cx = if sess.opts.debuginfo != NoDebugInfo {
169170
Some(debuginfo::CrateDebugContext::new(llmod))
170171
} else {
171172
None

src/librustc/middle/trans/controlflow.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
use lib::llvm::*;
12+
use driver::session::FullDebugInfo;
1213
use middle::lang_items::{FailFnLangItem, FailBoundsCheckFnLangItem};
1314
use middle::trans::base::*;
1415
use middle::trans::build::*;
@@ -54,7 +55,7 @@ pub fn trans_stmt<'a>(cx: &'a Block<'a>,
5455
match d.node {
5556
ast::DeclLocal(ref local) => {
5657
bcx = init_local(bcx, *local);
57-
if cx.sess().opts.debuginfo {
58+
if cx.sess().opts.debuginfo == FullDebugInfo {
5859
debuginfo::create_local_var_metadata(bcx, *local);
5960
}
6061
}

src/librustc/middle/trans/debuginfo.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ is still disabled, so there is no need to do anything special with source locati
126126

127127

128128
use driver::session;
129+
use driver::session::{FullDebugInfo, LimitedDebugInfo, NoDebugInfo};
129130
use lib::llvm::llvm;
130131
use lib::llvm::{ModuleRef, ContextRef, ValueRef};
131132
use lib::llvm::debuginfo::*;
@@ -530,7 +531,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
530531
fn_ast_id: ast::NodeId,
531532
param_substs: Option<@param_substs>,
532533
llfn: ValueRef) -> FunctionDebugContext {
533-
if !cx.sess.opts.debuginfo {
534+
if cx.sess.opts.debuginfo == NoDebugInfo {
534535
return DebugInfoDisabled;
535536
}
536537

@@ -706,7 +707,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
706707
fn_decl: &ast::FnDecl,
707708
param_substs: Option<@param_substs>,
708709
error_span: Span) -> DIArray {
709-
if !cx.sess.opts.debuginfo {
710+
if cx.sess.opts.debuginfo == LimitedDebugInfo {
710711
return create_DIArray(DIB(cx), []);
711712
}
712713

@@ -783,8 +784,8 @@ pub fn create_function_debug_context(cx: &CrateContext,
783784
name_to_append_suffix_to.push_str(",");
784785
}
785786

786-
// Only create type information if debuginfo is enabled
787-
if cx.sess.opts.debuginfo {
787+
// Only create type information if full debuginfo is enabled
788+
if cx.sess.opts.debuginfo == FullDebugInfo {
788789
let actual_self_type_metadata = type_metadata(cx,
789790
actual_self_type,
790791
codemap::DUMMY_SP);
@@ -827,8 +828,8 @@ pub fn create_function_debug_context(cx: &CrateContext,
827828
name_to_append_suffix_to.push_str(",");
828829
}
829830

830-
// Again, only create type information if debuginfo is enabled
831-
if cx.sess.opts.debuginfo {
831+
// Again, only create type information if full debuginfo is enabled
832+
if cx.sess.opts.debuginfo == FullDebugInfo {
832833
let actual_type_metadata = type_metadata(cx, actual_type, codemap::DUMMY_SP);
833834
let param_metadata = token::get_ident(ident).get()
834835
.with_c_str(|name| {

src/test/debug-info/issue7712.rs

Lines changed: 1 addition & 1 deletion
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) {

0 commit comments

Comments
 (0)