@@ -6,6 +6,7 @@ use crate::prelude::*;
6
6
use rustc_span:: { FileName , SourceFile , SourceFileAndLine , Pos , SourceFileHash , SourceFileHashAlgorithm } ;
7
7
8
8
use cranelift_codegen:: binemit:: CodeOffset ;
9
+ use cranelift_codegen:: machinst:: MachSrcLoc ;
9
10
10
11
use gimli:: write:: {
11
12
Address , AttributeValue , FileId , LineProgram , LineString , FileInfo , LineStringTable , UnitEntryId ,
@@ -128,18 +129,8 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
128
129
source_info_set : & indexmap:: IndexSet < SourceInfo > ,
129
130
) -> CodeOffset {
130
131
let tcx = self . debug_context . tcx ;
131
-
132
132
let line_program = & mut self . debug_context . dwarf . unit . line_program ;
133
-
134
- line_program. begin_sequence ( Some ( Address :: Symbol {
135
- symbol : self . symbol ,
136
- addend : 0 ,
137
- } ) ) ;
138
-
139
- let encinfo = isa. encoding_info ( ) ;
140
133
let func = & context. func ;
141
- let mut blocks = func. layout . blocks ( ) . collect :: < Vec < _ > > ( ) ;
142
- blocks. sort_by_key ( |block| func. offsets [ * block] ) ; // Ensure inst offsets always increase
143
134
144
135
let line_strings = & mut self . debug_context . dwarf . line_strings ;
145
136
let function_span = self . mir . span ;
@@ -197,22 +188,58 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
197
188
line_program. generate_row ( ) ;
198
189
} ;
199
190
200
- let mut end = 0 ;
201
- for block in blocks {
202
- for ( offset, inst, size) in func. inst_offsets ( block, & encinfo) {
203
- let srcloc = func. srclocs [ inst] ;
204
- line_program. row ( ) . address_offset = offset as u64 ;
205
- if !srcloc. is_default ( ) {
206
- let source_info = * source_info_set. get_index ( srcloc. bits ( ) as usize ) . unwrap ( ) ;
191
+ line_program. begin_sequence ( Some ( Address :: Symbol {
192
+ symbol : self . symbol ,
193
+ addend : 0 ,
194
+ } ) ) ;
195
+
196
+ let mut func_end = 0 ;
197
+
198
+ if let Some ( ref mcr) = & context. mach_compile_result {
199
+ for & MachSrcLoc { start, end, loc } in mcr. sections . get_srclocs_sorted ( ) {
200
+ // FIXME get_srclocs_sorted omits default srclocs
201
+ if func_end < start {
202
+ line_program. row ( ) . address_offset = func_end as u64 ;
203
+ create_row_for_span ( line_program, self . mir . span ) ;
204
+ }
205
+ line_program. row ( ) . address_offset = start as u64 ;
206
+ if !loc. is_default ( ) {
207
+ let source_info = * source_info_set. get_index ( loc. bits ( ) as usize ) . unwrap ( ) ;
207
208
create_row_for_span ( line_program, source_info. span ) ;
208
209
} else {
209
210
create_row_for_span ( line_program, self . mir . span ) ;
210
211
}
211
- end = offset + size;
212
+ func_end = end;
213
+ }
214
+ // FIXME get_srclocs_sorted omits default srclocs
215
+ if func_end < mcr. sections . total_size ( ) {
216
+ line_program. row ( ) . address_offset = func_end as u64 ;
217
+ create_row_for_span ( line_program, self . mir . span ) ;
218
+ func_end = mcr. sections . total_size ( ) ;
219
+ }
220
+ } else {
221
+ let encinfo = isa. encoding_info ( ) ;
222
+ let mut blocks = func. layout . blocks ( ) . collect :: < Vec < _ > > ( ) ;
223
+ blocks. sort_by_key ( |block| func. offsets [ * block] ) ; // Ensure inst offsets always increase
224
+
225
+ for block in blocks {
226
+ for ( offset, inst, size) in func. inst_offsets ( block, & encinfo) {
227
+ let srcloc = func. srclocs [ inst] ;
228
+ line_program. row ( ) . address_offset = offset as u64 ;
229
+ if !srcloc. is_default ( ) {
230
+ let source_info = * source_info_set. get_index ( srcloc. bits ( ) as usize ) . unwrap ( ) ;
231
+ create_row_for_span ( line_program, source_info. span ) ;
232
+ } else {
233
+ create_row_for_span ( line_program, self . mir . span ) ;
234
+ }
235
+ func_end = offset + size;
236
+ }
212
237
}
213
238
}
214
239
215
- line_program. end_sequence ( end as u64 ) ;
240
+ assert_ne ! ( func_end, 0 ) ;
241
+
242
+ line_program. end_sequence ( func_end as u64 ) ;
216
243
217
244
let entry = self . debug_context . dwarf . unit . get_mut ( self . entry_id ) ;
218
245
entry. set (
@@ -222,11 +249,11 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
222
249
addend : 0 ,
223
250
} ) ,
224
251
) ;
225
- entry. set ( gimli:: DW_AT_high_pc , AttributeValue :: Udata ( end as u64 ) ) ;
252
+ entry. set ( gimli:: DW_AT_high_pc , AttributeValue :: Udata ( func_end as u64 ) ) ;
226
253
227
254
self . debug_context
228
255
. emit_location ( self . entry_id , self . mir . span ) ;
229
256
230
- end
257
+ func_end
231
258
}
232
259
}
0 commit comments