LCOV - code coverage report
Current view: top level - lib/DebugInfo/DWARF - DWARFDebugRangeList.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 46 46 100.0 %
Date: 2017-09-14 15:23:50 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/Format.h"
      13             : #include "llvm/Support/raw_ostream.h"
      14             : #include <cinttypes>
      15             : #include <cstdint>
      16             : #include <utility>
      17             : 
      18             : using namespace llvm;
      19             : 
      20      230233 : void DWARFDebugRangeList::clear() {
      21      230233 :   Offset = -1U;
      22      230233 :   AddressSize = 0;
      23      460466 :   Entries.clear();
      24      230233 : }
      25             : 
      26      115077 : bool DWARFDebugRangeList::extract(const DWARFDataExtractor &data,
      27             :                                   uint32_t *offset_ptr) {
      28      115077 :   clear();
      29      230154 :   if (!data.isValidOffset(*offset_ptr))
      30             :     return false;
      31      114908 :   AddressSize = data.getAddressSize();
      32      114908 :   if (AddressSize != 4 && AddressSize != 8)
      33             :     return false;
      34      114907 :   Offset = *offset_ptr;
      35             :   while (true) {
      36             :     RangeListEntry Entry;
      37     1897189 :     Entry.SectionIndex = -1ULL;
      38             : 
      39     1897189 :     uint32_t prev_offset = *offset_ptr;
      40     1897189 :     Entry.StartAddress = data.getRelocatedAddress(offset_ptr);
      41     1897189 :     Entry.EndAddress =
      42     1897189 :         data.getRelocatedAddress(offset_ptr, &Entry.SectionIndex);
      43             : 
      44             :     // Check that both values were extracted correctly.
      45     1897189 :     if (*offset_ptr != prev_offset + 2 * AddressSize) {
      46           1 :       clear();
      47           1 :       return false;
      48             :     }
      49     1897188 :     if (Entry.isEndOfListEntry())
      50             :       break;
      51     1782282 :     Entries.push_back(Entry);
      52     1782282 :   }
      53      114906 :   return true;
      54             : }
      55             : 
      56          31 : void DWARFDebugRangeList::dump(raw_ostream &OS) const {
      57         216 :   for (const RangeListEntry &RLE : Entries) {
      58         184 :     const char *format_str = (AddressSize == 4
      59          92 :                               ? "%08x %08"  PRIx64 " %08"  PRIx64 "\n"
      60             :                               : "%08x %016" PRIx64 " %016" PRIx64 "\n");
      61         184 :     OS << format(format_str, Offset, RLE.StartAddress, RLE.EndAddress);
      62             :   }
      63          62 :   OS << format("%08x <End of list>\n", Offset);
      64          31 : }
      65             : 
      66      114867 : DWARFAddressRangesVector DWARFDebugRangeList::getAbsoluteRanges(
      67             :     llvm::Optional<BaseAddress> BaseAddr) const {
      68      114867 :   DWARFAddressRangesVector Res;
      69     2241642 :   for (const RangeListEntry &RLE : Entries) {
      70     3564356 :     if (RLE.isBaseAddressSelectionEntry(AddressSize)) {
      71          16 :       BaseAddr = {RLE.EndAddress, RLE.SectionIndex};
      72           8 :       continue;
      73             :     }
      74             : 
      75             :     DWARFAddressRange E;
      76     1782166 :     E.LowPC = RLE.StartAddress;
      77     1782166 :     E.HighPC = RLE.EndAddress;
      78     1782166 :     E.SectionIndex = RLE.SectionIndex;
      79             :     // Base address of a range list entry is determined by the closest preceding
      80             :     // base address selection entry in the same range list. It defaults to the
      81             :     // base address of the compilation unit if there is no such entry.
      82     1782166 :     if (BaseAddr) {
      83     1782163 :       E.LowPC += BaseAddr->Address;
      84     1782163 :       E.HighPC += BaseAddr->Address;
      85     1782163 :       if (E.SectionIndex == -1ULL)
      86     1782102 :         E.SectionIndex = BaseAddr->SectionIndex;
      87             :     }
      88     1782166 :     Res.push_back(E);
      89             :   }
      90      114867 :   return Res;
      91             : }

Generated by: LCOV version 1.13