@@ -10,7 +10,7 @@ use super::{TransformError, dbi_log};
1010use anyhow:: { Error , bail} ;
1111use cranelift_codegen:: isa:: TargetIsa ;
1212use gimli:: {
13- AttributeValue , DebugLineOffset , DebuggingInformationEntry , Dwarf , Unit , UnitOffset , write,
13+ AttributeValue , DebugLineOffset , DebuggingInformationEntry , UnitOffset , UnitRef , write,
1414} ;
1515
1616#[ derive( Debug ) ]
@@ -47,10 +47,9 @@ fn is_exprloc_to_loclist_allowed(attr_name: gimli::constants::DwAt) -> bool {
4747}
4848
4949pub ( crate ) fn clone_die_attributes < ' a > (
50- dwarf : & gimli:: Dwarf < Reader < ' a > > ,
51- unit : & Unit < Reader < ' a > > ,
50+ unit : UnitRef < Reader < ' a > > ,
5251 entry : & DebuggingInformationEntry < Reader < ' a > > ,
53- addr_tr : & ' a AddressTransform ,
52+ addr_tr : & AddressTransform ,
5453 frame_info : Option < & FunctionFrameInfo > ,
5554 out_unit : & mut write:: Unit ,
5655 out_entry_id : write:: UnitEntryId ,
@@ -59,7 +58,7 @@ pub(crate) fn clone_die_attributes<'a>(
5958 out_strings : & mut write:: StringTable ,
6059 pending_die_refs : & mut PendingUnitRefs ,
6160 pending_di_refs : & mut PendingDebugInfoRefs ,
62- mut attr_context : EntryAttributesContext < ' a > ,
61+ mut attr_context : EntryAttributesContext < ' _ > ,
6362 isa : & dyn TargetIsa ,
6463) -> Result < ( ) , Error > {
6564 let unit_encoding = unit. encoding ( ) ;
@@ -70,12 +69,12 @@ pub(crate) fn clone_die_attributes<'a>(
7069 // FIXME for CU: currently address_transform operate on a single
7170 // function range, and when CU spans multiple ranges the
7271 // transformation may be incomplete.
73- RangeInfoBuilder :: from ( dwarf , unit, entry) ?
72+ RangeInfoBuilder :: from ( unit, entry) ?
7473 } ;
7574 range_info. build ( addr_tr, out_unit, out_entry_id) ;
7675
7776 let mut is_obj_ptr = false ;
78- prepare_die_context ( dwarf , unit, entry, & mut attr_context, & mut is_obj_ptr) ?;
77+ prepare_die_context ( unit, entry, & mut attr_context, & mut is_obj_ptr) ?;
7978
8079 let mut attrs = entry. attrs ( ) ;
8180 while let Some ( attr) = attrs. next ( ) ? {
@@ -133,7 +132,7 @@ pub(crate) fn clone_die_attributes<'a>(
133132 continue ;
134133 }
135134 gimli:: DW_AT_name => {
136- let old_name: & str = & dwarf . attr_string ( unit , attr. value ( ) ) ?. to_string_lossy ( ) ;
135+ let old_name: & str = & unit . attr_string ( attr. value ( ) ) ?. to_string_lossy ( ) ;
137136 let new_name = format ! ( "__{old_name}" ) ;
138137 dbi_log ! (
139138 "Object pointer: renamed '{}' -> '{}'" ,
@@ -158,7 +157,7 @@ pub(crate) fn clone_die_attributes<'a>(
158157 write:: AttributeValue :: Address ( addr)
159158 }
160159 AttributeValue :: DebugAddrIndex ( i) => {
161- let u = dwarf . address ( unit , i) ?;
160+ let u = unit . address ( i) ?;
162161 let addr = addr_tr. translate ( u) . unwrap_or ( write:: Address :: Constant ( 0 ) ) ;
163162 write:: AttributeValue :: Address ( addr)
164163 }
@@ -202,28 +201,18 @@ pub(crate) fn clone_die_attributes<'a>(
202201 }
203202 AttributeValue :: String ( d) => write:: AttributeValue :: String ( d. to_vec ( ) ) ,
204203 AttributeValue :: DebugStrRef ( _) | AttributeValue :: DebugStrOffsetsIndex ( _) => {
205- let s = dwarf
206- . attr_string ( unit, attr_value) ?
207- . to_string_lossy ( )
208- . into_owned ( ) ;
204+ let s = unit. attr_string ( attr_value) ?. to_vec ( ) ;
209205 write:: AttributeValue :: StringRef ( out_strings. add ( s) )
210206 }
211207 AttributeValue :: RangeListsRef ( _) | AttributeValue :: DebugRngListsIndex ( _) => {
212- let r = dwarf . attr_ranges_offset ( unit , attr_value) ?. unwrap ( ) ;
213- let range_info = RangeInfoBuilder :: from_ranges_ref ( dwarf , unit, r) ?;
208+ let r = unit . attr_ranges_offset ( attr_value) ?. unwrap ( ) ;
209+ let range_info = RangeInfoBuilder :: from_ranges_ref ( unit, r) ?;
214210 let range_list_id = range_info. build_ranges ( addr_tr, & mut out_unit. ranges ) ;
215211 write:: AttributeValue :: RangeListRef ( range_list_id)
216212 }
217213 AttributeValue :: LocationListsRef ( _) | AttributeValue :: DebugLocListsIndex ( _) => {
218- let r = dwarf. attr_locations_offset ( unit, attr_value) ?. unwrap ( ) ;
219- let low_pc = 0 ;
220- let mut locs = dwarf. locations . locations (
221- r,
222- unit_encoding,
223- low_pc,
224- & dwarf. debug_addr ,
225- unit. addr_base ,
226- ) ?;
214+ let r = unit. attr_locations_offset ( attr_value) ?. unwrap ( ) ;
215+ let mut locs = unit. locations ( r) ?;
227216 let frame_base =
228217 if let EntryAttributesContext :: Children { frame_base, .. } = attr_context {
229218 frame_base
@@ -373,10 +362,9 @@ pub(crate) fn clone_die_attributes<'a>(
373362 Ok ( ( ) )
374363}
375364
376- fn prepare_die_context (
377- dwarf : & Dwarf < Reader < ' _ > > ,
378- unit : & Unit < Reader < ' _ > > ,
379- entry : & DebuggingInformationEntry < Reader < ' _ > > ,
365+ fn prepare_die_context < ' a > (
366+ unit : UnitRef < Reader < ' a > > ,
367+ entry : & DebuggingInformationEntry < Reader < ' a > > ,
380368 attr_context : & mut EntryAttributesContext < ' _ > ,
381369 is_obj_ptr : & mut bool ,
382370) -> Result < ( ) , Error > {
@@ -407,7 +395,7 @@ fn prepare_die_context(
407395 subprogram. param_num += 1 ;
408396
409397 if subprogram. obj_ptr == entry. offset ( )
410- || is_obj_ptr_param ( dwarf , unit, entry, subprogram. param_num ) ?
398+ || is_obj_ptr_param ( unit, entry, subprogram. param_num ) ?
411399 {
412400 * is_obj_ptr = true ;
413401 }
@@ -418,10 +406,9 @@ fn prepare_die_context(
418406 Ok ( ( ) )
419407}
420408
421- fn is_obj_ptr_param (
422- dwarf : & Dwarf < Reader < ' _ > > ,
423- unit : & Unit < Reader < ' _ > > ,
424- entry : & DebuggingInformationEntry < Reader < ' _ > > ,
409+ fn is_obj_ptr_param < ' a > (
410+ unit : UnitRef < Reader < ' a > > ,
411+ entry : & DebuggingInformationEntry < Reader < ' a > > ,
425412 param_num : isize ,
426413) -> Result < bool , Error > {
427414 debug_assert ! ( entry. tag( ) == gimli:: DW_TAG_formal_parameter ) ;
@@ -437,7 +424,7 @@ fn is_obj_ptr_param(
437424 {
438425 // Either this has no name (declarations omit them), or its explicitly "this".
439426 let name = entry. attr_value ( gimli:: DW_AT_name ) ?;
440- if name. is_none ( ) || dwarf . attr_string ( unit , name. unwrap ( ) ) ?. slice ( ) . eq ( b"this" ) {
427+ if name. is_none ( ) || unit . attr_string ( name. unwrap ( ) ) ?. slice ( ) . eq ( b"this" ) {
441428 // Finally, a type check. We expect a pointer.
442429 if let Some ( type_attr) = entry. attr_value ( gimli:: DW_AT_type ) ? {
443430 if let Some ( type_die) = resolve_die_ref ( unit, & type_attr) ? {
0 commit comments