@@ -7,18 +7,11 @@ mod unwind;
77
88use crate :: prelude:: * ;
99
10- use rustc_index:: vec:: IndexVec ;
11-
12- use cranelift_codegen:: entity:: EntityRef ;
13- use cranelift_codegen:: ir:: { Endianness , LabelValueLoc , ValueLabel } ;
10+ use cranelift_codegen:: ir:: Endianness ;
1411use cranelift_codegen:: isa:: TargetIsa ;
15- use cranelift_codegen:: ValueLocRange ;
1612
17- use gimli:: write:: {
18- Address , AttributeValue , DwarfUnit , Expression , LineProgram , LineString , Location ,
19- LocationList , Range , RangeList , UnitEntryId ,
20- } ;
21- use gimli:: { Encoding , Format , LineEncoding , RunTimeEndian , X86_64 } ;
13+ use gimli:: write:: { Address , AttributeValue , DwarfUnit , LineProgram , LineString , Range , RangeList } ;
14+ use gimli:: { Encoding , Format , LineEncoding , RunTimeEndian } ;
2215
2316pub ( crate ) use emit:: { DebugReloc , DebugRelocName } ;
2417pub ( crate ) use unwind:: UnwindContext ;
@@ -30,8 +23,6 @@ pub(crate) struct DebugContext<'tcx> {
3023
3124 dwarf : DwarfUnit ,
3225 unit_range_list : RangeList ,
33-
34- types : FxHashMap < Ty < ' tcx > , UnitEntryId > ,
3526}
3627
3728impl < ' tcx > DebugContext < ' tcx > {
@@ -101,124 +92,16 @@ impl<'tcx> DebugContext<'tcx> {
10192 root. set ( gimli:: DW_AT_low_pc , AttributeValue :: Address ( Address :: Constant ( 0 ) ) ) ;
10293 }
10394
104- DebugContext {
105- tcx,
106-
107- endian,
108-
109- dwarf,
110- unit_range_list : RangeList ( Vec :: new ( ) ) ,
111-
112- types : FxHashMap :: default ( ) ,
113- }
114- }
115-
116- fn dwarf_ty ( & mut self , ty : Ty < ' tcx > ) -> UnitEntryId {
117- if let Some ( type_id) = self . types . get ( & ty) {
118- return * type_id;
119- }
120-
121- let new_entry = |dwarf : & mut DwarfUnit , tag| dwarf. unit . add ( dwarf. unit . root ( ) , tag) ;
122-
123- let primitive = |dwarf : & mut DwarfUnit , ate| {
124- let type_id = new_entry ( dwarf, gimli:: DW_TAG_base_type ) ;
125- let type_entry = dwarf. unit . get_mut ( type_id) ;
126- type_entry. set ( gimli:: DW_AT_encoding , AttributeValue :: Encoding ( ate) ) ;
127- type_id
128- } ;
129-
130- let name = format ! ( "{}" , ty) ;
131- let layout = self . tcx . layout_of ( ParamEnv :: reveal_all ( ) . and ( ty) ) . unwrap ( ) ;
132-
133- let type_id = match ty. kind ( ) {
134- ty:: Bool => primitive ( & mut self . dwarf , gimli:: DW_ATE_boolean ) ,
135- ty:: Char => primitive ( & mut self . dwarf , gimli:: DW_ATE_UTF ) ,
136- ty:: Uint ( _) => primitive ( & mut self . dwarf , gimli:: DW_ATE_unsigned ) ,
137- ty:: Int ( _) => primitive ( & mut self . dwarf , gimli:: DW_ATE_signed ) ,
138- ty:: Float ( _) => primitive ( & mut self . dwarf , gimli:: DW_ATE_float ) ,
139- ty:: Ref ( _, pointee_ty, _mutbl)
140- | ty:: RawPtr ( ty:: TypeAndMut { ty : pointee_ty, mutbl : _mutbl } ) => {
141- let type_id = new_entry ( & mut self . dwarf , gimli:: DW_TAG_pointer_type ) ;
142-
143- // Ensure that type is inserted before recursing to avoid duplicates
144- self . types . insert ( ty, type_id) ;
145-
146- let pointee = self . dwarf_ty ( * pointee_ty) ;
147-
148- let type_entry = self . dwarf . unit . get_mut ( type_id) ;
149-
150- //type_entry.set(gimli::DW_AT_mutable, AttributeValue::Flag(mutbl == rustc_hir::Mutability::Mut));
151- type_entry. set ( gimli:: DW_AT_type , AttributeValue :: UnitRef ( pointee) ) ;
152-
153- type_id
154- }
155- ty:: Adt ( adt_def, _substs) if adt_def. is_struct ( ) && !layout. is_unsized ( ) => {
156- let type_id = new_entry ( & mut self . dwarf , gimli:: DW_TAG_structure_type ) ;
157-
158- // Ensure that type is inserted before recursing to avoid duplicates
159- self . types . insert ( ty, type_id) ;
160-
161- let variant = adt_def. non_enum_variant ( ) ;
162-
163- for ( field_idx, field_def) in variant. fields . iter ( ) . enumerate ( ) {
164- let field_offset = layout. fields . offset ( field_idx) ;
165- let field_layout = layout. field (
166- & layout:: LayoutCx { tcx : self . tcx , param_env : ParamEnv :: reveal_all ( ) } ,
167- field_idx,
168- ) ;
169-
170- let field_type = self . dwarf_ty ( field_layout. ty ) ;
171-
172- let field_id = self . dwarf . unit . add ( type_id, gimli:: DW_TAG_member ) ;
173- let field_entry = self . dwarf . unit . get_mut ( field_id) ;
174-
175- field_entry. set (
176- gimli:: DW_AT_name ,
177- AttributeValue :: String ( field_def. name . as_str ( ) . to_string ( ) . into_bytes ( ) ) ,
178- ) ;
179- field_entry. set (
180- gimli:: DW_AT_data_member_location ,
181- AttributeValue :: Udata ( field_offset. bytes ( ) ) ,
182- ) ;
183- field_entry. set ( gimli:: DW_AT_type , AttributeValue :: UnitRef ( field_type) ) ;
184- }
185-
186- type_id
187- }
188- _ => new_entry ( & mut self . dwarf , gimli:: DW_TAG_structure_type ) ,
189- } ;
190-
191- let type_entry = self . dwarf . unit . get_mut ( type_id) ;
192-
193- type_entry. set ( gimli:: DW_AT_name , AttributeValue :: String ( name. into_bytes ( ) ) ) ;
194- type_entry. set ( gimli:: DW_AT_byte_size , AttributeValue :: Udata ( layout. size . bytes ( ) ) ) ;
195-
196- self . types . insert ( ty, type_id) ;
197-
198- type_id
199- }
200-
201- fn define_local ( & mut self , scope : UnitEntryId , name : String , ty : Ty < ' tcx > ) -> UnitEntryId {
202- let dw_ty = self . dwarf_ty ( ty) ;
203-
204- let var_id = self . dwarf . unit . add ( scope, gimli:: DW_TAG_variable ) ;
205- let var_entry = self . dwarf . unit . get_mut ( var_id) ;
206-
207- var_entry. set ( gimli:: DW_AT_name , AttributeValue :: String ( name. into_bytes ( ) ) ) ;
208- var_entry. set ( gimli:: DW_AT_type , AttributeValue :: UnitRef ( dw_ty) ) ;
209-
210- var_id
95+ DebugContext { tcx, endian, dwarf, unit_range_list : RangeList ( Vec :: new ( ) ) }
21196 }
21297
21398 pub ( crate ) fn define_function (
21499 & mut self ,
215100 instance : Instance < ' tcx > ,
216101 func_id : FuncId ,
217102 name : & str ,
218- isa : & dyn TargetIsa ,
219103 context : & Context ,
220104 source_info_set : & indexmap:: IndexSet < SourceInfo > ,
221- local_map : IndexVec < mir:: Local , CPlace < ' tcx > > ,
222105 ) {
223106 let symbol = func_id. as_u32 ( ) as usize ;
224107 let mir = self . tcx . instance_mir ( instance. def ) ;
@@ -248,110 +131,5 @@ impl<'tcx> DebugContext<'tcx> {
248131 ) ;
249132 // Using Udata for DW_AT_high_pc requires at least DWARF4
250133 func_entry. set ( gimli:: DW_AT_high_pc , AttributeValue :: Udata ( u64:: from ( end) ) ) ;
251-
252- // FIXME make it more reliable and implement scopes before re-enabling this.
253- if false {
254- let value_labels_ranges = std:: collections:: HashMap :: new ( ) ; // FIXME
255-
256- for ( local, _local_decl) in mir. local_decls . iter_enumerated ( ) {
257- let ty = self . tcx . subst_and_normalize_erasing_regions (
258- instance. substs ,
259- ty:: ParamEnv :: reveal_all ( ) ,
260- mir. local_decls [ local] . ty ,
261- ) ;
262- let var_id = self . define_local ( entry_id, format ! ( "{:?}" , local) , ty) ;
263-
264- let location = place_location (
265- self ,
266- isa,
267- symbol,
268- & local_map,
269- & value_labels_ranges,
270- Place { local, projection : ty:: List :: empty ( ) } ,
271- ) ;
272-
273- let var_entry = self . dwarf . unit . get_mut ( var_id) ;
274- var_entry. set ( gimli:: DW_AT_location , location) ;
275- }
276- }
277-
278- // FIXME create locals for all entries in mir.var_debug_info
279- }
280- }
281-
282- fn place_location < ' tcx > (
283- debug_context : & mut DebugContext < ' tcx > ,
284- isa : & dyn TargetIsa ,
285- symbol : usize ,
286- local_map : & IndexVec < mir:: Local , CPlace < ' tcx > > ,
287- #[ allow( rustc:: default_hash_types) ] value_labels_ranges : & std:: collections:: HashMap <
288- ValueLabel ,
289- Vec < ValueLocRange > ,
290- > ,
291- place : Place < ' tcx > ,
292- ) -> AttributeValue {
293- assert ! ( place. projection. is_empty( ) ) ; // FIXME implement them
294-
295- match local_map[ place. local ] . inner ( ) {
296- CPlaceInner :: Var ( _local, var) => {
297- let value_label = cranelift_codegen:: ir:: ValueLabel :: new ( var. index ( ) ) ;
298- if let Some ( value_loc_ranges) = value_labels_ranges. get ( & value_label) {
299- let loc_list = LocationList (
300- value_loc_ranges
301- . iter ( )
302- . map ( |value_loc_range| Location :: StartEnd {
303- begin : Address :: Symbol {
304- symbol,
305- addend : i64:: from ( value_loc_range. start ) ,
306- } ,
307- end : Address :: Symbol { symbol, addend : i64:: from ( value_loc_range. end ) } ,
308- data : translate_loc ( isa, value_loc_range. loc ) . unwrap ( ) ,
309- } )
310- . collect ( ) ,
311- ) ;
312- let loc_list_id = debug_context. dwarf . unit . locations . add ( loc_list) ;
313-
314- AttributeValue :: LocationListRef ( loc_list_id)
315- } else {
316- // FIXME set value labels for unused locals
317-
318- AttributeValue :: Exprloc ( Expression :: new ( ) )
319- }
320- }
321- CPlaceInner :: VarPair ( _, _, _) => {
322- // FIXME implement this
323-
324- AttributeValue :: Exprloc ( Expression :: new ( ) )
325- }
326- CPlaceInner :: VarLane ( _, _, _) => {
327- // FIXME implement this
328-
329- AttributeValue :: Exprloc ( Expression :: new ( ) )
330- }
331- CPlaceInner :: Addr ( _, _) => {
332- // FIXME implement this (used by arguments and returns)
333-
334- AttributeValue :: Exprloc ( Expression :: new ( ) )
335-
336- // For PointerBase::Stack:
337- //AttributeValue::Exprloc(translate_loc(ValueLoc::Stack(*stack_slot)).unwrap())
338- }
339- }
340- }
341-
342- // Adapted from https://github.com/CraneStation/wasmtime/blob/5a1845b4caf7a5dba8eda1fef05213a532ed4259/crates/debug/src/transform/expression.rs#L59-L137
343- fn translate_loc ( isa : & dyn TargetIsa , loc : LabelValueLoc ) -> Option < Expression > {
344- match loc {
345- LabelValueLoc :: Reg ( reg) => {
346- let machine_reg = isa. map_regalloc_reg_to_dwarf ( reg) . unwrap ( ) ;
347- let mut expr = Expression :: new ( ) ;
348- expr. op_reg ( gimli:: Register ( machine_reg) ) ;
349- Some ( expr)
350- }
351- LabelValueLoc :: SPOffset ( offset) => {
352- let mut expr = Expression :: new ( ) ;
353- expr. op_breg ( X86_64 :: RSP , offset) ;
354- Some ( expr)
355- }
356134 }
357135}
0 commit comments