Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 1 | //===- DWARFDebugRangesList.cpp -------------------------------------------===// |
Alexey Samsonov | 034e57a | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 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 | |
George Rimar | ca53211 | 2017-04-24 10:19:45 +0000 | [diff] [blame^] | 10 | #include "llvm/DebugInfo/DWARF/DWARFContext.h" |
Zachary Turner | 82af943 | 2015-01-30 18:07:45 +0000 | [diff] [blame] | 11 | #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h" |
Alexey Samsonov | 034e57a | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 12 | #include "llvm/Support/Format.h" |
| 13 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 14 | #include <cinttypes> |
| 15 | #include <cstdint> |
| 16 | #include <utility> |
Alexey Samsonov | 034e57a | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace llvm; |
| 19 | |
| 20 | void DWARFDebugRangeList::clear() { |
| 21 | Offset = -1U; |
| 22 | AddressSize = 0; |
| 23 | Entries.clear(); |
| 24 | } |
| 25 | |
George Rimar | ca53211 | 2017-04-24 10:19:45 +0000 | [diff] [blame^] | 26 | bool DWARFDebugRangeList::extract(DataExtractor data, uint32_t *offset_ptr, |
| 27 | const RelocAddrMap &Relocs) { |
Alexey Samsonov | 034e57a | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 28 | 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 Rimar | ca53211 | 2017-04-24 10:19:45 +0000 | [diff] [blame^] | 38 | entry.StartAddress = |
| 39 | getRelocatedValue(data, AddressSize, offset_ptr, &Relocs); |
| 40 | entry.EndAddress = |
| 41 | getRelocatedValue(data, AddressSize, offset_ptr, &Relocs); |
| 42 | |
Alexey Samsonov | 034e57a | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 43 | // Check that both values were extracted correctly. |
| 44 | if (*offset_ptr != prev_offset + 2 * AddressSize) { |
| 45 | clear(); |
| 46 | return false; |
| 47 | } |
Alexey Samsonov | c942e6b | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 48 | if (entry.isEndOfListEntry()) |
Alexey Samsonov | 034e57a | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 49 | break; |
| 50 | Entries.push_back(entry); |
| 51 | } |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | void DWARFDebugRangeList::dump(raw_ostream &OS) const { |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 56 | for (const RangeListEntry &RLE : Entries) { |
NAKAMURA Takumi | 37338a8 | 2012-08-27 10:10:10 +0000 | [diff] [blame] | 57 | const char *format_str = (AddressSize == 4 |
Marshall Clow | ef271cc | 2012-08-27 22:53:35 +0000 | [diff] [blame] | 58 | ? "%08x %08" PRIx64 " %08" PRIx64 "\n" |
| 59 | : "%08x %016" PRIx64 " %016" PRIx64 "\n"); |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 60 | OS << format(format_str, Offset, RLE.StartAddress, RLE.EndAddress); |
Alexey Samsonov | 034e57a | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 61 | } |
| 62 | OS << format("%08x <End of list>\n", Offset); |
| 63 | } |
Alexey Samsonov | c942e6b | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 64 | |
Alexey Samsonov | 762343d | 2014-04-18 17:25:46 +0000 | [diff] [blame] | 65 | DWARFAddressRangesVector |
| 66 | DWARFDebugRangeList::getAbsoluteRanges(uint64_t BaseAddress) const { |
| 67 | DWARFAddressRangesVector Res; |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 68 | for (const RangeListEntry &RLE : Entries) { |
Alexey Samsonov | 762343d | 2014-04-18 17:25:46 +0000 | [diff] [blame] | 69 | if (RLE.isBaseAddressSelectionEntry(AddressSize)) { |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 70 | BaseAddress = RLE.EndAddress; |
Alexey Samsonov | 762343d | 2014-04-18 17:25:46 +0000 | [diff] [blame] | 71 | } else { |
| 72 | Res.push_back(std::make_pair(BaseAddress + RLE.StartAddress, |
| 73 | BaseAddress + RLE.EndAddress)); |
| 74 | } |
Alexey Samsonov | c942e6b | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 75 | } |
Alexey Samsonov | 762343d | 2014-04-18 17:25:46 +0000 | [diff] [blame] | 76 | return Res; |
Alexey Samsonov | c942e6b | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 77 | } |