1
1
mod emit;
2
+ mod line_info;
2
3
3
4
use crate :: prelude:: * ;
4
5
5
- use syntax:: source_map:: FileName ;
6
-
7
6
use cranelift:: codegen:: ir:: { StackSlots , ValueLoc } ;
8
7
use cranelift:: codegen:: isa:: RegUnit ;
9
8
10
9
use gimli:: write:: {
11
- self , Address , AttributeValue , DwarfUnit , Expression , FileId , LineProgram , LineString ,
12
- LineStringTable , Location , LocationList , Range , RangeList , UnitEntryId , Writer ,
10
+ self , Address , AttributeValue , DwarfUnit , Expression , LineProgram , LineString ,
11
+ Location , LocationList , RangeList , UnitEntryId , Writer ,
13
12
} ;
14
13
use gimli:: { Encoding , Format , LineEncoding , Register , RunTimeEndian , X86_64 } ;
15
14
@@ -24,40 +23,6 @@ fn target_endian(tcx: TyCtxt) -> RunTimeEndian {
24
23
}
25
24
}
26
25
27
- fn line_program_add_file (
28
- line_program : & mut LineProgram ,
29
- line_strings : & mut LineStringTable ,
30
- file : & FileName ,
31
- ) -> FileId {
32
- match file {
33
- FileName :: Real ( path) => {
34
- let dir_name = path. parent ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . as_bytes ( ) ;
35
- let dir_id = if !dir_name. is_empty ( ) {
36
- let dir_name = LineString :: new ( dir_name, line_program. encoding ( ) , line_strings) ;
37
- line_program. add_directory ( dir_name)
38
- } else {
39
- line_program. default_directory ( )
40
- } ;
41
- let file_name = LineString :: new (
42
- path. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . as_bytes ( ) ,
43
- line_program. encoding ( ) ,
44
- line_strings,
45
- ) ;
46
- line_program. add_file ( file_name, dir_id, None )
47
- }
48
- // FIXME give more appropriate file names
49
- _ => {
50
- let dir_id = line_program. default_directory ( ) ;
51
- let dummy_file_name = LineString :: new (
52
- file. to_string ( ) . into_bytes ( ) ,
53
- line_program. encoding ( ) ,
54
- line_strings,
55
- ) ;
56
- line_program. add_file ( dummy_file_name, dir_id, None )
57
- }
58
- }
59
- }
60
-
61
26
pub struct DebugContext < ' tcx > {
62
27
tcx : TyCtxt < ' tcx > ,
63
28
@@ -135,32 +100,6 @@ impl<'tcx> DebugContext<'tcx> {
135
100
}
136
101
}
137
102
138
- fn emit_location ( & mut self , entry_id : UnitEntryId , span : Span ) {
139
- let loc = self . tcx . sess . source_map ( ) . lookup_char_pos ( span. lo ( ) ) ;
140
-
141
- let file_id = line_program_add_file (
142
- & mut self . dwarf . unit . line_program ,
143
- & mut self . dwarf . line_strings ,
144
- & loc. file . name ,
145
- ) ;
146
-
147
- let entry = self . dwarf . unit . get_mut ( entry_id) ;
148
-
149
- entry. set (
150
- gimli:: DW_AT_decl_file ,
151
- AttributeValue :: FileIndex ( Some ( file_id) ) ,
152
- ) ;
153
- entry. set (
154
- gimli:: DW_AT_decl_line ,
155
- AttributeValue :: Udata ( loc. line as u64 ) ,
156
- ) ;
157
- // FIXME: probably omit this
158
- entry. set (
159
- gimli:: DW_AT_decl_column ,
160
- AttributeValue :: Udata ( loc. col . to_usize ( ) as u64 ) ,
161
- ) ;
162
- }
163
-
164
103
fn dwarf_ty ( & mut self , ty : Ty < ' tcx > ) -> UnitEntryId {
165
104
if let Some ( type_id) = self . types . get ( ty) {
166
105
return * type_id;
@@ -248,13 +187,6 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
248
187
AttributeValue :: StringRef ( name_id) ,
249
188
) ;
250
189
251
- entry. set (
252
- gimli:: DW_AT_low_pc ,
253
- AttributeValue :: Address ( Address :: Symbol { symbol, addend : 0 } ) ,
254
- ) ;
255
-
256
- debug_context. emit_location ( entry_id, mir. span ) ;
257
-
258
190
FunctionDebugContext {
259
191
debug_context,
260
192
entry_id,
@@ -305,58 +237,7 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
305
237
isa : & dyn cranelift:: codegen:: isa:: TargetIsa ,
306
238
source_info_set : & indexmap:: IndexSet < ( Span , mir:: SourceScope ) > ,
307
239
) {
308
- let tcx = self . debug_context . tcx ;
309
-
310
- let line_program = & mut self . debug_context . dwarf . unit . line_program ;
311
-
312
- line_program. begin_sequence ( Some ( Address :: Symbol {
313
- symbol : self . symbol ,
314
- addend : 0 ,
315
- } ) ) ;
316
-
317
- let encinfo = isa. encoding_info ( ) ;
318
- let func = & context. func ;
319
- let mut ebbs = func. layout . ebbs ( ) . collect :: < Vec < _ > > ( ) ;
320
- ebbs. sort_by_key ( |ebb| func. offsets [ * ebb] ) ; // Ensure inst offsets always increase
321
-
322
- let line_strings = & mut self . debug_context . dwarf . line_strings ;
323
- let mut create_row_for_span = |line_program : & mut LineProgram , span : Span | {
324
- let loc = tcx. sess . source_map ( ) . lookup_char_pos ( span. lo ( ) ) ;
325
- let file_id = line_program_add_file ( line_program, line_strings, & loc. file . name ) ;
326
-
327
- /*println!(
328
- "srcloc {:>04X} {}:{}:{}",
329
- line_program.row().address_offset,
330
- file.display(),
331
- loc.line,
332
- loc.col.to_u32()
333
- );*/
334
-
335
- line_program. row ( ) . file = file_id;
336
- line_program. row ( ) . line = loc. line as u64 ;
337
- line_program. row ( ) . column = loc. col . to_u32 ( ) as u64 + 1 ;
338
- line_program. generate_row ( ) ;
339
- } ;
340
-
341
- let mut end = 0 ;
342
- for ebb in ebbs {
343
- for ( offset, inst, size) in func. inst_offsets ( ebb, & encinfo) {
344
- let srcloc = func. srclocs [ inst] ;
345
- line_program. row ( ) . address_offset = offset as u64 ;
346
- if !srcloc. is_default ( ) {
347
- let source_info = * source_info_set. get_index ( srcloc. bits ( ) as usize ) . unwrap ( ) ;
348
- create_row_for_span ( line_program, source_info. 0 ) ;
349
- } else {
350
- create_row_for_span ( line_program, self . mir . span ) ;
351
- }
352
- end = offset + size;
353
- }
354
- }
355
-
356
- line_program. end_sequence ( end as u64 ) ;
357
-
358
- let entry = self . debug_context . dwarf . unit . get_mut ( self . entry_id ) ;
359
- entry. set ( gimli:: DW_AT_high_pc , AttributeValue :: Udata ( end as u64 ) ) ;
240
+ self . create_debug_lines ( context, isa, source_info_set) ;
360
241
361
242
{
362
243
let value_labels_ranges = context. build_value_labels_ranges ( isa) . unwrap ( ) ;
@@ -391,17 +272,6 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
391
272
) ;
392
273
}
393
274
}
394
-
395
- self . debug_context
396
- . unit_range_list
397
- . 0
398
- . push ( Range :: StartLength {
399
- begin : Address :: Symbol {
400
- symbol : self . symbol ,
401
- addend : 0 ,
402
- } ,
403
- length : end as u64 ,
404
- } ) ;
405
275
}
406
276
}
407
277
0 commit comments