Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 1 | //===- DWARFDebugLoc.cpp --------------------------------------------------===// |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +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 | |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 10 | #include "llvm/ADT/StringRef.h" |
George Rimar | f8a9642 | 2017-04-21 09:12:18 +0000 | [diff] [blame^] | 11 | #include "llvm/DebugInfo/DWARF/DWARFContext.h" |
Zachary Turner | 82af943 | 2015-01-30 18:07:45 +0000 | [diff] [blame] | 12 | #include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h" |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 13 | #include "llvm/DebugInfo/DWARF/DWARFRelocMap.h" |
Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 14 | #include "llvm/Support/Dwarf.h" |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 15 | #include "llvm/Support/Format.h" |
| 16 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 17 | #include <algorithm> |
| 18 | #include <cinttypes> |
| 19 | #include <cstdint> |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace llvm; |
| 22 | |
| 23 | void DWARFDebugLoc::dump(raw_ostream &OS) const { |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 24 | for (const LocationList &L : Locations) { |
| 25 | OS << format("0x%8.8x: ", L.Offset); |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 26 | const unsigned Indent = 12; |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 27 | for (const Entry &E : L.Entries) { |
| 28 | if (&E != L.Entries.begin()) |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 29 | OS.indent(Indent); |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 30 | OS << "Beginning address offset: " << format("0x%016" PRIx64, E.Begin) |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 31 | << '\n'; |
David Blaikie | b9a1870 | 2013-06-19 21:42:05 +0000 | [diff] [blame] | 32 | OS.indent(Indent) << " Ending address offset: " |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 33 | << format("0x%016" PRIx64, E.End) << '\n'; |
David Blaikie | b9a1870 | 2013-06-19 21:42:05 +0000 | [diff] [blame] | 34 | OS.indent(Indent) << " Location description: "; |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 35 | for (unsigned char Loc : E.Loc) { |
| 36 | OS << format("%2.2x ", Loc); |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 37 | } |
| 38 | OS << "\n\n"; |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | void DWARFDebugLoc::parse(DataExtractor data, unsigned AddressSize) { |
| 44 | uint32_t Offset = 0; |
Adrian Prantl | 6f84d31 | 2014-02-11 21:22:53 +0000 | [diff] [blame] | 45 | while (data.isValidOffset(Offset+AddressSize-1)) { |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 46 | Locations.resize(Locations.size() + 1); |
| 47 | LocationList &Loc = Locations.back(); |
| 48 | Loc.Offset = Offset; |
| 49 | // 2.6.2 Location Lists |
| 50 | // A location list entry consists of: |
| 51 | while (true) { |
George Rimar | f8a9642 | 2017-04-21 09:12:18 +0000 | [diff] [blame^] | 52 | // A beginning and ending address offsets. |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 53 | Entry E; |
George Rimar | f8a9642 | 2017-04-21 09:12:18 +0000 | [diff] [blame^] | 54 | E.Begin = getRelocatedValue(data, AddressSize, &Offset, &RelocMap); |
| 55 | E.End = getRelocatedValue(data, AddressSize, &Offset, &RelocMap); |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 56 | |
| 57 | // The end of any given location list is marked by an end of list entry, |
| 58 | // which consists of a 0 for the beginning address offset and a 0 for the |
| 59 | // ending address offset. |
| 60 | if (E.Begin == 0 && E.End == 0) |
| 61 | break; |
| 62 | |
| 63 | unsigned Bytes = data.getU16(&Offset); |
| 64 | // A single location description describing the location of the object... |
| 65 | StringRef str = data.getData().substr(Offset, Bytes); |
| 66 | Offset += Bytes; |
Benjamin Kramer | 4f6ac16 | 2015-02-28 10:11:12 +0000 | [diff] [blame] | 67 | E.Loc.append(str.begin(), str.end()); |
Chandler Carruth | 002da5d | 2014-03-02 04:08:41 +0000 | [diff] [blame] | 68 | Loc.Entries.push_back(std::move(E)); |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 69 | } |
| 70 | } |
Adrian Prantl | 6f84d31 | 2014-02-11 21:22:53 +0000 | [diff] [blame] | 71 | if (data.isValidOffset(Offset)) |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 72 | errs() << "error: failed to consume entire .debug_loc section\n"; |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 73 | } |
David Blaikie | 9c550ac | 2014-03-25 01:44:02 +0000 | [diff] [blame] | 74 | |
| 75 | void DWARFDebugLocDWO::parse(DataExtractor data) { |
| 76 | uint32_t Offset = 0; |
| 77 | while (data.isValidOffset(Offset)) { |
| 78 | Locations.resize(Locations.size() + 1); |
| 79 | LocationList &Loc = Locations.back(); |
| 80 | Loc.Offset = Offset; |
| 81 | dwarf::LocationListEntry Kind; |
| 82 | while ((Kind = static_cast<dwarf::LocationListEntry>( |
Adrian Prantl | c4fbbcf | 2016-10-28 17:59:50 +0000 | [diff] [blame] | 83 | data.getU8(&Offset))) != dwarf::DW_LLE_end_of_list) { |
David Blaikie | 9c550ac | 2014-03-25 01:44:02 +0000 | [diff] [blame] | 84 | |
Adrian Prantl | c4fbbcf | 2016-10-28 17:59:50 +0000 | [diff] [blame] | 85 | if (Kind != dwarf::DW_LLE_startx_length) { |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 86 | errs() << "error: dumping support for LLE of kind " << (int)Kind |
| 87 | << " not implemented\n"; |
David Blaikie | 9c550ac | 2014-03-25 01:44:02 +0000 | [diff] [blame] | 88 | return; |
| 89 | } |
| 90 | |
| 91 | Entry E; |
| 92 | |
| 93 | E.Start = data.getULEB128(&Offset); |
| 94 | E.Length = data.getU32(&Offset); |
| 95 | |
| 96 | unsigned Bytes = data.getU16(&Offset); |
| 97 | // A single location description describing the location of the object... |
| 98 | StringRef str = data.getData().substr(Offset, Bytes); |
| 99 | Offset += Bytes; |
| 100 | E.Loc.resize(str.size()); |
| 101 | std::copy(str.begin(), str.end(), E.Loc.begin()); |
| 102 | |
| 103 | Loc.Entries.push_back(std::move(E)); |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | void DWARFDebugLocDWO::dump(raw_ostream &OS) const { |
| 109 | for (const LocationList &L : Locations) { |
| 110 | OS << format("0x%8.8x: ", L.Offset); |
| 111 | const unsigned Indent = 12; |
| 112 | for (const Entry &E : L.Entries) { |
| 113 | if (&E != L.Entries.begin()) |
| 114 | OS.indent(Indent); |
| 115 | OS << "Beginning address index: " << E.Start << '\n'; |
| 116 | OS.indent(Indent) << " Length: " << E.Length << '\n'; |
| 117 | OS.indent(Indent) << " Location description: "; |
| 118 | for (unsigned char Loc : E.Loc) |
| 119 | OS << format("%2.2x ", Loc); |
| 120 | OS << "\n\n"; |
| 121 | } |
| 122 | } |
| 123 | } |