]> git.lizzy.rs Git - rust.git/commitdiff
Remove FunctionDebugContext
authorbjorn3 <bjorn3@users.noreply.github.com>
Sat, 13 Jun 2020 15:03:34 +0000 (17:03 +0200)
committerbjorn3 <bjorn3@users.noreply.github.com>
Sat, 13 Jun 2020 15:03:34 +0000 (17:03 +0200)
src/base.rs
src/debuginfo/line_info.rs
src/debuginfo/mod.rs
src/lib.rs

index acdfba4323af3fe9e4162b9982cf9848a4e0f5d9..244e06f76278e901666c0d6b3bcafe7762f92b1f 100644 (file)
@@ -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);
     });
 
index 31431404cc3f7eb3fccf1bcd9a4f3b7b452d14a0..1a84f6584d48d0cd311ea6988281b83ed5f13530 100644 (file)
@@ -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<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 @@ 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
     }
index e48694cb8b95b0177c9af3069dcdcaf1594c6acf..bfcb7cfd2146d1615cf9448fd163871af1b17d2e 100644 (file)
@@ -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<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 @@ 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<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 @@ 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<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 {
index afaeb6d1e25a3f2df0ee3d4c29a2ac7ad313958f..517ccd41706ce38af844308e952347b888c1638a 100644 (file)
@@ -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};