3
3
use std:: ffi:: OsStr ;
4
4
use std:: path:: { Component , Path } ;
5
5
6
+ use crate :: debuginfo:: FunctionDebugContext ;
6
7
use crate :: prelude:: * ;
7
8
8
9
use rustc_data_structures:: sync:: Lrc ;
@@ -15,7 +16,6 @@ use cranelift_codegen::MachSrcLoc;
15
16
16
17
use gimli:: write:: {
17
18
Address , AttributeValue , FileId , FileInfo , LineProgram , LineString , LineStringTable ,
18
- UnitEntryId ,
19
19
} ;
20
20
21
21
// OPTIMIZATION: It is cheaper to do this in one pass than using `.parent()` and `.file_name()`.
@@ -121,19 +121,39 @@ fn line_program_add_file(
121
121
}
122
122
}
123
123
124
- impl DebugContext {
124
+ impl FunctionDebugContext {
125
+ pub ( super ) fn set_function_span (
126
+ & mut self ,
127
+ debug_context : & mut DebugContext ,
128
+ tcx : TyCtxt < ' _ > ,
129
+ span : Span ,
130
+ ) {
131
+ let ( file, line, column) = get_span_loc ( tcx, span, span) ;
132
+
133
+ let file_id = line_program_add_file (
134
+ & mut debug_context. dwarf . unit . line_program ,
135
+ & mut debug_context. dwarf . line_strings ,
136
+ & file,
137
+ ) ;
138
+
139
+ let entry = debug_context. dwarf . unit . get_mut ( self . entry_id ) ;
140
+ entry. set ( gimli:: DW_AT_decl_file , AttributeValue :: FileIndex ( Some ( file_id) ) ) ;
141
+ entry. set ( gimli:: DW_AT_decl_line , AttributeValue :: Udata ( line) ) ;
142
+ entry. set ( gimli:: DW_AT_decl_column , AttributeValue :: Udata ( column) ) ;
143
+ }
144
+
125
145
pub ( super ) fn create_debug_lines (
126
146
& mut self ,
147
+ debug_context : & mut DebugContext ,
127
148
tcx : TyCtxt < ' _ > ,
128
149
symbol : usize ,
129
- entry_id : UnitEntryId ,
130
150
context : & Context ,
131
151
function_span : Span ,
132
152
source_info_set : & indexmap:: IndexSet < SourceInfo > ,
133
153
) -> CodeOffset {
134
- let line_program = & mut self . dwarf . unit . line_program ;
154
+ let line_program = & mut debug_context . dwarf . unit . line_program ;
135
155
136
- let line_strings = & mut self . dwarf . line_strings ;
156
+ let line_strings = & mut debug_context . dwarf . line_strings ;
137
157
let mut last_span = None ;
138
158
let mut last_file = None ;
139
159
let mut create_row_for_span = |line_program : & mut LineProgram , span : Span | {
@@ -189,24 +209,12 @@ impl DebugContext {
189
209
190
210
assert_ne ! ( func_end, 0 ) ;
191
211
192
- let ( function_file, function_line, function_col) =
193
- get_span_loc ( tcx, function_span, function_span) ;
194
-
195
- let function_file_id = line_program_add_file (
196
- & mut self . dwarf . unit . line_program ,
197
- & mut self . dwarf . line_strings ,
198
- & function_file,
199
- ) ;
200
-
201
- let entry = self . dwarf . unit . get_mut ( entry_id) ;
212
+ let entry = debug_context. dwarf . unit . get_mut ( self . entry_id ) ;
202
213
entry. set (
203
214
gimli:: DW_AT_low_pc ,
204
215
AttributeValue :: Address ( Address :: Symbol { symbol, addend : 0 } ) ,
205
216
) ;
206
217
entry. set ( gimli:: DW_AT_high_pc , AttributeValue :: Udata ( u64:: from ( func_end) ) ) ;
207
- entry. set ( gimli:: DW_AT_decl_file , AttributeValue :: FileIndex ( Some ( function_file_id) ) ) ;
208
- entry. set ( gimli:: DW_AT_decl_line , AttributeValue :: Udata ( function_line) ) ;
209
- entry. set ( gimli:: DW_AT_decl_column , AttributeValue :: Udata ( function_col) ) ;
210
218
211
219
func_end
212
220
}
0 commit comments