Alexey Samsonov | 034e57a | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 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 | |
Zachary Turner | 82af943 | 2015-01-30 18:07:45 +0000 | [diff] [blame] | 10 | #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h" |
Alexey Samsonov | 034e57a | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 11 | #include "llvm/Support/Format.h" |
| 12 | #include "llvm/Support/raw_ostream.h" |
| 13 | |
| 14 | using namespace llvm; |
| 15 | |
| 16 | void DWARFDebugRangeList::clear() { |
| 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 | } |
Alexey Samsonov | c942e6b | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 40 | if (entry.isEndOfListEntry()) |
Alexey Samsonov | 034e57a | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 41 | break; |
| 42 | Entries.push_back(entry); |
| 43 | } |
| 44 | return true; |
| 45 | } |
| 46 | |
| 47 | void DWARFDebugRangeList::dump(raw_ostream &OS) const { |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 48 | for (const RangeListEntry &RLE : Entries) { |
NAKAMURA Takumi | 37338a8 | 2012-08-27 10:10:10 +0000 | [diff] [blame] | 49 | const char *format_str = (AddressSize == 4 |
Marshall Clow | ef271cc | 2012-08-27 22:53:35 +0000 | [diff] [blame] | 50 | ? "%08x %08" PRIx64 " %08" PRIx64 "\n" |
| 51 | : "%08x %016" PRIx64 " %016" PRIx64 "\n"); |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 52 | OS << format(format_str, Offset, RLE.StartAddress, RLE.EndAddress); |
Alexey Samsonov | 034e57a | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 53 | } |
| 54 | OS << format("%08x <End of list>\n", Offset); |
| 55 | } |
Alexey Samsonov | c942e6b | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 56 | |
Alexey Samsonov | 762343d | 2014-04-18 17:25:46 +0000 | [diff] [blame] | 57 | DWARFAddressRangesVector |
| 58 | DWARFDebugRangeList::getAbsoluteRanges(uint64_t BaseAddress) const { |
| 59 | DWARFAddressRangesVector Res; |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 60 | for (const RangeListEntry &RLE : Entries) { |
Alexey Samsonov | 762343d | 2014-04-18 17:25:46 +0000 | [diff] [blame] | 61 | if (RLE.isBaseAddressSelectionEntry(AddressSize)) { |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 62 | BaseAddress = RLE.EndAddress; |
Alexey Samsonov | 762343d | 2014-04-18 17:25:46 +0000 | [diff] [blame] | 63 | } else { |
| 64 | Res.push_back(std::make_pair(BaseAddress + RLE.StartAddress, |
| 65 | BaseAddress + RLE.EndAddress)); |
| 66 | } |
Alexey Samsonov | c942e6b | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 67 | } |
Alexey Samsonov | 762343d | 2014-04-18 17:25:46 +0000 | [diff] [blame] | 68 | return Res; |
Alexey Samsonov | c942e6b | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 69 | } |