@@ -10,7 +10,9 @@ use crate::prelude::*;
1010use cranelift_codegen:: ir:: Endianness ;
1111use cranelift_codegen:: isa:: TargetIsa ;
1212
13- use gimli:: write:: { Address , AttributeValue , DwarfUnit , LineProgram , LineString , Range , RangeList } ;
13+ use gimli:: write:: {
14+ Address , AttributeValue , DwarfUnit , LineProgram , LineString , Range , RangeList , UnitEntryId ,
15+ } ;
1416use gimli:: { Encoding , Format , LineEncoding , RunTimeEndian } ;
1517
1618pub ( crate ) use emit:: { DebugReloc , DebugRelocName } ;
@@ -23,6 +25,10 @@ pub(crate) struct DebugContext {
2325 unit_range_list : RangeList ,
2426}
2527
28+ pub ( crate ) struct FunctionDebugContext {
29+ entry_id : UnitEntryId ,
30+ }
31+
2632impl DebugContext {
2733 pub ( crate ) fn new ( tcx : TyCtxt < ' _ > , isa : & dyn TargetIsa ) -> Self {
2834 let encoding = Encoding {
@@ -93,17 +99,7 @@ impl DebugContext {
9399 DebugContext { endian, dwarf, unit_range_list : RangeList ( Vec :: new ( ) ) }
94100 }
95101
96- pub ( crate ) fn define_function (
97- & mut self ,
98- tcx : TyCtxt < ' _ > ,
99- func_id : FuncId ,
100- name : & str ,
101- context : & Context ,
102- function_span : Span ,
103- source_info_set : & indexmap:: IndexSet < SourceInfo > ,
104- ) {
105- let symbol = func_id. as_u32 ( ) as usize ;
106-
102+ pub ( crate ) fn define_function ( & mut self , name : & str ) -> FunctionDebugContext {
107103 // FIXME: add to appropriate scope instead of root
108104 let scope = self . dwarf . unit . root ( ) ;
109105
@@ -114,15 +110,37 @@ impl DebugContext {
114110 entry. set ( gimli:: DW_AT_name , AttributeValue :: StringRef ( name_id) ) ;
115111 entry. set ( gimli:: DW_AT_linkage_name , AttributeValue :: StringRef ( name_id) ) ;
116112
117- let end =
118- self . create_debug_lines ( tcx, symbol, entry_id, context, function_span, source_info_set) ;
113+ FunctionDebugContext { entry_id }
114+ }
115+ }
116+
117+ impl FunctionDebugContext {
118+ pub ( crate ) fn finalize (
119+ self ,
120+ debug_context : & mut DebugContext ,
121+ tcx : TyCtxt < ' _ > ,
122+ func_id : FuncId ,
123+ context : & Context ,
124+ function_span : Span ,
125+ source_info_set : & indexmap:: IndexSet < SourceInfo > ,
126+ ) {
127+ let symbol = func_id. as_u32 ( ) as usize ;
128+
129+ let end = debug_context. create_debug_lines (
130+ tcx,
131+ symbol,
132+ self . entry_id ,
133+ context,
134+ function_span,
135+ source_info_set,
136+ ) ;
119137
120- self . unit_range_list . 0 . push ( Range :: StartLength {
138+ debug_context . unit_range_list . 0 . push ( Range :: StartLength {
121139 begin : Address :: Symbol { symbol, addend : 0 } ,
122140 length : u64:: from ( end) ,
123141 } ) ;
124142
125- let func_entry = self . dwarf . unit . get_mut ( entry_id) ;
143+ let func_entry = debug_context . dwarf . unit . get_mut ( self . entry_id ) ;
126144 // Gdb requires both DW_AT_low_pc and DW_AT_high_pc. Otherwise the DW_TAG_subprogram is skipped.
127145 func_entry. set (
128146 gimli:: DW_AT_low_pc ,
0 commit comments