diff options
| author | bjorn3 <bjorn3@users.noreply.github.com> | 2020-06-13 17:03:34 +0200 |
|---|---|---|
| committer | bjorn3 <bjorn3@users.noreply.github.com> | 2020-06-13 17:03:34 +0200 |
| commit | eb5ce4e92ae8d512804279fda1101032c7ec9f28 (patch) | |
| tree | 325f7e33aaf929334f3d76affa49222aa498943f /src/debuginfo | |
| parent | 16b5dac4635dd919b8b56bdf1533a10e8423adb6 (diff) | |
| download | rust-eb5ce4e92ae8d512804279fda1101032c7ec9f28.tar.gz rust-eb5ce4e92ae8d512804279fda1101032c7ec9f28.zip | |
Remove FunctionDebugContext
Diffstat (limited to 'src/debuginfo')
| -rw-r--r-- | src/debuginfo/line_info.rs | 27 | ||||
| -rw-r--r-- | src/debuginfo/mod.rs | 118 |
2 files changed, 62 insertions, 83 deletions
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 @@ impl<'tcx> DebugContext<'tcx> { 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<SourceInfo>, ) -> 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 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> { }; line_program.begin_sequence(Some(Address::Symbol { - symbol: self.symbol, + symbol, addend: 0, })); @@ -202,7 +202,7 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> { 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 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> { 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 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> { 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 @@ impl<'tcx> DebugContext<'tcx> { 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<SourceInfo>, + local_map: FxHashMap<mir::Local, CPlace<'tcx>>, + ) { + 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 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> { 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<SourceInfo>, - local_map: FxHashMap<mir::Local, CPlace<'tcx>>, - ) { - 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 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> { 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 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> { }; 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 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> { 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 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> { }, ); - 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 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> { } } -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<mir::Local, CPlace<'tcx>>, #[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 { |
