]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_codegen_llvm/debuginfo/mod.rs
Rollup merge of #69609 - TimDiekmann:excess, r=Amanieu
[rust.git] / src / librustc_codegen_llvm / debuginfo / mod.rs
index c4a52a73e25d9f6cd655bb32a633ea3aa6b23bd0..6515d5e3bec7ff655877dfdad89c2bd4875b4cc7 100644 (file)
@@ -5,7 +5,6 @@
 
 use self::metadata::{file_metadata, type_metadata, TypeMap};
 use self::namespace::mangled_name_of_instance;
-use self::source_loc::InternalDebugLocation::{self, UnknownLocation};
 use self::type_names::compute_debuginfo_type_name;
 use self::utils::{create_DIArray, is_node_local_to_unit, span_start, DIB};
 
 use std::ffi::CString;
 
 use rustc::ty::layout::{self, HasTyCtxt, LayoutOf, Size};
+use rustc_ast::ast;
 use rustc_codegen_ssa::traits::*;
 use rustc_span::symbol::Symbol;
-use rustc_span::{self, BytePos, Pos, Span};
+use rustc_span::{self, BytePos, Span};
 use smallvec::SmallVec;
-use syntax::ast;
 
 mod create_scope_map;
 pub mod gdb;
@@ -52,7 +51,6 @@
 pub use self::create_scope_map::compute_mir_scopes;
 pub use self::metadata::create_global_var_metadata;
 pub use self::metadata::extend_scope_to_file;
-pub use self::source_loc::set_source_location;
 
 #[allow(non_upper_case_globals)]
 const DW_TAG_auto_variable: c_uint = 0x100;
@@ -148,7 +146,6 @@ impl DebugInfoBuilderMethods for Builder<'a, 'll, 'tcx> {
     // names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
     fn dbg_var_addr(
         &mut self,
-        dbg_context: &FunctionDebugContext<&'ll DIScope>,
         dbg_var: &'ll DIVariable,
         scope_metadata: &'ll DIScope,
         variable_alloca: Self::Value,
@@ -156,12 +153,11 @@ fn dbg_var_addr(
         indirect_offsets: &[Size],
         span: Span,
     ) {
-        assert!(!dbg_context.source_locations_enabled);
         let cx = self.cx();
 
-        let loc = span_start(cx, span);
-
         // Convert the direct and indirect offsets to address ops.
+        // FIXME(eddyb) use `const`s instead of getting the values via FFI,
+        // the values should match the ones in the DWARF standard anyway.
         let op_deref = || unsafe { llvm::LLVMRustDIBuilderCreateOpDeref() };
         let op_plus_uconst = || unsafe { llvm::LLVMRustDIBuilderCreateOpPlusUconst() };
         let mut addr_ops = SmallVec::<[_; 8]>::new();
@@ -178,37 +174,32 @@ fn dbg_var_addr(
             }
         }
 
-        // FIXME(eddyb) maybe this information could be extracted from `var`,
+        // FIXME(eddyb) maybe this information could be extracted from `dbg_var`,
         // to avoid having to pass it down in both places?
-        source_loc::set_debug_location(
-            self,
-            InternalDebugLocation::new(scope_metadata, loc.line, loc.col.to_usize()),
-        );
+        // NB: `var` doesn't seem to know about the column, so that's a limitation.
+        let dbg_loc = cx.create_debug_loc(scope_metadata, span);
         unsafe {
-            let debug_loc = llvm::LLVMGetCurrentDebugLocation(self.llbuilder);
             // FIXME(eddyb) replace `llvm.dbg.declare` with `llvm.dbg.addr`.
-            let instr = llvm::LLVMRustDIBuilderInsertDeclareAtEnd(
+            llvm::LLVMRustDIBuilderInsertDeclareAtEnd(
                 DIB(cx),
                 variable_alloca,
                 dbg_var,
                 addr_ops.as_ptr(),
                 addr_ops.len() as c_uint,
-                debug_loc,
+                dbg_loc,
                 self.llbb(),
             );
-
-            llvm::LLVMSetInstDebugLocation(self.llbuilder, instr);
         }
-        source_loc::set_debug_location(self, UnknownLocation);
     }
 
-    fn set_source_location(
-        &mut self,
-        debug_context: &mut FunctionDebugContext<&'ll DIScope>,
-        scope: &'ll DIScope,
-        span: Span,
-    ) {
-        set_source_location(debug_context, &self, scope, span)
+    fn set_source_location(&mut self, scope: &'ll DIScope, span: Span) {
+        debug!("set_source_location: {}", self.sess().source_map().span_to_string(span));
+
+        let dbg_loc = self.cx().create_debug_loc(scope, span);
+
+        unsafe {
+            llvm::LLVMSetCurrentDebugLocation(self.llbuilder, dbg_loc);
+        }
     }
     fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) {
         gdb::insert_reference_to_gdb_debug_scripts_section_global(self)
@@ -342,7 +333,6 @@ fn create_function_debug_context(
         };
         let mut fn_debug_context = FunctionDebugContext {
             scopes: IndexVec::from_elem(null_scope, &mir.source_scopes),
-            source_locations_enabled: false,
             defining_crate: def_id.krate,
         };
 
@@ -569,7 +559,7 @@ fn create_dbg_var(
                 file_metadata,
                 loc.line as c_uint,
                 type_metadata,
-                self.sess().opts.optimize != config::OptLevel::No,
+                true,
                 DIFlags::FlagZero,
                 argument_index,
                 align.bytes() as u32,