blob: 0b6ae86fd94b22e3ee85a1f204a309491f2e2b33 [file] [log] [blame]
Eugene Zelenko28db7e62017-03-01 01:14:23 +00001//===- DWARFDebugRangesList.cpp -------------------------------------------===//
Alexey Samsonov034e57a2012-08-27 07:17:47 +00002//
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
Zachary Turner82af9432015-01-30 18:07:45 +000010#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000011#include "llvm/DebugInfo/DWARF/DWARFContext.h"
Alexey Samsonov034e57a2012-08-27 07:17:47 +000012#include "llvm/Support/Format.h"
13#include "llvm/Support/raw_ostream.h"
Eugene Zelenko28db7e62017-03-01 01:14:23 +000014#include <cinttypes>
15#include <cstdint>
16#include <utility>
Alexey Samsonov034e57a2012-08-27 07:17:47 +000017
18using namespace llvm;
19
20void DWARFDebugRangeList::clear() {
21 Offset = -1U;
22 AddressSize = 0;
23 Entries.clear();
24}
25
Paul Robinson17536b92017-06-29 16:52:08 +000026bool DWARFDebugRangeList::extract(const DWARFDataExtractor &data,
27 uint32_t *offset_ptr) {
Alexey Samsonov034e57a2012-08-27 07:17:47 +000028 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;
Paul Robinson17536b92017-06-29 16:52:08 +000038 entry.StartAddress =
39 data.getRelocatedAddress(offset_ptr, &entry.SectionIndex);
40 entry.EndAddress = data.getRelocatedAddress(offset_ptr);
George Rimarca532112017-04-24 10:19:45 +000041
Alexey Samsonov034e57a2012-08-27 07:17:47 +000042 // Check that both values were extracted correctly.
43 if (*offset_ptr != prev_offset + 2 * AddressSize) {
44 clear();
45 return false;
46 }
Alexey Samsonovc942e6b2012-09-04 08:12:33 +000047 if (entry.isEndOfListEntry())
Alexey Samsonov034e57a2012-08-27 07:17:47 +000048 break;
49 Entries.push_back(entry);
50 }
51 return true;
52}
53
54void DWARFDebugRangeList::dump(raw_ostream &OS) const {
Alexey Samsonov1eabf982014-03-13 07:52:54 +000055 for (const RangeListEntry &RLE : Entries) {
NAKAMURA Takumi37338a82012-08-27 10:10:10 +000056 const char *format_str = (AddressSize == 4
Marshall Clowef271cc2012-08-27 22:53:35 +000057 ? "%08x %08" PRIx64 " %08" PRIx64 "\n"
58 : "%08x %016" PRIx64 " %016" PRIx64 "\n");
Alexey Samsonov1eabf982014-03-13 07:52:54 +000059 OS << format(format_str, Offset, RLE.StartAddress, RLE.EndAddress);
Alexey Samsonov034e57a2012-08-27 07:17:47 +000060 }
61 OS << format("%08x <End of list>\n", Offset);
62}
Alexey Samsonovc942e6b2012-09-04 08:12:33 +000063
Alexey Samsonov762343d2014-04-18 17:25:46 +000064DWARFAddressRangesVector
65DWARFDebugRangeList::getAbsoluteRanges(uint64_t BaseAddress) const {
66 DWARFAddressRangesVector Res;
Alexey Samsonov1eabf982014-03-13 07:52:54 +000067 for (const RangeListEntry &RLE : Entries) {
Alexey Samsonov762343d2014-04-18 17:25:46 +000068 if (RLE.isBaseAddressSelectionEntry(AddressSize)) {
Alexey Samsonov1eabf982014-03-13 07:52:54 +000069 BaseAddress = RLE.EndAddress;
Alexey Samsonov762343d2014-04-18 17:25:46 +000070 } else {
George Rimara25d3292017-05-27 18:10:23 +000071 Res.push_back({BaseAddress + RLE.StartAddress,
72 BaseAddress + RLE.EndAddress, RLE.SectionIndex});
Alexey Samsonov762343d2014-04-18 17:25:46 +000073 }
Alexey Samsonovc942e6b2012-09-04 08:12:33 +000074 }
Alexey Samsonov762343d2014-04-18 17:25:46 +000075 return Res;
Alexey Samsonovc942e6b2012-09-04 08:12:33 +000076}