about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
diff options
context:
space:
mode:
authorEduard-Mihai Burtescu <edy.burt@gmail.com>2020-02-10 22:52:30 +0200
committerEduard-Mihai Burtescu <edy.burt@gmail.com>2020-10-21 04:43:57 +0300
commit737499593db6d7702de3bf9d0070ec3f8e65d71e (patch)
tree30b14ba847c56ec3a71b80f248fc42b0e2dbf014 /compiler/rustc_codegen_llvm/src
parent88d874de6395a5422caad1f61783dadd395d49d0 (diff)
downloadrust-737499593db6d7702de3bf9d0070ec3f8e65d71e.tar.gz
rust-737499593db6d7702de3bf9d0070ec3f8e65d71e.zip
rustc_codegen_llvm: expose DILocation to rustc_codegen_ssa.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
-rw-r--r--compiler/rustc_codegen_llvm/src/builder.rs1
-rw-r--r--compiler/rustc_codegen_llvm/src/common.rs1
-rw-r--r--compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs10
-rw-r--r--compiler/rustc_codegen_llvm/src/debuginfo/mod.rs94
-rw-r--r--compiler/rustc_codegen_llvm/src/debuginfo/source_loc.rs61
5 files changed, 77 insertions, 90 deletions
diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs
index 491191d058c..978ad37c0f3 100644
--- a/compiler/rustc_codegen_llvm/src/builder.rs
+++ b/compiler/rustc_codegen_llvm/src/builder.rs
@@ -56,6 +56,7 @@ impl BackendTypes for Builder<'_, 'll, 'tcx> {
     type Funclet = <CodegenCx<'ll, 'tcx> as BackendTypes>::Funclet;
 
     type DIScope = <CodegenCx<'ll, 'tcx> as BackendTypes>::DIScope;
+    type DILocation = <CodegenCx<'ll, 'tcx> as BackendTypes>::DILocation;
     type DIVariable = <CodegenCx<'ll, 'tcx> as BackendTypes>::DIVariable;
 }
 
