diff options
Diffstat (limited to 'src/librustc_codegen_llvm/debuginfo/mod.rs')
| -rw-r--r-- | src/librustc_codegen_llvm/debuginfo/mod.rs | 93 |
1 files changed, 45 insertions, 48 deletions
diff --git a/src/librustc_codegen_llvm/debuginfo/mod.rs b/src/librustc_codegen_llvm/debuginfo/mod.rs index 22effb102fd..8c9a2c09c27 100644 --- a/src/librustc_codegen_llvm/debuginfo/mod.rs +++ b/src/librustc_codegen_llvm/debuginfo/mod.rs @@ -3,43 +3,39 @@ mod doc; use rustc_codegen_ssa::mir::debuginfo::VariableKind::*; -use self::metadata::{file_metadata, type_metadata, TypeMap}; +use self::metadata::{file_metadata, type_metadata, TypeMap, 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, span_start, DIB}; +use self::utils::{create_DIArray, is_node_local_to_unit, DIB}; +use crate::abi::FnAbi; +use crate::builder::Builder; +use crate::common::CodegenCx; use crate::llvm; use crate::llvm::debuginfo::{ DIArray, DIBuilder, DIFile, DIFlags, DILexicalBlock, DISPFlags, DIScope, DIType, DIVariable, }; -use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags; -use rustc::ty::subst::{GenericArgKind, SubstsRef}; -use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE}; - -use crate::abi::FnAbi; -use crate::builder::Builder; -use crate::common::CodegenCx; use crate::value::Value; -use rustc::mir; -use rustc::session::config::{self, DebugInfo}; -use rustc::ty::{self, Instance, InstanceDef, ParamEnv, Ty}; + 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::small_c_str::SmallCStr; +use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE}; use rustc_index::vec::IndexVec; +use rustc_middle::mir; +use rustc_middle::ty::layout::HasTyCtxt; +use rustc_middle::ty::subst::{GenericArgKind, SubstsRef}; +use rustc_middle::ty::{self, Instance, ParamEnv, Ty}; +use rustc_session::config::{self, DebugInfo}; +use rustc_span::symbol::Symbol; +use rustc_span::{self, BytePos, Span}; +use rustc_target::abi::{LayoutOf, Primitive, Size}; use libc::c_uint; use log::debug; -use std::cell::RefCell; -use std::ffi::CString; - -use rustc::ty::layout::{self, HasTyCtxt, LayoutOf, Size}; -use rustc_codegen_ssa::traits::*; -use rustc_span::symbol::Symbol; -use rustc_span::{self, BytePos, Span}; use smallvec::SmallVec; -use syntax::ast; +use std::cell::RefCell; mod create_scope_map; pub mod gdb; @@ -63,7 +59,7 @@ pub struct CrateDebugContext<'a, 'tcx> { llmod: &'a llvm::Module, builder: &'a mut DIBuilder<'a>, created_files: RefCell<FxHashMap<(Option<String>, Option<String>), &'a DIFile>>, - created_enum_disr_types: RefCell<FxHashMap<(DefId, layout::Primitive), &'a DIType>>, + created_enum_disr_types: RefCell<FxHashMap<(DefId, Primitive), &'a DIType>>, type_map: RefCell<TypeMap<'a, 'tcx>>, namespace_map: RefCell<DefIdMap<&'a DIScope>>, @@ -241,12 +237,6 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { return None; } - if let InstanceDef::Item(def_id) = instance.def { - if self.tcx().codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::NO_DEBUG) { - return None; - } - } - let span = mir.span; // This can be the case for functions inlined from another crate @@ -257,8 +247,8 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { let def_id = instance.def_id(); let containing_scope = get_containing_scope(self, instance); - let loc = span_start(self, span); - let file_metadata = file_metadata(self, &loc.file.name, def_id.krate); + let loc = self.lookup_debug_loc(span.lo()); + let file_metadata = file_metadata(self, &loc.file, def_id.krate); let function_type_metadata = unsafe { let fn_signature = get_function_signature(self, fn_abi); @@ -280,13 +270,11 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { // Get the linkage_name, which is just the symbol name let linkage_name = mangled_name_of_instance(self, instance); + let linkage_name = linkage_name.name.as_str(); // FIXME(eddyb) does this need to be separate from `loc.line` for some reason? let scope_line = loc.line; - let function_name = CString::new(name).unwrap(); - let linkage_name = SmallCStr::new(&linkage_name.name.as_str()); - let mut flags = DIFlags::FlagPrototyped; if fn_abi.ret.layout.abi.is_uninhabited() { @@ -301,7 +289,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { spflags |= DISPFlags::SPFlagOptimized; } if let Some((id, _)) = self.tcx.entry_fn(LOCAL_CRATE) { - if id == def_id { + if id.to_def_id() == def_id { spflags |= DISPFlags::SPFlagMainSubprogram; } } @@ -310,12 +298,14 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { llvm::LLVMRustDIBuilderCreateFunction( DIB(self), containing_scope, - function_name.as_ptr(), - linkage_name.as_ptr(), + name.as_ptr().cast(), + name.len(), + linkage_name.as_ptr().cast(), + linkage_name.len(), file_metadata, - loc.line as c_uint, + loc.line.unwrap_or(UNKNOWN_LINE_NUMBER), function_type_metadata, - scope_line as c_uint, + scope_line.unwrap_or(UNKNOWN_LINE_NUMBER), flags, spflags, llfn, @@ -431,12 +421,13 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), ty); let actual_type_metadata = type_metadata(cx, actual_type, rustc_span::DUMMY_SP); - let name = SmallCStr::new(&name.as_str()); + let name = name.as_str(); Some(unsafe { Some(llvm::LLVMRustDIBuilderCreateTemplateTypeParameter( DIB(cx), None, - name.as_ptr(), + name.as_ptr().cast(), + name.len(), actual_type_metadata, file_metadata, 0, @@ -452,7 +443,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { vec![] }; - return create_DIArray(DIB(cx), &template_params[..]); + create_DIArray(DIB(cx), &template_params[..]) } fn get_parameter_names(cx: &CodegenCx<'_, '_>, generics: &ty::Generics) -> Vec<Symbol> { @@ -483,7 +474,12 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { // so avoid methods on other types (e.g., `<*mut T>::null`). match impl_self_ty.kind { ty::Adt(def, ..) if !def.is_box() => { - Some(type_metadata(cx, impl_self_ty, rustc_span::DUMMY_SP)) + // Again, only create type information if full debuginfo is enabled + if cx.sess().opts.debuginfo == DebugInfo::Full { + Some(type_metadata(cx, impl_self_ty, rustc_span::DUMMY_SP)) + } else { + Some(namespace::item_namespace(cx, def.did)) + } } _ => None, } @@ -532,14 +528,14 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { fn create_dbg_var( &self, dbg_context: &FunctionDebugContext<&'ll DIScope>, - variable_name: ast::Name, + variable_name: Symbol, variable_type: Ty<'tcx>, scope_metadata: &'ll DIScope, variable_kind: VariableKind, span: Span, ) -> &'ll DIVariable { - let loc = span_start(self, span); - let file_metadata = file_metadata(self, &loc.file.name, dbg_context.defining_crate); + let loc = self.lookup_debug_loc(span.lo()); + let file_metadata = file_metadata(self, &loc.file, dbg_context.defining_crate); let type_metadata = type_metadata(self, variable_type, span); @@ -549,15 +545,16 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { }; let align = self.align_of(variable_type); - let name = SmallCStr::new(&variable_name.as_str()); + let name = variable_name.as_str(); unsafe { llvm::LLVMRustDIBuilderCreateVariable( DIB(self), dwarf_tag, scope_metadata, - name.as_ptr(), + name.as_ptr().cast(), + name.len(), file_metadata, - loc.line as c_uint, + loc.line.unwrap_or(UNKNOWN_LINE_NUMBER), type_metadata, true, DIFlags::FlagZero, |
