LLVM  3.7.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 
11 #include "llvm/Support/Format.h"
13 
14 using namespace llvm;
15 
17  Offset = -1U;
18  AddressSize = 0;
19  Entries.clear();
20 }
21 
22 bool DWARFDebugRangeList::extract(DataExtractor data, uint32_t *offset_ptr) {
23  clear();
24  if (!data.isValidOffset(*offset_ptr))
25  return false;
26  AddressSize = data.getAddressSize();
27  if (AddressSize != 4 && AddressSize != 8)
28  return false;
29  Offset = *offset_ptr;
30  while (true) {
31  RangeListEntry entry;
32  uint32_t prev_offset = *offset_ptr;
33  entry.StartAddress = data.getAddress(offset_ptr);
34  entry.EndAddress = data.getAddress(offset_ptr);
35  // Check that both values were extracted correctly.
36  if (*offset_ptr != prev_offset + 2 * AddressSize) {
37  clear();
38  return false;
39  }
40  if (entry.isEndOfListEntry())
41  break;
42  Entries.push_back(entry);
43  }
44  return true;
45 }
46 
48  for (const RangeListEntry &RLE : Entries) {
49  const char *format_str = (AddressSize == 4
50  ? "%08x %08" PRIx64 " %08" PRIx64 "\n"
51  : "%08x %016" PRIx64 " %016" PRIx64 "\n");
52  OS << format(format_str, Offset, RLE.StartAddress, RLE.EndAddress);
53  }
54  OS << format("%08x <End of list>\n", Offset);
55 }
56 
58 DWARFDebugRangeList::getAbsoluteRanges(uint64_t BaseAddress) const {
60  for (const RangeListEntry &RLE : Entries) {
61  if (RLE.isBaseAddressSelectionEntry(AddressSize)) {
62  BaseAddress = RLE.EndAddress;
63  } else {
64  Res.push_back(std::make_pair(BaseAddress + RLE.StartAddress,
65  BaseAddress + RLE.EndAddress));
66  }
67  }
68  return Res;
69 }
std::vector< std::pair< uint64_t, uint64_t > > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
uint8_t getAddressSize() const
Get the address size for this extractor.
Definition: DataExtractor.h:35
bool isValidOffset(uint32_t offset) const
Test the validity of offset.
bool extract(DataExtractor data, uint32_t *offset_ptr)
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:111
DWARFAddressRangesVector getAbsoluteRanges(uint64_t BaseAddress) const
getAbsoluteRanges - Returns absolute address ranges defined by this range list.
void dump(raw_ostream &OS) const
uint64_t getAddress(uint32_t *offset_ptr) const
Extract an pointer from *offset_ptr.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38