@@ -4,13 +4,13 @@ use crate::prelude::*;
4
4
5
5
use std:: marker:: PhantomData ;
6
6
7
- use gimli:: { Endianity , Format , RunTimeEndian } ;
8
7
use gimli:: write:: {
9
8
Address , AttributeValue , CompilationUnit , DebugAbbrev , DebugInfo , DebugLine , DebugRanges ,
10
9
DebugRngLists , DebugStr , EndianVec , LineProgram , LineProgramId , LineProgramTable , Range ,
11
- RangeList , RangeListTable , Result , SectionId , StringTable , UnitEntryId , UnitId , UnitTable , Writer ,
10
+ RangeList , RangeListTable , Result , SectionId , StringTable , UnitEntryId , UnitId , UnitTable ,
11
+ Writer ,
12
12
} ;
13
-
13
+ use gimli :: { Endianity , Format , RunTimeEndian } ;
14
14
15
15
use faerie:: * ;
16
16
@@ -71,7 +71,7 @@ impl<'a, 'tcx: 'a> DebugContext<'tcx> {
71
71
let range_lists = RangeListTable :: default ( ) ;
72
72
73
73
let global_line_program = line_programs. add ( LineProgram :: new (
74
- version ,
74
+ 3 , // FIXME https://github.com/gimli-rs/gimli/issues/363
75
75
address_size,
76
76
format,
77
77
1 ,
@@ -383,7 +383,7 @@ impl<'a, 'b, 'tcx: 'b> FunctionDebugContext<'a, 'tcx> {
383
383
& mut self ,
384
384
tcx : TyCtxt ,
385
385
//module: &mut Module<impl Backend>,
386
- size : u32 ,
386
+ code_size : u32 ,
387
387
context : & Context ,
388
388
isa : & cranelift:: codegen:: isa:: TargetIsa ,
389
389
source_info_set : & indexmap:: IndexSet < SourceInfo > ,
@@ -392,7 +392,7 @@ impl<'a, 'b, 'tcx: 'b> FunctionDebugContext<'a, 'tcx> {
392
392
// FIXME: add to appropriate scope intead of root
393
393
let entry = unit. get_mut ( self . entry_id ) ;
394
394
let mut size_array = [ 0 ; 8 ] ;
395
- target_endian ( tcx) . write_u64 ( & mut size_array, size as u64 ) ;
395
+ target_endian ( tcx) . write_u64 ( & mut size_array, code_size as u64 ) ;
396
396
entry. set ( gimli:: DW_AT_high_pc , AttributeValue :: Data8 ( size_array) ) ;
397
397
398
398
self . debug_context . unit_range_list . 0 . push ( Range {
@@ -402,7 +402,7 @@ impl<'a, 'b, 'tcx: 'b> FunctionDebugContext<'a, 'tcx> {
402
402
} ,
403
403
end : Address :: Relative {
404
404
symbol : self . symbol ,
405
- addend : size as i64 ,
405
+ addend : code_size as i64 ,
406
406
} ,
407
407
} ) ;
408
408
@@ -420,39 +420,54 @@ impl<'a, 'b, 'tcx: 'b> FunctionDebugContext<'a, 'tcx> {
420
420
let func = & context. func ;
421
421
let mut ebbs = func. layout . ebbs ( ) . collect :: < Vec < _ > > ( ) ;
422
422
ebbs. sort_by_key ( |ebb| func. offsets [ * ebb] ) ; // Ensure inst offsets always increase
423
- for ebb in ebbs {
424
- for ( offset, inst, _size) in func. inst_offsets ( ebb, & encinfo) {
425
- fn create_row_for_span ( tcx : TyCtxt , line_program : & mut LineProgram , offset : u64 , span : Span ) {
426
- let loc = tcx. sess . source_map ( ) . lookup_char_pos ( span. lo ( ) ) ;
427
- let file = loc. file . name . to_string ( ) ;
428
- let file = :: std:: path:: Path :: new ( & file) ;
429
- let dir_id = line_program
430
- . add_directory ( file. parent ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . as_bytes ( ) ) ;
431
- let file_id = line_program. add_file (
432
- file. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . as_bytes ( ) ,
433
- dir_id,
434
- None ,
435
- ) ;
436
- line_program. row ( ) . file = file_id;
437
- //tcx.sess
438
- // .warn(&format!("srcloc {} {}:{}:{}", offset, file, loc.line, loc.col.to_usize()));
439
- line_program. row ( ) . address_offset = offset;
440
- line_program. row ( ) . line = loc. line as u64 ;
441
- line_program. generate_row ( ) ;
442
- }
443
423
424
+ let create_row_for_span = |line_program : & mut LineProgram , span : Span | {
425
+ let loc = tcx. sess . source_map ( ) . lookup_char_pos ( span. lo ( ) ) ;
426
+ let file = loc. file . name . to_string ( ) ;
427
+ let file = :: std:: path:: Path :: new ( & file) ;
428
+ let dir_id =
429
+ line_program. add_directory ( file. parent ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . as_bytes ( ) ) ;
430
+ let file_id = line_program. add_file (
431
+ file. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . as_bytes ( ) ,
432
+ dir_id,
433
+ None ,
434
+ ) ;
435
+
436
+ /*println!(
437
+ "srcloc {:>04X} {}:{}:{}",
438
+ line_program.row().address_offset,
439
+ file.display(),
440
+ loc.line,
441
+ loc.col.to_u32()
442
+ );*/
443
+
444
+ line_program. row ( ) . file = file_id;
445
+ line_program. row ( ) . line = loc. line as u64 ;
446
+ line_program. row ( ) . column = loc. col . to_u32 ( ) as u64 + 1 ;
447
+ line_program. generate_row ( ) ;
448
+ } ;
449
+
450
+ let mut end = 0 ;
451
+ for ebb in ebbs {
452
+ for ( offset, inst, size) in func. inst_offsets ( ebb, & encinfo) {
444
453
let srcloc = func. srclocs [ inst] ;
454
+ line_program. row ( ) . address_offset = offset as u64 ;
445
455
if !srcloc. is_default ( ) {
446
456
let source_info = * source_info_set. get_index ( srcloc. bits ( ) as usize ) . unwrap ( ) ;
447
- create_row_for_span ( tcx , line_program, offset as u64 , source_info. span ) ;
457
+ create_row_for_span ( line_program, source_info. span ) ;
448
458
} else {
449
- create_row_for_span ( tcx , line_program, offset as u64 , self . mir_span ) ;
459
+ create_row_for_span ( line_program, self . mir_span ) ;
450
460
}
461
+ end = offset + size;
451
462
}
452
463
}
453
464
454
- let address_offset = line_program. row ( ) . address_offset ;
455
- line_program. end_sequence ( address_offset) ;
465
+ if code_size != end {
466
+ line_program. row ( ) . address_offset = end as u64 ;
467
+ create_row_for_span ( line_program, self . mir_span ) ;
468
+ }
469
+
470
+ line_program. end_sequence ( code_size as u64 ) ;
456
471
}
457
472
}
458
473
0 commit comments