blob: 9380fe8fe85d8a718f0098b67d1eb3ad76fa1507 [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
George Rimarca532112017-04-24 10:19:45 +000010#include "llvm/DebugInfo/DWARF/DWARFContext.h"
Zachary Turner82af9432015-01-30 18:07:45 +000011#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.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
George Rimarca532112017-04-24 10:19:45 +000026bool DWARFDebugRangeList::extract(DataExtractor data, uint32_t *offset_ptr,
27 const RelocAddrMap &Relocs) {
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;
George Rimarca532112017-04-24 10:19:45 +000038 entry.StartAddress =
39 getRelocatedValue(data, AddressSize, offset_ptr, &Relocs);
40 entry.EndAddress =
41 getRelocatedValue(data, AddressSize, offset_ptr, &Relocs);
42
Alexey Samsonov034e57a2012-08-27 07:17:47 +000043 // Check that both values were extracted correctly.
44 if (*offset_ptr != prev_offset + 2 * AddressSize) {
45 clear();
46 return false;
47 }
Alexey Samsonovc942e6b2012-09-04 08:12:33 +000048 if (entry.isEndOfListEntry())
Alexey Samsonov034e57a2012-08-27 07:17:47 +000049 break;
50 Entries.push_back(entry);
51 }
52 return true;
53}
54
55void DWARFDebugRangeList::dump(raw_ostream &OS) const {
Alexey Samsonov1eabf982014-03-13 07:52:54 +000056 for (const RangeListEntry &RLE : Entries) {
NAKAMURA Takumi37338a82012-08-27 10:10:10 +000057 const char *format_str = (AddressSize == 4
Marshall Clowef271cc2012-08-27 22:53:35 +000058 ? "%08x %08" PRIx64 " %08" PRIx64 "\n"
59 : "%08x %016" PRIx64 " %016" PRIx64 "\n");
Alexey Samsonov1eabf982014-03-13 07:52:54 +000060 OS << format(format_str, Offset, RLE.StartAddress, RLE.EndAddress);
Alexey Samsonov034e57a2012-08-27 07:17:47 +000061 }
62 OS << format("%08x <End of list>\n", Offset);
63}
Alexey Samsonovc942e6b2012-09-04 08:12:33 +000064
Alexey Samsonov762343d2014-04-18 17:25:46 +000065DWARFAddressRangesVector
66DWARFDebugRangeList::getAbsoluteRanges(uint64_t BaseAddress) const {
67 DWARFAddressRangesVector Res;
Alexey Samsonov1eabf982014-03-13 07:52:54 +000068 for (const RangeListEntry &RLE : Entries) {
Alexey Samsonov762343d2014-04-18 17:25:46 +000069 if (RLE.isBaseAddressSelectionEntry(AddressSize)) {
Alexey Samsonov1eabf982014-03-13 07:52:54 +000070 BaseAddress = RLE.EndAddress;
Alexey Samsonov762343d2014-04-18 17:25:46 +000071 } else {
72 Res.push_back(std::make_pair(BaseAddress + RLE.StartAddress,
73 BaseAddress + RLE.EndAddress));
74 }
Alexey Samsonovc942e6b2012-09-04 08:12:33 +000075 }
Alexey Samsonov762343d2014-04-18 17:25:46 +000076 return Res;
Alexey Samsonovc942e6b2012-09-04 08:12:33 +000077}