MCPcopy Create free account
hub / github.com/Rust-for-Linux/klint / ranges

Method ranges

src/binary_analysis/dwarf.rs:361–434  ·  view source on GitHub ↗

Obtain PC ranges related to a DIE.

(
        &self,
        unit: &Unit<ReaderTy<'_>>,
        die: &DebuggingInformationEntry<ReaderTy<'_>>,
    )

Source from the content-addressed store, hash-verified

359
360 /// Obtain PC ranges related to a DIE.
361 fn ranges(
362 &self,
363 unit: &Unit<ReaderTy<'_>>,
364 die: &DebuggingInformationEntry<ReaderTy<'_>>,
365 ) -> Result<(SectionIndex, Vec<Range<i64>>), Error> {
366 let mut ranges = Vec::new();
367
368 for attr in die.attrs() {
369 match attr.name() {
370 gimli::DW_AT_low_pc => {
371 let Some(low_pc) = self.dwarf().attr_address(unit, attr.value())? else {
372 Err(Error::UnexpectedDwarf("DW_AT_low_pc is not an address"))?
373 };
374
375 let Some(high_pc) = die.attr_value(gimli::DW_AT_high_pc) else {
376 Err(Error::UnexpectedDwarf(
377 "DW_AT_high_pc not found at DW_TAG_inlined_subroutine",
378 ))?
379 };
380
381 let Some(high_pc) = high_pc.udata_value() else {
382 Err(Error::UnexpectedDwarf("DW_AT_high_pc is not udata"))?
383 };
384
385 ranges.push((low_pc, high_pc));
386 }
387
388 // This is handled by DW_AT_low_pc.
389 gimli::DW_AT_high_pc => (),
390
391 gimli::DW_AT_ranges => {
392 let offset = match attr.value() {
393 AttributeValue::DebugRngListsIndex(offset) => {
394 self.dwarf().ranges_offset(unit, offset)?
395 }
396 AttributeValue::RangeListsRef(offset) => {
397 self.dwarf().ranges_offset_from_raw(unit, offset)
398 }
399 _ => Err(Error::UnexpectedDwarf(
400 "DW_AT_ranges is not rnglist reference",
401 ))?,
402 };
403 let mut range = self.dwarf().ranges(unit, offset)?;
404 while let Some(range) = range.next()? {
405 ranges.push((range.begin, range.end.wrapping_sub(range.begin)));
406 }
407 }
408
409 _ => (),
410 }
411 }
412
413 if ranges.is_empty() {
414 return Ok((SectionIndex(0), Vec::new()));
415 }
416
417 let encoded_section = self.section_layout.decode(ranges[0].0)?.0;
418

Callers 1

inline_infoMethod · 0.80

Calls 8

nameMethod · 0.80
dwarfMethod · 0.80
pushMethod · 0.80
nextMethod · 0.80
decodeMethod · 0.80
mapMethod · 0.80
into_iterMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected