@@ -172,7 +172,6 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
172
172
instance : Instance < ' tcx > ,
173
173
func_id : FuncId ,
174
174
name : & str ,
175
- _sig : & Signature ,
176
175
) -> Self {
177
176
let mir = debug_context. tcx . instance_mir ( instance. def ) ;
178
177
@@ -235,6 +234,7 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
235
234
context : & Context ,
236
235
isa : & dyn cranelift:: codegen:: isa:: TargetIsa ,
237
236
source_info_set : & indexmap:: IndexSet < ( Span , mir:: SourceScope ) > ,
237
+ local_map : HashMap < mir:: Local , CPlace < ' tcx > > ,
238
238
) {
239
239
let end = self . create_debug_lines ( context, isa, source_info_set) ;
240
240
@@ -251,34 +251,53 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
251
251
252
252
let value_labels_ranges = context. build_value_labels_ranges ( isa) . unwrap ( ) ;
253
253
254
- for ( value_label, value_loc_ranges) in value_labels_ranges. iter ( ) {
255
- let var_id = self . define_local ( mir:: Local :: from_u32 ( value_label. as_u32 ( ) ) ) ;
256
-
257
- let loc_list = LocationList (
258
- value_loc_ranges
259
- . iter ( )
260
- . map ( |value_loc_range| Location :: StartEnd {
261
- begin : Address :: Symbol {
262
- symbol : self . symbol ,
263
- addend : i64:: from ( value_loc_range. start ) ,
264
- } ,
265
- end : Address :: Symbol {
266
- symbol : self . symbol ,
267
- addend : i64:: from ( value_loc_range. end ) ,
268
- } ,
269
- data : Expression (
270
- translate_loc ( value_loc_range. loc , & context. func . stack_slots ) . unwrap ( ) ,
271
- ) ,
272
- } )
273
- . collect ( ) ,
274
- ) ;
275
- let loc_list_id = self . debug_context . dwarf . unit . locations . add ( loc_list) ;
254
+ for ( local, _local_decl) in self . mir . local_decls . iter_enumerated ( ) {
255
+ let var_id = self . define_local ( local) ;
256
+ let value_label = cranelift:: codegen:: ir:: ValueLabel :: from_u32 ( local. as_u32 ( ) ) ;
257
+
258
+ let location = match local_map[ & local] . inner ( ) {
259
+ CPlaceInner :: Var ( _) => {
260
+ if let Some ( value_loc_ranges) = value_labels_ranges. get ( & value_label) {
261
+ let loc_list = LocationList (
262
+ value_loc_ranges
263
+ . iter ( )
264
+ . map ( |value_loc_range| Location :: StartEnd {
265
+ begin : Address :: Symbol {
266
+ symbol : self . symbol ,
267
+ addend : i64:: from ( value_loc_range. start ) ,
268
+ } ,
269
+ end : Address :: Symbol {
270
+ symbol : self . symbol ,
271
+ addend : i64:: from ( value_loc_range. end ) ,
272
+ } ,
273
+ data : Expression (
274
+ translate_loc ( value_loc_range. loc , & context. func . stack_slots ) . unwrap ( ) ,
275
+ ) ,
276
+ } )
277
+ . collect ( ) ,
278
+ ) ;
279
+ let loc_list_id = self . debug_context . dwarf . unit . locations . add ( loc_list) ;
280
+
281
+ AttributeValue :: LocationListRef ( loc_list_id)
282
+ } else {
283
+ // FIXME set value labels for unused locals
284
+
285
+ AttributeValue :: Exprloc ( Expression ( vec ! [ ] ) )
286
+ }
287
+ }
288
+ CPlaceInner :: Addr ( _, _) => {
289
+ // FIXME implement this (used by arguments and returns)
290
+
291
+ AttributeValue :: Exprloc ( Expression ( vec ! [ ] ) )
292
+ }
293
+ CPlaceInner :: Stack ( stack_slot) => {
294
+ AttributeValue :: Exprloc ( Expression ( translate_loc ( ValueLoc :: Stack ( * stack_slot) , & context. func . stack_slots ) . unwrap ( ) ) )
295
+ }
296
+ CPlaceInner :: NoPlace => AttributeValue :: Exprloc ( Expression ( vec ! [ ] ) ) ,
297
+ } ;
276
298
277
299
let var_entry = self . debug_context . dwarf . unit . get_mut ( var_id) ;
278
- var_entry. set (
279
- gimli:: DW_AT_location ,
280
- AttributeValue :: LocationListRef ( loc_list_id) ,
281
- ) ;
300
+ var_entry. set ( gimli:: DW_AT_location , location) ;
282
301
}
283
302
}
284
303
}
0 commit comments