@@ -337,6 +337,7 @@ pub struct FunctionDebugContext<'a, 'tcx> {
337
337
debug_context : & ' a mut DebugContext < ' tcx > ,
338
338
entry_id : UnitEntryId ,
339
339
symbol : usize ,
340
+ mir_span : Span ,
340
341
}
341
342
342
343
impl < ' a , ' b , ' tcx : ' b > FunctionDebugContext < ' a , ' tcx > {
@@ -373,6 +374,7 @@ impl<'a, 'b, 'tcx: 'b> FunctionDebugContext<'a, 'tcx> {
373
374
debug_context,
374
375
entry_id,
375
376
symbol,
377
+ mir_span : mir. span ,
376
378
}
377
379
}
378
380
@@ -419,9 +421,7 @@ impl<'a, 'b, 'tcx: 'b> FunctionDebugContext<'a, 'tcx> {
419
421
ebbs. sort_by_key ( |ebb| func. offsets [ * ebb] ) ; // Ensure inst offsets always increase
420
422
for ebb in ebbs {
421
423
for ( offset, inst, _size) in func. inst_offsets ( ebb, & encinfo) {
422
- let srcloc = func. srclocs [ inst] ;
423
- if !srcloc. is_default ( ) {
424
- let span = spans[ srcloc. bits ( ) as usize ] ;
424
+ fn create_row_for_span ( tcx : TyCtxt , line_program : & mut LineProgram , offset : u64 , span : Span ) {
425
425
let loc = tcx. sess . source_map ( ) . lookup_char_pos ( span. lo ( ) ) ;
426
426
let file = loc. file . name . to_string ( ) ;
427
427
let file = :: std:: path:: Path :: new ( & file) ;
@@ -435,10 +435,18 @@ impl<'a, 'b, 'tcx: 'b> FunctionDebugContext<'a, 'tcx> {
435
435
line_program. row ( ) . file = file_id;
436
436
//tcx.sess
437
437
// .warn(&format!("srcloc {} {}:{}:{}", offset, file, loc.line, loc.col.to_usize()));
438
- line_program. row ( ) . address_offset = offset as u64 ;
438
+ line_program. row ( ) . address_offset = offset;
439
439
line_program. row ( ) . line = loc. line as u64 ;
440
440
line_program. generate_row ( ) ;
441
441
}
442
+
443
+ let srcloc = func. srclocs [ inst] ;
444
+ if !srcloc. is_default ( ) {
445
+ let span = spans[ srcloc. bits ( ) as usize ] ;
446
+ create_row_for_span ( tcx, line_program, offset as u64 , span) ;
447
+ } else {
448
+ create_row_for_span ( tcx, line_program, offset as u64 , self . mir_span ) ;
449
+ }
442
450
}
443
451
}
444
452
0 commit comments