From: bjorn3 Date: Sat, 13 Jun 2020 15:03:34 +0000 (+0200) Subject: Remove FunctionDebugContext X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=eb5ce4e92ae8d512804279fda1101032c7ec9f28;p=rust.git Remove FunctionDebugContext --- diff --git a/src/base.rs b/src/base.rs index acdfba4323a..244e06f7627 100644 --- a/src/base.rs +++ b/src/base.rs @@ -15,10 +15,6 @@ pub(crate) fn trans_fn<'tcx, B: Backend + 'static>( // Declare function let (name, sig) = get_function_name_and_sig(tcx, cx.module.isa().triple(), instance, false); let func_id = cx.module.declare_function(&name, linkage, &sig).unwrap(); - let mut debug_context = cx - .debug_context - .as_mut() - .map(|debug_context| FunctionDebugContext::new(debug_context, instance, func_id, &name)); // Make FunctionBuilder let context = &mut cx.cached_context; @@ -122,11 +118,12 @@ pub(crate) fn trans_fn<'tcx, B: Backend + 'static>( // Define debuginfo for function let isa = cx.module.isa(); + let debug_context = &mut cx.debug_context; let unwind_context = &mut cx.unwind_context; tcx.sess.time("generate debug info", || { - debug_context - .as_mut() - .map(|x| x.define(context, isa, &source_info_set, local_map)); + if let Some(debug_context) = debug_context { + debug_context.define_function(instance, func_id, &name, isa, context, &source_info_set, local_map); + } unwind_context.add_function(func_id, &context, isa); }); diff --git a/src/debuginfo/line_info.rs b/src/debuginfo/line_info.rs index 31431404cc3..1a84f6584d4 100644 --- a/src/debuginfo/line_info.rs +++ b/src/debuginfo/line_info.rs @@ -119,21 +119,21 @@ pub(super) fn emit_location(&mut self, entry_id: UnitEntryId, span: Span) { AttributeValue::Udata(loc.col.to_usize() as u64), ); } -} -impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> { pub(super) fn create_debug_lines( &mut self, - context: &Context, isa: &dyn cranelift_codegen::isa::TargetIsa, + symbol: usize, + entry_id: UnitEntryId, + context: &Context, + function_span: Span, source_info_set: &indexmap::IndexSet, ) -> CodeOffset { - let tcx = self.debug_context.tcx; - let line_program = &mut self.debug_context.dwarf.unit.line_program; + let tcx = self.tcx; + let line_program = &mut self.dwarf.unit.line_program; let func = &context.func; - let line_strings = &mut self.debug_context.dwarf.line_strings; - let function_span = self.mir.span; + let line_strings = &mut self.dwarf.line_strings; let mut last_span = None; let mut last_file = None; let mut create_row_for_span = |line_program: &mut LineProgram, span: Span| { @@ -189,7 +189,7 @@ pub(super) fn create_debug_lines( }; line_program.begin_sequence(Some(Address::Symbol { - symbol: self.symbol, + symbol, addend: 0, })); @@ -202,7 +202,7 @@ pub(super) fn create_debug_lines( let source_info = *source_info_set.get_index(loc.bits() as usize).unwrap(); create_row_for_span(line_program, source_info.span); } else { - create_row_for_span(line_program, self.mir.span); + create_row_for_span(line_program, function_span); } func_end = end; } @@ -223,7 +223,7 @@ pub(super) fn create_debug_lines( let source_info = *source_info_set.get_index(srcloc.bits() as usize).unwrap(); create_row_for_span(line_program, source_info.span); } else { - create_row_for_span(line_program, self.mir.span); + create_row_for_span(line_program, function_span); } func_end = offset + size; } @@ -233,18 +233,17 @@ pub(super) fn create_debug_lines( assert_ne!(func_end, 0); - let entry = self.debug_context.dwarf.unit.get_mut(self.entry_id); + let entry = self.dwarf.unit.get_mut(entry_id); entry.set( gimli::DW_AT_low_pc, AttributeValue::Address(Address::Symbol { - symbol: self.symbol, + symbol, addend: 0, }), ); entry.set(gimli::DW_AT_high_pc, AttributeValue::Udata(func_end as u64)); - self.debug_context - .emit_location(self.entry_id, self.mir.span); + self.emit_location(entry_id, function_span); func_end } diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs index e48694cb8b9..bfcb7cfd214 100644 --- a/src/debuginfo/mod.rs +++ b/src/debuginfo/mod.rs @@ -233,34 +233,44 @@ fn dwarf_ty(&mut self, ty: Ty<'tcx>) -> UnitEntryId { type_id } -} -pub(crate) struct FunctionDebugContext<'a, 'tcx> { - debug_context: &'a mut DebugContext<'tcx>, - entry_id: UnitEntryId, - symbol: usize, - instance: Instance<'tcx>, - mir: &'tcx mir::Body<'tcx>, -} + fn define_local(&mut self, scope: UnitEntryId, name: String, ty: Ty<'tcx>) -> UnitEntryId { + let dw_ty = self.dwarf_ty(ty); + + let var_id = self + .dwarf + .unit + .add(scope, gimli::DW_TAG_variable); + let var_entry = self.dwarf.unit.get_mut(var_id); + + var_entry.set(gimli::DW_AT_name, AttributeValue::String(name.into_bytes())); + var_entry.set(gimli::DW_AT_type, AttributeValue::UnitRef(dw_ty)); -impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> { - pub(crate) fn new( - debug_context: &'a mut DebugContext<'tcx>, + var_id + } + + pub(crate) fn define_function( + &mut self, instance: Instance<'tcx>, func_id: FuncId, name: &str, - ) -> Self { - let mir = debug_context.tcx.instance_mir(instance.def); + isa: &dyn TargetIsa, + context: &Context, + source_info_set: &indexmap::IndexSet, + local_map: FxHashMap>, + ) { + let symbol = func_id.as_u32() as usize; + let mir = self.tcx.instance_mir(instance.def); - // FIXME: add to appropriate scope intead of root - let scope = debug_context.dwarf.unit.root(); + // FIXME: add to appropriate scope instead of root + let scope = self.dwarf.unit.root(); - let entry_id = debug_context + let entry_id = self .dwarf .unit .add(scope, gimli::DW_TAG_subprogram); - let entry = debug_context.dwarf.unit.get_mut(entry_id); - let name_id = debug_context.dwarf.strings.add(name); + let entry = self.dwarf.unit.get_mut(entry_id); + let name_id = self.dwarf.strings.add(name); // Gdb requires DW_AT_name. Otherwise the DW_TAG_subprogram is skipped. entry.set( gimli::DW_AT_name, @@ -271,46 +281,14 @@ pub(crate) fn new( AttributeValue::StringRef(name_id), ); - FunctionDebugContext { - debug_context, - entry_id, - symbol: func_id.as_u32() as usize, - instance, - mir, - } - } - - fn define_local(&mut self, name: String, ty: Ty<'tcx>) -> UnitEntryId { - let dw_ty = self.debug_context.dwarf_ty(ty); - - let var_id = self - .debug_context - .dwarf - .unit - .add(self.entry_id, gimli::DW_TAG_variable); - let var_entry = self.debug_context.dwarf.unit.get_mut(var_id); - - var_entry.set(gimli::DW_AT_name, AttributeValue::String(name.into_bytes())); - var_entry.set(gimli::DW_AT_type, AttributeValue::UnitRef(dw_ty)); - - var_id - } - - pub(crate) fn define( - &mut self, - context: &Context, - isa: &dyn TargetIsa, - source_info_set: &indexmap::IndexSet, - local_map: FxHashMap>, - ) { - let end = self.create_debug_lines(context, isa, source_info_set); + let end = self.create_debug_lines(isa, symbol, entry_id, context, mir.span, source_info_set); - self.debug_context + self .unit_range_list .0 .push(Range::StartLength { begin: Address::Symbol { - symbol: self.symbol, + symbol, addend: 0, }, length: u64::from(end), @@ -320,10 +298,10 @@ pub(crate) fn define( return; // Not yet implemented for the AArch64 backend. } - let func_entry = self.debug_context.dwarf.unit.get_mut(self.entry_id); + let func_entry = self.dwarf.unit.get_mut(entry_id); // Gdb requires both DW_AT_low_pc and DW_AT_high_pc. Otherwise the DW_TAG_subprogram is skipped. func_entry.set(gimli::DW_AT_low_pc, AttributeValue::Address(Address::Symbol { - symbol: self.symbol, + symbol, addend: 0, })); // Using Udata for DW_AT_high_pc requires at least DWARF4 @@ -340,11 +318,11 @@ pub(crate) fn define( }; let name = format!("{}{}", base_name, i); - let dw_ty = self.debug_context.dwarf_ty_for_clif_ty(param.value_type); + let dw_ty = self.dwarf_ty_for_clif_ty(param.value_type); let loc = translate_loc(isa, context.func.locations[val], &context.func.stack_slots).unwrap(); - let arg_id = self.debug_context.dwarf.unit.add(self.entry_id, gimli::DW_TAG_formal_parameter); - let var_entry = self.debug_context.dwarf.unit.get_mut(arg_id); + let arg_id = self.dwarf.unit.add(entry_id, gimli::DW_TAG_formal_parameter); + let var_entry = self.dwarf.unit.get_mut(arg_id); var_entry.set(gimli::DW_AT_name, AttributeValue::String(name.into_bytes())); var_entry.set(gimli::DW_AT_type, AttributeValue::UnitRef(dw_ty)); @@ -355,17 +333,18 @@ pub(crate) fn define( if false { let value_labels_ranges = context.build_value_labels_ranges(isa).unwrap(); - for (local, _local_decl) in self.mir.local_decls.iter_enumerated() { - let ty = self.debug_context.tcx.subst_and_normalize_erasing_regions( - self.instance.substs, + for (local, _local_decl) in mir.local_decls.iter_enumerated() { + let ty = self.tcx.subst_and_normalize_erasing_regions( + instance.substs, ty::ParamEnv::reveal_all(), - &self.mir.local_decls[local].ty, + &mir.local_decls[local].ty, ); - let var_id = self.define_local(format!("{:?}", local), ty); + let var_id = self.define_local(entry_id, format!("{:?}", local), ty); let location = place_location( self, isa, + symbol, context, &local_map, &value_labels_ranges, @@ -375,7 +354,7 @@ pub(crate) fn define( }, ); - let var_entry = self.debug_context.dwarf.unit.get_mut(var_id); + let var_entry = self.dwarf.unit.get_mut(var_id); var_entry.set(gimli::DW_AT_location, location); } } @@ -384,9 +363,10 @@ pub(crate) fn define( } } -fn place_location<'a, 'tcx>( - func_debug_ctx: &mut FunctionDebugContext<'a, 'tcx>, +fn place_location<'tcx>( + debug_context: &mut DebugContext<'tcx>, isa: &dyn TargetIsa, + symbol: usize, context: &Context, local_map: &FxHashMap>, #[allow(rustc::default_hash_types)] @@ -404,18 +384,18 @@ fn place_location<'a, 'tcx>( .iter() .map(|value_loc_range| Location::StartEnd { begin: Address::Symbol { - symbol: func_debug_ctx.symbol, + symbol, addend: i64::from(value_loc_range.start), }, end: Address::Symbol { - symbol: func_debug_ctx.symbol, + symbol, addend: i64::from(value_loc_range.end), }, data: translate_loc(isa, value_loc_range.loc, &context.func.stack_slots).unwrap(), }) .collect(), ); - let loc_list_id = func_debug_ctx.debug_context.dwarf.unit.locations.add(loc_list); + let loc_list_id = debug_context.dwarf.unit.locations.add(loc_list); AttributeValue::LocationListRef(loc_list_id) } else { diff --git a/src/lib.rs b/src/lib.rs index afaeb6d1e25..517ccd41706 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -106,7 +106,7 @@ mod prelude { pub(crate) use crate::base::{trans_operand, trans_place}; pub(crate) use crate::cast::*; pub(crate) use crate::common::*; - pub(crate) use crate::debuginfo::{DebugContext, FunctionDebugContext, UnwindContext}; + pub(crate) use crate::debuginfo::{DebugContext, UnwindContext}; pub(crate) use crate::pointer::Pointer; pub(crate) use crate::trap::*; pub(crate) use crate::value_and_place::{CPlace, CPlaceInner, CValue};