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 "llvm/DebugInfo/DWARF/DWARFContext.h"
11 #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
12 #include "llvm/Support/Format.h"
13 #include "llvm/Support/raw_ostream.h"
20 void DWARFDebugRangeList::clear() {
26 bool DWARFDebugRangeList::extract(DataExtractor data, uint32_t *offset_ptr,
27 const RelocAddrMap &Relocs) {
29 if (!data.isValidOffset(*offset_ptr))
31 AddressSize = data.getAddressSize();
32 if (AddressSize != 4 && AddressSize != 8)
37 uint32_t prev_offset = *offset_ptr;
38 entry.StartAddress = getRelocatedValue(data, AddressSize, offset_ptr,
39 &Relocs, &entry.SectionIndex);
41 getRelocatedValue(data, AddressSize, offset_ptr, &Relocs);
43 // Check that both values were extracted correctly.
44 if (*offset_ptr != prev_offset + 2 * AddressSize) {
48 if (entry.isEndOfListEntry())
50 Entries.push_back(entry);
55 void DWARFDebugRangeList::dump(raw_ostream &OS) const {
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);
62 OS << format("%08x <End of list>\n", Offset);
65 DWARFAddressRangesVector
66 DWARFDebugRangeList::getAbsoluteRanges(uint64_t BaseAddress) const {
67 DWARFAddressRangesVector Res;
68 for (const RangeListEntry &RLE : Entries) {
69 if (RLE.isBaseAddressSelectionEntry(AddressSize)) {
70 BaseAddress = RLE.EndAddress;
72 Res.push_back({BaseAddress + RLE.StartAddress,
73 BaseAddress + RLE.EndAddress, RLE.SectionIndex});