rustc_codegen_llvm: create DIFiles from just SourceFiles.

This commit is contained in:
Eduard-Mihai Burtescu 2020-02-10 03:03:24 +02:00
parent 2bfb462b58
commit 9d57c417fc
6 changed files with 21 additions and 54 deletions

View file

@ -76,7 +76,7 @@ fn make_mir_scope(
} }
let loc = cx.lookup_debug_loc(scope_data.span.lo()); let loc = cx.lookup_debug_loc(scope_data.span.lo());
let file_metadata = file_metadata(cx, &loc.file, debug_context.defining_crate); let file_metadata = file_metadata(cx, &loc.file);
let scope_metadata = unsafe { let scope_metadata = unsafe {
Some(llvm::LLVMRustDIBuilderCreateLexicalBlock( Some(llvm::LLVMRustDIBuilderCreateLexicalBlock(

View file

@ -28,7 +28,7 @@
//! utilizing a cache. The way to get a shared metadata node when needed is //! utilizing a cache. The way to get a shared metadata node when needed is
//! thus to just call the corresponding function in this module: //! thus to just call the corresponding function in this module:
//! //!
//! let file_metadata = file_metadata(crate_context, path); //! let file_metadata = file_metadata(cx, file);
//! //!
//! The function will take care of probing the cache for an existing node for //! The function will take care of probing the cache for an existing node for
//! that exact file path. //! that exact file path.

View file

@ -26,7 +26,7 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_fs_util::path_to_c_string; use rustc_fs_util::path_to_c_string;
use rustc_hir::def::CtorKind; use rustc_hir::def::CtorKind;
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::vec::{Idx, IndexVec};
use rustc_middle::ich::NodeIdHashingMode; use rustc_middle::ich::NodeIdHashingMode;
use rustc_middle::mir::interpret::truncate; use rustc_middle::mir::interpret::truncate;
@ -760,16 +760,12 @@ fn hex_encode(data: &[u8]) -> String {
hex_string hex_string
} }
pub fn file_metadata( pub fn file_metadata(cx: &CodegenCx<'ll, '_>, source_file: &SourceFile) -> &'ll DIFile {
cx: &CodegenCx<'ll, '_>, debug!("file_metadata: file_name: {}", source_file.name);
source_file: &SourceFile,
defining_crate: CrateNum,
) -> &'ll DIFile {
debug!("file_metadata: file_name: {}, defining_crate: {}", source_file.name, defining_crate);
let hash = Some(&source_file.src_hash); let hash = Some(&source_file.src_hash);
let file_name = Some(source_file.name.to_string()); let file_name = Some(source_file.name.to_string());
let directory = if defining_crate == LOCAL_CRATE { let directory = if source_file.is_real_file() && !source_file.is_imported() {
Some(cx.sess().working_dir.0.to_string_lossy().to_string()) Some(cx.sess().working_dir.0.to_string_lossy().to_string())
} else { } else {
// If the path comes from an upstream crate we assume it has been made // If the path comes from an upstream crate we assume it has been made
@ -1835,7 +1831,7 @@ impl<'tcx> VariantInfo<'_, 'tcx> {
if !span.is_dummy() { if !span.is_dummy() {
let loc = cx.lookup_debug_loc(span.lo()); let loc = cx.lookup_debug_loc(span.lo());
return Some(SourceInfo { return Some(SourceInfo {
file: file_metadata(cx, &loc.file, def_id.krate), file: file_metadata(cx, &loc.file),
line: loc.line.unwrap_or(UNKNOWN_LINE_NUMBER), line: loc.line.unwrap_or(UNKNOWN_LINE_NUMBER),
}); });
} }
@ -2474,7 +2470,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global
let (file_metadata, line_number) = if !span.is_dummy() { let (file_metadata, line_number) = if !span.is_dummy() {
let loc = cx.lookup_debug_loc(span.lo()); let loc = cx.lookup_debug_loc(span.lo());
(file_metadata(cx, &loc.file, LOCAL_CRATE), loc.line) (file_metadata(cx, &loc.file), loc.line)
} else { } else {
(unknown_file_metadata(cx), None) (unknown_file_metadata(cx), None)
}; };
@ -2576,9 +2572,8 @@ pub fn create_vtable_metadata(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>, vtable: &
pub fn extend_scope_to_file( pub fn extend_scope_to_file(
cx: &CodegenCx<'ll, '_>, cx: &CodegenCx<'ll, '_>,
scope_metadata: &'ll DIScope, scope_metadata: &'ll DIScope,
file: &rustc_span::SourceFile, file: &SourceFile,
defining_crate: CrateNum,
) -> &'ll DILexicalBlock { ) -> &'ll DILexicalBlock {
let file_metadata = file_metadata(cx, &file, defining_crate); let file_metadata = file_metadata(cx, file);
unsafe { llvm::LLVMRustDIBuilderCreateLexicalBlockFile(DIB(cx), scope_metadata, file_metadata) } unsafe { llvm::LLVMRustDIBuilderCreateLexicalBlockFile(DIB(cx), scope_metadata, file_metadata) }
} }

View file

@ -21,7 +21,7 @@ use rustc_codegen_ssa::debuginfo::type_names;
use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext, VariableKind}; use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext, VariableKind};
use rustc_codegen_ssa::traits::*; use rustc_codegen_ssa::traits::*;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE}; use rustc_hir::def_id::{DefId, DefIdMap, LOCAL_CRATE};
use rustc_index::vec::IndexVec; use rustc_index::vec::IndexVec;
use rustc_middle::mir; use rustc_middle::mir;
use rustc_middle::ty::layout::HasTyCtxt; use rustc_middle::ty::layout::HasTyCtxt;
@ -246,7 +246,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
let def_id = instance.def_id(); let def_id = instance.def_id();
let containing_scope = get_containing_scope(self, instance); let containing_scope = get_containing_scope(self, instance);
let loc = self.lookup_debug_loc(span.lo()); let loc = self.lookup_debug_loc(span.lo());
let file_metadata = file_metadata(self, &loc.file, def_id.krate); let file_metadata = file_metadata(self, &loc.file);
let function_type_metadata = unsafe { let function_type_metadata = unsafe {
let fn_signature = get_function_signature(self, fn_abi); let fn_signature = get_function_signature(self, fn_abi);
@ -318,10 +318,8 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
file_start_pos: BytePos(0), file_start_pos: BytePos(0),
file_end_pos: BytePos(0), file_end_pos: BytePos(0),
}; };
let mut fn_debug_context = FunctionDebugContext { let mut fn_debug_context =
scopes: IndexVec::from_elem(null_scope, &mir.source_scopes), FunctionDebugContext { scopes: IndexVec::from_elem(null_scope, &mir.source_scopes) };
defining_crate: def_id.krate,
};
// Fill in all the scopes, with the information from the MIR body. // Fill in all the scopes, with the information from the MIR body.
compute_mir_scopes(self, mir, fn_metadata, &mut fn_debug_context); compute_mir_scopes(self, mir, fn_metadata, &mut fn_debug_context);
@ -509,9 +507,8 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
&self, &self,
scope_metadata: &'ll DIScope, scope_metadata: &'ll DIScope,
file: &rustc_span::SourceFile, file: &rustc_span::SourceFile,
defining_crate: CrateNum,
) -> &'ll DILexicalBlock { ) -> &'ll DILexicalBlock {
metadata::extend_scope_to_file(&self, scope_metadata, file, defining_crate) metadata::extend_scope_to_file(&self, scope_metadata, file)
} }
fn debuginfo_finalize(&self) { fn debuginfo_finalize(&self) {
@ -522,7 +519,6 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
// names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.). // names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
fn create_dbg_var( fn create_dbg_var(
&self, &self,
dbg_context: &FunctionDebugContext<&'ll DIScope>,
variable_name: Symbol, variable_name: Symbol,
variable_type: Ty<'tcx>, variable_type: Ty<'tcx>,
scope_metadata: &'ll DIScope, scope_metadata: &'ll DIScope,
@ -530,7 +526,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
span: Span, span: Span,
) -> &'ll DIVariable { ) -> &'ll DIVariable {
let loc = self.lookup_debug_loc(span.lo()); let loc = self.lookup_debug_loc(span.lo());
let file_metadata = file_metadata(self, &loc.file, dbg_context.defining_crate); let file_metadata = file_metadata(self, &loc.file);
let type_metadata = type_metadata(self, variable_type, span); let type_metadata = type_metadata(self, variable_type, span);

View file

@ -1,5 +1,4 @@
use crate::traits::*; use crate::traits::*;
use rustc_hir::def_id::CrateNum;
use rustc_index::vec::IndexVec; use rustc_index::vec::IndexVec;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir; use rustc_middle::mir;
@ -15,7 +14,6 @@ use super::{FunctionCx, LocalRef};
pub struct FunctionDebugContext<D> { pub struct FunctionDebugContext<D> {
pub scopes: IndexVec<mir::SourceScope, DebugScope<D>>, pub scopes: IndexVec<mir::SourceScope, DebugScope<D>>,
pub defining_crate: CrateNum,
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
@ -95,19 +93,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
pos: BytePos, pos: BytePos,
) -> Option<Bx::DIScope> { ) -> Option<Bx::DIScope> {
let debug_context = self.debug_context.as_ref()?; let debug_context = self.debug_context.as_ref()?;
let scope_metadata = debug_context.scopes[scope_id].scope_metadata; let scope_metadata = debug_context.scopes[scope_id].scope_metadata?;
if pos < debug_context.scopes[scope_id].file_start_pos if pos < debug_context.scopes[scope_id].file_start_pos
|| pos >= debug_context.scopes[scope_id].file_end_pos || pos >= debug_context.scopes[scope_id].file_end_pos
{ {
let sm = self.cx.sess().source_map(); let sm = self.cx.sess().source_map();
let defining_crate = debug_context.defining_crate; Some(self.cx.extend_scope_to_file(scope_metadata, &sm.lookup_char_pos(pos).file))
Some(self.cx.extend_scope_to_file(
scope_metadata.unwrap(),
&sm.lookup_char_pos(pos).file,
defining_crate,
))
} else { } else {
scope_metadata Some(scope_metadata)
} }
} }
@ -158,14 +151,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// FIXME(eddyb) is this `+ 1` needed at all? // FIXME(eddyb) is this `+ 1` needed at all?
let kind = VariableKind::ArgumentVariable(arg_index + 1); let kind = VariableKind::ArgumentVariable(arg_index + 1);
self.cx.create_dbg_var( self.cx.create_dbg_var(name, self.monomorphize(&decl.ty), scope, kind, span)
self.debug_context.as_ref().unwrap(),
name,
self.monomorphize(&decl.ty),
scope,
kind,
span,
)
}); });
Some(PerLocalVarDebugInfo { Some(PerLocalVarDebugInfo {
@ -340,14 +326,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
} else { } else {
VariableKind::LocalVariable VariableKind::LocalVariable
}; };
self.cx.create_dbg_var( self.cx.create_dbg_var(var.name, var_ty, scope, var_kind, span)
self.debug_context.as_ref().unwrap(),
var.name,
var_ty,
scope,
var_kind,
span,
)
}); });
per_local[var.place.local].push(PerLocalVarDebugInfo { per_local[var.place.local].push(PerLocalVarDebugInfo {

View file

@ -1,6 +1,5 @@
use super::BackendTypes; use super::BackendTypes;
use crate::mir::debuginfo::{FunctionDebugContext, VariableKind}; use crate::mir::debuginfo::{FunctionDebugContext, VariableKind};
use rustc_hir::def_id::CrateNum;
use rustc_middle::mir; use rustc_middle::mir;
use rustc_middle::ty::{Instance, Ty}; use rustc_middle::ty::{Instance, Ty};
use rustc_span::{SourceFile, Span, Symbol}; use rustc_span::{SourceFile, Span, Symbol};
@ -26,7 +25,6 @@ pub trait DebugInfoMethods<'tcx>: BackendTypes {
&self, &self,
scope_metadata: Self::DIScope, scope_metadata: Self::DIScope,
file: &SourceFile, file: &SourceFile,
defining_crate: CrateNum,
) -> Self::DIScope; ) -> Self::DIScope;
fn debuginfo_finalize(&self); fn debuginfo_finalize(&self);
@ -34,7 +32,6 @@ pub trait DebugInfoMethods<'tcx>: BackendTypes {
// names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.). // names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
fn create_dbg_var( fn create_dbg_var(
&self, &self,
dbg_context: &FunctionDebugContext<Self::DIScope>,
variable_name: Symbol, variable_name: Symbol,
variable_type: Ty<'tcx>, variable_type: Ty<'tcx>,
scope_metadata: Self::DIScope, scope_metadata: Self::DIScope,