Skip to content

Commit 6f88258

Browse files
debuginfo: Create debuginfo for for-loop variables again.
1 parent 62fb41c commit 6f88258

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

src/librustc_trans/trans/_match.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,8 @@ pub fn store_for_loop_binding<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
15541554
-> Block<'blk, 'tcx> {
15551555
let _icx = push_ctxt("match::store_for_loop_binding");
15561556

1557-
if simple_identifier(&*pat).is_some() {
1557+
if simple_identifier(&*pat).is_some() &&
1558+
bcx.sess().opts.debuginfo != FullDebugInfo {
15581559
// Generate nicer LLVM for the common case of a `for` loop pattern
15591560
// like `for x in blahblah { ... }`.
15601561
let binding_type = node_id_type(bcx, pat.id);

src/librustc_trans/trans/controlflow.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ pub fn trans_for<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
286286
debug!("iterator type is {}, datum type is {}",
287287
ppaux::ty_to_string(bcx.tcx(), iterator_type),
288288
ppaux::ty_to_string(bcx.tcx(), iterator_datum.ty));
289+
289290
let lliterator = load_ty(bcx, iterator_datum.val, iterator_datum.ty);
290291

291292
// Create our basic blocks and set up our loop cleanups.
@@ -365,6 +366,8 @@ pub fn trans_for<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
365366
llpayload,
366367
binding_cleanup_scope_id);
367368

369+
debuginfo::create_for_loop_var_metadata(body_bcx_in, pat);
370+
368371
// Codegen the body.
369372
body_bcx_out = trans_block(body_bcx_out, body, expr::Ignore);
370373
body_bcx_out =

src/librustc_trans/trans/debuginfo.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,43 @@ pub fn create_argument_metadata(bcx: Block, arg: &ast::Arg) {
10491049
})
10501050
}
10511051

1052+
/// Creates debug information for the given for-loop variable.
1053+
///
1054+
/// Adds the created metadata nodes directly to the crate's IR.
1055+
pub fn create_for_loop_var_metadata(bcx: Block, pat: &ast::Pat) {
1056+
if fn_should_be_ignored(bcx.fcx) {
1057+
return;
1058+
}
1059+
1060+
let def_map = &bcx.tcx().def_map;
1061+
1062+
pat_util::pat_bindings(def_map, pat, |_, node_id, span, spanned_ident| {
1063+
let datum = match bcx.fcx.lllocals.borrow().get(&node_id).cloned() {
1064+
Some(datum) => datum,
1065+
None => {
1066+
bcx.sess().span_bug(span,
1067+
format!("no entry in lllocals table for {}",
1068+
node_id).as_slice());
1069+
}
1070+
};
1071+
1072+
if unsafe { llvm::LLVMIsAAllocaInst(datum.val) } == ptr::null_mut() {
1073+
bcx.sess().span_bug(span, "debuginfo::create_for_loop_var_metadata() - \
1074+
Referenced variable location is not an alloca!");
1075+
}
1076+
1077+
let scope_metadata = scope_metadata(bcx.fcx, node_id, span);
1078+
1079+
declare_local(bcx,
1080+
spanned_ident.node,
1081+
datum.ty,
1082+
scope_metadata,
1083+
DirectVariable { alloca: datum.val },
1084+
LocalVariable,
1085+
span);
1086+
})
1087+
}
1088+
10521089
pub fn get_cleanup_debug_loc_for_ast_node<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
10531090
node_id: ast::NodeId,
10541091
node_span: Span,

src/test/debuginfo/lexical-scope-in-for-loop.rs

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

1111
// ignore-android: FIXME(#10381)
12-
// ignore-test: Not sure what is going on here --pcwalton
1312
// min-lldb-version: 310
1413

1514
// compile-flags:-g

0 commit comments

Comments
 (0)