blob: 2733bef7baee64d36e05592f3f22a9f49a2cb37e [file] [log] [blame]
Eugene Zelenko28db7e62017-03-01 01:14:23 +00001//===- DWARFContext.cpp ---------------------------------------------------===//
Benjamin Krameraa2f78f2011-09-13 19:42:23 +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
Alexey Samsonove16e16a2012-07-19 07:03:58 +000010#include "llvm/ADT/SmallString.h"
Eugene Zelenko28db7e62017-03-01 01:14:23 +000011#include "llvm/ADT/SmallVector.h"
12#include "llvm/ADT/STLExtras.h"
Alexey Samsonov3d0e3ed2013-04-17 14:27:04 +000013#include "llvm/ADT/StringSwitch.h"
Eugene Zelenko28db7e62017-03-01 01:14:23 +000014#include "llvm/ADT/StringRef.h"
Zachary Turner82af9432015-01-30 18:07:45 +000015#include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"
Eugene Zelenko28db7e62017-03-01 01:14:23 +000016#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
17#include "llvm/DebugInfo/DWARF/DWARFContext.h"
18#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
19#include "llvm/DebugInfo/DWARF/DWARFDebugAranges.h"
Zachary Turner82af9432015-01-30 18:07:45 +000020#include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h"
Eugene Zelenko28db7e62017-03-01 01:14:23 +000021#include "llvm/DebugInfo/DWARF/DWARFDebugFrame.h"
22#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
23#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
24#include "llvm/DebugInfo/DWARF/DWARFDebugMacro.h"
George Rimare71e33f2016-12-17 09:10:32 +000025#include "llvm/DebugInfo/DWARF/DWARFDebugPubTable.h"
Eugene Zelenko28db7e62017-03-01 01:14:23 +000026#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
27#include "llvm/DebugInfo/DWARF/DWARFDie.h"
28#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
29#include "llvm/DebugInfo/DWARF/DWARFGdbIndex.h"
30#include "llvm/DebugInfo/DWARF/DWARFSection.h"
David Blaikie65a8efe2015-11-11 19:28:21 +000031#include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"
George Rimar4bf30832017-01-11 15:26:41 +000032#include "llvm/Object/Decompressor.h"
Reid Klecknerdafc5d72016-07-06 16:56:42 +000033#include "llvm/Object/MachO.h"
Eugene Zelenko28db7e62017-03-01 01:14:23 +000034#include "llvm/Object/ObjectFile.h"
Reid Klecknerdafc5d72016-07-06 16:56:42 +000035#include "llvm/Object/RelocVisitor.h"
Eugene Zelenko28db7e62017-03-01 01:14:23 +000036#include "llvm/Support/Casting.h"
37#include "llvm/Support/DataExtractor.h"
38#include "llvm/Support/Debug.h"
39#include "llvm/Support/Error.h"
Benjamin Kramer07d4b1c2011-09-15 16:57:13 +000040#include "llvm/Support/Format.h"
Eugene Zelenko28db7e62017-03-01 01:14:23 +000041#include "llvm/Support/MemoryBuffer.h"
Benjamin Kramera6002fd2011-09-14 01:09:52 +000042#include "llvm/Support/raw_ostream.h"
Benjamin Kramer2602ca62011-09-15 20:43:22 +000043#include <algorithm>
Eugene Zelenko28db7e62017-03-01 01:14:23 +000044#include <cstdint>
Greg Claytonc7695a82017-05-02 20:28:33 +000045#include <map>
46#include <set>
Eugene Zelenko28db7e62017-03-01 01:14:23 +000047#include <string>
48#include <utility>
49#include <vector>
50
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000051using namespace llvm;
Benjamin Kramer6dda0322011-09-15 18:02:20 +000052using namespace dwarf;
Rafael Espindola4f60a382013-05-30 03:05:14 +000053using namespace object;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000054
Chandler Carruthe96dd892014-04-21 22:55:11 +000055#define DEBUG_TYPE "dwarf"
56
Eric Christopher494109b2012-10-16 23:46:25 +000057typedef DWARFDebugLine::LineTable DWARFLineTable;
Alexey Samsonovdce67342014-05-15 21:24:32 +000058typedef DILineInfoSpecifier::FileLineInfoKind FileLineInfoKind;
59typedef DILineInfoSpecifier::FunctionNameKind FunctionNameKind;
Eric Christopher494109b2012-10-16 23:46:25 +000060
George Rimarf8a96422017-04-21 09:12:18 +000061uint64_t llvm::getRelocatedValue(const DataExtractor &Data, uint32_t Size,
62 uint32_t *Off, const RelocAddrMap *Relocs) {
63 if (!Relocs)
64 return Data.getUnsigned(Off, Size);
65 RelocAddrMap::const_iterator AI = Relocs->find(*Off);
66 if (AI == Relocs->end())
67 return Data.getUnsigned(Off, Size);
68 return Data.getUnsigned(Off, Size) + AI->second.second;
69}
70
Frederic Riss7c500472014-11-14 19:30:08 +000071static void dumpAccelSection(raw_ostream &OS, StringRef Name,
72 const DWARFSection& Section, StringRef StringSection,
73 bool LittleEndian) {
74 DataExtractor AccelSection(Section.Data, LittleEndian, 0);
Frederic Risse837ec22014-11-14 16:15:53 +000075 DataExtractor StrData(StringSection, LittleEndian, 0);
76 OS << "\n." << Name << " contents:\n";
Frederic Riss7c500472014-11-14 19:30:08 +000077 DWARFAcceleratorTable Accel(AccelSection, StrData, Section.Relocs);
Frederic Risse837ec22014-11-14 16:15:53 +000078 if (!Accel.extract())
79 return;
80 Accel.dump(OS);
81}
82
David Blaikie50cc27e2016-10-18 21:09:48 +000083void DWARFContext::dump(raw_ostream &OS, DIDumpType DumpType, bool DumpEH,
84 bool SummarizeTypes) {
Eli Bendersky7a94daa2013-01-25 20:26:43 +000085 if (DumpType == DIDT_All || DumpType == DIDT_Abbrev) {
86 OS << ".debug_abbrev contents:\n";
87 getDebugAbbrev()->dump(OS);
88 }
Benjamin Kramera6002fd2011-09-14 01:09:52 +000089
David Blaikie66865d62014-01-09 00:13:35 +000090 if (DumpType == DIDT_All || DumpType == DIDT_AbbrevDwo)
91 if (const DWARFDebugAbbrev *D = getDebugAbbrevDWO()) {
David Blaikie622dce42014-01-08 23:29:59 +000092 OS << "\n.debug_abbrev.dwo contents:\n";
David Blaikie66865d62014-01-09 00:13:35 +000093 D->dump(OS);
David Blaikie622dce42014-01-08 23:29:59 +000094 }
David Blaikie622dce42014-01-08 23:29:59 +000095
Eli Bendersky7a94daa2013-01-25 20:26:43 +000096 if (DumpType == DIDT_All || DumpType == DIDT_Info) {
97 OS << "\n.debug_info contents:\n";
Alexey Samsonov1eabf982014-03-13 07:52:54 +000098 for (const auto &CU : compile_units())
99 CU->dump(OS);
Eli Bendersky7a94daa2013-01-25 20:26:43 +0000100 }
Benjamin Kramera6002fd2011-09-14 01:09:52 +0000101
David Blaikie66865d62014-01-09 00:13:35 +0000102 if ((DumpType == DIDT_All || DumpType == DIDT_InfoDwo) &&
103 getNumDWOCompileUnits()) {
104 OS << "\n.debug_info.dwo contents:\n";
Alexey Samsonov1eabf982014-03-13 07:52:54 +0000105 for (const auto &DWOCU : dwo_compile_units())
106 DWOCU->dump(OS);
David Blaikie66865d62014-01-09 00:13:35 +0000107 }
David Blaikie622dce42014-01-08 23:29:59 +0000108
David Blaikie66865d62014-01-09 00:13:35 +0000109 if ((DumpType == DIDT_All || DumpType == DIDT_Types) && getNumTypeUnits()) {
David Blaikie03c089c2013-09-23 22:44:47 +0000110 OS << "\n.debug_types contents:\n";
Frederic Riss312a02e2014-09-29 13:56:39 +0000111 for (const auto &TUS : type_unit_sections())
112 for (const auto &TU : TUS)
David Blaikie50cc27e2016-10-18 21:09:48 +0000113 TU->dump(OS, SummarizeTypes);
David Blaikie03c089c2013-09-23 22:44:47 +0000114 }
115
Alexey Samsonov1eabf982014-03-13 07:52:54 +0000116 if ((DumpType == DIDT_All || DumpType == DIDT_TypesDwo) &&
117 getNumDWOTypeUnits()) {
118 OS << "\n.debug_types.dwo contents:\n";
Frederic Riss312a02e2014-09-29 13:56:39 +0000119 for (const auto &DWOTUS : dwo_type_unit_sections())
120 for (const auto &DWOTU : DWOTUS)
David Blaikie50cc27e2016-10-18 21:09:48 +0000121 DWOTU->dump(OS, SummarizeTypes);
Alexey Samsonov1eabf982014-03-13 07:52:54 +0000122 }
David Blaikie92d9d622014-01-09 05:08:24 +0000123
David Blaikie18e73502013-06-19 21:37:13 +0000124 if (DumpType == DIDT_All || DumpType == DIDT_Loc) {
David Blaikie03c089c2013-09-23 22:44:47 +0000125 OS << "\n.debug_loc contents:\n";
David Blaikie18e73502013-06-19 21:37:13 +0000126 getDebugLoc()->dump(OS);
127 }
128
David Blaikie9c550ac2014-03-25 01:44:02 +0000129 if (DumpType == DIDT_All || DumpType == DIDT_LocDwo) {
130 OS << "\n.debug_loc.dwo contents:\n";
131 getDebugLocDWO()->dump(OS);
132 }
133
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000134 if (DumpType == DIDT_All || DumpType == DIDT_Frames) {
135 OS << "\n.debug_frame contents:\n";
136 getDebugFrame()->dump(OS);
Igor Laevsky03a670c2016-01-26 15:09:42 +0000137 if (DumpEH) {
138 OS << "\n.eh_frame contents:\n";
139 getEHFrame()->dump(OS);
140 }
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000141 }
142
Amjad Aboude59cc3e2015-11-12 09:38:54 +0000143 if (DumpType == DIDT_All || DumpType == DIDT_Macro) {
144 OS << "\n.debug_macinfo contents:\n";
145 getDebugMacro()->dump(OS);
146 }
147
Benjamin Kramera6002fd2011-09-14 01:09:52 +0000148 uint32_t offset = 0;
Eli Bendersky7a94daa2013-01-25 20:26:43 +0000149 if (DumpType == DIDT_All || DumpType == DIDT_Aranges) {
150 OS << "\n.debug_aranges contents:\n";
151 DataExtractor arangesData(getARangeSection(), isLittleEndian(), 0);
152 DWARFDebugArangeSet set;
153 while (set.extract(arangesData, &offset))
154 set.dump(OS);
155 }
Benjamin Kramer5acab502011-09-15 02:12:05 +0000156
Alexey Samsonov034e57a2012-08-27 07:17:47 +0000157 uint8_t savedAddressByteSize = 0;
Eli Bendersky7a94daa2013-01-25 20:26:43 +0000158 if (DumpType == DIDT_All || DumpType == DIDT_Line) {
159 OS << "\n.debug_line contents:\n";
Alexey Samsonov1eabf982014-03-13 07:52:54 +0000160 for (const auto &CU : compile_units()) {
161 savedAddressByteSize = CU->getAddressByteSize();
Greg Claytonc8c10322016-12-13 18:25:19 +0000162 auto CUDIE = CU->getUnitDIE();
163 if (!CUDIE)
Alexey Samsonov7a18c062015-05-19 21:54:32 +0000164 continue;
Greg Clayton97d22182017-01-13 21:08:18 +0000165 if (auto StmtOffset = toSectionOffset(CUDIE.find(DW_AT_stmt_list))) {
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000166 DataExtractor lineData(getLineSection().Data, isLittleEndian(),
Eli Bendersky7a94daa2013-01-25 20:26:43 +0000167 savedAddressByteSize);
Alexey Samsonov110d5952014-04-30 00:09:19 +0000168 DWARFDebugLine::LineTable LineTable;
Greg Clayton52fe1f62016-12-14 22:38:08 +0000169 uint32_t Offset = *StmtOffset;
170 LineTable.parse(lineData, &getLineSection().Relocs, &Offset);
Alexey Samsonov110d5952014-04-30 00:09:19 +0000171 LineTable.dump(OS);
Eli Bendersky7a94daa2013-01-25 20:26:43 +0000172 }
Benjamin Kramer6dda0322011-09-15 18:02:20 +0000173 }
174 }
Benjamin Kramer07d4b1c2011-09-15 16:57:13 +0000175
David Blaikie65a8efe2015-11-11 19:28:21 +0000176 if (DumpType == DIDT_All || DumpType == DIDT_CUIndex) {
177 OS << "\n.debug_cu_index contents:\n";
David Blaikieb073cb92015-12-02 06:21:34 +0000178 getCUIndex().dump(OS);
David Blaikie65a8efe2015-11-11 19:28:21 +0000179 }
180
David Blaikie51c40282015-11-11 19:40:49 +0000181 if (DumpType == DIDT_All || DumpType == DIDT_TUIndex) {
182 OS << "\n.debug_tu_index contents:\n";
David Blaikieb073cb92015-12-02 06:21:34 +0000183 getTUIndex().dump(OS);
David Blaikie51c40282015-11-11 19:40:49 +0000184 }
185
David Blaikie1d4736e2014-02-24 23:58:54 +0000186 if (DumpType == DIDT_All || DumpType == DIDT_LineDwo) {
187 OS << "\n.debug_line.dwo contents:\n";
188 unsigned stmtOffset = 0;
189 DataExtractor lineData(getLineDWOSection().Data, isLittleEndian(),
190 savedAddressByteSize);
Alexey Samsonov110d5952014-04-30 00:09:19 +0000191 DWARFDebugLine::LineTable LineTable;
192 while (LineTable.Prologue.parse(lineData, &stmtOffset)) {
193 LineTable.dump(OS);
194 LineTable.clear();
195 }
David Blaikie1d4736e2014-02-24 23:58:54 +0000196 }
197
Eli Bendersky7a94daa2013-01-25 20:26:43 +0000198 if (DumpType == DIDT_All || DumpType == DIDT_Str) {
199 OS << "\n.debug_str contents:\n";
200 DataExtractor strData(getStringSection(), isLittleEndian(), 0);
201 offset = 0;
202 uint32_t strOffset = 0;
203 while (const char *s = strData.getCStr(&offset)) {
204 OS << format("0x%8.8x: \"%s\"\n", strOffset, s);
205 strOffset = offset;
206 }
Benjamin Kramer07d4b1c2011-09-15 16:57:13 +0000207 }
Alexey Samsonov034e57a2012-08-27 07:17:47 +0000208
David Blaikie66865d62014-01-09 00:13:35 +0000209 if ((DumpType == DIDT_All || DumpType == DIDT_StrDwo) &&
210 !getStringDWOSection().empty()) {
211 OS << "\n.debug_str.dwo contents:\n";
212 DataExtractor strDWOData(getStringDWOSection(), isLittleEndian(), 0);
213 offset = 0;
214 uint32_t strDWOOffset = 0;
215 while (const char *s = strDWOData.getCStr(&offset)) {
216 OS << format("0x%8.8x: \"%s\"\n", strDWOOffset, s);
217 strDWOOffset = offset;
David Blaikie622dce42014-01-08 23:29:59 +0000218 }
David Blaikie66865d62014-01-09 00:13:35 +0000219 }
David Blaikie622dce42014-01-08 23:29:59 +0000220
Eli Bendersky7a94daa2013-01-25 20:26:43 +0000221 if (DumpType == DIDT_All || DumpType == DIDT_Ranges) {
222 OS << "\n.debug_ranges contents:\n";
223 // In fact, different compile units may have different address byte
224 // sizes, but for simplicity we just use the address byte size of the last
225 // compile unit (there is no easy and fast way to associate address range
226 // list and the compile unit it describes).
George Rimarca532112017-04-24 10:19:45 +0000227 DataExtractor rangesData(getRangeSection().Data, isLittleEndian(),
Eli Bendersky7a94daa2013-01-25 20:26:43 +0000228 savedAddressByteSize);
229 offset = 0;
230 DWARFDebugRangeList rangeList;
George Rimarca532112017-04-24 10:19:45 +0000231 while (rangeList.extract(rangesData, &offset, getRangeSection().Relocs))
Eli Bendersky7a94daa2013-01-25 20:26:43 +0000232 rangeList.dump(OS);
Eric Christopherda4b2192013-01-02 23:52:13 +0000233 }
Eric Christopher962c9082013-01-15 23:56:56 +0000234
Eric Christopher0de53592013-09-25 23:02:36 +0000235 if (DumpType == DIDT_All || DumpType == DIDT_Pubnames)
George Rimare71e33f2016-12-17 09:10:32 +0000236 DWARFDebugPubTable(getPubNamesSection(), isLittleEndian(), false)
237 .dump("debug_pubnames", OS);
Krzysztof Parzyszek97438dc2013-02-12 16:20:28 +0000238
Eric Christopher4c7e6ba2013-09-25 23:02:41 +0000239 if (DumpType == DIDT_All || DumpType == DIDT_Pubtypes)
George Rimare71e33f2016-12-17 09:10:32 +0000240 DWARFDebugPubTable(getPubTypesSection(), isLittleEndian(), false)
241 .dump("debug_pubtypes", OS);
Eric Christopher4c7e6ba2013-09-25 23:02:41 +0000242
David Blaikieecd21ff2013-09-24 19:50:00 +0000243 if (DumpType == DIDT_All || DumpType == DIDT_GnuPubnames)
George Rimare71e33f2016-12-17 09:10:32 +0000244 DWARFDebugPubTable(getGnuPubNamesSection(), isLittleEndian(),
245 true /* GnuStyle */)
246 .dump("debug_gnu_pubnames", OS);
David Blaikieecd21ff2013-09-24 19:50:00 +0000247
248 if (DumpType == DIDT_All || DumpType == DIDT_GnuPubtypes)
George Rimare71e33f2016-12-17 09:10:32 +0000249 DWARFDebugPubTable(getGnuPubTypesSection(), isLittleEndian(),
250 true /* GnuStyle */)
251 .dump("debug_gnu_pubtypes", OS);
David Blaikie404d3042013-09-19 23:01:29 +0000252
David Blaikie66865d62014-01-09 00:13:35 +0000253 if ((DumpType == DIDT_All || DumpType == DIDT_StrOffsetsDwo) &&
254 !getStringOffsetDWOSection().empty()) {
255 OS << "\n.debug_str_offsets.dwo contents:\n";
256 DataExtractor strOffsetExt(getStringOffsetDWOSection(), isLittleEndian(),
257 0);
258 offset = 0;
259 uint64_t size = getStringOffsetDWOSection().size();
260 while (offset < size) {
261 OS << format("0x%8.8x: ", offset);
262 OS << format("%8.8x\n", strOffsetExt.getU32(&offset));
Eric Christopher92f3c0b2013-05-06 17:50:42 +0000263 }
David Blaikie66865d62014-01-09 00:13:35 +0000264 }
Frederic Risse837ec22014-11-14 16:15:53 +0000265
George Rimar4f82df52016-09-23 11:01:53 +0000266 if ((DumpType == DIDT_All || DumpType == DIDT_GdbIndex) &&
267 !getGdbIndexSection().empty()) {
268 OS << "\n.gnu_index contents:\n";
269 getGdbIndex().dump(OS);
270 }
271
Frederic Risse837ec22014-11-14 16:15:53 +0000272 if (DumpType == DIDT_All || DumpType == DIDT_AppleNames)
273 dumpAccelSection(OS, "apple_names", getAppleNamesSection(),
274 getStringSection(), isLittleEndian());
275
276 if (DumpType == DIDT_All || DumpType == DIDT_AppleTypes)
277 dumpAccelSection(OS, "apple_types", getAppleTypesSection(),
278 getStringSection(), isLittleEndian());
279
280 if (DumpType == DIDT_All || DumpType == DIDT_AppleNamespaces)
281 dumpAccelSection(OS, "apple_namespaces", getAppleNamespacesSection(),
282 getStringSection(), isLittleEndian());
283
284 if (DumpType == DIDT_All || DumpType == DIDT_AppleObjC)
285 dumpAccelSection(OS, "apple_objc", getAppleObjCSection(),
286 getStringSection(), isLittleEndian());
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000287}
288
Greg Claytonc7695a82017-05-02 20:28:33 +0000289DWARFDie DWARFContext::getDIEForOffset(uint32_t Offset) {
290 parseCompileUnits();
291 if (auto *CU = CUs.getUnitForOffset(Offset))
292 return CU->getDIEForOffset(Offset);
293 return DWARFDie();
294}
295
296namespace {
297
298class Verifier {
299 raw_ostream &OS;
300 DWARFContext &DCtx;
301public:
302 Verifier(raw_ostream &S, DWARFContext &D) : OS(S), DCtx(D) {}
303
304 bool HandleDebugInfo() {
305 bool Success = true;
306 // A map that tracks all references (converted absolute references) so we
307 // can verify each reference points to a valid DIE and not an offset that
308 // lies between to valid DIEs.
309 std::map<uint64_t, std::set<uint32_t>> ReferenceToDIEOffsets;
310
Greg Clayton48432cf2017-05-01 22:07:02 +0000311 OS << "Verifying .debug_info...\n";
Greg Claytonc7695a82017-05-02 20:28:33 +0000312 for (const auto &CU : DCtx.compile_units()) {
Greg Clayton48432cf2017-05-01 22:07:02 +0000313 unsigned NumDies = CU->getNumDIEs();
314 for (unsigned I = 0; I < NumDies; ++I) {
315 auto Die = CU->getDIEAtIndex(I);
316 const auto Tag = Die.getTag();
317 if (Tag == DW_TAG_null)
318 continue;
319 for (auto AttrValue : Die.attributes()) {
320 const auto Attr = AttrValue.Attr;
321 const auto Form = AttrValue.Value.getForm();
322 switch (Attr) {
Greg Claytonc7695a82017-05-02 20:28:33 +0000323 case DW_AT_ranges:
324 // Make sure the offset in the DW_AT_ranges attribute is valid.
325 if (auto SectionOffset = AttrValue.Value.getAsSectionOffset()) {
326 if (*SectionOffset >= DCtx.getRangeSection().Data.size()) {
327 Success = false;
328 OS << "error: DW_AT_ranges offset is beyond .debug_ranges "
329 "bounds:\n";
330 Die.dump(OS, 0);
331 OS << "\n";
332 }
333 } else {
Greg Clayton48432cf2017-05-01 22:07:02 +0000334 Success = false;
Greg Claytonc7695a82017-05-02 20:28:33 +0000335 OS << "error: DIE has invalid DW_AT_ranges encoding:\n";
Greg Clayton48432cf2017-05-01 22:07:02 +0000336 Die.dump(OS, 0);
337 OS << "\n";
338 }
Greg Claytonc7695a82017-05-02 20:28:33 +0000339 break;
340 case DW_AT_stmt_list:
341 // Make sure the offset in the DW_AT_stmt_list attribute is valid.
342 if (auto SectionOffset = AttrValue.Value.getAsSectionOffset()) {
343 if (*SectionOffset >= DCtx.getLineSection().Data.size()) {
344 Success = false;
345 OS << "error: DW_AT_stmt_list offset is beyond .debug_line "
346 "bounds: "
347 << format("0x%08" PRIx32, *SectionOffset) << "\n";
348 CU->getUnitDIE().dump(OS, 0);
349 OS << "\n";
350 }
351 } else {
Greg Clayton48432cf2017-05-01 22:07:02 +0000352 Success = false;
Greg Claytonc7695a82017-05-02 20:28:33 +0000353 OS << "error: DIE has invalid DW_AT_stmt_list encoding:\n";
354 Die.dump(OS, 0);
Greg Clayton48432cf2017-05-01 22:07:02 +0000355 OS << "\n";
356 }
Greg Claytonc7695a82017-05-02 20:28:33 +0000357 break;
358
359 default:
360 break;
Greg Clayton48432cf2017-05-01 22:07:02 +0000361 }
362 switch (Form) {
Greg Claytonc7695a82017-05-02 20:28:33 +0000363 case DW_FORM_ref1:
364 case DW_FORM_ref2:
365 case DW_FORM_ref4:
366 case DW_FORM_ref8:
367 case DW_FORM_ref_udata: {
368 // Verify all CU relative references are valid CU offsets.
369 Optional<uint64_t> RefVal = AttrValue.Value.getAsReference();
370 assert(RefVal);
371 if (RefVal) {
372 auto DieCU = Die.getDwarfUnit();
373 auto CUSize = DieCU->getNextUnitOffset() - DieCU->getOffset();
374 auto CUOffset = AttrValue.Value.getRawUValue();
375 if (CUOffset >= CUSize) {
376 Success = false;
377 OS << "error: " << FormEncodingString(Form) << " CU offset "
378 << format("0x%08" PRIx32, CUOffset)
379 << " is invalid (must be less than CU size of "
380 << format("0x%08" PRIx32, CUSize) << "):\n";
381 Die.dump(OS, 0);
382 OS << "\n";
383 } else {
384 // Valid reference, but we will verify it points to an actual
385 // DIE later.
386 ReferenceToDIEOffsets[*RefVal].insert(Die.getOffset());
387 }
388 }
389 break;
390 }
391 case DW_FORM_ref_addr: {
392 // Verify all absolute DIE references have valid offsets in the
393 // .debug_info section.
394 Optional<uint64_t> RefVal = AttrValue.Value.getAsReference();
395 assert(RefVal);
396 if (RefVal) {
397 if(*RefVal >= DCtx.getInfoSection().Data.size()) {
398 Success = false;
399 OS << "error: DW_FORM_ref_addr offset beyond .debug_info "
400 "bounds:\n";
401 Die.dump(OS, 0);
402 OS << "\n";
403 } else {
404 // Valid reference, but we will verify it points to an actual
405 // DIE later.
406 ReferenceToDIEOffsets[*RefVal].insert(Die.getOffset());
407 }
408 }
409 break;
410 }
411 case DW_FORM_strp: {
412 auto SecOffset = AttrValue.Value.getAsSectionOffset();
413 assert(SecOffset); // DW_FORM_strp is a section offset.
414 if (SecOffset && *SecOffset >= DCtx.getStringSection().size()) {
Greg Clayton48432cf2017-05-01 22:07:02 +0000415 Success = false;
Greg Claytonc7695a82017-05-02 20:28:33 +0000416 OS << "error: DW_FORM_strp offset beyond .debug_str bounds:\n";
Greg Clayton48432cf2017-05-01 22:07:02 +0000417 Die.dump(OS, 0);
418 OS << "\n";
419 }
Greg Claytonc7695a82017-05-02 20:28:33 +0000420 break;
Greg Clayton48432cf2017-05-01 22:07:02 +0000421 }
Greg Claytonc7695a82017-05-02 20:28:33 +0000422 default:
423 break;
Greg Clayton48432cf2017-05-01 22:07:02 +0000424 }
425 }
426 }
427 }
Greg Claytonc7695a82017-05-02 20:28:33 +0000428
429 // Take all references and make sure they point to an actual DIE by
430 // getting the DIE by offset and emitting an error
431 OS << "Verifying .debug_info references...\n";
432 for (auto Pair: ReferenceToDIEOffsets) {
433 auto Die = DCtx.getDIEForOffset(Pair.first);
434 if (Die)
435 continue;
436 Success = false;
437 OS << "error: invalid DIE reference " << format("0x%08" PRIx64, Pair.first)
438 << ". Offset is in between DIEs:\n";
439 for (auto Offset: Pair.second) {
440 auto ReferencingDie = DCtx.getDIEForOffset(Offset);
441 ReferencingDie.dump(OS, 0);
442 OS << "\n";
443 }
444 OS << "\n";
445 }
446 return Success;
447 }
Greg Clayton67070462017-05-02 22:48:52 +0000448
449 bool HandleDebugLine() {
Greg Clayton8df55b42017-05-03 15:45:31 +0000450 std::map<uint64_t, DWARFDie> StmtListToDie;
Greg Clayton67070462017-05-02 22:48:52 +0000451 bool Success = true;
452 OS << "Verifying .debug_line...\n";
453 for (const auto &CU : DCtx.compile_units()) {
454 uint32_t LineTableOffset = 0;
Greg Clayton8df55b42017-05-03 15:45:31 +0000455 auto CUDie = CU->getUnitDIE();
456 auto StmtFormValue = CUDie.find(DW_AT_stmt_list);
Greg Clayton67070462017-05-02 22:48:52 +0000457 if (!StmtFormValue) {
458 // No line table for this compile unit.
459 continue;
460 }
461 // Get the attribute value as a section offset. No need to produce an
462 // error here if the encoding isn't correct because we validate this in
463 // the .debug_info verifier.
464 if (auto StmtSectionOffset = toSectionOffset(StmtFormValue)) {
465 LineTableOffset = *StmtSectionOffset;
466 if (LineTableOffset >= DCtx.getLineSection().Data.size()) {
467 // Make sure we don't get a valid line table back if the offset
468 // is wrong.
469 assert(DCtx.getLineTableForUnit(CU.get()) == nullptr);
470 // Skip this line table as it isn't valid. No need to create an error
471 // here because we validate this in the .debug_info verifier.
472 continue;
Greg Clayton8df55b42017-05-03 15:45:31 +0000473 } else {
474 auto Iter = StmtListToDie.find(LineTableOffset);
475 if (Iter != StmtListToDie.end()) {
476 Success = false;
477 OS << "error: two compile unit DIEs, "
478 << format("0x%08" PRIx32, Iter->second.getOffset()) << " and "
479 << format("0x%08" PRIx32, CUDie.getOffset())
480 << ", have the same DW_AT_stmt_list section offset:\n";
481 Iter->second.dump(OS, 0);
482 CUDie.dump(OS, 0);
483 OS << '\n';
484 // Already verified this line table before, no need to do it again.
485 continue;
486 }
487 StmtListToDie[LineTableOffset] = CUDie;
Greg Clayton67070462017-05-02 22:48:52 +0000488 }
489 }
490 auto LineTable = DCtx.getLineTableForUnit(CU.get());
491 if (!LineTable) {
492 Success = false;
493 OS << "error: .debug_line[" << format("0x%08" PRIx32, LineTableOffset)
494 << "] was not able to be parsed for CU:\n";
Greg Clayton8df55b42017-05-03 15:45:31 +0000495 CUDie.dump(OS, 0);
Greg Clayton67070462017-05-02 22:48:52 +0000496 OS << '\n';
497 continue;
498 }
499 uint32_t MaxFileIndex = LineTable->Prologue.FileNames.size();
500 uint64_t PrevAddress = 0;
501 uint32_t RowIndex = 0;
502 for (const auto &Row : LineTable->Rows) {
503 if (Row.Address < PrevAddress) {
504 Success = false;
505 OS << "error: .debug_line[" << format("0x%08" PRIx32, LineTableOffset)
506 << "] row[" << RowIndex
507 << "] decreases in address from previous row:\n";
508
509 DWARFDebugLine::Row::dumpTableHeader(OS);
510 if (RowIndex > 0)
511 LineTable->Rows[RowIndex - 1].dump(OS);
512 Row.dump(OS);
513 OS << '\n';
514 }
515
516 if (Row.File > MaxFileIndex) {
517 Success = false;
518 OS << "error: .debug_line[" << format("0x%08" PRIx32, LineTableOffset)
519 << "][" << RowIndex << "] has invalid file index " << Row.File
520 << " (valid values are [1," << MaxFileIndex << "]):\n";
521 DWARFDebugLine::Row::dumpTableHeader(OS);
522 Row.dump(OS);
523 OS << '\n';
524 }
525 if (Row.EndSequence)
526 PrevAddress = 0;
527 else
528 PrevAddress = Row.Address;
529 ++RowIndex;
530 }
531 }
532 return Success;
533 }
Greg Claytonc7695a82017-05-02 20:28:33 +0000534};
535
536} // anonymous namespace
537
538bool DWARFContext::verify(raw_ostream &OS, DIDumpType DumpType) {
539 bool Success = true;
540 Verifier verifier(OS, *this);
541 if (DumpType == DIDT_All || DumpType == DIDT_Info) {
542 if (!verifier.HandleDebugInfo())
543 Success = false;
Greg Clayton48432cf2017-05-01 22:07:02 +0000544 }
Greg Clayton67070462017-05-02 22:48:52 +0000545 if (DumpType == DIDT_All || DumpType == DIDT_Line) {
546 if (!verifier.HandleDebugLine())
547 Success = false;
548 }
Greg Clayton48432cf2017-05-01 22:07:02 +0000549 return Success;
550}
David Blaikie82641be2015-11-17 00:39:55 +0000551const DWARFUnitIndex &DWARFContext::getCUIndex() {
552 if (CUIndex)
553 return *CUIndex;
554
555 DataExtractor CUIndexData(getCUIndexSection(), isLittleEndian(), 0);
556
David Blaikieb073cb92015-12-02 06:21:34 +0000557 CUIndex = llvm::make_unique<DWARFUnitIndex>(DW_SECT_INFO);
David Blaikie82641be2015-11-17 00:39:55 +0000558 CUIndex->parse(CUIndexData);
559 return *CUIndex;
560}
561
562const DWARFUnitIndex &DWARFContext::getTUIndex() {
563 if (TUIndex)
564 return *TUIndex;
565
566 DataExtractor TUIndexData(getTUIndexSection(), isLittleEndian(), 0);
567
David Blaikieb073cb92015-12-02 06:21:34 +0000568 TUIndex = llvm::make_unique<DWARFUnitIndex>(DW_SECT_TYPES);
David Blaikie82641be2015-11-17 00:39:55 +0000569 TUIndex->parse(TUIndexData);
570 return *TUIndex;
571}
572
George Rimar4f82df52016-09-23 11:01:53 +0000573DWARFGdbIndex &DWARFContext::getGdbIndex() {
574 if (GdbIndex)
575 return *GdbIndex;
576
577 DataExtractor GdbIndexData(getGdbIndexSection(), true /*LE*/, 0);
578 GdbIndex = llvm::make_unique<DWARFGdbIndex>();
579 GdbIndex->parse(GdbIndexData);
580 return *GdbIndex;
581}
582
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000583const DWARFDebugAbbrev *DWARFContext::getDebugAbbrev() {
584 if (Abbrev)
585 return Abbrev.get();
586
587 DataExtractor abbrData(getAbbrevSection(), isLittleEndian(), 0);
588
589 Abbrev.reset(new DWARFDebugAbbrev());
Alexey Samsonov4316df52014-04-25 21:10:56 +0000590 Abbrev->extract(abbrData);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000591 return Abbrev.get();
592}
593
Eric Christopherda4b2192013-01-02 23:52:13 +0000594const DWARFDebugAbbrev *DWARFContext::getDebugAbbrevDWO() {
595 if (AbbrevDWO)
596 return AbbrevDWO.get();
597
598 DataExtractor abbrData(getAbbrevDWOSection(), isLittleEndian(), 0);
599 AbbrevDWO.reset(new DWARFDebugAbbrev());
Alexey Samsonov4316df52014-04-25 21:10:56 +0000600 AbbrevDWO->extract(abbrData);
Eric Christopherda4b2192013-01-02 23:52:13 +0000601 return AbbrevDWO.get();
602}
603
David Blaikie18e73502013-06-19 21:37:13 +0000604const DWARFDebugLoc *DWARFContext::getDebugLoc() {
605 if (Loc)
606 return Loc.get();
607
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000608 DataExtractor LocData(getLocSection().Data, isLittleEndian(), 0);
609 Loc.reset(new DWARFDebugLoc(getLocSection().Relocs));
David Blaikie18e73502013-06-19 21:37:13 +0000610 // assume all compile units have the same address byte size
611 if (getNumCompileUnits())
612 Loc->parse(LocData, getCompileUnitAtIndex(0)->getAddressByteSize());
613 return Loc.get();
614}
615
David Blaikie9c550ac2014-03-25 01:44:02 +0000616const DWARFDebugLocDWO *DWARFContext::getDebugLocDWO() {
617 if (LocDWO)
618 return LocDWO.get();
619
620 DataExtractor LocData(getLocDWOSection().Data, isLittleEndian(), 0);
621 LocDWO.reset(new DWARFDebugLocDWO());
622 LocDWO->parse(LocData);
623 return LocDWO.get();
624}
625
Benjamin Kramera6002fd2011-09-14 01:09:52 +0000626const DWARFDebugAranges *DWARFContext::getDebugAranges() {
627 if (Aranges)
628 return Aranges.get();
629
Benjamin Kramera6002fd2011-09-14 01:09:52 +0000630 Aranges.reset(new DWARFDebugAranges());
Alexey Samsonova1694c12012-11-16 08:36:25 +0000631 Aranges->generate(this);
Benjamin Kramera6002fd2011-09-14 01:09:52 +0000632 return Aranges.get();
633}
634
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000635const DWARFDebugFrame *DWARFContext::getDebugFrame() {
636 if (DebugFrame)
637 return DebugFrame.get();
638
639 // There's a "bug" in the DWARFv3 standard with respect to the target address
640 // size within debug frame sections. While DWARF is supposed to be independent
641 // of its container, FDEs have fields with size being "target address size",
642 // which isn't specified in DWARF in general. It's only specified for CUs, but
643 // .eh_frame can appear without a .debug_info section. Follow the example of
644 // other tools (libdwarf) and extract this from the container (ObjectFile
645 // provides this information). This problem is fixed in DWARFv4
646 // See this dwarf-discuss discussion for more details:
647 // http://lists.dwarfstd.org/htdig.cgi/dwarf-discuss-dwarfstd.org/2011-December/001173.html
648 DataExtractor debugFrameData(getDebugFrameSection(), isLittleEndian(),
649 getAddressSize());
Igor Laevsky03a670c2016-01-26 15:09:42 +0000650 DebugFrame.reset(new DWARFDebugFrame(false /* IsEH */));
651 DebugFrame->parse(debugFrameData);
652 return DebugFrame.get();
653}
654
655const DWARFDebugFrame *DWARFContext::getEHFrame() {
656 if (EHFrame)
657 return EHFrame.get();
658
659 DataExtractor debugFrameData(getEHFrameSection(), isLittleEndian(),
660 getAddressSize());
661 DebugFrame.reset(new DWARFDebugFrame(true /* IsEH */));
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000662 DebugFrame->parse(debugFrameData);
663 return DebugFrame.get();
664}
665
Amjad Aboude59cc3e2015-11-12 09:38:54 +0000666const DWARFDebugMacro *DWARFContext::getDebugMacro() {
667 if (Macro)
668 return Macro.get();
669
670 DataExtractor MacinfoData(getMacinfoSection(), isLittleEndian(), 0);
671 Macro.reset(new DWARFDebugMacro());
672 Macro->parse(MacinfoData);
673 return Macro.get();
674}
675
Eric Christopher494109b2012-10-16 23:46:25 +0000676const DWARFLineTable *
Alexey Samsonov7a18c062015-05-19 21:54:32 +0000677DWARFContext::getLineTableForUnit(DWARFUnit *U) {
Benjamin Kramer679e1752011-09-15 20:43:18 +0000678 if (!Line)
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000679 Line.reset(new DWARFDebugLine(&getLineSection().Relocs));
David Blaikiec4e2bed2015-11-17 21:08:05 +0000680
Greg Claytonc8c10322016-12-13 18:25:19 +0000681 auto UnitDIE = U->getUnitDIE();
682 if (!UnitDIE)
Alexey Samsonov7a18c062015-05-19 21:54:32 +0000683 return nullptr;
David Blaikiec4e2bed2015-11-17 21:08:05 +0000684
Greg Clayton97d22182017-01-13 21:08:18 +0000685 auto Offset = toSectionOffset(UnitDIE.find(DW_AT_stmt_list));
Greg Clayton52fe1f62016-12-14 22:38:08 +0000686 if (!Offset)
Craig Topper2617dcc2014-04-15 06:32:26 +0000687 return nullptr; // No line table for this compile unit.
Benjamin Kramer5acab502011-09-15 02:12:05 +0000688
Greg Clayton52fe1f62016-12-14 22:38:08 +0000689 uint32_t stmtOffset = *Offset + U->getLineTableOffset();
Benjamin Kramer679e1752011-09-15 20:43:18 +0000690 // See if the line table is cached.
Eric Christopher494109b2012-10-16 23:46:25 +0000691 if (const DWARFLineTable *lt = Line->getLineTable(stmtOffset))
Benjamin Kramer679e1752011-09-15 20:43:18 +0000692 return lt;
693
694 // We have to parse it first.
David Blaikiec4e2bed2015-11-17 21:08:05 +0000695 DataExtractor lineData(U->getLineSection(), isLittleEndian(),
Alexey Samsonov7a18c062015-05-19 21:54:32 +0000696 U->getAddressByteSize());
Benjamin Kramer679e1752011-09-15 20:43:18 +0000697 return Line->getOrParseLineTable(lineData, stmtOffset);
Benjamin Kramer5acab502011-09-15 02:12:05 +0000698}
699
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000700void DWARFContext::parseCompileUnits() {
Alexey Samsonov8cd4c9d2014-10-08 00:07:53 +0000701 CUs.parse(*this, getInfoSection());
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000702}
Benjamin Kramer2602ca62011-09-15 20:43:22 +0000703
David Blaikie03c089c2013-09-23 22:44:47 +0000704void DWARFContext::parseTypeUnits() {
Alexey Samsonov1eabf982014-03-13 07:52:54 +0000705 if (!TUs.empty())
706 return;
707 for (const auto &I : getTypesSections()) {
Benjamin Kramerf5e2fc42015-05-29 19:43:39 +0000708 TUs.emplace_back();
Alexey Samsonov8cd4c9d2014-10-08 00:07:53 +0000709 TUs.back().parse(*this, I.second);
David Blaikie03c089c2013-09-23 22:44:47 +0000710 }
711}
712
Eric Christopherda4b2192013-01-02 23:52:13 +0000713void DWARFContext::parseDWOCompileUnits() {
Alexey Samsonov8cd4c9d2014-10-08 00:07:53 +0000714 DWOCUs.parseDWO(*this, getInfoDWOSection());
Eric Christopherda4b2192013-01-02 23:52:13 +0000715}
716
David Blaikie92d9d622014-01-09 05:08:24 +0000717void DWARFContext::parseDWOTypeUnits() {
Alexey Samsonov1eabf982014-03-13 07:52:54 +0000718 if (!DWOTUs.empty())
719 return;
720 for (const auto &I : getTypesDWOSections()) {
Benjamin Kramerf5e2fc42015-05-29 19:43:39 +0000721 DWOTUs.emplace_back();
Alexey Samsonov8cd4c9d2014-10-08 00:07:53 +0000722 DWOTUs.back().parseDWO(*this, I.second);
David Blaikie92d9d622014-01-09 05:08:24 +0000723 }
724}
725
Alexey Samsonov45be7932012-08-30 07:49:50 +0000726DWARFCompileUnit *DWARFContext::getCompileUnitForOffset(uint32_t Offset) {
Alexey Samsonov1eabf982014-03-13 07:52:54 +0000727 parseCompileUnits();
Frederic Riss4e126a02014-09-15 07:50:27 +0000728 return CUs.getUnitForOffset(Offset);
Benjamin Kramer2602ca62011-09-15 20:43:22 +0000729}
730
Alexey Samsonov45be7932012-08-30 07:49:50 +0000731DWARFCompileUnit *DWARFContext::getCompileUnitForAddress(uint64_t Address) {
Benjamin Kramer112ec172011-09-15 21:59:13 +0000732 // First, get the offset of the compile unit.
Alexey Samsonov45be7932012-08-30 07:49:50 +0000733 uint32_t CUOffset = getDebugAranges()->findAddress(Address);
Benjamin Kramer2602ca62011-09-15 20:43:22 +0000734 // Retrieve the compile unit.
Alexey Samsonov45be7932012-08-30 07:49:50 +0000735 return getCompileUnitForOffset(CUOffset);
736}
737
David Blaikieefc4eba2017-02-06 20:19:02 +0000738static bool getFunctionNameAndStartLineForAddress(DWARFCompileUnit *CU,
739 uint64_t Address,
740 FunctionNameKind Kind,
741 std::string &FunctionName,
742 uint32_t &StartLine) {
Alexey Samsonovd0109992014-04-18 21:36:39 +0000743 // The address may correspond to instruction in some inlined function,
744 // so we have to build the chain of inlined functions and take the
David Blaikieefc4eba2017-02-06 20:19:02 +0000745 // name of the topmost function in it.
Greg Claytonc8c10322016-12-13 18:25:19 +0000746 SmallVector<DWARFDie, 4> InlinedChain;
747 CU->getInlinedChainForAddress(Address, InlinedChain);
David Blaikieefc4eba2017-02-06 20:19:02 +0000748 if (InlinedChain.empty())
Alexey Samsonovd0109992014-04-18 21:36:39 +0000749 return false;
David Blaikieefc4eba2017-02-06 20:19:02 +0000750
751 const DWARFDie &DIE = InlinedChain[0];
752 bool FoundResult = false;
753 const char *Name = nullptr;
754 if (Kind != FunctionNameKind::None && (Name = DIE.getSubroutineName(Kind))) {
Alexey Samsonovd0109992014-04-18 21:36:39 +0000755 FunctionName = Name;
David Blaikieefc4eba2017-02-06 20:19:02 +0000756 FoundResult = true;
Alexey Samsonovd0109992014-04-18 21:36:39 +0000757 }
David Blaikieefc4eba2017-02-06 20:19:02 +0000758 if (auto DeclLineResult = DIE.getDeclLine()) {
759 StartLine = DeclLineResult;
760 FoundResult = true;
761 }
762
763 return FoundResult;
Alexey Samsonovd0109992014-04-18 21:36:39 +0000764}
765
Alexey Samsonov45be7932012-08-30 07:49:50 +0000766DILineInfo DWARFContext::getLineInfoForAddress(uint64_t Address,
Alexey Samsonovdce67342014-05-15 21:24:32 +0000767 DILineInfoSpecifier Spec) {
Alexey Samsonovd0109992014-04-18 21:36:39 +0000768 DILineInfo Result;
769
Alexey Samsonov45be7932012-08-30 07:49:50 +0000770 DWARFCompileUnit *CU = getCompileUnitForAddress(Address);
771 if (!CU)
Alexey Samsonovd0109992014-04-18 21:36:39 +0000772 return Result;
David Blaikieefc4eba2017-02-06 20:19:02 +0000773 getFunctionNameAndStartLineForAddress(CU, Address, Spec.FNKind,
774 Result.FunctionName,
775 Result.StartLine);
Alexey Samsonovdce67342014-05-15 21:24:32 +0000776 if (Spec.FLIKind != FileLineInfoKind::None) {
Frederic Riss101b5e22014-09-19 15:11:51 +0000777 if (const DWARFLineTable *LineTable = getLineTableForUnit(CU))
778 LineTable->getFileLineInfoForAddress(Address, CU->getCompilationDir(),
779 Spec.FLIKind, Result);
Alexey Samsonovf4462fa2012-07-02 05:54:45 +0000780 }
Alexey Samsonovd0109992014-04-18 21:36:39 +0000781 return Result;
Benjamin Kramer2602ca62011-09-15 20:43:22 +0000782}
David Blaikiea379b1812011-12-20 02:50:00 +0000783
Alexey Samsonovdce67342014-05-15 21:24:32 +0000784DILineInfoTable
785DWARFContext::getLineInfoForAddressRange(uint64_t Address, uint64_t Size,
786 DILineInfoSpecifier Spec) {
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000787 DILineInfoTable Lines;
788 DWARFCompileUnit *CU = getCompileUnitForAddress(Address);
789 if (!CU)
790 return Lines;
791
792 std::string FunctionName = "<invalid>";
David Blaikieefc4eba2017-02-06 20:19:02 +0000793 uint32_t StartLine = 0;
794 getFunctionNameAndStartLineForAddress(CU, Address, Spec.FNKind, FunctionName,
795 StartLine);
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000796
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000797 // If the Specifier says we don't need FileLineInfo, just
798 // return the top-most function at the starting address.
Alexey Samsonovdce67342014-05-15 21:24:32 +0000799 if (Spec.FLIKind == FileLineInfoKind::None) {
Alexey Samsonovd0109992014-04-18 21:36:39 +0000800 DILineInfo Result;
801 Result.FunctionName = FunctionName;
David Blaikieefc4eba2017-02-06 20:19:02 +0000802 Result.StartLine = StartLine;
Alexey Samsonovd0109992014-04-18 21:36:39 +0000803 Lines.push_back(std::make_pair(Address, Result));
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000804 return Lines;
805 }
806
Frederic Rissec8a5ba2014-09-04 06:14:40 +0000807 const DWARFLineTable *LineTable = getLineTableForUnit(CU);
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000808
809 // Get the index of row we're looking for in the line table.
810 std::vector<uint32_t> RowVector;
811 if (!LineTable->lookupAddressRange(Address, Size, RowVector))
812 return Lines;
813
Alexey Samsonov1eabf982014-03-13 07:52:54 +0000814 for (uint32_t RowIndex : RowVector) {
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000815 // Take file number and line/column from the row.
816 const DWARFDebugLine::Row &Row = LineTable->Rows[RowIndex];
Alexey Samsonovd0109992014-04-18 21:36:39 +0000817 DILineInfo Result;
Frederic Riss101b5e22014-09-19 15:11:51 +0000818 LineTable->getFileNameByIndex(Row.File, CU->getCompilationDir(),
819 Spec.FLIKind, Result.FileName);
Alexey Samsonovd0109992014-04-18 21:36:39 +0000820 Result.FunctionName = FunctionName;
821 Result.Line = Row.Line;
822 Result.Column = Row.Column;
David Blaikieefc4eba2017-02-06 20:19:02 +0000823 Result.StartLine = StartLine;
Alexey Samsonovd0109992014-04-18 21:36:39 +0000824 Lines.push_back(std::make_pair(Row.Address, Result));
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000825 }
826
827 return Lines;
828}
829
Alexey Samsonovdce67342014-05-15 21:24:32 +0000830DIInliningInfo
831DWARFContext::getInliningInfoForAddress(uint64_t Address,
832 DILineInfoSpecifier Spec) {
Alexey Samsonov5c39fdf2014-04-18 22:22:44 +0000833 DIInliningInfo InliningInfo;
834
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000835 DWARFCompileUnit *CU = getCompileUnitForAddress(Address);
836 if (!CU)
Alexey Samsonov5c39fdf2014-04-18 22:22:44 +0000837 return InliningInfo;
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000838
Alexey Samsonov5c39fdf2014-04-18 22:22:44 +0000839 const DWARFLineTable *LineTable = nullptr;
Greg Claytonc8c10322016-12-13 18:25:19 +0000840 SmallVector<DWARFDie, 4> InlinedChain;
841 CU->getInlinedChainForAddress(Address, InlinedChain);
842 if (InlinedChain.size() == 0) {
Alexey Samsonov5c39fdf2014-04-18 22:22:44 +0000843 // If there is no DIE for address (e.g. it is in unavailable .dwo file),
844 // try to at least get file/line info from symbol table.
Alexey Samsonovdce67342014-05-15 21:24:32 +0000845 if (Spec.FLIKind != FileLineInfoKind::None) {
Alexey Samsonov5c39fdf2014-04-18 22:22:44 +0000846 DILineInfo Frame;
Frederic Rissec8a5ba2014-09-04 06:14:40 +0000847 LineTable = getLineTableForUnit(CU);
Frederic Riss101b5e22014-09-19 15:11:51 +0000848 if (LineTable &&
849 LineTable->getFileLineInfoForAddress(Address, CU->getCompilationDir(),
850 Spec.FLIKind, Frame))
Alexey Samsonov5c39fdf2014-04-18 22:22:44 +0000851 InliningInfo.addFrame(Frame);
Alexey Samsonov5c39fdf2014-04-18 22:22:44 +0000852 }
853 return InliningInfo;
854 }
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000855
Dehao Chenef700d52017-04-17 20:10:39 +0000856 uint32_t CallFile = 0, CallLine = 0, CallColumn = 0, CallDiscriminator = 0;
Greg Claytonc8c10322016-12-13 18:25:19 +0000857 for (uint32_t i = 0, n = InlinedChain.size(); i != n; i++) {
858 DWARFDie &FunctionDIE = InlinedChain[i];
Alexey Samsonovd0109992014-04-18 21:36:39 +0000859 DILineInfo Frame;
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000860 // Get function name if necessary.
Greg Claytonc8c10322016-12-13 18:25:19 +0000861 if (const char *Name = FunctionDIE.getSubroutineName(Spec.FNKind))
Alexey Samsonovdce67342014-05-15 21:24:32 +0000862 Frame.FunctionName = Name;
David Blaikieefc4eba2017-02-06 20:19:02 +0000863 if (auto DeclLineResult = FunctionDIE.getDeclLine())
864 Frame.StartLine = DeclLineResult;
Alexey Samsonovdce67342014-05-15 21:24:32 +0000865 if (Spec.FLIKind != FileLineInfoKind::None) {
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000866 if (i == 0) {
867 // For the topmost frame, initialize the line table of this
868 // compile unit and fetch file/line info from it.
Frederic Rissec8a5ba2014-09-04 06:14:40 +0000869 LineTable = getLineTableForUnit(CU);
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000870 // For the topmost routine, get file/line info from line table.
Frederic Riss101b5e22014-09-19 15:11:51 +0000871 if (LineTable)
872 LineTable->getFileLineInfoForAddress(Address, CU->getCompilationDir(),
873 Spec.FLIKind, Frame);
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000874 } else {
875 // Otherwise, use call file, call line and call column from
876 // previous DIE in inlined chain.
Frederic Riss101b5e22014-09-19 15:11:51 +0000877 if (LineTable)
878 LineTable->getFileNameByIndex(CallFile, CU->getCompilationDir(),
879 Spec.FLIKind, Frame.FileName);
Alexey Samsonovd0109992014-04-18 21:36:39 +0000880 Frame.Line = CallLine;
881 Frame.Column = CallColumn;
Dehao Chenef700d52017-04-17 20:10:39 +0000882 Frame.Discriminator = CallDiscriminator;
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000883 }
884 // Get call file/line/column of a current DIE.
885 if (i + 1 < n) {
Dehao Chenef700d52017-04-17 20:10:39 +0000886 FunctionDIE.getCallerFrame(CallFile, CallLine, CallColumn,
887 CallDiscriminator);
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000888 }
889 }
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000890 InliningInfo.addFrame(Frame);
891 }
892 return InliningInfo;
893}
894
George Rimar702dac62017-04-12 08:59:15 +0000895static Error createError(const Twine &Reason, llvm::Error E) {
896 return make_error<StringError>(Reason + toString(std::move(E)),
897 inconvertibleErrorCode());
898}
899
900/// Returns the address of symbol relocation used against. Used for futher
901/// relocations computation. Symbol's section load address is taken in account if
902/// LoadedObjectInfo interface is provided.
903static Expected<uint64_t> getSymbolAddress(const object::ObjectFile &Obj,
904 const RelocationRef &Reloc,
905 const LoadedObjectInfo *L) {
906 uint64_t Ret = 0;
907 object::section_iterator RSec = Obj.section_end();
908 object::symbol_iterator Sym = Reloc.getSymbol();
909
910 // First calculate the address of the symbol or section as it appears
911 // in the object file
912 if (Sym != Obj.symbol_end()) {
913 Expected<uint64_t> SymAddrOrErr = Sym->getAddress();
914 if (!SymAddrOrErr)
915 return createError("error: failed to compute symbol address: ",
916 SymAddrOrErr.takeError());
917
918 // Also remember what section this symbol is in for later
919 auto SectOrErr = Sym->getSection();
920 if (!SectOrErr)
921 return createError("error: failed to get symbol section: ",
922 SectOrErr.takeError());
923
924 RSec = *SectOrErr;
925 Ret = *SymAddrOrErr;
926 } else if (auto *MObj = dyn_cast<MachOObjectFile>(&Obj)) {
927 RSec = MObj->getRelocationSection(Reloc.getRawDataRefImpl());
928 Ret = RSec->getAddress();
929 }
930
931 // If we are given load addresses for the sections, we need to adjust:
932 // SymAddr = (Address of Symbol Or Section in File) -
933 // (Address of Section in File) +
934 // (Load Address of Section)
935 // RSec is now either the section being targeted or the section
936 // containing the symbol being targeted. In either case,
937 // we need to perform the same computation.
938 if (L && RSec != Obj.section_end())
939 if (uint64_t SectionLoadAddress = L->getSectionLoadAddress(*RSec))
940 Ret += SectionLoadAddress - RSec->getAddress();
941 return Ret;
942}
943
944static bool isRelocScattered(const object::ObjectFile &Obj,
945 const RelocationRef &Reloc) {
George Rimard4998b02017-04-13 09:52:50 +0000946 const MachOObjectFile *MachObj = dyn_cast<MachOObjectFile>(&Obj);
947 if (!MachObj)
George Rimar702dac62017-04-12 08:59:15 +0000948 return false;
949 // MachO also has relocations that point to sections and
950 // scattered relocations.
George Rimar702dac62017-04-12 08:59:15 +0000951 auto RelocInfo = MachObj->getRelocation(Reloc.getRawDataRefImpl());
952 return MachObj->isRelocationScattered(RelocInfo);
953}
954
Keno Fischerc780e8e2015-05-21 21:24:32 +0000955DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj,
956 const LoadedObjectInfo *L)
Rafael Espindolaa04bb5b2014-07-31 20:19:36 +0000957 : IsLittleEndian(Obj.isLittleEndian()),
958 AddressSize(Obj.getBytesInAddress()) {
959 for (const SectionRef &Section : Obj.sections()) {
Eric Christopher7370b552012-11-12 21:40:38 +0000960 StringRef name;
Alexey Samsonov063eb3f2014-03-13 13:52:54 +0000961 Section.getName(name);
David Majnemerdac39852014-09-26 22:32:16 +0000962 // Skip BSS and Virtual sections, they aren't interesting.
Rafael Espindola80291272014-10-08 15:28:58 +0000963 bool IsBSS = Section.isBSS();
David Majnemerdac39852014-09-26 22:32:16 +0000964 if (IsBSS)
965 continue;
Rafael Espindola80291272014-10-08 15:28:58 +0000966 bool IsVirtual = Section.isVirtual();
David Majnemerdac39852014-09-26 22:32:16 +0000967 if (IsVirtual)
968 continue;
Eric Christopher7370b552012-11-12 21:40:38 +0000969 StringRef data;
Keno Fischerc780e8e2015-05-21 21:24:32 +0000970
Lang Hames2e88f4f2015-07-28 17:52:11 +0000971 section_iterator RelocatedSection = Section.getRelocatedSection();
Keno Fischerc780e8e2015-05-21 21:24:32 +0000972 // Try to obtain an already relocated version of this section.
973 // Else use the unrelocated section from the object file. We'll have to
974 // apply relocations ourselves later.
Lang Hames2e88f4f2015-07-28 17:52:11 +0000975 if (!L || !L->getLoadedSectionContents(*RelocatedSection,data))
Keno Fischerc780e8e2015-05-21 21:24:32 +0000976 Section.getContents(data);
Eric Christopher7370b552012-11-12 21:40:38 +0000977
George Rimar4bf30832017-01-11 15:26:41 +0000978 if (Decompressor::isCompressed(Section)) {
979 Expected<Decompressor> Decompressor =
980 Decompressor::create(name, data, IsLittleEndian, AddressSize == 8);
981 if (!Decompressor)
982 continue;
George Rimar401e4e52016-05-24 12:48:46 +0000983 SmallString<32> Out;
George Rimar4bf30832017-01-11 15:26:41 +0000984 if (auto Err = Decompressor->decompress(Out))
Alexey Samsonov068fc8a2013-04-23 10:17:34 +0000985 continue;
George Rimar401e4e52016-05-24 12:48:46 +0000986 UncompressedSections.emplace_back(std::move(Out));
David Blaikiea505f242014-04-05 21:26:44 +0000987 data = UncompressedSections.back();
Alexey Samsonov068fc8a2013-04-23 10:17:34 +0000988 }
989
George Rimar4bf30832017-01-11 15:26:41 +0000990 // Compressed sections names in GNU style starts from ".z",
991 // at this point section is decompressed and we drop compression prefix.
992 name = name.substr(
993 name.find_first_not_of("._z")); // Skip ".", "z" and "_" prefixes.
994
Chris Bieneman2e752db2017-01-20 19:03:14 +0000995 if (StringRef *SectionData = MapSectionToMember(name)) {
Alexey Samsonov063eb3f2014-03-13 13:52:54 +0000996 *SectionData = data;
Rafael Espindola4f60a382013-05-30 03:05:14 +0000997 if (name == "debug_ranges") {
998 // FIXME: Use the other dwo range section when we emit it.
George Rimarca532112017-04-24 10:19:45 +0000999 RangeDWOSection.Data = data;
Rafael Espindola4f60a382013-05-30 03:05:14 +00001000 }
David Blaikie03c089c2013-09-23 22:44:47 +00001001 } else if (name == "debug_types") {
David Blaikie427e4352013-09-23 23:39:55 +00001002 // Find debug_types data by section rather than name as there are
1003 // multiple, comdat grouped, debug_types sections.
Alexey Samsonov063eb3f2014-03-13 13:52:54 +00001004 TypesSections[Section].Data = data;
David Blaikie92d9d622014-01-09 05:08:24 +00001005 } else if (name == "debug_types.dwo") {
Alexey Samsonov063eb3f2014-03-13 13:52:54 +00001006 TypesDWOSections[Section].Data = data;
Eric Christopherda4b2192013-01-02 23:52:13 +00001007 }
Eric Christopher7370b552012-11-12 21:40:38 +00001008
Rafael Espindolaa04bb5b2014-07-31 20:19:36 +00001009 if (RelocatedSection == Obj.section_end())
Rafael Espindola4f60a382013-05-30 03:05:14 +00001010 continue;
1011
1012 StringRef RelSecName;
Keno Fischerc780e8e2015-05-21 21:24:32 +00001013 StringRef RelSecData;
Rafael Espindola4f60a382013-05-30 03:05:14 +00001014 RelocatedSection->getName(RelSecName);
Keno Fischerc780e8e2015-05-21 21:24:32 +00001015
1016 // If the section we're relocating was relocated already by the JIT,
1017 // then we used the relocated version above, so we do not need to process
1018 // relocations for it now.
Lang Hames2e88f4f2015-07-28 17:52:11 +00001019 if (L && L->getLoadedSectionContents(*RelocatedSection,RelSecData))
Keno Fischerc780e8e2015-05-21 21:24:32 +00001020 continue;
1021
Frederic Riss7bb12262015-08-23 04:44:21 +00001022 // In Mach-o files, the relocations do not need to be applied if
1023 // there is no load offset to apply. The value read at the
1024 // relocation point already factors in the section address
1025 // (actually applying the relocations will produce wrong results
1026 // as the section address will be added twice).
Craig Topper66059c92015-11-18 07:07:59 +00001027 if (!L && isa<MachOObjectFile>(&Obj))
Frederic Riss7bb12262015-08-23 04:44:21 +00001028 continue;
1029
Rafael Espindola4f60a382013-05-30 03:05:14 +00001030 RelSecName = RelSecName.substr(
1031 RelSecName.find_first_not_of("._")); // Skip . and _ prefixes.
1032
Andrew Kaylord55d7012013-01-25 22:50:58 +00001033 // TODO: Add support for relocations in other sections as needed.
1034 // Record relocations for the debug_info and debug_line sections.
Rafael Espindola4f60a382013-05-30 03:05:14 +00001035 RelocAddrMap *Map = StringSwitch<RelocAddrMap*>(RelSecName)
David Blaikie1b5ee5d2013-09-23 17:42:01 +00001036 .Case("debug_info", &InfoSection.Relocs)
1037 .Case("debug_loc", &LocSection.Relocs)
1038 .Case("debug_info.dwo", &InfoDWOSection.Relocs)
1039 .Case("debug_line", &LineSection.Relocs)
George Rimarca532112017-04-24 10:19:45 +00001040 .Case("debug_ranges", &RangeSection.Relocs)
Frederic Riss7c500472014-11-14 19:30:08 +00001041 .Case("apple_names", &AppleNamesSection.Relocs)
1042 .Case("apple_types", &AppleTypesSection.Relocs)
1043 .Case("apple_namespaces", &AppleNamespacesSection.Relocs)
1044 .Case("apple_namespac", &AppleNamespacesSection.Relocs)
1045 .Case("apple_objc", &AppleObjCSection.Relocs)
Craig Topper2617dcc2014-04-15 06:32:26 +00001046 .Default(nullptr);
David Blaikie03c089c2013-09-23 22:44:47 +00001047 if (!Map) {
David Blaikie427e4352013-09-23 23:39:55 +00001048 // Find debug_types relocs by section rather than name as there are
1049 // multiple, comdat grouped, debug_types sections.
David Blaikie92d9d622014-01-09 05:08:24 +00001050 if (RelSecName == "debug_types")
1051 Map = &TypesSections[*RelocatedSection].Relocs;
1052 else if (RelSecName == "debug_types.dwo")
1053 Map = &TypesDWOSections[*RelocatedSection].Relocs;
1054 else
1055 continue;
David Blaikie03c089c2013-09-23 22:44:47 +00001056 }
Eric Christopher7370b552012-11-12 21:40:38 +00001057
Alexey Samsonov063eb3f2014-03-13 13:52:54 +00001058 if (Section.relocation_begin() != Section.relocation_end()) {
Rafael Espindola80291272014-10-08 15:28:58 +00001059 uint64_t SectionSize = RelocatedSection->getSize();
Alexey Samsonovaa4d2952014-03-14 14:22:49 +00001060 for (const RelocationRef &Reloc : Section.relocations()) {
George Rimar702dac62017-04-12 08:59:15 +00001061 // FIXME: it's not clear how to correctly handle scattered
1062 // relocations.
1063 if (isRelocScattered(Obj, Reloc))
1064 continue;
Keno Fischerc780e8e2015-05-21 21:24:32 +00001065
George Rimar702dac62017-04-12 08:59:15 +00001066 Expected<uint64_t> SymAddrOrErr = getSymbolAddress(Obj, Reloc, L);
1067 if (!SymAddrOrErr) {
Krasimir Georgiev4ed589d2017-04-12 11:33:26 +00001068 errs() << toString(SymAddrOrErr.takeError()) << '\n';
George Rimar702dac62017-04-12 08:59:15 +00001069 continue;
Keno Fischerc780e8e2015-05-21 21:24:32 +00001070 }
Eric Christopher7370b552012-11-12 21:40:38 +00001071
Eric Christopher47e079d2014-10-06 06:55:55 +00001072 object::RelocVisitor V(Obj);
George Rimar702dac62017-04-12 08:59:15 +00001073 object::RelocToApply R(V.visit(Reloc.getType(), Reloc, *SymAddrOrErr));
Eric Christopher7370b552012-11-12 21:40:38 +00001074 if (V.error()) {
1075 SmallString<32> Name;
Rafael Espindola41bb4322015-06-30 04:08:37 +00001076 Reloc.getTypeName(Name);
Eric Christopher7370b552012-11-12 21:40:38 +00001077 errs() << "error: failed to compute relocation: "
1078 << Name << "\n";
1079 continue;
1080 }
George Rimar702dac62017-04-12 08:59:15 +00001081 uint64_t Address = Reloc.getOffset();
Eric Christopher7370b552012-11-12 21:40:38 +00001082 if (Address + R.Width > SectionSize) {
1083 errs() << "error: " << R.Width << "-byte relocation starting "
1084 << Address << " bytes into section " << name << " which is "
1085 << SectionSize << " bytes long.\n";
1086 continue;
1087 }
1088 if (R.Width > 8) {
1089 errs() << "error: can't handle a relocation of more than 8 bytes at "
1090 "a time.\n";
1091 continue;
1092 }
1093 DEBUG(dbgs() << "Writing " << format("%p", R.Value)
1094 << " at " << format("%p", Address)
1095 << " with width " << format("%d", R.Width)
1096 << "\n");
Eric Christopherda4b2192013-01-02 23:52:13 +00001097 Map->insert(std::make_pair(Address, std::make_pair(R.Width, R.Value)));
Eric Christopher7370b552012-11-12 21:40:38 +00001098 }
1099 }
1100 }
1101}
1102
Chris Bieneman2e752db2017-01-20 19:03:14 +00001103DWARFContextInMemory::DWARFContextInMemory(
1104 const StringMap<std::unique_ptr<MemoryBuffer>> &Sections, uint8_t AddrSize,
1105 bool isLittleEndian)
1106 : IsLittleEndian(isLittleEndian), AddressSize(AddrSize) {
1107 for (const auto &SecIt : Sections) {
1108 if (StringRef *SectionData = MapSectionToMember(SecIt.first()))
1109 *SectionData = SecIt.second->getBuffer();
1110 }
1111}
1112
1113StringRef *DWARFContextInMemory::MapSectionToMember(StringRef Name) {
1114 return StringSwitch<StringRef *>(Name)
1115 .Case("debug_info", &InfoSection.Data)
1116 .Case("debug_abbrev", &AbbrevSection)
1117 .Case("debug_loc", &LocSection.Data)
1118 .Case("debug_line", &LineSection.Data)
1119 .Case("debug_aranges", &ARangeSection)
1120 .Case("debug_frame", &DebugFrameSection)
1121 .Case("eh_frame", &EHFrameSection)
1122 .Case("debug_str", &StringSection)
George Rimarca532112017-04-24 10:19:45 +00001123 .Case("debug_ranges", &RangeSection.Data)
Chris Bieneman2e752db2017-01-20 19:03:14 +00001124 .Case("debug_macinfo", &MacinfoSection)
1125 .Case("debug_pubnames", &PubNamesSection)
1126 .Case("debug_pubtypes", &PubTypesSection)
1127 .Case("debug_gnu_pubnames", &GnuPubNamesSection)
1128 .Case("debug_gnu_pubtypes", &GnuPubTypesSection)
1129 .Case("debug_info.dwo", &InfoDWOSection.Data)
1130 .Case("debug_abbrev.dwo", &AbbrevDWOSection)
1131 .Case("debug_loc.dwo", &LocDWOSection.Data)
1132 .Case("debug_line.dwo", &LineDWOSection.Data)
1133 .Case("debug_str.dwo", &StringDWOSection)
1134 .Case("debug_str_offsets.dwo", &StringOffsetDWOSection)
1135 .Case("debug_addr", &AddrSection)
1136 .Case("apple_names", &AppleNamesSection.Data)
1137 .Case("apple_types", &AppleTypesSection.Data)
1138 .Case("apple_namespaces", &AppleNamespacesSection.Data)
1139 .Case("apple_namespac", &AppleNamespacesSection.Data)
1140 .Case("apple_objc", &AppleObjCSection.Data)
1141 .Case("debug_cu_index", &CUIndexSection)
1142 .Case("debug_tu_index", &TUIndexSection)
1143 .Case("gdb_index", &GdbIndexSection)
1144 // Any more debug info sections go here.
1145 .Default(nullptr);
1146}
1147
Eugene Zelenko28db7e62017-03-01 01:14:23 +00001148void DWARFContextInMemory::anchor() {}