Skip to content

Commit

Permalink
rustc_codegen_llvm: remove InternalDebugLocation and simplify dbg_var…
Browse files Browse the repository at this point in the history
…_addr.
  • Loading branch information
eddyb committed Feb 8, 2020
1 parent d6ccbf6 commit 1385fc4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 73 deletions.
25 changes: 8 additions & 17 deletions src/librustc_codegen_llvm/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -148,20 +147,18 @@ 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,
direct_offset: Size,
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();
Expand All @@ -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(
Expand Down
74 changes: 27 additions & 47 deletions src/librustc_codegen_llvm/debuginfo/source_loc.rs
Original file line number Diff line number Diff line change
@@ -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::*;

Expand All @@ -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);
}
}
2 changes: 0 additions & 2 deletions src/librustc_codegen_llvm/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions src/librustc_codegen_ssa/mir/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/librustc_codegen_ssa/traits/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1385fc4

Please sign in to comment.