]> git.lizzy.rs Git - rust.git/commitdiff
debuginfo: Create debuginfo for for-loop variables again.
authorMichael Woerister <michaelwoerister@posteo>
Fri, 19 Dec 2014 08:48:28 +0000 (09:48 +0100)
committerMichael Woerister <michaelwoerister@posteo>
Tue, 23 Dec 2014 09:45:16 +0000 (10:45 +0100)
src/librustc_trans/trans/_match.rs
src/librustc_trans/trans/controlflow.rs
src/librustc_trans/trans/debuginfo.rs
src/test/debuginfo/lexical-scope-in-for-loop.rs

index 33fd14a441b8a955e27b5b013fbb048389bcb25c..fb8006905f9f214336a2ecd1a4f3948b3419366d 100644 (file)
@@ -1554,7 +1554,8 @@ pub fn store_for_loop_binding<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
                                           -> Block<'blk, 'tcx> {
     let _icx = push_ctxt("match::store_for_loop_binding");
 
-    if simple_identifier(&*pat).is_some() {
+    if simple_identifier(&*pat).is_some() &&
+       bcx.sess().opts.debuginfo != FullDebugInfo {
         // Generate nicer LLVM for the common case of a `for` loop pattern
         // like `for x in blahblah { ... }`.
         let binding_type = node_id_type(bcx, pat.id);
index b19faf4df1fcdd6d8b732ece9f31762c5046e5ad..3b24ded6717cc9612ea4ab97aecae1d04acfc9c7 100644 (file)
@@ -286,6 +286,7 @@ pub fn trans_for<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
     debug!("iterator type is {}, datum type is {}",
            ppaux::ty_to_string(bcx.tcx(), iterator_type),
            ppaux::ty_to_string(bcx.tcx(), iterator_datum.ty));
+
     let lliterator = load_ty(bcx, iterator_datum.val, iterator_datum.ty);
 
     // 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>,
                                        llpayload,
                                        binding_cleanup_scope_id);
 
+    debuginfo::create_for_loop_var_metadata(body_bcx_in, pat);
+
     // Codegen the body.
     body_bcx_out = trans_block(body_bcx_out, body, expr::Ignore);
     body_bcx_out =
index 6226aace8a8a11a0cda3476c93bc72c64811f0b5..be4d584acb78245816859b02e576a3b1de32bd97 100644 (file)
@@ -1049,6 +1049,43 @@ pub fn create_argument_metadata(bcx: Block, arg: &ast::Arg) {
     })
 }
 
+/// Creates debug information for the given for-loop variable.
+///
+/// Adds the created metadata nodes directly to the crate's IR.
+pub fn create_for_loop_var_metadata(bcx: Block, pat: &ast::Pat) {
+    if fn_should_be_ignored(bcx.fcx) {
+        return;
+    }
+
+    let def_map = &bcx.tcx().def_map;
+
+    pat_util::pat_bindings(def_map, pat, |_, node_id, span, spanned_ident| {
+        let datum = match bcx.fcx.lllocals.borrow().get(&node_id).cloned() {
+            Some(datum) => datum,
+            None => {
+                bcx.sess().span_bug(span,
+                    format!("no entry in lllocals table for {}",
+                            node_id).as_slice());
+            }
+        };
+
+        if unsafe { llvm::LLVMIsAAllocaInst(datum.val) } == ptr::null_mut() {
+            bcx.sess().span_bug(span, "debuginfo::create_for_loop_var_metadata() - \
+                                       Referenced variable location is not an alloca!");
+        }
+
+        let scope_metadata = scope_metadata(bcx.fcx, node_id, span);
+
+        declare_local(bcx,
+                      spanned_ident.node,
+                      datum.ty,
+                      scope_metadata,
+                      DirectVariable { alloca: datum.val },
+                      LocalVariable,
+                      span);
+    })
+}
+
 pub fn get_cleanup_debug_loc_for_ast_node<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
                                                     node_id: ast::NodeId,
                                                     node_span: Span,
index bcaebb5c153f5d411f685243110d9aec4b4c25ac..7636ffdb07dcd6a02a54e656d3db53d5a5a9bd75 100644 (file)
@@ -9,7 +9,6 @@
 // except according to those terms.
 
 // ignore-android: FIXME(#10381)
-// ignore-test: Not sure what is going on here --pcwalton
 // min-lldb-version: 310
 
 // compile-flags:-g