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
+
1
15
use gecko_profile:: { Frame , ProfileBuilder , StringIndex , ThreadBuilder } ;
2
16
use gimli:: {
3
17
AttributeValue , DW_AT_high_pc , DW_AT_ranges , DW_TAG_inlined_subroutine , DebugInfoOffset ,
@@ -336,7 +350,7 @@ impl<'a> InlineFunctionFrameBuilder<'a> {
336
350
function_ranges : & mut Vec < ( u64 , u64 , Frame ) > ,
337
351
start_lookup : & mut HashMap < u64 , Vec < usize > > ,
338
352
) -> Result < ( ) , ProfilerError > {
339
- let name = self . get_abstract_origin_name ( unit, entry) ?;
353
+ let name = self . abstract_origin_name ( unit, entry) ?;
340
354
341
355
let demangled_name = demangle ( & name) . to_string ( ) ;
342
356
@@ -349,10 +363,10 @@ impl<'a> InlineFunctionFrameBuilder<'a> {
349
363
350
364
let mut ranges = vec ! [ ] ;
351
365
352
- if let Some ( range) = self . get_pc_range ( unit, entry) ? {
366
+ if let Some ( range) = self . pc_range ( unit, entry) ? {
353
367
ranges. push ( range) ;
354
368
} else {
355
- ranges. extend ( self . get_pc_ranges ( unit, entry) ?) ;
369
+ ranges. extend ( self . pc_ranges ( unit, entry) ?) ;
356
370
}
357
371
358
372
for ( low_pc, high_pc) in ranges {
@@ -369,12 +383,12 @@ impl<'a> InlineFunctionFrameBuilder<'a> {
369
383
Ok ( ( ) )
370
384
}
371
385
372
- fn get_pc_ranges (
386
+ fn pc_ranges (
373
387
& self ,
374
388
unit : & Unit < EndianArcSlice < RunTimeEndian > > ,
375
389
entry : & DebuggingInformationEntry < ' _ , ' _ , EndianArcSlice < RunTimeEndian > > ,
376
390
) -> 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 {
378
392
return Ok ( vec ! [ ] ) ;
379
393
} ;
380
394
@@ -393,29 +407,25 @@ impl<'a> InlineFunctionFrameBuilder<'a> {
393
407
Ok ( ranges)
394
408
}
395
409
396
- fn get_pc_range (
410
+ fn pc_range (
397
411
& self ,
398
412
unit : & Unit < EndianArcSlice < RunTimeEndian > > ,
399
413
entry : & DebuggingInformationEntry < ' _ , ' _ , EndianArcSlice < RunTimeEndian > > ,
400
414
) -> 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 {
402
416
return Ok ( None ) ;
403
417
} ;
404
- let high_pc = self . get_high_pc ( unit, entry, low_pc) ?;
418
+ let high_pc = self . high_pc ( unit, entry, low_pc) ?;
405
419
406
420
Ok ( Some ( ( low_pc, high_pc) ) )
407
421
}
408
422
409
- fn get_low_pc (
423
+ fn low_pc (
410
424
& 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 > > ,
417
427
) -> 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 {
419
429
return Ok ( None ) ;
420
430
} ;
421
431
let low_pc = match value {
@@ -426,35 +436,35 @@ impl<'a> InlineFunctionFrameBuilder<'a> {
426
436
Ok ( ( low_pc != 0 ) . then_some ( low_pc) )
427
437
}
428
438
429
- fn get_high_pc (
439
+ fn high_pc (
430
440
& self ,
431
441
unit : & Unit < EndianArcSlice < RunTimeEndian > > ,
432
442
entry : & DebuggingInformationEntry < ' _ , ' _ , EndianArcSlice < RunTimeEndian > > ,
433
443
low_pc : u64 ,
434
444
) -> Result < u64 , ProfilerError > {
435
- match dwarf_attr ( entry, DW_AT_high_pc ) ? {
445
+ match entry_attr ( entry, DW_AT_high_pc ) ? {
436
446
AttributeValue :: Addr ( val) => Ok ( val) ,
437
447
AttributeValue :: DebugAddrIndex ( index) => Ok ( self . dwarf . address ( unit, index) ?) ,
438
448
AttributeValue :: Udata ( val) => Ok ( low_pc + val) ,
439
449
_ => Err ( ProfilerError :: UnexpectedAbstractOrigin ) ,
440
450
}
441
451
}
442
452
443
- fn get_abstract_origin_name (
453
+ fn abstract_origin_name (
444
454
& self ,
445
455
unit : & Unit < EndianArcSlice < RunTimeEndian > > ,
446
456
entry : & DebuggingInformationEntry < ' _ , ' _ , EndianArcSlice < RunTimeEndian > > ,
447
457
) -> Result < String , ProfilerError > {
448
- match dwarf_attr ( entry, gimli:: DW_AT_abstract_origin ) ? {
458
+ match entry_attr ( entry, gimli:: DW_AT_abstract_origin ) ? {
449
459
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) ?)
451
461
}
452
462
gimli:: AttributeValue :: DebugInfoRef ( debug_info_offset) => {
453
463
let unit = find_unit ( self . units . as_slice ( ) , debug_info_offset) ?;
454
464
let unit_offset = debug_info_offset
455
465
. to_unit_offset ( & unit. header )
456
466
. 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) ?)
458
468
}
459
469
_ => Err ( ProfilerError :: UnexpectedAbstractOrigin ) ,
460
470
}
@@ -486,14 +496,14 @@ fn load_section(
486
496
EndianArcSlice :: new ( Arc :: from ( & * data) , endian)
487
497
}
488
498
489
- fn dwarf_attr < ReaderT : Reader > (
499
+ fn entry_attr < ReaderT : Reader > (
490
500
entry : & DebuggingInformationEntry < ' _ , ' _ , ReaderT > ,
491
501
dw_at : DwAt ,
492
502
) -> Result < AttributeValue < ReaderT > , ProfilerError > {
493
503
Ok ( entry. attr ( dw_at) ?. ok_or ( ProfilerError :: DwAtMissing ( dw_at) ) ?. value ( ) )
494
504
}
495
505
496
- fn get_abstract_origin_name (
506
+ fn abstract_origin_name (
497
507
dwarf : & Dwarf < EndianArcSlice < RunTimeEndian > > ,
498
508
unit : & Unit < EndianArcSlice < RunTimeEndian > > ,
499
509
abstract_origin : UnitOffset < usize > ,
0 commit comments