LCOV - code coverage report
Current view: top level - lib/DebugInfo/DWARF - DWARFDebugRangeList.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 43 44 97.7 %
Date: 2018-10-20 13:21:21 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- DWARFDebugRangesList.cpp -------------------------------------------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : 
      10             : #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
      11             : #include "llvm/DebugInfo/DWARF/DWARFContext.h"
      12             : #include "llvm/Support/Errc.h"
      13             : #include "llvm/Support/Format.h"
      14             : #include "llvm/Support/raw_ostream.h"
      15             : #include <cinttypes>
      16             : #include <cstdint>
      17             : 
      18             : using namespace llvm;
      19             : 
      20        2590 : void DWARFDebugRangeList::clear() {
      21        2590 :   Offset = -1U;
      22        2590 :   AddressSize = 0;
      23             :   Entries.clear();
      24        2590 : }
      25             : 
      26        1210 : Error DWARFDebugRangeList::extract(const DWARFDataExtractor &data,
      27             :                                    uint32_t *offset_ptr) {
      28        1210 :   clear();
      29        2420 :   if (!data.isValidOffset(*offset_ptr))
      30             :     return createStringError(errc::invalid_argument,
      31           3 :                        "invalid range list offset 0x%" PRIx32, *offset_ptr);
      32             : 
      33        1207 :   AddressSize = data.getAddressSize();
      34        1207 :   if (AddressSize != 4 && AddressSize != 8)
      35             :     return createStringError(errc::invalid_argument,
      36           0 :                        "invalid address size: %" PRIu8, AddressSize);
      37        1207 :   Offset = *offset_ptr;
      38             :   while (true) {
      39             :     RangeListEntry Entry;
      40        7798 :     Entry.SectionIndex = -1ULL;
      41             : 
      42        7798 :     uint32_t prev_offset = *offset_ptr;
      43        7798 :     Entry.StartAddress = data.getRelocatedAddress(offset_ptr);
      44        7798 :     Entry.EndAddress =
      45             :         data.getRelocatedAddress(offset_ptr, &Entry.SectionIndex);
      46             : 
      47             :     // Check that both values were extracted correctly.
      48        7798 :     if (*offset_ptr != prev_offset + 2 * AddressSize) {
      49           3 :       clear();
      50             :       return createStringError(errc::invalid_argument,
      51             :                          "invalid range list entry at offset 0x%" PRIx32,
      52           3 :                          prev_offset);
      53             :     }
      54        7795 :     if (Entry.isEndOfListEntry())
      55             :       break;
      56        6591 :     Entries.push_back(Entry);
      57        6591 :   }
      58             :   return Error::success();
      59             : }
      60             : 
      61          32 : void DWARFDebugRangeList::dump(raw_ostream &OS) const {
      62         128 :   for (const RangeListEntry &RLE : Entries) {
      63          96 :     const char *format_str = (AddressSize == 4
      64          96 :                               ? "%08x %08"  PRIx64 " %08"  PRIx64 "\n"
      65             :                               : "%08x %016" PRIx64 " %016" PRIx64 "\n");
      66         192 :     OS << format(format_str, Offset, RLE.StartAddress, RLE.EndAddress);
      67             :   }
      68          64 :   OS << format("%08x <End of list>\n", Offset);
      69          32 : }
      70             : 
      71        1160 : DWARFAddressRangesVector DWARFDebugRangeList::getAbsoluteRanges(
      72             :     llvm::Optional<BaseAddress> BaseAddr) const {
      73             :   DWARFAddressRangesVector Res;
      74        7631 :   for (const RangeListEntry &RLE : Entries) {
      75       12942 :     if (RLE.isBaseAddressSelectionEntry(AddressSize)) {
      76           6 :       BaseAddr = {RLE.EndAddress, RLE.SectionIndex};
      77           6 :       continue;
      78             :     }
      79             : 
      80             :     DWARFAddressRange E;
      81        6465 :     E.LowPC = RLE.StartAddress;
      82        6465 :     E.HighPC = RLE.EndAddress;
      83        6465 :     E.SectionIndex = RLE.SectionIndex;
      84             :     // Base address of a range list entry is determined by the closest preceding
      85             :     // base address selection entry in the same range list. It defaults to the
      86             :     // base address of the compilation unit if there is no such entry.
      87        6465 :     if (BaseAddr) {
      88        6460 :       E.LowPC += BaseAddr->Address;
      89        6460 :       E.HighPC += BaseAddr->Address;
      90        6460 :       if (E.SectionIndex == -1ULL)
      91        6398 :         E.SectionIndex = BaseAddr->SectionIndex;
      92             :     }
      93        6465 :     Res.push_back(E);
      94             :   }
      95        1160 :   return Res;
      96             : }

Generated by: LCOV version 1.13