LLVM  7.0.0svn
DWARFDebugRangeList.cpp
Go to the documentation of this file.
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 
12 #include "llvm/Support/Format.h"
14 #include <cinttypes>
15 #include <cstdint>
16 
17 using namespace llvm;
18 
20  Offset = -1U;
21  AddressSize = 0;
22  Entries.clear();
23 }
24 
26  uint32_t *offset_ptr) {
27  clear();
28  if (!data.isValidOffset(*offset_ptr))
29  return false;
30  AddressSize = data.getAddressSize();
31  if (AddressSize != 4 && AddressSize != 8)
32  return false;
33  Offset = *offset_ptr;
34  while (true) {
35  RangeListEntry Entry;
36  Entry.SectionIndex = -1ULL;
37 
38  uint32_t prev_offset = *offset_ptr;
39  Entry.StartAddress = data.getRelocatedAddress(offset_ptr);
40  Entry.EndAddress =
41  data.getRelocatedAddress(offset_ptr, &Entry.SectionIndex);
42 
43  // Check that both values were extracted correctly.
44  if (*offset_ptr != prev_offset + 2 * AddressSize) {
45  clear();
46  return false;
47  }
48  if (Entry.isEndOfListEntry())
49  break;
50  Entries.push_back(Entry);
51  }
52  return true;
53 }
54 
56  for (const RangeListEntry &RLE : Entries) {
57  const char *format_str = (AddressSize == 4
58  ? "%08x %08" PRIx64 " %08" PRIx64 "\n"
59  : "%08x %016" PRIx64 " %016" PRIx64 "\n");
60  OS << format(format_str, Offset, RLE.StartAddress, RLE.EndAddress);
61  }
62  OS << format("%08x <End of list>\n", Offset);
63 }
64 
66  llvm::Optional<BaseAddress> BaseAddr) const {
68  for (const RangeListEntry &RLE : Entries) {
69  if (RLE.isBaseAddressSelectionEntry(AddressSize)) {
70  BaseAddr = {RLE.EndAddress, RLE.SectionIndex};
71  continue;
72  }
73 
75  E.LowPC = RLE.StartAddress;
76  E.HighPC = RLE.EndAddress;
77  E.SectionIndex = RLE.SectionIndex;
78  // Base address of a range list entry is determined by the closest preceding
79  // base address selection entry in the same range list. It defaults to the
80  // base address of the compilation unit if there is no such entry.
81  if (BaseAddr) {
82  E.LowPC += BaseAddr->Address;
83  E.HighPC += BaseAddr->Address;
84  if (E.SectionIndex == -1ULL)
85  E.SectionIndex = BaseAddr->SectionIndex;
86  }
87  Res.push_back(E);
88  }
89  return Res;
90 }
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
uint64_t SectionIndex
A section index this range belongs to.
void dump(raw_ostream &OS) const
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
uint64_t getRelocatedAddress(uint32_t *Off, uint64_t *SecIx=nullptr) const
Extracts an address-sized value and applies a relocation to the result if one exists for the given of...
uint64_t Address
Definition: DWARFUnit.h:164
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
uint8_t getAddressSize() const
Get the address size for this extractor.
Definition: DataExtractor.h:59
DWARFAddressRangesVector getAbsoluteRanges(llvm::Optional< BaseAddress > BaseAddr) const
getAbsoluteRanges - Returns absolute address ranges defined by this range list.
uint64_t SectionIndex
Definition: DWARFUnit.h:165
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
uint64_t EndAddress
An ending address offset.
bool isEndOfListEntry() const
The end of any given range list is marked by an end of list entry, which consists of a 0 for the begi...
bool isValidOffset(uint32_t offset) const
Test the validity of offset.
std::vector< DWARFAddressRange > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
uint64_t StartAddress
A beginning address offset.
bool extract(const DWARFDataExtractor &data, uint32_t *offset_ptr)