@@ -3,8 +3,9 @@ mod line_info;
3
3
4
4
use crate :: prelude:: * ;
5
5
6
- use cranelift:: codegen:: ir:: { StackSlots , ValueLoc } ;
6
+ use cranelift:: codegen:: ir:: { StackSlots , ValueLabel , ValueLoc } ;
7
7
use cranelift:: codegen:: isa:: RegUnit ;
8
+ use cranelift:: codegen:: ValueLocRange ;
8
9
9
10
use gimli:: write:: {
10
11
self , Address , AttributeValue , DwarfUnit , Expression , LineProgram , LineString , Location ,
@@ -228,22 +229,14 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
228
229
}
229
230
}
230
231
231
- fn define_local ( & mut self , local : mir:: Local ) -> UnitEntryId {
232
- let local_decl = & self . mir . local_decls [ local] ;
233
-
232
+ fn define_local ( & mut self , name : String , ty : Ty < ' tcx > ) -> UnitEntryId {
234
233
let ty = self . debug_context . tcx . subst_and_normalize_erasing_regions (
235
234
self . instance . substs ,
236
235
ty:: ParamEnv :: reveal_all ( ) ,
237
- & local_decl . ty ,
236
+ & ty,
238
237
) ;
239
238
let dw_ty = self . debug_context . dwarf_ty ( ty) ;
240
239
241
- let name = if let Some ( name) = local_decl. name {
242
- format ! ( "{}{:?}" , name. as_str( ) , local)
243
- } else {
244
- format ! ( "{:?}" , local)
245
- } ;
246
-
247
240
let var_id = self
248
241
. debug_context
249
242
. dwarf
@@ -280,57 +273,82 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
280
273
let value_labels_ranges = context. build_value_labels_ranges ( isa) . unwrap ( ) ;
281
274
282
275
for ( local, _local_decl) in self . mir . local_decls . iter_enumerated ( ) {
283
- let var_id = self . define_local ( local) ;
284
- let value_label = cranelift:: codegen:: ir:: ValueLabel :: from_u32 ( local. as_u32 ( ) ) ;
285
-
286
- let location = match local_map[ & local] . inner ( ) {
287
- CPlaceInner :: Var ( _) => {
288
- if let Some ( value_loc_ranges) = value_labels_ranges. get ( & value_label) {
289
- let loc_list = LocationList (
290
- value_loc_ranges
291
- . iter ( )
292
- . map ( |value_loc_range| Location :: StartEnd {
293
- begin : Address :: Symbol {
294
- symbol : self . symbol ,
295
- addend : i64:: from ( value_loc_range. start ) ,
296
- } ,
297
- end : Address :: Symbol {
298
- symbol : self . symbol ,
299
- addend : i64:: from ( value_loc_range. end ) ,
300
- } ,
301
- data : Expression (
302
- translate_loc ( value_loc_range. loc , & context. func . stack_slots ) . unwrap ( ) ,
303
- ) ,
304
- } )
305
- . collect ( ) ,
306
- ) ;
307
- let loc_list_id = self . debug_context . dwarf . unit . locations . add ( loc_list) ;
308
-
309
- AttributeValue :: LocationListRef ( loc_list_id)
310
- } else {
311
- // FIXME set value labels for unused locals
312
-
313
- AttributeValue :: Exprloc ( Expression ( vec ! [ ] ) )
314
- }
315
- }
316
- CPlaceInner :: Addr ( _, _) => {
317
- // FIXME implement this (used by arguments and returns)
318
-
319
- AttributeValue :: Exprloc ( Expression ( vec ! [ ] ) )
320
- }
321
- CPlaceInner :: Stack ( stack_slot) => {
322
- AttributeValue :: Exprloc ( Expression ( translate_loc ( ValueLoc :: Stack ( * stack_slot) , & context. func . stack_slots ) . unwrap ( ) ) )
323
- }
324
- CPlaceInner :: NoPlace => AttributeValue :: Exprloc ( Expression ( vec ! [ ] ) ) ,
325
- } ;
276
+ let var_id = self . define_local ( format ! ( "{:?}" , local) , & self . mir . local_decls [ local] . ty ) ;
277
+
278
+ let location = place_location (
279
+ self ,
280
+ context,
281
+ & local_map,
282
+ & value_labels_ranges,
283
+ Place {
284
+ base : PlaceBase :: Local ( local) ,
285
+ projection : ty:: List :: empty ( ) ,
286
+ } ,
287
+ ) ;
326
288
327
289
let var_entry = self . debug_context . dwarf . unit . get_mut ( var_id) ;
328
290
var_entry. set ( gimli:: DW_AT_location , location) ;
329
291
}
292
+
293
+ // FIXME create locals for all entries in mir.var_debug_info
330
294
}
331
295
}
332
296
297
+ fn place_location < ' a , ' tcx > (
298
+ func_debug_ctx : & mut FunctionDebugContext < ' a , ' tcx > ,
299
+ context : & Context ,
300
+ local_map : & HashMap < mir:: Local , CPlace < ' tcx > > ,
301
+ value_labels_ranges : & HashMap < ValueLabel , Vec < ValueLocRange > > ,
302
+ place : Place < ' tcx > ,
303
+ ) -> AttributeValue {
304
+ assert ! ( place. projection. is_empty( ) ) ; // FIXME implement them
305
+ let cplace = match place. base {
306
+ PlaceBase :: Local ( local) => local_map[ & local] ,
307
+ PlaceBase :: Static ( _) => bug ! ( "Unenforced invariant that the place is based on a Local violated: {:?}" , place) ,
308
+ } ;
309
+
310
+ match cplace. inner ( ) {
311
+ CPlaceInner :: Var ( local) => {
312
+ let value_label = cranelift:: codegen:: ir:: ValueLabel :: from_u32 ( local. as_u32 ( ) ) ;
313
+ if let Some ( value_loc_ranges) = value_labels_ranges. get ( & value_label) {
314
+ let loc_list = LocationList (
315
+ value_loc_ranges
316
+ . iter ( )
317
+ . map ( |value_loc_range| Location :: StartEnd {
318
+ begin : Address :: Symbol {
319
+ symbol : func_debug_ctx. symbol ,
320
+ addend : i64:: from ( value_loc_range. start ) ,
321
+ } ,
322
+ end : Address :: Symbol {
323
+ symbol : func_debug_ctx. symbol ,
324
+ addend : i64:: from ( value_loc_range. end ) ,
325
+ } ,
326
+ data : Expression (
327
+ translate_loc ( value_loc_range. loc , & context. func . stack_slots ) . unwrap ( ) ,
328
+ ) ,
329
+ } )
330
+ . collect ( ) ,
331
+ ) ;
332
+ let loc_list_id = func_debug_ctx. debug_context . dwarf . unit . locations . add ( loc_list) ;
333
+
334
+ AttributeValue :: LocationListRef ( loc_list_id)
335
+ } else {
336
+ // FIXME set value labels for unused locals
337
+
338
+ AttributeValue :: Exprloc ( Expression ( vec ! [ ] ) )
339
+ }
340
+ }
341
+ CPlaceInner :: Addr ( _, _) => {
342
+ // FIXME implement this (used by arguments and returns)
333
343
344
+ AttributeValue :: Exprloc ( Expression ( vec ! [ ] ) )
345
+ }
346
+ CPlaceInner :: Stack ( stack_slot) => {
347
+ AttributeValue :: Exprloc ( Expression ( translate_loc ( ValueLoc :: Stack ( * stack_slot) , & context. func . stack_slots ) . unwrap ( ) ) )
348
+ }
349
+ CPlaceInner :: NoPlace => AttributeValue :: Exprloc ( Expression ( vec ! [ ] ) ) ,
350
+ }
351
+ }
334
352
335
353
336
354
0 commit comments