1 //===-- DWARFDebugRangesList.cpp ------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "DWARFDebugRangeList.h"
11 #include "llvm/Support/Format.h"
12 #include "llvm/Support/raw_ostream.h"
16 void DWARFDebugRangeList::clear() {
22 bool DWARFDebugRangeList::extract(DataExtractor data, uint32_t *offset_ptr) {
24 if (!data.isValidOffset(*offset_ptr))
26 AddressSize = data.getAddressSize();
27 if (AddressSize != 4 && AddressSize != 8)
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) {
40 if (entry.isEndOfListEntry())
42 Entries.push_back(entry);
47 void DWARFDebugRangeList::dump(raw_ostream &OS) const {
48 for (int i = 0, n = Entries.size(); i != n; ++i) {
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, Entries[i].StartAddress,
53 Entries[i].EndAddress);
55 OS << format("%08x <End of list>\n", Offset);
58 bool DWARFDebugRangeList::containsAddress(uint64_t BaseAddress,
59 uint64_t Address) const {
60 for (int i = 0, n = Entries.size(); i != n; ++i) {
61 if (Entries[i].isBaseAddressSelectionEntry(AddressSize))
62 BaseAddress = Entries[i].EndAddress;
63 else if (Entries[i].containsAddress(BaseAddress, Address))