@@ -10,7 +10,9 @@ use crate::prelude::*;
10
10
use cranelift_codegen:: ir:: Endianness ;
11
11
use cranelift_codegen:: isa:: TargetIsa ;
12
12
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
+ } ;
14
16
use gimli:: { Encoding , Format , LineEncoding , RunTimeEndian } ;
15
17
16
18
pub ( crate ) use emit:: { DebugReloc , DebugRelocName } ;
@@ -23,6 +25,10 @@ pub(crate) struct DebugContext {
23
25
unit_range_list : RangeList ,
24
26
}
25
27
28
+ pub ( crate ) struct FunctionDebugContext {
29
+ entry_id : UnitEntryId ,
30
+ }
31
+
26
32
impl DebugContext {
27
33
pub ( crate ) fn new ( tcx : TyCtxt < ' _ > , isa : & dyn TargetIsa ) -> Self {
28
34
let encoding = Encoding {
@@ -93,17 +99,7 @@ impl DebugContext {
93
99
DebugContext { endian, dwarf, unit_range_list : RangeList ( Vec :: new ( ) ) }
94
100
}
95
101
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 {
107
103
// FIXME: add to appropriate scope instead of root
108
104
let scope = self . dwarf . unit . root ( ) ;
109
105
@@ -114,15 +110,37 @@ impl DebugContext {
114
110
entry. set ( gimli:: DW_AT_name , AttributeValue :: StringRef ( name_id) ) ;
115
111
entry. set ( gimli:: DW_AT_linkage_name , AttributeValue :: StringRef ( name_id) ) ;
116
112
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
+ ) ;
119
137
120
- self . unit_range_list . 0 . push ( Range :: StartLength {
138
+ debug_context . unit_range_list . 0 . push ( Range :: StartLength {
121
139
begin : Address :: Symbol { symbol, addend : 0 } ,
122
140
length : u64:: from ( end) ,
123
141
} ) ;
124
142
125
- let func_entry = self . dwarf . unit . get_mut ( entry_id) ;
143
+ let func_entry = debug_context . dwarf . unit . get_mut ( self . entry_id ) ;
126
144
// Gdb requires both DW_AT_low_pc and DW_AT_high_pc. Otherwise the DW_TAG_subprogram is skipped.
127
145
func_entry. set (
128
146
gimli:: DW_AT_low_pc ,
0 commit comments