diff --git a/compiler/rustc_codegen_llvm/src/common.rs b/compiler/rustc_codegen_llvm/src/common.rs
index 2cd745ec420..7633dd0600d 100644
--- a/compiler/rustc_codegen_llvm/src/common.rs
+++ b/compiler/rustc_codegen_llvm/src/common.rs
@@ -88,6 +88,7 @@ impl BackendTypes for CodegenCx<'ll, 'tcx> {
     type Funclet = Funclet<'ll>;
 
     type DIScope = &'ll llvm::debuginfo::DIScope;
+    type DILocation = &'ll llvm::debuginfo::DILocation;
     type DIVariable = &'ll llvm::debuginfo::DIVariable;
 }
 
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs
index 11855675ccf..f6b7f257f2f 100644
--- a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs
+++ b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs
@@ -49,7 +49,7 @@ fn make_mir_scope(
     debug_context: &mut FunctionDebugContext<&'ll DIScope>,
     scope: SourceScope,
 ) {
-    if debug_context.scopes[scope].is_valid() {
+    if debug_context.scopes[scope].dbg_scope.is_some() {
         return;
     }
 
@@ -61,7 +61,7 @@ fn make_mir_scope(
         // The root is the function itself.
         let loc = cx.lookup_debug_loc(mir.span.lo());
         debug_context.scopes[scope] = DebugScope {
-            scope_metadata: Some(fn_dbg_scope),
+            dbg_scope: Some(fn_dbg_scope),
             file_start_pos: loc.file.start_pos,
             file_end_pos: loc.file.end_pos,
         };
@@ -78,17 +78,17 @@ fn make_mir_scope(
     let loc = cx.lookup_debug_loc(scope_data.span.lo());
     let file_metadata = file_metadata(cx, &loc.file);
 
-    let scope_metadata = unsafe {
+    let dbg_scope = unsafe {
         Some(llvm::LLVMRustDIBuilderCreateLexicalBlock(
             DIB(cx),
-            parent_scope.scope_metadata.unwrap(),
+            parent_scope.dbg_scope.unwrap(),
             file_metadata,
             loc.line.unwrap_or(UNKNOWN_LINE_NUMBER),
             loc.col.unwrap_or(UNKNOWN_COLUMN_NUMBER),
         ))
     };
     debug_context.scopes[scope] = DebugScope {
-        scope_metadata,
+        dbg_scope,
         file_start_pos: loc.file.start_pos,
         file_end_pos: loc.file.end_pos,
     };
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
index c940656b256..7b416f1f6ad 100644
--- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
+++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
@@ -3,7 +3,8 @@ mod doc;
 
 use rustc_codegen_ssa::mir::debuginfo::VariableKind::*;
 
-use self::metadata::{file_metadata, type_metadata, TypeMap, UNKNOWN_LINE_NUMBER};
+use self::metadata::{file_metadata, type_metadata, TypeMap};
+use self::metadata::{UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER};
 use self::namespace::mangled_name_of_instance;
 use self::type_names::compute_debuginfo_type_name;
 use self::utils::{create_DIArray, is_node_local_to_unit, DIB};
@@ -13,7 +14,8 @@ use crate::builder::Builder;
 use crate::common::CodegenCx;
 use crate::llvm;
 use crate::llvm::debuginfo::{
-    DIArray, DIBuilder, DIFile, DIFlags, DILexicalBlock, DISPFlags, DIScope, DIType, DIVariable,
+    DIArray, DIBuilder, DIFile, DIFlags, DILexicalBlock, DILocation, DISPFlags, DIScope, DIType,
+    DIVariable,
 };
 use crate::value::Value;
 
@@ -21,6 +23,7 @@ use rustc_codegen_ssa::debuginfo::type_names;
 use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext, VariableKind};
 use rustc_codegen_ssa::traits::*;
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
+use rustc_data_structures::sync::Lrc;
 use rustc_hir::def_id::{DefId, DefIdMap, LOCAL_CRATE};
 use rustc_index::vec::IndexVec;
 use rustc_middle::mir;
@@ -29,7 +32,7 @@ use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
 use rustc_middle::ty::{self, Instance, ParamEnv, Ty, TypeFoldable};
 use rustc_session::config::{self, DebugInfo};
 use rustc_span::symbol::Symbol;
-use rustc_span::{self, BytePos, Span};
+use rustc_span::{self, BytePos, Pos, SourceFile, SourceFileAndLine, Span};
 use rustc_target::abi::{LayoutOf, Primitive, Size};
 
 use libc::c_uint;
@@ -41,7 +44,6 @@ mod create_scope_map;
 pub mod gdb;
 pub mod metadata;
 mod namespace;
-mod source_loc;
 mod utils;
 
 pub use self::create_scope_map::compute_mir_scopes;
@@ -141,14 +143,11 @@ impl DebugInfoBuilderMethods for Builder<'a, 'll, 'tcx> {
     fn dbg_var_addr(
         &mut self,
         dbg_var: &'ll DIVariable,
-        scope_metadata: &'ll DIScope,
+        dbg_loc: &'ll DILocation,
         variable_alloca: Self::Value,
         direct_offset: Size,
         indirect_offsets: &[Size],
-        span: Span,
     ) {
-        let cx = self.cx();
-
         // 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.
@@ -168,14 +167,10 @@ impl DebugInfoBuilderMethods for Builder<'a, 'll, 'tcx> {
             }
         }
 
-        // FIXME(eddyb) maybe this information could be extracted from `dbg_var`,
-        // to avoid having to pass it down in both places?
-        // 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 {
             // FIXME(eddyb) replace `llvm.dbg.declare` with `llvm.dbg.addr`.
             llvm::LLVMRustDIBuilderInsertDeclareAtEnd(
-                DIB(cx),
+                DIB(self.cx()),
                 variable_alloca,
                 dbg_var,
                 addr_ops.as_ptr(),
@@ -186,16 +181,13 @@ impl DebugInfoBuilderMethods for Builder<'a, 'll, 'tcx> {
         }
     }
 
-    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);
-
+    fn set_dbg_loc(&mut self, dbg_loc: &'ll DILocation) {
         unsafe {
             let dbg_loc_as_llval = llvm::LLVMRustMetadataAsValue(self.cx().llcx, dbg_loc);
             llvm::LLVMSetCurrentDebugLocation(self.llbuilder, dbg_loc_as_llval);
         }
     }
+
     fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) {
         gdb::insert_reference_to_gdb_debug_scripts_section_global(self)
     }
@@ -224,6 +216,49 @@ impl DebugInfoBuilderMethods for Builder<'a, 'll, 'tcx> {
     }
 }
 
+/// A source code location used to generate debug information.
+// FIXME(eddyb) rename this to better indicate it's a duplicate of
+// `rustc_span::Loc` rather than `DILocation`, perhaps by making
+// `lookup_char_pos` return the right information instead.
+pub struct DebugLoc {
+    /// Information about the original source file.
+    pub file: Lrc<SourceFile>,
+    /// The (1-based) line number.
+    pub line: Option<u32>,
+    /// The (1-based) column number.
+    pub col: Option<u32>,
+}
+
+impl CodegenCx<'ll, '_> {
+    /// Looks up debug source information about a `BytePos`.
+    // FIXME(eddyb) rename this to better indicate it's a duplicate of
+    // `lookup_char_pos` rather than `dbg_loc`, perhaps by making
+    // `lookup_char_pos` return the right information instead.
+    pub fn lookup_debug_loc(&self, pos: BytePos) -> DebugLoc {
+        let (file, line, col) = match self.sess().source_map().lookup_line(pos) {
+            Ok(SourceFileAndLine { sf: file, line }) => {
+                let line_pos = file.line_begin_pos(pos);
+
+                // Use 1-based indexing.
+                let line = (line + 1) as u32;
+                let col = (pos - line_pos).to_u32() + 1;
+
+                (file, Some(line), Some(col))
+            }
+            Err(file) => (file, None, None),
+        };
+
+        // For MSVC, omit the column number.
+        // Otherwise, emit it. This mimics clang behaviour.
+        // See discussion in https://github.com/rust-lang/rust/issues/42921
+        if self.sess().target.options.is_like_msvc {
+            DebugLoc { file, line, col: None }
+        } else {
+            DebugLoc { file, line, col }
+        }
+    }
+}
+
 impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
     fn create_function_debug_context(
         &self,
@@ -237,12 +272,9 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
         }
 
         // Initialize fn debug context (including scopes).
