LLVM  5.0.0
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 #include <utility>
17 
18 using namespace llvm;
19 
21  Offset = -1U;
22  AddressSize = 0;
23  Entries.clear();
24 }
25 
27  uint32_t *offset_ptr) {
28  clear();
29  if (!data.isValidOffset(*offset_ptr))
30  return false;
31  AddressSize = data.getAddressSize();
32  if (AddressSize != 4 && AddressSize != 8)
33  return false;
34  Offset = *offset_ptr;
35  while (true) {
36  RangeListEntry entry;
37  uint32_t prev_offset = *offset_ptr;
38  entry.StartAddress =
39  data.getRelocatedAddress(offset_ptr, &entry.SectionIndex);
40  entry.EndAddress = data.getRelocatedAddress(offset_ptr);
41 
42  // Check that both values were extracted correctly.
43  if (*offset_ptr != prev_offset + 2 * AddressSize) {
44  clear();
45  return false;
46  }
47  if (entry.isEndOfListEntry())
48  break;
49  Entries.push_back(entry);
50  }
51  return true;
52 }
53 
55  for (const RangeListEntry &RLE : Entries) {
56  const char *format_str = (AddressSize == 4
57  ? "%08x %08" PRIx64 " %08" PRIx64 "\n"
58  : "%08x %016" PRIx64 " %016" PRIx64 "\n");
59  OS << format(format_str, Offset, RLE.StartAddress, RLE.EndAddress);
60  }
61  OS << format("%08x <End of list>\n", Offset);
62 }
63 
65 DWARFDebugRangeList::getAbsoluteRanges(uint64_t BaseAddress) const {
67  for (const RangeListEntry &RLE : Entries) {
68  if (RLE.isBaseAddressSelectionEntry(AddressSize)) {
69  BaseAddress = RLE.EndAddress;
70  } else {
71  Res.push_back({BaseAddress + RLE.StartAddress,
72  BaseAddress + RLE.EndAddress, RLE.SectionIndex});
73  }
74  }
75  return Res;
76 }
uint64_t SectionIndex
A section index this range belongs to.
uint8_t getAddressSize() const
Get the address size for this extractor.
Definition: DataExtractor.h:59
bool isValidOffset(uint32_t offset) const
Test the validity of 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...
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...
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
DWARFAddressRangesVector getAbsoluteRanges(uint64_t BaseAddress) const
getAbsoluteRanges - Returns absolute address ranges defined by this range list.
void dump(raw_ostream &OS) const
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.
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)