rustc_codegen_llvm: remove InternalDebugLocation and simplify dbg_var_addr.

This commit is contained in:
Eduard-Mihai Burtescu 2020-02-08 18:07:44 +02:00
parent d6ccbf6ff8
commit 1385fc4c40
5 changed files with 38 additions and 76 deletions

View File

@ -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(

View File

@ -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
};
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 }
}
}
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
}
None
};
unsafe {
llvm::LLVMSetCurrentDebugLocation(bx.llbuilder, metadata_node);
llvm::LLVMSetCurrentDebugLocation(bx.llbuilder, dbg_loc);
}
}
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,
)
}
}
}

View File

@ -910,8 +910,6 @@ extern "C" {
// Metadata
pub fn LLVMSetCurrentDebugLocation(Builder: &Builder<'a>, L: Option<&'a Value>);
pub fn LLVMGetCurrentDebugLocation(Builder: &Builder<'a>) -> &'a Value;
pub fn LLVMSetInstDebugLocation(Builder: &Builder<'a>, Inst: &'a Value);
// Terminators
pub fn LLVMBuildRetVoid(B: &Builder<'a>) -> &'a Value;

View File

@ -210,11 +210,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
return;
}
let debug_context = match &self.debug_context {
Some(debug_context) => debug_context,
None => return,
};
// FIXME(eddyb) add debuginfo for unsized places too.
let base = match local_ref {
LocalRef::Place(place) => place,
@ -264,7 +259,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
if let Some(scope) = scope {
if let Some(dbg_var) = var.dbg_var {
bx.dbg_var_addr(
debug_context,
dbg_var,
scope,
base.llval,

View File

@ -49,7 +49,6 @@ pub trait DebugInfoBuilderMethods: BackendTypes {
// names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
fn dbg_var_addr(
&mut self,
dbg_context: &FunctionDebugContext<Self::DIScope>,
dbg_var: Self::DIVariable,
scope_metadata: Self::DIScope,
variable_alloca: Self::Value,