提交 82016458 编写于 作者: M Mark-Simulacrum 提交者: Mark Simulacrum

Remove DebugLoc.

上级 be981dce
......@@ -49,7 +49,6 @@
use rustc::ty::layout;
use rustc::ty::{self, Ty, AdtKind};
use common::*;
use debuginfo::DebugLoc;
use glue;
use base;
use machine;
......@@ -595,8 +594,6 @@ fn struct_field_ptr<'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>,
return bcx.struct_gep(ptr_val, ix);
}
let dbloc = DebugLoc::None;
// We need to get the pointer manually now.
// We do this by casting to a *i8, then offsetting it by the appropriate amount.
// We do this instead of, say, simply adjusting the pointer from the result of a GEP
......@@ -627,7 +624,6 @@ fn struct_field_ptr<'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>,
// (unaligned offset + (align - 1)) & -align
// Calculate offset
dbloc.apply(bcx.fcx());
let align_sub_1 = bcx.sub(align, C_uint(bcx.ccx(), 1u64));
let offset = bcx.and(bcx.add(unaligned_offset, align_sub_1),
bcx.neg(align));
......
......@@ -60,7 +60,7 @@
use common;
use consts;
use context::{SharedCrateContext, CrateContextList};
use debuginfo::{self, DebugLoc};
use debuginfo;
use declare;
use machine;
use machine::{llalign_of_min, llsize_of};
......@@ -649,7 +649,6 @@ pub fn alloc_ty<'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>,
}
pub fn alloca(cx: &BlockAndBuilder, ty: Type, name: &str) -> ValueRef {
DebugLoc::None.apply(cx.fcx());
cx.fcx().alloca(ty, name)
}
......@@ -658,8 +657,6 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
/// and builds the return block.
pub fn finish(&'blk self, ret_cx: &BlockAndBuilder<'blk, 'tcx>) {
self.build_return_block(ret_cx);
DebugLoc::None.apply(self);
self.cleanup();
}
......
......@@ -16,6 +16,7 @@
use llvm;
use llvm::{ValueRef, BasicBlockRef, BuilderRef, ContextRef, TypeKind};
use llvm::{True, False, Bool, OperandBundleDef, get_param};
use llvm::debuginfo::DIScope;
use monomorphize::Instance;
use rustc::hir::def::Def;
use rustc::hir::def_id::DefId;
......@@ -578,6 +579,10 @@ pub fn new(llbb: BasicBlockRef, fcx: &'blk FunctionContext<'blk, 'tcx>) -> Self
}
}
pub fn set_source_location(&self, scope: DIScope, sp: Span) {
debuginfo::set_source_location(self.fcx(), self, scope, sp)
}
pub fn at_start<F, R>(&self, f: F) -> R
where F: FnOnce(&BlockAndBuilder<'blk, 'tcx>) -> R
{
......
......@@ -27,7 +27,7 @@
use rustc::ty::subst::Substs;
use abi::Abi;
use common::{CrateContext, FunctionContext, BlockAndBuilder};
use common::{CrateContext, BlockAndBuilder};
use monomorphize::{self, Instance};
use rustc::ty::{self, Ty};
use rustc::mir;
......@@ -55,6 +55,7 @@
pub use self::source_loc::start_emitting_source_locations;
pub use self::metadata::create_global_var_metadata;
pub use self::metadata::extend_scope_to_file;
pub use self::source_loc::set_source_location;
#[allow(non_upper_case_globals)]
const DW_TAG_auto_variable: c_uint = 0x100;
......@@ -507,19 +508,3 @@ pub fn declare_local<'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>,
_ => { /* nothing to do */ }
}
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum DebugLoc {
ScopeAt(DIScope, Span),
None
}
impl DebugLoc {
pub fn apply(self, fcx: &FunctionContext) {
source_loc::set_source_location(fcx, None, self);
}
pub fn apply_to_bcx(self, bcx: &BlockAndBuilder) {
source_loc::set_source_location(bcx.fcx(), Some(bcx), self);
}
}
......@@ -11,8 +11,8 @@
use self::InternalDebugLocation::*;
use super::utils::{debug_context, span_start};
use super::metadata::{UNKNOWN_COLUMN_NUMBER};
use super::{FunctionDebugContext, DebugLoc};
use super::metadata::UNKNOWN_COLUMN_NUMBER;
use super::FunctionDebugContext;
use llvm;
use llvm::debuginfo::DIScope;
......@@ -21,41 +21,30 @@
use libc::c_uint;
use std::ptr;
use syntax_pos::Pos;
use syntax_pos::{Span, Pos};
/// Sets the current debug location at the beginning of the span.
///
/// Maps to a call to llvm::LLVMSetCurrentDebugLocation(...).
pub fn set_source_location(fcx: &FunctionContext,
builder: Option<&Builder>,
debug_loc: DebugLoc) {
let builder = builder.map(|b| b.llbuilder);
pub fn set_source_location(fcx: &FunctionContext, builder: &Builder, scope: DIScope, span: Span) {
let builder = builder.llbuilder;
let function_debug_context = match fcx.debug_context {
FunctionDebugContext::DebugInfoDisabled => return,
FunctionDebugContext::FunctionWithoutDebugInfo => {
set_debug_location(fcx.ccx, builder, UnknownLocation);
set_debug_location(fcx.ccx, Some(builder), UnknownLocation);
return;
}
FunctionDebugContext::RegularContext(ref data) => data
};
let dbg_loc = if function_debug_context.source_locations_enabled.get() {
let (scope, span) = match debug_loc {
DebugLoc::ScopeAt(scope, span) => (scope, span),
DebugLoc::None => {
set_debug_location(fcx.ccx, builder, UnknownLocation);
return;
}
};
debug!("set_source_location: {}",
fcx.ccx.sess().codemap().span_to_string(span));
debug!("set_source_location: {}", fcx.ccx.sess().codemap().span_to_string(span));
let loc = span_start(fcx.ccx, span);
InternalDebugLocation::new(scope, loc.line, loc.col.to_usize())
} else {
UnknownLocation
};
set_debug_location(fcx.ccx, builder, dbg_loc);
set_debug_location(fcx.ccx, Some(builder), dbg_loc);
}
/// Enables emitting source locations for the given functions.
......
......@@ -18,7 +18,6 @@
use adt;
use base::*;
use common::*;
use debuginfo::DebugLoc;
use declare;
use glue;
use type_of;
......@@ -31,7 +30,7 @@
use syntax::symbol::Symbol;
use rustc::session::Session;
use syntax_pos::{Span, DUMMY_SP};
use syntax_pos::Span;
use std::cmp::Ordering;
use std::iter;
......@@ -90,7 +89,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>,
fn_ty: &FnType,
llargs: &[ValueRef],
llresult: ValueRef,
call_debug_location: DebugLoc) {
span: Span) {
let fcx = bcx.fcx();
let ccx = fcx.ccx;
let tcx = bcx.tcx();
......@@ -105,14 +104,6 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>,
let ret_ty = sig.output();
let name = &*tcx.item_name(def_id).as_str();
let span = match call_debug_location {
DebugLoc::ScopeAt(_, span) => span,
DebugLoc::None => {
span_bug!(fcx.span.unwrap_or(DUMMY_SP),
"intrinsic `{}` called with missing span", name);
}
};
// These are the only intrinsic functions that diverge.
if name == "abort" {
let llfn = ccx.get_intrinsic(&("llvm.trap"));
......
......@@ -20,7 +20,6 @@
use common::{self, BlockAndBuilder, Funclet};
use common::{C_bool, C_str_slice, C_struct, C_u32, C_undef};
use consts;
use debuginfo::DebugLoc;
use Disr;
use machine::{llalign_of_min, llbitsize_of_real};
use meth;
......@@ -115,9 +114,8 @@ pub fn trans_block(&mut self, bb: mir::BasicBlock,
debug!("trans_block: terminator: {:?}", terminator);
let span = terminator.source_info.span;
let debug_loc = self.debug_loc(terminator.source_info);
debug_loc.apply_to_bcx(&bcx);
debug_loc.apply(bcx.fcx());
let (scope, debug_span) = self.debug_loc(terminator.source_info);
bcx.set_source_location(scope, debug_span);
match terminator.kind {
mir::TerminatorKind::Resume => {
if let Some(cleanup_pad) = cleanup_pad {
......@@ -329,7 +327,7 @@ pub fn trans_block(&mut self, bb: mir::BasicBlock,
// After this point, bcx is the block for the call to panic.
bcx = panic_block;
debug_loc.apply_to_bcx(&bcx);
bcx.set_source_location(scope, debug_span);
// Get the location information.
let loc = bcx.sess().codemap().lookup_char_pos(span.lo);
......@@ -605,7 +603,7 @@ pub fn trans_block(&mut self, bb: mir::BasicBlock,
bug!("Cannot use direct operand with an intrinsic call")
};
trans_intrinsic_call(&bcx, callee.ty, &fn_ty, &llargs, dest, debug_loc);
trans_intrinsic_call(&bcx, callee.ty, &fn_ty, &llargs, dest, debug_span);
if let ReturnDest::IndirectOperand(dst, _) = ret_dest {
// Make a fake operand for store_return
......@@ -645,7 +643,7 @@ pub fn trans_block(&mut self, bb: mir::BasicBlock,
if let Some((_, target)) = *destination {
let ret_bcx = self.build_block(target);
ret_bcx.at_start(|ret_bcx| {
debug_loc.apply_to_bcx(ret_bcx);
bcx.set_source_location(scope, debug_span);
let op = OperandRef {
val: Immediate(invokeret),
ty: sig.output(),
......@@ -885,7 +883,6 @@ pub fn init_cpad(&mut self, bb: mir::BasicBlock,
}
CleanupKind::Funclet => {
bcx.set_personality_fn(self.fcx.eh_personality());
DebugLoc::None.apply_to_bcx(&bcx);
let cleanup_pad = bcx.cleanup_pad(None, &[]);
funclets[bb] = Funclet::msvc(cleanup_pad);
}
......
......@@ -10,16 +10,18 @@
use libc::c_uint;
use llvm::{self, ValueRef, BasicBlockRef};
use llvm::debuginfo::DIScope;
use rustc::ty;
use rustc::mir;
use rustc::mir::tcx::LvalueTy;
use session::config::FullDebugInfo;
use base;
use common::{self, BlockAndBuilder, CrateContext, FunctionContext, C_null, Funclet};
use debuginfo::{self, declare_local, DebugLoc, VariableAccess, VariableKind, FunctionDebugContext};
use debuginfo::{self, declare_local, VariableAccess, VariableKind, FunctionDebugContext};
use machine;
use type_of;
use syntax_pos::{DUMMY_SP, NO_EXPANSION, COMMAND_LINE_EXPN, BytePos};
use syntax_pos::{DUMMY_SP, NO_EXPANSION, COMMAND_LINE_EXPN, BytePos, Span};
use syntax::symbol::keywords;
use std::cell::Ref;
......@@ -88,15 +90,12 @@ pub struct MirContext<'bcx, 'tcx:'bcx> {
}
impl<'blk, 'tcx> MirContext<'blk, 'tcx> {
pub fn debug_loc(&mut self, source_info: mir::SourceInfo) -> DebugLoc {
pub fn debug_loc(&mut self, source_info: mir::SourceInfo) -> (DIScope, Span) {
// Bail out if debug info emission is not enabled.
match self.fcx.debug_context {
FunctionDebugContext::DebugInfoDisabled |
FunctionDebugContext::FunctionWithoutDebugInfo => {
// Can't return DebugLoc::None here because intrinsic::trans_intrinsic_call()
// relies on debug location to obtain span of the call site.
return DebugLoc::ScopeAt(self.scopes[source_info.scope].scope_metadata,
source_info.span);
return (self.scopes[source_info.scope].scope_metadata, source_info.span);
}
FunctionDebugContext::RegularContext(_) =>{}
}
......@@ -109,8 +108,8 @@ pub fn debug_loc(&mut self, source_info: mir::SourceInfo) -> DebugLoc {
self.fcx.ccx.sess().opts.debugging_opts.debug_macros {
let scope_metadata = self.scope_metadata_for_loc(source_info.scope,
source_info.span.lo);
DebugLoc::ScopeAt(scope_metadata, source_info.span)
source_info.span.lo);
(scope_metadata, source_info.span)
} else {
let cm = self.fcx.ccx.sess().codemap();
// Walk up the macro expansion chain until we reach a non-expanded span.
......@@ -125,7 +124,7 @@ pub fn debug_loc(&mut self, source_info: mir::SourceInfo) -> DebugLoc {
}
let scope_metadata = self.scope_metadata_for_loc(source_info.scope, span.lo);
// Use span of the outermost call site, while keeping the original lexical scope
DebugLoc::ScopeAt(scope_metadata, span)
(scope_metadata, span)
}
}
......@@ -236,14 +235,10 @@ pub fn trans_mir<'blk, 'tcx: 'blk>(fcx: &'blk FunctionContext<'blk, 'tcx>) {
debug!("alloc: {:?} ({}) -> lvalue", local, name);
let lvalue = LvalueRef::alloca(&bcx, ty, &name.as_str());
if dbg {
let dbg_loc = mircx.debug_loc(source_info);
if let DebugLoc::ScopeAt(scope, span) = dbg_loc {
declare_local(&bcx, name, ty, scope,
VariableAccess::DirectVariable { alloca: lvalue.llval },
VariableKind::LocalVariable, span);
} else {
panic!("Unexpected");
}
let (scope, span) = mircx.debug_loc(source_info);
declare_local(&bcx, name, ty, scope,
VariableAccess::DirectVariable { alloca: lvalue.llval },
VariableKind::LocalVariable, span);
}
LocalRef::Lvalue(lvalue)
} else {
......@@ -312,7 +307,6 @@ pub fn trans_mir<'blk, 'tcx: 'blk>(fcx: &'blk FunctionContext<'blk, 'tcx>) {
}
}
DebugLoc::None.apply(fcx);
fcx.cleanup();
}
......
......@@ -25,9 +25,8 @@ pub fn trans_statement(&mut self,
-> BlockAndBuilder<'bcx, 'tcx> {
debug!("trans_statement(statement={:?})", statement);
let debug_loc = self.debug_loc(statement.source_info);
debug_loc.apply_to_bcx(&bcx);
debug_loc.apply(bcx.fcx());
let (scope, span) = self.debug_loc(statement.source_info);
bcx.set_source_location(scope, span);
match statement.kind {
mir::StatementKind::Assign(ref lvalue, ref rvalue) => {
if let mir::Lvalue::Local(index) = *lvalue {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册