Skip to content

Commit b048114

Browse files
debuginfo: Create debuginfo for for-loop variables again.
1 parent f9a4849 commit b048114

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

src/librustc_trans/trans/controlflow.rs

+3
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ pub fn trans_for<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
277277
debug!("iterator type is {}, datum type is {}",
278278
ppaux::ty_to_string(bcx.tcx(), iterator_type),
279279
ppaux::ty_to_string(bcx.tcx(), iterator_datum.ty));
280+
280281
let lliterator = load_ty(bcx, iterator_datum.val, iterator_datum.ty);
281282

282283
// Create our basic blocks and set up our loop cleanups.
@@ -356,6 +357,8 @@ pub fn trans_for<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
356357
llpayload,
357358
binding_cleanup_scope_id);
358359

360+
debuginfo::create_for_loop_var_metadata(body_bcx_in, pat);
361+
359362
// Codegen the body.
360363
body_bcx_out = trans_block(body_bcx_out, body, expr::Ignore);
361364
body_bcx_out =

src/librustc_trans/trans/debuginfo.rs

+37
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,43 @@ pub fn create_argument_metadata(bcx: Block, arg: &ast::Arg) {
10511051
})
10521052
}
10531053

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

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

-1
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)