1+ // Copyright 2023 RISC Zero, Inc.
2+ //
3+ // Licensed under the Apache License, Version 2.0 (the "License");
4+ // you may not use this file except in compliance with the License.
5+ // You may obtain a copy of the License at
6+ //
7+ // http://www.apache.org/licenses/LICENSE-2.0
8+ //
9+ // Unless required by applicable law or agreed to in writing, software
10+ // distributed under the License is distributed on an "AS IS" BASIS,
11+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ // See the License for the specific language governing permissions and
13+ // limitations under the License.
14+
115use gecko_profile:: { Frame , ProfileBuilder , StringIndex , ThreadBuilder } ;
216use gimli:: {
317 AttributeValue , DW_AT_high_pc , DW_AT_ranges , DW_TAG_inlined_subroutine , DebugInfoOffset ,
@@ -336,7 +350,7 @@ impl<'a> InlineFunctionFrameBuilder<'a> {
336350 function_ranges : & mut Vec < ( u64 , u64 , Frame ) > ,
337351 start_lookup : & mut HashMap < u64 , Vec < usize > > ,
338352 ) -> Result < ( ) , ProfilerError > {
339- let name = self . get_abstract_origin_name ( unit, entry) ?;
353+ let name = self . abstract_origin_name ( unit, entry) ?;
340354
341355 let demangled_name = demangle ( & name) . to_string ( ) ;
342356
@@ -349,10 +363,10 @@ impl<'a> InlineFunctionFrameBuilder<'a> {
349363
350364 let mut ranges = vec ! [ ] ;
351365
352- if let Some ( range) = self . get_pc_range ( unit, entry) ? {
366+ if let Some ( range) = self . pc_range ( unit, entry) ? {
353367 ranges. push ( range) ;
354368 } else {
355- ranges. extend ( self . get_pc_ranges ( unit, entry) ?) ;
369+ ranges. extend ( self . pc_ranges ( unit, entry) ?) ;
356370 }
357371
358372 for ( low_pc, high_pc) in ranges {
@@ -369,12 +383,12 @@ impl<'a> InlineFunctionFrameBuilder<'a> {
369383 Ok ( ( ) )
370384 }
371385
372- fn get_pc_ranges (
386+ fn pc_ranges (
373387 & self ,
374388 unit : & Unit < EndianArcSlice < RunTimeEndian > > ,
375389 entry : & DebuggingInformationEntry < ' _ , ' _ , EndianArcSlice < RunTimeEndian > > ,
376390 ) -> Result < Vec < ( u64 , u64 ) > , gimli:: Error > {
377- let Ok ( value) = dwarf_attr ( entry, DW_AT_ranges ) else {
391+ let Ok ( value) = entry_attr ( entry, DW_AT_ranges ) else {
378392 return Ok ( vec ! [ ] ) ;
379393 } ;
380394
@@ -393,29 +407,25 @@ impl<'a> InlineFunctionFrameBuilder<'a> {
393407 Ok ( ranges)
394408 }
395409
396- fn get_pc_range (
410+ fn pc_range (
397411 & self ,
398412 unit : & Unit < EndianArcSlice < RunTimeEndian > > ,
399413 entry : & DebuggingInformationEntry < ' _ , ' _ , EndianArcSlice < RunTimeEndian > > ,
400414 ) -> Result < Option < ( u64 , u64 ) > , ProfilerError > {
401- let Some ( low_pc) = self . get_low_pc ( unit, entry) ? else {
415+ let Some ( low_pc) = self . low_pc ( unit, entry) ? else {
402416 return Ok ( None ) ;
403417 } ;
404- let high_pc = self . get_high_pc ( unit, entry, low_pc) ?;
418+ let high_pc = self . high_pc ( unit, entry, low_pc) ?;
405419
406420 Ok ( Some ( ( low_pc, high_pc) ) )
407421 }
408422
409- fn get_low_pc (
423+ fn low_pc (
410424 & self ,
411- unit : & gimli:: Unit < gimli:: EndianArcSlice < gimli:: RunTimeEndian > > ,
412- entry : & gimli:: DebuggingInformationEntry <
413- ' _ ,
414- ' _ ,
415- gimli:: EndianArcSlice < gimli:: RunTimeEndian > ,
416- > ,
425+ unit : & Unit < EndianArcSlice < RunTimeEndian > > ,
426+ entry : & DebuggingInformationEntry < ' _ , ' _ , EndianArcSlice < RunTimeEndian > > ,
417427 ) -> Result < Option < u64 > , ProfilerError > {
418- let Ok ( value) = dwarf_attr ( entry, gimli:: DW_AT_low_pc ) else {
428+ let Ok ( value) = entry_attr ( entry, gimli:: DW_AT_low_pc ) else {
419429 return Ok ( None ) ;
420430 } ;
421431 let low_pc = match value {
@@ -426,35 +436,35 @@ impl<'a> InlineFunctionFrameBuilder<'a> {
426436 Ok ( ( low_pc != 0 ) . then_some ( low_pc) )
427437 }
428438
429- fn get_high_pc (
439+ fn high_pc (
430440 & self ,
431441 unit : & Unit < EndianArcSlice < RunTimeEndian > > ,
432442 entry : & DebuggingInformationEntry < ' _ , ' _ , EndianArcSlice < RunTimeEndian > > ,
433443 low_pc : u64 ,
434444 ) -> Result < u64 , ProfilerError > {
435- match dwarf_attr ( entry, DW_AT_high_pc ) ? {
445+ match entry_attr ( entry, DW_AT_high_pc ) ? {
436446 AttributeValue :: Addr ( val) => Ok ( val) ,
437447 AttributeValue :: DebugAddrIndex ( index) => Ok ( self . dwarf . address ( unit, index) ?) ,
438448 AttributeValue :: Udata ( val) => Ok ( low_pc + val) ,
439449 _ => Err ( ProfilerError :: UnexpectedAbstractOrigin ) ,
440450 }
441451 }
442452
443- fn get_abstract_origin_name (
453+ fn abstract_origin_name (
444454 & self ,
445455 unit : & Unit < EndianArcSlice < RunTimeEndian > > ,
446456 entry : & DebuggingInformationEntry < ' _ , ' _ , EndianArcSlice < RunTimeEndian > > ,
447457 ) -> Result < String , ProfilerError > {
448- match dwarf_attr ( entry, gimli:: DW_AT_abstract_origin ) ? {
458+ match entry_attr ( entry, gimli:: DW_AT_abstract_origin ) ? {
449459 gimli:: AttributeValue :: UnitRef ( unit_offset) => {
450- Ok ( get_abstract_origin_name ( self . dwarf , unit, unit_offset) ?)
460+ Ok ( abstract_origin_name ( self . dwarf , unit, unit_offset) ?)
451461 }
452462 gimli:: AttributeValue :: DebugInfoRef ( debug_info_offset) => {
453463 let unit = find_unit ( self . units . as_slice ( ) , debug_info_offset) ?;
454464 let unit_offset = debug_info_offset
455465 . to_unit_offset ( & unit. header )
456466 . ok_or ( ProfilerError :: InvalidAttributeAbstractOrigin ) ?;
457- Ok ( get_abstract_origin_name ( self . dwarf , unit, unit_offset) ?)
467+ Ok ( abstract_origin_name ( self . dwarf , unit, unit_offset) ?)
458468 }
459469 _ => Err ( ProfilerError :: UnexpectedAbstractOrigin ) ,
460470 }
@@ -486,14 +496,14 @@ fn load_section(
486496 EndianArcSlice :: new ( Arc :: from ( & * data) , endian)
487497}
488498
489- fn dwarf_attr < ReaderT : Reader > (
499+ fn entry_attr < ReaderT : Reader > (
490500 entry : & DebuggingInformationEntry < ' _ , ' _ , ReaderT > ,
491501 dw_at : DwAt ,
492502) -> Result < AttributeValue < ReaderT > , ProfilerError > {
493503 Ok ( entry. attr ( dw_at) ?. ok_or ( ProfilerError :: DwAtMissing ( dw_at) ) ?. value ( ) )
494504}
495505
496- fn get_abstract_origin_name (
506+ fn abstract_origin_name (
497507 dwarf : & Dwarf < EndianArcSlice < RunTimeEndian > > ,
498508 unit : & Unit < EndianArcSlice < RunTimeEndian > > ,
499509 abstract_origin : UnitOffset < usize > ,
0 commit comments