diff options
| author | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2020-02-08 18:07:44 +0200 |
|---|---|---|
| committer | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2020-02-08 18:07:44 +0200 |
| commit | 1385fc4c40cb96eca5f3df2c3043425889073646 (patch) | |
| tree | ff523f8c9dc519ca603a61555f1ff25a98b10367 /src/librustc_codegen_llvm/debuginfo | |
| parent | d6ccbf6ff80ce66884ab70fdb679353245f05e5b (diff) | |
| download | rust-1385fc4c40cb96eca5f3df2c3043425889073646.tar.gz rust-1385fc4c40cb96eca5f3df2c3043425889073646.zip | |
rustc_codegen_llvm: remove InternalDebugLocation and simplify dbg_var_addr.
Diffstat (limited to 'src/librustc_codegen_llvm/debuginfo')
| -rw-r--r-- | src/librustc_codegen_llvm/debuginfo/mod.rs | 25 | ||||
| -rw-r--r-- | src/librustc_codegen_llvm/debuginfo/source_loc.rs | 74 |
2 files changed, 35 insertions, 64 deletions
diff --git a/src/librustc_codegen_llvm/debuginfo/mod.rs b/src/librustc_codegen_llvm/debuginfo/mod.rs index c4a52a73e25..46f186191e3 100644 --- a/src/librustc_codegen_llvm/debuginfo/mod.rs +++ b/src/librustc_codegen_llvm/debuginfo/mod.rs @@ -5,7 +5,6 @@ use rustc_codegen_ssa::mir::debuginfo::VariableKind::*; 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}; @@ -38,7 +37,7 @@ 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, Pos, Span}; +use rustc_span::{self, BytePos, Span}; use smallvec::SmallVec; use syntax::ast; @@ -148,7 +147,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 +154,11 @@ impl DebugInfoBuilderMethods for Builder<'a, 'll, 'tcx> { 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,28 +175,22 @@ impl DebugInfoBuilderMethods for Builder<'a, 'll, 'tcx> { } } - // 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( diff --git a/src/librustc_codegen_llvm/debuginfo/source_loc.rs b/src/librustc_codegen_llvm/debuginfo/source_loc.rs index 6afaca44e0e..78dc1ac250e 100644 --- a/src/librustc_codegen_llvm/debuginfo/source_loc.rs +++ b/src/librustc_codegen_llvm/debuginfo/source_loc.rs @@ -1,12 +1,11 @@ -use self::InternalDebugLocation::*; - use super::metadata::UNKNOWN_COLUMN_NUMBER; use super::utils::{debug_context, span_start}; use rustc_codegen_ssa::mir::debuginfo::FunctionDebugContext; use crate::builder::Builder; -use crate::llvm; +use crate::common::CodegenCx; use crate::llvm::debuginfo::DIScope; +use crate::llvm::{self, Value}; use log::debug; use rustc_codegen_ssa::traits::*; @@ -24,56 +23,37 @@ pub fn set_source_location<D>( ) { let dbg_loc = if debug_context.source_locations_enabled { debug!("set_source_location: {}", bx.sess().source_map().span_to_string(span)); - let loc = span_start(bx.cx(), span); - InternalDebugLocation::new(scope, loc.line, loc.col.to_usize()) + Some(bx.cx().create_debug_loc(scope, span)) } else { - UnknownLocation + None }; - set_debug_location(bx, dbg_loc); -} -#[derive(Copy, Clone, PartialEq)] -pub enum InternalDebugLocation<'ll> { - KnownLocation { scope: &'ll DIScope, line: usize, col: usize }, - UnknownLocation, -} - -impl InternalDebugLocation<'ll> { - pub fn new(scope: &'ll DIScope, line: usize, col: usize) -> Self { - KnownLocation { scope, line, col } + unsafe { + llvm::LLVMSetCurrentDebugLocation(bx.llbuilder, dbg_loc); } } -pub fn set_debug_location(bx: &Builder<'_, 'll, '_>, debug_location: InternalDebugLocation<'ll>) { - let metadata_node = match debug_location { - KnownLocation { scope, line, col } => { - // For MSVC, set the column number to zero. - // Otherwise, emit it. This mimics clang behaviour. - // See discussion in https://github.com/rust-lang/rust/issues/42921 - let col_used = if bx.sess().target.target.options.is_like_msvc { - UNKNOWN_COLUMN_NUMBER - } else { - col as c_uint - }; - debug!("setting debug location to {} {}", line, col); - - unsafe { - Some(llvm::LLVMRustDIBuilderCreateDebugLocation( - debug_context(bx.cx()).llcontext, - line as c_uint, - col_used, - scope, - None, - )) - } - } - UnknownLocation => { - debug!("clearing debug location "); - None +impl CodegenCx<'ll, '_> { + pub fn create_debug_loc(&self, scope: &'ll DIScope, span: Span) -> &'ll Value { + let loc = span_start(self, span); + + // For MSVC, set the column number to zero. + // Otherwise, emit it. This mimics clang behaviour. + // See discussion in https://github.com/rust-lang/rust/issues/42921 + let col_used = if self.sess().target.target.options.is_like_msvc { + UNKNOWN_COLUMN_NUMBER + } else { + loc.col.to_usize() as c_uint + }; + + unsafe { + llvm::LLVMRustDIBuilderCreateDebugLocation( + debug_context(self).llcontext, + loc.line as c_uint, + col_used, + scope, + None, + ) } - }; - - unsafe { - llvm::LLVMSetCurrentDebugLocation(bx.llbuilder, metadata_node); } } |