-        // FIXME(eddyb) figure out a way to not need `Option` for `scope_metadata`.
-        let empty_scope = DebugScope {
-            scope_metadata: None,
-            file_start_pos: BytePos(0),
-            file_end_pos: BytePos(0),
-        };
+        // FIXME(eddyb) figure out a way to not need `Option` for `dbg_scope`.
+        let empty_scope =
+            DebugScope { dbg_scope: None, file_start_pos: BytePos(0), file_end_pos: BytePos(0) };
         let mut fn_debug_context =
             FunctionDebugContext { scopes: IndexVec::from_elem(empty_scope, &mir.source_scopes) };
 
@@ -505,6 +537,20 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
         }
     }
 
+    fn dbg_loc(&self, scope: &'ll DIScope, span: Span) -> &'ll DILocation {
+        let DebugLoc { line, col, .. } = self.lookup_debug_loc(span.lo());
+
+        unsafe {
+            llvm::LLVMRustDIBuilderCreateDebugLocation(
+                utils::debug_context(self).llcontext,
+                line.unwrap_or(UNKNOWN_LINE_NUMBER),
+                col.unwrap_or(UNKNOWN_COLUMN_NUMBER),
+                scope,
+                None,
+            )
+        }
+    }
+
     fn create_vtable_metadata(&self, ty: Ty<'tcx>, vtable: Self::Value) {
         metadata::create_vtable_metadata(self, ty, vtable)
     }
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/source_loc.rs b/compiler/rustc_codegen_llvm/src/debuginfo/source_loc.rs
deleted file mode 100644
index f1d9b8653bc..00000000000
--- a/compiler/rustc_codegen_llvm/src/debuginfo/source_loc.rs
+++ /dev/null
@@ -1,61 +0,0 @@
-use super::metadata::{UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER};
-use super::utils::debug_context;
-
-use crate::common::CodegenCx;
-use crate::llvm;
-use crate::llvm::debuginfo::{DILocation, DIScope};
-use rustc_codegen_ssa::traits::*;
-
-use rustc_data_structures::sync::Lrc;
-use rustc_span::{BytePos, Pos, SourceFile, SourceFileAndLine, Span};
-
-/// A source code location used to generate debug information.
-pub struct DebugLoc {
-    /// Information about the original source file.
-    pub file: Lrc<SourceFile>,
-    /// The (1-based) line number.
-    pub line: Option<u32>,
-    /// The (1-based) column number.
-    pub col: Option<u32>,
-}
-
-impl CodegenCx<'ll, '_> {
-    /// Looks up debug source information about a `BytePos`.
-    pub fn lookup_debug_loc(&self, pos: BytePos) -> DebugLoc {
-        let (file, line, col) = match self.sess().source_map().lookup_line(pos) {
-            Ok(SourceFileAndLine { sf: file, line }) => {
-                let line_pos = file.line_begin_pos(pos);
-
-                // Use 1-based indexing.
-                let line = (line + 1) as u32;
-                let col = (pos - line_pos).to_u32() + 1;
-
-                (file, Some(line), Some(col))
-            }
-            Err(file) => (file, None, None),
-        };
-
-        // For MSVC, omit the column number.
-        // Otherwise, emit it. This mimics clang behaviour.
-        // See discussion in https://github.com/rust-lang/rust/issues/42921
-        if self.sess().target.options.is_like_msvc {
-            DebugLoc { file, line, col: None }
-        } else {
-            DebugLoc { file, line, col }
-        }
-    }
-
-    pub fn create_debug_loc(&self, scope: &'ll DIScope, span: Span) -> &'ll DILocation {
-        let DebugLoc { line, col, .. } = self.lookup_debug_loc(span.lo());
-
-        unsafe {
-            llvm::LLVMRustDIBuilderCreateDebugLocation(
-                debug_context(self).llcontext,
-                line.unwrap_or(UNKNOWN_LINE_NUMBER),
-                col.unwrap_or(UNKNOWN_COLUMN_NUMBER),
-                scope,
-                None,
-            )
-        }
-    }
-}