blob: e4aa5dcce27e808b4429804535db25987f3089a5 [file] [log] [blame]
David Blaikie3df7d2f2013-06-19 21:37:13 +00001//===-- DWARFDebugLoc.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
10#include "DWARFDebugLoc.h"
11#include "llvm/Support/Compiler.h"
12#include "llvm/Support/Format.h"
13#include "llvm/Support/raw_ostream.h"
Stephen Hines36b56882014-04-23 16:57:46 -070014#include "llvm/Support/Dwarf.h"
David Blaikie3df7d2f2013-06-19 21:37:13 +000015
16using namespace llvm;
17
18void DWARFDebugLoc::dump(raw_ostream &OS) const {
Stephen Hines36b56882014-04-23 16:57:46 -070019 for (const LocationList &L : Locations) {
20 OS << format("0x%8.8x: ", L.Offset);
David Blaikie3df7d2f2013-06-19 21:37:13 +000021 const unsigned Indent = 12;
Stephen Hines36b56882014-04-23 16:57:46 -070022 for (const Entry &E : L.Entries) {
23 if (&E != L.Entries.begin())
David Blaikie3df7d2f2013-06-19 21:37:13 +000024 OS.indent(Indent);
Stephen Hines36b56882014-04-23 16:57:46 -070025 OS << "Beginning address offset: " << format("0x%016" PRIx64, E.Begin)
David Blaikie3df7d2f2013-06-19 21:37:13 +000026 << '\n';
David Blaikie08123042013-06-19 21:42:05 +000027 OS.indent(Indent) << " Ending address offset: "
Stephen Hines36b56882014-04-23 16:57:46 -070028 << format("0x%016" PRIx64, E.End) << '\n';
David Blaikie08123042013-06-19 21:42:05 +000029 OS.indent(Indent) << " Location description: ";
Stephen Hines36b56882014-04-23 16:57:46 -070030 for (unsigned char Loc : E.Loc) {
31 OS << format("%2.2x ", Loc);
David Blaikie3df7d2f2013-06-19 21:37:13 +000032 }
33 OS << "\n\n";
34 }
35 }
36}
37
38void DWARFDebugLoc::parse(DataExtractor data, unsigned AddressSize) {
39 uint32_t Offset = 0;
Stephen Hines36b56882014-04-23 16:57:46 -070040 while (data.isValidOffset(Offset+AddressSize-1)) {
David Blaikie3df7d2f2013-06-19 21:37:13 +000041 Locations.resize(Locations.size() + 1);
42 LocationList &Loc = Locations.back();
43 Loc.Offset = Offset;
44 // 2.6.2 Location Lists
45 // A location list entry consists of:
46 while (true) {
47 Entry E;
48 RelocAddrMap::const_iterator AI = RelocMap.find(Offset);
49 // 1. A beginning address offset. ...
50 E.Begin = data.getUnsigned(&Offset, AddressSize);
51 if (AI != RelocMap.end())
52 E.Begin += AI->second.second;
53
54 AI = RelocMap.find(Offset);
55 // 2. An ending address offset. ...
56 E.End = data.getUnsigned(&Offset, AddressSize);
57 if (AI != RelocMap.end())
58 E.End += AI->second.second;
59
60 // The end of any given location list is marked by an end of list entry,
61 // which consists of a 0 for the beginning address offset and a 0 for the
62 // ending address offset.
63 if (E.Begin == 0 && E.End == 0)
64 break;
65
66 unsigned Bytes = data.getU16(&Offset);
67 // A single location description describing the location of the object...
68 StringRef str = data.getData().substr(Offset, Bytes);
69 Offset += Bytes;
70 E.Loc.reserve(str.size());
71 std::copy(str.begin(), str.end(), std::back_inserter(E.Loc));
Stephen Hines36b56882014-04-23 16:57:46 -070072 Loc.Entries.push_back(std::move(E));
73 }
74 }
75 if (data.isValidOffset(Offset))
76 llvm::errs() << "error: failed to consume entire .debug_loc section\n";
77}
78
79void DWARFDebugLocDWO::parse(DataExtractor data) {
80 uint32_t Offset = 0;
81 while (data.isValidOffset(Offset)) {
82 Locations.resize(Locations.size() + 1);
83 LocationList &Loc = Locations.back();
84 Loc.Offset = Offset;
85 dwarf::LocationListEntry Kind;
86 while ((Kind = static_cast<dwarf::LocationListEntry>(
87 data.getU8(&Offset))) != dwarf::DW_LLE_end_of_list_entry) {
88
89 if (Kind != dwarf::DW_LLE_start_length_entry) {
90 llvm::errs() << "error: dumping support for LLE of kind " << (int)Kind
91 << " not implemented\n";
92 return;
93 }
94
95 Entry E;
96
97 E.Start = data.getULEB128(&Offset);
98 E.Length = data.getU32(&Offset);
99
100 unsigned Bytes = data.getU16(&Offset);
101 // A single location description describing the location of the object...
102 StringRef str = data.getData().substr(Offset, Bytes);
103 Offset += Bytes;
104 E.Loc.resize(str.size());
105 std::copy(str.begin(), str.end(), E.Loc.begin());
106
107 Loc.Entries.push_back(std::move(E));
David Blaikie3df7d2f2013-06-19 21:37:13 +0000108 }
109 }
110}
Stephen Hines36b56882014-04-23 16:57:46 -0700111
112void DWARFDebugLocDWO::dump(raw_ostream &OS) const {
113 for (const LocationList &L : Locations) {
114 OS << format("0x%8.8x: ", L.Offset);
115 const unsigned Indent = 12;
116 for (const Entry &E : L.Entries) {
117 if (&E != L.Entries.begin())
118 OS.indent(Indent);
119 OS << "Beginning address index: " << E.Start << '\n';
120 OS.indent(Indent) << " Length: " << E.Length << '\n';
121 OS.indent(Indent) << " Location description: ";
122 for (unsigned char Loc : E.Loc)
123 OS << format("%2.2x ", Loc);
124 OS << "\n\n";
125 }
126 }
127}
128