blob: a2255cdab0668c9f410b46f51260640f303463b9 [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
Greg Claytonb8c162b2017-05-03 16:02:29 +000010#include "llvm/DebugInfo/DWARF/DWARFContext.h"
11#include "llvm/ADT/STLExtras.h"
Alexey Samsonove16e16a2012-07-19 07:03:58 +000012#include "llvm/ADT/SmallString.h"
Eugene Zelenko28db7e62017-03-01 01:14:23 +000013#include "llvm/ADT/SmallVector.h"
Eugene Zelenko28db7e62017-03-01 01:14:23 +000014#include "llvm/ADT/StringRef.h"
Greg Claytonb8c162b2017-05-03 16:02:29 +000015#include "llvm/ADT/StringSwitch.h"
Eugene Zelenko2db0cfa2017-06-23 21:57:40 +000016#include "llvm/BinaryFormat/Dwarf.h"
Zachary Turner82af9432015-01-30 18:07:45 +000017#include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"
Eugene Zelenko28db7e62017-03-01 01:14:23 +000018#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
Eugene Zelenko28db7e62017-03-01 01:14:23 +000019#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
Zachary Turner82af9432015-01-30 18:07:45 +000020#include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h"
Greg Claytonb8c162b2017-05-03 16:02:29 +000021#include "llvm/DebugInfo/DWARF/DWARFDebugAranges.h"
Eugene Zelenko28db7e62017-03-01 01:14:23 +000022#include "llvm/DebugInfo/DWARF/DWARFDebugFrame.h"
23#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
24#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
25#include "llvm/DebugInfo/DWARF/DWARFDebugMacro.h"
George Rimare71e33f2016-12-17 09:10:32 +000026#include "llvm/DebugInfo/DWARF/DWARFDebugPubTable.h"
Eugene Zelenko28db7e62017-03-01 01:14:23 +000027#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
28#include "llvm/DebugInfo/DWARF/DWARFDie.h"
29#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
30#include "llvm/DebugInfo/DWARF/DWARFGdbIndex.h"
31#include "llvm/DebugInfo/DWARF/DWARFSection.h"
David Blaikie65a8efe2015-11-11 19:28:21 +000032#include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"
Greg Claytonb8c162b2017-05-03 16:02:29 +000033#include "llvm/DebugInfo/DWARF/DWARFVerifier.h"
George Rimar4bf30832017-01-11 15:26:41 +000034#include "llvm/Object/Decompressor.h"
Reid Klecknerdafc5d72016-07-06 16:56:42 +000035#include "llvm/Object/MachO.h"
Eugene Zelenko28db7e62017-03-01 01:14:23 +000036#include "llvm/Object/ObjectFile.h"
Reid Klecknerdafc5d72016-07-06 16:56:42 +000037#include "llvm/Object/RelocVisitor.h"
Eugene Zelenko28db7e62017-03-01 01:14:23 +000038#include "llvm/Support/Casting.h"
39#include "llvm/Support/DataExtractor.h"
Eugene Zelenko28db7e62017-03-01 01:14:23 +000040#include "llvm/Support/Error.h"
Benjamin Kramer07d4b1c2011-09-15 16:57:13 +000041#include "llvm/Support/Format.h"
Eugene Zelenko28db7e62017-03-01 01:14:23 +000042#include "llvm/Support/MemoryBuffer.h"
Benjamin Kramera6002fd2011-09-14 01:09:52 +000043#include "llvm/Support/raw_ostream.h"
Benjamin Kramer2602ca62011-09-15 20:43:22 +000044#include <algorithm>
Eugene Zelenko28db7e62017-03-01 01:14:23 +000045#include <cstdint>
Greg Claytonc7695a82017-05-02 20:28:33 +000046#include <map>
Eugene Zelenko28db7e62017-03-01 01:14:23 +000047#include <string>
Eugene Zelenko2db0cfa2017-06-23 21:57:40 +000048#include <tuple>
Eugene Zelenko28db7e62017-03-01 01:14:23 +000049#include <utility>
50#include <vector>
51
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000052using namespace llvm;
Benjamin Kramer6dda0322011-09-15 18:02:20 +000053using namespace dwarf;
Rafael Espindola4f60a382013-05-30 03:05:14 +000054using namespace object;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000055
Chandler Carruthe96dd892014-04-21 22:55:11 +000056#define DEBUG_TYPE "dwarf"
57
Eugene Zelenko2db0cfa2017-06-23 21:57:40 +000058using DWARFLineTable = DWARFDebugLine::LineTable;
59using FileLineInfoKind = DILineInfoSpecifier::FileLineInfoKind;
60using FunctionNameKind = DILineInfoSpecifier::FunctionNameKind;
Eric Christopher494109b2012-10-16 23:46:25 +000061
Frederic Riss7c500472014-11-14 19:30:08 +000062static void dumpAccelSection(raw_ostream &OS, StringRef Name,
63 const DWARFSection& Section, StringRef StringSection,
64 bool LittleEndian) {
Paul Robinson17536b92017-06-29 16:52:08 +000065 DWARFDataExtractor AccelSection(Section, LittleEndian, 0);
Frederic Risse837ec22014-11-14 16:15:53 +000066 DataExtractor StrData(StringSection, LittleEndian, 0);
67 OS << "\n." << Name << " contents:\n";
Paul Robinson17536b92017-06-29 16:52:08 +000068 DWARFAcceleratorTable Accel(AccelSection, StrData);
Frederic Risse837ec22014-11-14 16:15:53 +000069 if (!Accel.extract())
70 return;
71 Accel.dump(OS);
72}
73
Wolfgang Pieb77d3e932017-06-06 01:22:34 +000074static void
75dumpDWARFv5StringOffsetsSection(raw_ostream &OS, StringRef SectionName,
76 const DWARFSection &StringOffsetsSection,
77 StringRef StringSection, bool LittleEndian) {
Paul Robinson17536b92017-06-29 16:52:08 +000078 DWARFDataExtractor StrOffsetExt(StringOffsetsSection, LittleEndian, 0);
Wolfgang Pieb77d3e932017-06-06 01:22:34 +000079 uint32_t Offset = 0;
80 uint64_t SectionSize = StringOffsetsSection.Data.size();
81
82 while (Offset < SectionSize) {
83 unsigned Version = 0;
84 DwarfFormat Format = DWARF32;
85 unsigned EntrySize = 4;
86 // Perform validation and extract the segment size from the header.
87 if (!StrOffsetExt.isValidOffsetForDataOfSize(Offset, 4)) {
88 OS << "error: invalid contribution to string offsets table in section ."
89 << SectionName << ".\n";
90 return;
91 }
92 uint32_t ContributionStart = Offset;
93 uint64_t ContributionSize = StrOffsetExt.getU32(&Offset);
94 // A contribution size of 0xffffffff indicates DWARF64, with the actual size
95 // in the following 8 bytes. Otherwise, the DWARF standard mandates that
96 // the contribution size must be at most 0xfffffff0.
97 if (ContributionSize == 0xffffffff) {
98 if (!StrOffsetExt.isValidOffsetForDataOfSize(Offset, 8)) {
99 OS << "error: invalid contribution to string offsets table in section ."
100 << SectionName << ".\n";
101 return;
102 }
103 Format = DWARF64;
104 EntrySize = 8;
105 ContributionSize = StrOffsetExt.getU64(&Offset);
106 } else if (ContributionSize > 0xfffffff0) {
107 OS << "error: invalid contribution to string offsets table in section ."
108 << SectionName << ".\n";
109 return;
110 }
111
112 // We must ensure that we don't read a partial record at the end, so we
113 // validate for a multiple of EntrySize. Also, we're expecting a version
114 // number and padding, which adds an additional 4 bytes.
115 uint64_t ValidationSize =
116 4 + ((ContributionSize + EntrySize - 1) & (-(uint64_t)EntrySize));
117 if (!StrOffsetExt.isValidOffsetForDataOfSize(Offset, ValidationSize)) {
118 OS << "error: contribution to string offsets table in section ."
119 << SectionName << " has invalid length.\n";
120 return;
121 }
122
123 Version = StrOffsetExt.getU16(&Offset);
124 Offset += 2;
125 OS << format("0x%8.8x: ", ContributionStart);
126 OS << "Contribution size = " << ContributionSize
127 << ", Version = " << Version << "\n";
128
129 uint32_t ContributionBase = Offset;
130 DataExtractor StrData(StringSection, LittleEndian, 0);
131 while (Offset - ContributionBase < ContributionSize) {
132 OS << format("0x%8.8x: ", Offset);
133 // FIXME: We can only extract strings in DWARF32 format at the moment.
Paul Robinson17536b92017-06-29 16:52:08 +0000134 uint64_t StringOffset =
135 StrOffsetExt.getRelocatedValue(EntrySize, &Offset);
Wolfgang Pieb77d3e932017-06-06 01:22:34 +0000136 if (Format == DWARF32) {
137 OS << format("%8.8x ", StringOffset);
138 uint32_t StringOffset32 = (uint32_t)StringOffset;
139 const char *S = StrData.getCStr(&StringOffset32);
140 if (S)
141 OS << format("\"%s\"", S);
142 } else
143 OS << format("%16.16x ", StringOffset);
144 OS << "\n";
145 }
146 }
147}
148
149// Dump a DWARF string offsets section. This may be a DWARF v5 formatted
150// string offsets section, where each compile or type unit contributes a
151// number of entries (string offsets), with each contribution preceded by
152// a header containing size and version number. Alternatively, it may be a
153// monolithic series of string offsets, as generated by the pre-DWARF v5
154// implementation of split DWARF.
155static void dumpStringOffsetsSection(raw_ostream &OS, StringRef SectionName,
156 const DWARFSection &StringOffsetsSection,
157 StringRef StringSection, bool LittleEndian,
158 unsigned MaxVersion) {
159 if (StringOffsetsSection.Data.empty())
160 return;
161 OS << "\n." << SectionName << " contents:\n";
162 // If we have at least one (compile or type) unit with DWARF v5 or greater,
163 // we assume that the section is formatted like a DWARF v5 string offsets
164 // section.
165 if (MaxVersion >= 5)
166 dumpDWARFv5StringOffsetsSection(OS, SectionName, StringOffsetsSection,
167 StringSection, LittleEndian);
168 else {
169 DataExtractor strOffsetExt(StringOffsetsSection.Data, LittleEndian, 0);
170 uint32_t offset = 0;
171 uint64_t size = StringOffsetsSection.Data.size();
172 // Ensure that size is a multiple of the size of an entry.
173 if (size & ((uint64_t)(sizeof(uint32_t) - 1))) {
174 OS << "error: size of ." << SectionName << " is not a multiple of "
175 << sizeof(uint32_t) << ".\n";
176 size &= -(uint64_t)sizeof(uint32_t);
177 }
178 DataExtractor StrData(StringSection, LittleEndian, 0);
179 while (offset < size) {
180 OS << format("0x%8.8x: ", offset);
181 uint32_t StringOffset = strOffsetExt.getU32(&offset);
182 OS << format("%8.8x ", StringOffset);
183 const char *S = StrData.getCStr(&StringOffset);
184 if (S)
185 OS << format("\"%s\"", S);
186 OS << "\n";
187 }
188 }
189}
190
Eugene Zelenko2db0cfa2017-06-23 21:57:40 +0000191void DWARFContext::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
Adrian Prantlf4bc1f72017-06-01 18:18:23 +0000192 DIDumpType DumpType = DumpOpts.DumpType;
193 bool DumpEH = DumpOpts.DumpEH;
194 bool SummarizeTypes = DumpOpts.SummarizeTypes;
195
Eli Bendersky7a94daa2013-01-25 20:26:43 +0000196 if (DumpType == DIDT_All || DumpType == DIDT_Abbrev) {
197 OS << ".debug_abbrev contents:\n";
198 getDebugAbbrev()->dump(OS);
199 }
Benjamin Kramera6002fd2011-09-14 01:09:52 +0000200
David Blaikie66865d62014-01-09 00:13:35 +0000201 if (DumpType == DIDT_All || DumpType == DIDT_AbbrevDwo)
202 if (const DWARFDebugAbbrev *D = getDebugAbbrevDWO()) {
David Blaikie622dce42014-01-08 23:29:59 +0000203 OS << "\n.debug_abbrev.dwo contents:\n";
David Blaikie66865d62014-01-09 00:13:35 +0000204 D->dump(OS);
David Blaikie622dce42014-01-08 23:29:59 +0000205 }
David Blaikie622dce42014-01-08 23:29:59 +0000206
Eli Bendersky7a94daa2013-01-25 20:26:43 +0000207 if (DumpType == DIDT_All || DumpType == DIDT_Info) {
208 OS << "\n.debug_info contents:\n";
Alexey Samsonov1eabf982014-03-13 07:52:54 +0000209 for (const auto &CU : compile_units())
Adrian Prantl318d1192017-06-06 23:28:45 +0000210 CU->dump(OS, DumpOpts);
Eli Bendersky7a94daa2013-01-25 20:26:43 +0000211 }
Benjamin Kramera6002fd2011-09-14 01:09:52 +0000212
David Blaikie66865d62014-01-09 00:13:35 +0000213 if ((DumpType == DIDT_All || DumpType == DIDT_InfoDwo) &&
214 getNumDWOCompileUnits()) {
215 OS << "\n.debug_info.dwo contents:\n";
Alexey Samsonov1eabf982014-03-13 07:52:54 +0000216 for (const auto &DWOCU : dwo_compile_units())
Adrian Prantl318d1192017-06-06 23:28:45 +0000217 DWOCU->dump(OS, DumpOpts);
David Blaikie66865d62014-01-09 00:13:35 +0000218 }
David Blaikie622dce42014-01-08 23:29:59 +0000219
David Blaikie66865d62014-01-09 00:13:35 +0000220 if ((DumpType == DIDT_All || DumpType == DIDT_Types) && getNumTypeUnits()) {
David Blaikie03c089c2013-09-23 22:44:47 +0000221 OS << "\n.debug_types contents:\n";
Frederic Riss312a02e2014-09-29 13:56:39 +0000222 for (const auto &TUS : type_unit_sections())
223 for (const auto &TU : TUS)
David Blaikie50cc27e2016-10-18 21:09:48 +0000224 TU->dump(OS, SummarizeTypes);
David Blaikie03c089c2013-09-23 22:44:47 +0000225 }
226
Alexey Samsonov1eabf982014-03-13 07:52:54 +0000227 if ((DumpType == DIDT_All || DumpType == DIDT_TypesDwo) &&
228 getNumDWOTypeUnits()) {
229 OS << "\n.debug_types.dwo contents:\n";
Frederic Riss312a02e2014-09-29 13:56:39 +0000230 for (const auto &DWOTUS : dwo_type_unit_sections())
231 for (const auto &DWOTU : DWOTUS)
David Blaikie50cc27e2016-10-18 21:09:48 +0000232 DWOTU->dump(OS, SummarizeTypes);
Alexey Samsonov1eabf982014-03-13 07:52:54 +0000233 }
David Blaikie92d9d622014-01-09 05:08:24 +0000234
David Blaikie18e73502013-06-19 21:37:13 +0000235 if (DumpType == DIDT_All || DumpType == DIDT_Loc) {
David Blaikie03c089c2013-09-23 22:44:47 +0000236 OS << "\n.debug_loc contents:\n";
David Blaikie18e73502013-06-19 21:37:13 +0000237 getDebugLoc()->dump(OS);
238 }
239
David Blaikie9c550ac2014-03-25 01:44:02 +0000240 if (DumpType == DIDT_All || DumpType == DIDT_LocDwo) {
241 OS << "\n.debug_loc.dwo contents:\n";
242 getDebugLocDWO()->dump(OS);
243 }
244
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000245 if (DumpType == DIDT_All || DumpType == DIDT_Frames) {
246 OS << "\n.debug_frame contents:\n";
247 getDebugFrame()->dump(OS);
Igor Laevsky03a670c2016-01-26 15:09:42 +0000248 if (DumpEH) {
249 OS << "\n.eh_frame contents:\n";
250 getEHFrame()->dump(OS);
251 }
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000252 }
253
Amjad Aboude59cc3e2015-11-12 09:38:54 +0000254 if (DumpType == DIDT_All || DumpType == DIDT_Macro) {
255 OS << "\n.debug_macinfo contents:\n";
256 getDebugMacro()->dump(OS);
257 }
258
Benjamin Kramera6002fd2011-09-14 01:09:52 +0000259 uint32_t offset = 0;
Eli Bendersky7a94daa2013-01-25 20:26:43 +0000260 if (DumpType == DIDT_All || DumpType == DIDT_Aranges) {
261 OS << "\n.debug_aranges contents:\n";
262 DataExtractor arangesData(getARangeSection(), isLittleEndian(), 0);
263 DWARFDebugArangeSet set;
264 while (set.extract(arangesData, &offset))
265 set.dump(OS);
266 }
Benjamin Kramer5acab502011-09-15 02:12:05 +0000267
Alexey Samsonov034e57a2012-08-27 07:17:47 +0000268 uint8_t savedAddressByteSize = 0;
Eli Bendersky7a94daa2013-01-25 20:26:43 +0000269 if (DumpType == DIDT_All || DumpType == DIDT_Line) {
270 OS << "\n.debug_line contents:\n";
Alexey Samsonov1eabf982014-03-13 07:52:54 +0000271 for (const auto &CU : compile_units()) {
272 savedAddressByteSize = CU->getAddressByteSize();
Greg Claytonc8c10322016-12-13 18:25:19 +0000273 auto CUDIE = CU->getUnitDIE();
274 if (!CUDIE)
Alexey Samsonov7a18c062015-05-19 21:54:32 +0000275 continue;
Greg Clayton97d22182017-01-13 21:08:18 +0000276 if (auto StmtOffset = toSectionOffset(CUDIE.find(DW_AT_stmt_list))) {
Paul Robinson17536b92017-06-29 16:52:08 +0000277 DWARFDataExtractor lineData(getLineSection(), isLittleEndian(),
278 savedAddressByteSize);
Alexey Samsonov110d5952014-04-30 00:09:19 +0000279 DWARFDebugLine::LineTable LineTable;
Greg Clayton52fe1f62016-12-14 22:38:08 +0000280 uint32_t Offset = *StmtOffset;
Paul Robinson17536b92017-06-29 16:52:08 +0000281 LineTable.parse(lineData, &Offset);
Alexey Samsonov110d5952014-04-30 00:09:19 +0000282 LineTable.dump(OS);
Eli Bendersky7a94daa2013-01-25 20:26:43 +0000283 }
Benjamin Kramer6dda0322011-09-15 18:02:20 +0000284 }
285 }
Benjamin Kramer07d4b1c2011-09-15 16:57:13 +0000286
David Blaikie65a8efe2015-11-11 19:28:21 +0000287 if (DumpType == DIDT_All || DumpType == DIDT_CUIndex) {
288 OS << "\n.debug_cu_index contents:\n";
David Blaikieb073cb92015-12-02 06:21:34 +0000289 getCUIndex().dump(OS);
David Blaikie65a8efe2015-11-11 19:28:21 +0000290 }
291
David Blaikie51c40282015-11-11 19:40:49 +0000292 if (DumpType == DIDT_All || DumpType == DIDT_TUIndex) {
293 OS << "\n.debug_tu_index contents:\n";
David Blaikieb073cb92015-12-02 06:21:34 +0000294 getTUIndex().dump(OS);
David Blaikie51c40282015-11-11 19:40:49 +0000295 }
296
David Blaikie1d4736e2014-02-24 23:58:54 +0000297 if (DumpType == DIDT_All || DumpType == DIDT_LineDwo) {
298 OS << "\n.debug_line.dwo contents:\n";
299 unsigned stmtOffset = 0;
Paul Robinson17536b92017-06-29 16:52:08 +0000300 DWARFDataExtractor lineData(getLineDWOSection(), isLittleEndian(),
301 savedAddressByteSize);
Alexey Samsonov110d5952014-04-30 00:09:19 +0000302 DWARFDebugLine::LineTable LineTable;
303 while (LineTable.Prologue.parse(lineData, &stmtOffset)) {
304 LineTable.dump(OS);
305 LineTable.clear();
306 }
David Blaikie1d4736e2014-02-24 23:58:54 +0000307 }
308
Eli Bendersky7a94daa2013-01-25 20:26:43 +0000309 if (DumpType == DIDT_All || DumpType == DIDT_Str) {
310 OS << "\n.debug_str contents:\n";
311 DataExtractor strData(getStringSection(), isLittleEndian(), 0);
312 offset = 0;
313 uint32_t strOffset = 0;
314 while (const char *s = strData.getCStr(&offset)) {
315 OS << format("0x%8.8x: \"%s\"\n", strOffset, s);
316 strOffset = offset;
317 }
Benjamin Kramer07d4b1c2011-09-15 16:57:13 +0000318 }
Alexey Samsonov034e57a2012-08-27 07:17:47 +0000319
David Blaikie66865d62014-01-09 00:13:35 +0000320 if ((DumpType == DIDT_All || DumpType == DIDT_StrDwo) &&
321 !getStringDWOSection().empty()) {
322 OS << "\n.debug_str.dwo contents:\n";
323 DataExtractor strDWOData(getStringDWOSection(), isLittleEndian(), 0);
324 offset = 0;
325 uint32_t strDWOOffset = 0;
326 while (const char *s = strDWOData.getCStr(&offset)) {
327 OS << format("0x%8.8x: \"%s\"\n", strDWOOffset, s);
328 strDWOOffset = offset;
David Blaikie622dce42014-01-08 23:29:59 +0000329 }
David Blaikie66865d62014-01-09 00:13:35 +0000330 }
David Blaikie622dce42014-01-08 23:29:59 +0000331
Eli Bendersky7a94daa2013-01-25 20:26:43 +0000332 if (DumpType == DIDT_All || DumpType == DIDT_Ranges) {
333 OS << "\n.debug_ranges contents:\n";
334 // In fact, different compile units may have different address byte
335 // sizes, but for simplicity we just use the address byte size of the last
336 // compile unit (there is no easy and fast way to associate address range
337 // list and the compile unit it describes).
Paul Robinson17536b92017-06-29 16:52:08 +0000338 DWARFDataExtractor rangesData(getRangeSection(), isLittleEndian(),
339 savedAddressByteSize);
Eli Bendersky7a94daa2013-01-25 20:26:43 +0000340 offset = 0;
341 DWARFDebugRangeList rangeList;
Paul Robinson17536b92017-06-29 16:52:08 +0000342 while (rangeList.extract(rangesData, &offset))
Eli Bendersky7a94daa2013-01-25 20:26:43 +0000343 rangeList.dump(OS);
Eric Christopherda4b2192013-01-02 23:52:13 +0000344 }
Eric Christopher962c9082013-01-15 23:56:56 +0000345
Eric Christopher0de53592013-09-25 23:02:36 +0000346 if (DumpType == DIDT_All || DumpType == DIDT_Pubnames)
George Rimare71e33f2016-12-17 09:10:32 +0000347 DWARFDebugPubTable(getPubNamesSection(), isLittleEndian(), false)
348 .dump("debug_pubnames", OS);
Krzysztof Parzyszek97438dc2013-02-12 16:20:28 +0000349
Eric Christopher4c7e6ba2013-09-25 23:02:41 +0000350 if (DumpType == DIDT_All || DumpType == DIDT_Pubtypes)
George Rimare71e33f2016-12-17 09:10:32 +0000351 DWARFDebugPubTable(getPubTypesSection(), isLittleEndian(), false)
352 .dump("debug_pubtypes", OS);
Eric Christopher4c7e6ba2013-09-25 23:02:41 +0000353
David Blaikieecd21ff2013-09-24 19:50:00 +0000354 if (DumpType == DIDT_All || DumpType == DIDT_GnuPubnames)
George Rimare71e33f2016-12-17 09:10:32 +0000355 DWARFDebugPubTable(getGnuPubNamesSection(), isLittleEndian(),
356 true /* GnuStyle */)
357 .dump("debug_gnu_pubnames", OS);
David Blaikieecd21ff2013-09-24 19:50:00 +0000358
359 if (DumpType == DIDT_All || DumpType == DIDT_GnuPubtypes)
George Rimare71e33f2016-12-17 09:10:32 +0000360 DWARFDebugPubTable(getGnuPubTypesSection(), isLittleEndian(),
361 true /* GnuStyle */)
362 .dump("debug_gnu_pubtypes", OS);
David Blaikie404d3042013-09-19 23:01:29 +0000363
Wolfgang Pieb77d3e932017-06-06 01:22:34 +0000364 if (DumpType == DIDT_All || DumpType == DIDT_StrOffsets)
365 dumpStringOffsetsSection(OS, "debug_str_offsets", getStringOffsetSection(),
366 getStringSection(), isLittleEndian(),
367 getMaxVersion());
368
369 if (DumpType == DIDT_All || DumpType == DIDT_StrOffsetsDwo) {
370 dumpStringOffsetsSection(OS, "debug_str_offsets.dwo",
371 getStringOffsetDWOSection(), getStringDWOSection(),
372 isLittleEndian(), getMaxVersion());
David Blaikie66865d62014-01-09 00:13:35 +0000373 }
Frederic Risse837ec22014-11-14 16:15:53 +0000374
George Rimar4f82df52016-09-23 11:01:53 +0000375 if ((DumpType == DIDT_All || DumpType == DIDT_GdbIndex) &&
376 !getGdbIndexSection().empty()) {
377 OS << "\n.gnu_index contents:\n";
378 getGdbIndex().dump(OS);
379 }
380
Frederic Risse837ec22014-11-14 16:15:53 +0000381 if (DumpType == DIDT_All || DumpType == DIDT_AppleNames)
382 dumpAccelSection(OS, "apple_names", getAppleNamesSection(),
383 getStringSection(), isLittleEndian());
384
385 if (DumpType == DIDT_All || DumpType == DIDT_AppleTypes)
386 dumpAccelSection(OS, "apple_types", getAppleTypesSection(),
387 getStringSection(), isLittleEndian());
388
389 if (DumpType == DIDT_All || DumpType == DIDT_AppleNamespaces)
390 dumpAccelSection(OS, "apple_namespaces", getAppleNamespacesSection(),
391 getStringSection(), isLittleEndian());
392
393 if (DumpType == DIDT_All || DumpType == DIDT_AppleObjC)
394 dumpAccelSection(OS, "apple_objc", getAppleObjCSection(),
395 getStringSection(), isLittleEndian());
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000396}
397
David Blaikie15d85fc2017-05-23 06:48:53 +0000398DWARFCompileUnit *DWARFContext::getDWOCompileUnitForHash(uint64_t Hash) {
399 // FIXME: Improve this for the case where this DWO file is really a DWP file
400 // with an index - use the index for lookup instead of a linear search.
401 for (const auto &DWOCU : dwo_compile_units())
402 if (DWOCU->getDWOId() == Hash)
403 return DWOCU.get();
404 return nullptr;
405}
406
Greg Claytonc7695a82017-05-02 20:28:33 +0000407DWARFDie DWARFContext::getDIEForOffset(uint32_t Offset) {
408 parseCompileUnits();
409 if (auto *CU = CUs.getUnitForOffset(Offset))
410 return CU->getDIEForOffset(Offset);
411 return DWARFDie();
412}
413
Greg Claytonc7695a82017-05-02 20:28:33 +0000414bool DWARFContext::verify(raw_ostream &OS, DIDumpType DumpType) {
415 bool Success = true;
Greg Claytonb8c162b2017-05-03 16:02:29 +0000416 DWARFVerifier verifier(OS, *this);
Greg Claytonc7695a82017-05-02 20:28:33 +0000417 if (DumpType == DIDT_All || DumpType == DIDT_Info) {
Greg Claytonb8c162b2017-05-03 16:02:29 +0000418 if (!verifier.handleDebugInfo())
Greg Claytonc7695a82017-05-02 20:28:33 +0000419 Success = false;
Greg Clayton48432cf2017-05-01 22:07:02 +0000420 }
Greg Clayton67070462017-05-02 22:48:52 +0000421 if (DumpType == DIDT_All || DumpType == DIDT_Line) {
Greg Claytonb8c162b2017-05-03 16:02:29 +0000422 if (!verifier.handleDebugLine())
Greg Clayton67070462017-05-02 22:48:52 +0000423 Success = false;
424 }
Spyridoula Gravanie41823b2017-06-14 00:17:55 +0000425 if (DumpType == DIDT_All || DumpType == DIDT_AppleNames) {
426 if (!verifier.handleAppleNames())
427 Success = false;
428 }
Greg Clayton48432cf2017-05-01 22:07:02 +0000429 return Success;
430}
Spyridoula Gravanie41823b2017-06-14 00:17:55 +0000431
David Blaikie82641be2015-11-17 00:39:55 +0000432const DWARFUnitIndex &DWARFContext::getCUIndex() {
433 if (CUIndex)
434 return *CUIndex;
435
436 DataExtractor CUIndexData(getCUIndexSection(), isLittleEndian(), 0);
437
David Blaikieb073cb92015-12-02 06:21:34 +0000438 CUIndex = llvm::make_unique<DWARFUnitIndex>(DW_SECT_INFO);
David Blaikie82641be2015-11-17 00:39:55 +0000439 CUIndex->parse(CUIndexData);
440 return *CUIndex;
441}
442
443const DWARFUnitIndex &DWARFContext::getTUIndex() {
444 if (TUIndex)
445 return *TUIndex;
446
447 DataExtractor TUIndexData(getTUIndexSection(), isLittleEndian(), 0);
448
David Blaikieb073cb92015-12-02 06:21:34 +0000449 TUIndex = llvm::make_unique<DWARFUnitIndex>(DW_SECT_TYPES);
David Blaikie82641be2015-11-17 00:39:55 +0000450 TUIndex->parse(TUIndexData);
451 return *TUIndex;
452}
453
George Rimar4f82df52016-09-23 11:01:53 +0000454DWARFGdbIndex &DWARFContext::getGdbIndex() {
455 if (GdbIndex)
456 return *GdbIndex;
457
458 DataExtractor GdbIndexData(getGdbIndexSection(), true /*LE*/, 0);
459 GdbIndex = llvm::make_unique<DWARFGdbIndex>();
460 GdbIndex->parse(GdbIndexData);
461 return *GdbIndex;
462}
463
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000464const DWARFDebugAbbrev *DWARFContext::getDebugAbbrev() {
465 if (Abbrev)
466 return Abbrev.get();
467
468 DataExtractor abbrData(getAbbrevSection(), isLittleEndian(), 0);
469
470 Abbrev.reset(new DWARFDebugAbbrev());
Alexey Samsonov4316df52014-04-25 21:10:56 +0000471 Abbrev->extract(abbrData);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000472 return Abbrev.get();
473}
474
Eric Christopherda4b2192013-01-02 23:52:13 +0000475const DWARFDebugAbbrev *DWARFContext::getDebugAbbrevDWO() {
476 if (AbbrevDWO)
477 return AbbrevDWO.get();
478
479 DataExtractor abbrData(getAbbrevDWOSection(), isLittleEndian(), 0);
480 AbbrevDWO.reset(new DWARFDebugAbbrev());
Alexey Samsonov4316df52014-04-25 21:10:56 +0000481 AbbrevDWO->extract(abbrData);
Eric Christopherda4b2192013-01-02 23:52:13 +0000482 return AbbrevDWO.get();
483}
484
David Blaikie18e73502013-06-19 21:37:13 +0000485const DWARFDebugLoc *DWARFContext::getDebugLoc() {
486 if (Loc)
487 return Loc.get();
488
Paul Robinson17536b92017-06-29 16:52:08 +0000489 Loc.reset(new DWARFDebugLoc);
David Blaikie18e73502013-06-19 21:37:13 +0000490 // assume all compile units have the same address byte size
Paul Robinson17536b92017-06-29 16:52:08 +0000491 if (getNumCompileUnits()) {
492 DWARFDataExtractor LocData(getLocSection(), isLittleEndian(),
493 getCompileUnitAtIndex(0)->getAddressByteSize());
494 Loc->parse(LocData);
495 }
David Blaikie18e73502013-06-19 21:37:13 +0000496 return Loc.get();
497}
498
David Blaikie9c550ac2014-03-25 01:44:02 +0000499const DWARFDebugLocDWO *DWARFContext::getDebugLocDWO() {
500 if (LocDWO)
501 return LocDWO.get();
502
503 DataExtractor LocData(getLocDWOSection().Data, isLittleEndian(), 0);
504 LocDWO.reset(new DWARFDebugLocDWO());
505 LocDWO->parse(LocData);
506 return LocDWO.get();
507}
508
Benjamin Kramera6002fd2011-09-14 01:09:52 +0000509const DWARFDebugAranges *DWARFContext::getDebugAranges() {
510 if (Aranges)
511 return Aranges.get();
512
Benjamin Kramera6002fd2011-09-14 01:09:52 +0000513 Aranges.reset(new DWARFDebugAranges());
Alexey Samsonova1694c12012-11-16 08:36:25 +0000514 Aranges->generate(this);
Benjamin Kramera6002fd2011-09-14 01:09:52 +0000515 return Aranges.get();
516}
517
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000518const DWARFDebugFrame *DWARFContext::getDebugFrame() {
519 if (DebugFrame)
520 return DebugFrame.get();
521
522 // There's a "bug" in the DWARFv3 standard with respect to the target address
523 // size within debug frame sections. While DWARF is supposed to be independent
524 // of its container, FDEs have fields with size being "target address size",
525 // which isn't specified in DWARF in general. It's only specified for CUs, but
526 // .eh_frame can appear without a .debug_info section. Follow the example of
527 // other tools (libdwarf) and extract this from the container (ObjectFile
528 // provides this information). This problem is fixed in DWARFv4
529 // See this dwarf-discuss discussion for more details:
530 // http://lists.dwarfstd.org/htdig.cgi/dwarf-discuss-dwarfstd.org/2011-December/001173.html
531 DataExtractor debugFrameData(getDebugFrameSection(), isLittleEndian(),
532 getAddressSize());
Igor Laevsky03a670c2016-01-26 15:09:42 +0000533 DebugFrame.reset(new DWARFDebugFrame(false /* IsEH */));
534 DebugFrame->parse(debugFrameData);
535 return DebugFrame.get();
536}
537
538const DWARFDebugFrame *DWARFContext::getEHFrame() {
539 if (EHFrame)
540 return EHFrame.get();
541
542 DataExtractor debugFrameData(getEHFrameSection(), isLittleEndian(),
543 getAddressSize());
544 DebugFrame.reset(new DWARFDebugFrame(true /* IsEH */));
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000545 DebugFrame->parse(debugFrameData);
546 return DebugFrame.get();
547}
548
Amjad Aboude59cc3e2015-11-12 09:38:54 +0000549const DWARFDebugMacro *DWARFContext::getDebugMacro() {
550 if (Macro)
551 return Macro.get();
552
553 DataExtractor MacinfoData(getMacinfoSection(), isLittleEndian(), 0);
554 Macro.reset(new DWARFDebugMacro());
555 Macro->parse(MacinfoData);
556 return Macro.get();
557}
558
Eric Christopher494109b2012-10-16 23:46:25 +0000559const DWARFLineTable *
Alexey Samsonov7a18c062015-05-19 21:54:32 +0000560DWARFContext::getLineTableForUnit(DWARFUnit *U) {
Benjamin Kramer679e1752011-09-15 20:43:18 +0000561 if (!Line)
Paul Robinson17536b92017-06-29 16:52:08 +0000562 Line.reset(new DWARFDebugLine);
David Blaikiec4e2bed2015-11-17 21:08:05 +0000563
Greg Claytonc8c10322016-12-13 18:25:19 +0000564 auto UnitDIE = U->getUnitDIE();
565 if (!UnitDIE)
Alexey Samsonov7a18c062015-05-19 21:54:32 +0000566 return nullptr;
David Blaikiec4e2bed2015-11-17 21:08:05 +0000567
Greg Clayton97d22182017-01-13 21:08:18 +0000568 auto Offset = toSectionOffset(UnitDIE.find(DW_AT_stmt_list));
Greg Clayton52fe1f62016-12-14 22:38:08 +0000569 if (!Offset)
Craig Topper2617dcc2014-04-15 06:32:26 +0000570 return nullptr; // No line table for this compile unit.
Benjamin Kramer5acab502011-09-15 02:12:05 +0000571
Greg Clayton52fe1f62016-12-14 22:38:08 +0000572 uint32_t stmtOffset = *Offset + U->getLineTableOffset();
Benjamin Kramer679e1752011-09-15 20:43:18 +0000573 // See if the line table is cached.
Eric Christopher494109b2012-10-16 23:46:25 +0000574 if (const DWARFLineTable *lt = Line->getLineTable(stmtOffset))
Benjamin Kramer679e1752011-09-15 20:43:18 +0000575 return lt;
576
Greg Clayton48ff66a2017-05-04 18:29:44 +0000577 // Make sure the offset is good before we try to parse.
Paul Robinson17536b92017-06-29 16:52:08 +0000578 if (stmtOffset >= U->getLineSection().Data.size())
Greg Clayton48ff66a2017-05-04 18:29:44 +0000579 return nullptr;
580
Benjamin Kramer679e1752011-09-15 20:43:18 +0000581 // We have to parse it first.
Paul Robinson17536b92017-06-29 16:52:08 +0000582 DWARFDataExtractor lineData(U->getLineSection(), isLittleEndian(),
583 U->getAddressByteSize());
Benjamin Kramer679e1752011-09-15 20:43:18 +0000584 return Line->getOrParseLineTable(lineData, stmtOffset);
Benjamin Kramer5acab502011-09-15 02:12:05 +0000585}
586
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000587void DWARFContext::parseCompileUnits() {
Alexey Samsonov8cd4c9d2014-10-08 00:07:53 +0000588 CUs.parse(*this, getInfoSection());
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000589}
Benjamin Kramer2602ca62011-09-15 20:43:22 +0000590
David Blaikie03c089c2013-09-23 22:44:47 +0000591void DWARFContext::parseTypeUnits() {
Alexey Samsonov1eabf982014-03-13 07:52:54 +0000592 if (!TUs.empty())
593 return;
594 for (const auto &I : getTypesSections()) {
Benjamin Kramerf5e2fc42015-05-29 19:43:39 +0000595 TUs.emplace_back();
Alexey Samsonov8cd4c9d2014-10-08 00:07:53 +0000596 TUs.back().parse(*this, I.second);
David Blaikie03c089c2013-09-23 22:44:47 +0000597 }
598}
599
Eric Christopherda4b2192013-01-02 23:52:13 +0000600void DWARFContext::parseDWOCompileUnits() {
Alexey Samsonov8cd4c9d2014-10-08 00:07:53 +0000601 DWOCUs.parseDWO(*this, getInfoDWOSection());
Eric Christopherda4b2192013-01-02 23:52:13 +0000602}
603
David Blaikie92d9d622014-01-09 05:08:24 +0000604void DWARFContext::parseDWOTypeUnits() {
Alexey Samsonov1eabf982014-03-13 07:52:54 +0000605 if (!DWOTUs.empty())
606 return;
607 for (const auto &I : getTypesDWOSections()) {
Benjamin Kramerf5e2fc42015-05-29 19:43:39 +0000608 DWOTUs.emplace_back();
Alexey Samsonov8cd4c9d2014-10-08 00:07:53 +0000609 DWOTUs.back().parseDWO(*this, I.second);
David Blaikie92d9d622014-01-09 05:08:24 +0000610 }
611}
612
Alexey Samsonov45be7932012-08-30 07:49:50 +0000613DWARFCompileUnit *DWARFContext::getCompileUnitForOffset(uint32_t Offset) {
Alexey Samsonov1eabf982014-03-13 07:52:54 +0000614 parseCompileUnits();
Frederic Riss4e126a02014-09-15 07:50:27 +0000615 return CUs.getUnitForOffset(Offset);
Benjamin Kramer2602ca62011-09-15 20:43:22 +0000616}
617
Alexey Samsonov45be7932012-08-30 07:49:50 +0000618DWARFCompileUnit *DWARFContext::getCompileUnitForAddress(uint64_t Address) {
Benjamin Kramer112ec172011-09-15 21:59:13 +0000619 // First, get the offset of the compile unit.
Alexey Samsonov45be7932012-08-30 07:49:50 +0000620 uint32_t CUOffset = getDebugAranges()->findAddress(Address);
Benjamin Kramer2602ca62011-09-15 20:43:22 +0000621 // Retrieve the compile unit.
Alexey Samsonov45be7932012-08-30 07:49:50 +0000622 return getCompileUnitForOffset(CUOffset);
623}
624
David Blaikieefc4eba2017-02-06 20:19:02 +0000625static bool getFunctionNameAndStartLineForAddress(DWARFCompileUnit *CU,
626 uint64_t Address,
627 FunctionNameKind Kind,
628 std::string &FunctionName,
629 uint32_t &StartLine) {
Alexey Samsonovd0109992014-04-18 21:36:39 +0000630 // The address may correspond to instruction in some inlined function,
631 // so we have to build the chain of inlined functions and take the
David Blaikieefc4eba2017-02-06 20:19:02 +0000632 // name of the topmost function in it.
Greg Claytonc8c10322016-12-13 18:25:19 +0000633 SmallVector<DWARFDie, 4> InlinedChain;
634 CU->getInlinedChainForAddress(Address, InlinedChain);
David Blaikieefc4eba2017-02-06 20:19:02 +0000635 if (InlinedChain.empty())
Alexey Samsonovd0109992014-04-18 21:36:39 +0000636 return false;
David Blaikieefc4eba2017-02-06 20:19:02 +0000637
638 const DWARFDie &DIE = InlinedChain[0];
639 bool FoundResult = false;
640 const char *Name = nullptr;
641 if (Kind != FunctionNameKind::None && (Name = DIE.getSubroutineName(Kind))) {
Alexey Samsonovd0109992014-04-18 21:36:39 +0000642 FunctionName = Name;
David Blaikieefc4eba2017-02-06 20:19:02 +0000643 FoundResult = true;
Alexey Samsonovd0109992014-04-18 21:36:39 +0000644 }
David Blaikieefc4eba2017-02-06 20:19:02 +0000645 if (auto DeclLineResult = DIE.getDeclLine()) {
646 StartLine = DeclLineResult;
647 FoundResult = true;
648 }
649
650 return FoundResult;
Alexey Samsonovd0109992014-04-18 21:36:39 +0000651}
652
Alexey Samsonov45be7932012-08-30 07:49:50 +0000653DILineInfo DWARFContext::getLineInfoForAddress(uint64_t Address,
Alexey Samsonovdce67342014-05-15 21:24:32 +0000654 DILineInfoSpecifier Spec) {
Alexey Samsonovd0109992014-04-18 21:36:39 +0000655 DILineInfo Result;
656
Alexey Samsonov45be7932012-08-30 07:49:50 +0000657 DWARFCompileUnit *CU = getCompileUnitForAddress(Address);
658 if (!CU)
Alexey Samsonovd0109992014-04-18 21:36:39 +0000659 return Result;
David Blaikieefc4eba2017-02-06 20:19:02 +0000660 getFunctionNameAndStartLineForAddress(CU, Address, Spec.FNKind,
661 Result.FunctionName,
662 Result.StartLine);
Alexey Samsonovdce67342014-05-15 21:24:32 +0000663 if (Spec.FLIKind != FileLineInfoKind::None) {
Frederic Riss101b5e22014-09-19 15:11:51 +0000664 if (const DWARFLineTable *LineTable = getLineTableForUnit(CU))
665 LineTable->getFileLineInfoForAddress(Address, CU->getCompilationDir(),
666 Spec.FLIKind, Result);
Alexey Samsonovf4462fa2012-07-02 05:54:45 +0000667 }
Alexey Samsonovd0109992014-04-18 21:36:39 +0000668 return Result;
Benjamin Kramer2602ca62011-09-15 20:43:22 +0000669}
David Blaikiea379b1812011-12-20 02:50:00 +0000670
Alexey Samsonovdce67342014-05-15 21:24:32 +0000671DILineInfoTable
672DWARFContext::getLineInfoForAddressRange(uint64_t Address, uint64_t Size,
673 DILineInfoSpecifier Spec) {
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000674 DILineInfoTable Lines;
675 DWARFCompileUnit *CU = getCompileUnitForAddress(Address);
676 if (!CU)
677 return Lines;
678
679 std::string FunctionName = "<invalid>";
David Blaikieefc4eba2017-02-06 20:19:02 +0000680 uint32_t StartLine = 0;
681 getFunctionNameAndStartLineForAddress(CU, Address, Spec.FNKind, FunctionName,
682 StartLine);
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000683
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000684 // If the Specifier says we don't need FileLineInfo, just
685 // return the top-most function at the starting address.
Alexey Samsonovdce67342014-05-15 21:24:32 +0000686 if (Spec.FLIKind == FileLineInfoKind::None) {
Alexey Samsonovd0109992014-04-18 21:36:39 +0000687 DILineInfo Result;
688 Result.FunctionName = FunctionName;
David Blaikieefc4eba2017-02-06 20:19:02 +0000689 Result.StartLine = StartLine;
Alexey Samsonovd0109992014-04-18 21:36:39 +0000690 Lines.push_back(std::make_pair(Address, Result));
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000691 return Lines;
692 }
693
Frederic Rissec8a5ba2014-09-04 06:14:40 +0000694 const DWARFLineTable *LineTable = getLineTableForUnit(CU);
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000695
696 // Get the index of row we're looking for in the line table.
697 std::vector<uint32_t> RowVector;
698 if (!LineTable->lookupAddressRange(Address, Size, RowVector))
699 return Lines;
700
Alexey Samsonov1eabf982014-03-13 07:52:54 +0000701 for (uint32_t RowIndex : RowVector) {
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000702 // Take file number and line/column from the row.
703 const DWARFDebugLine::Row &Row = LineTable->Rows[RowIndex];
Alexey Samsonovd0109992014-04-18 21:36:39 +0000704 DILineInfo Result;
Frederic Riss101b5e22014-09-19 15:11:51 +0000705 LineTable->getFileNameByIndex(Row.File, CU->getCompilationDir(),
706 Spec.FLIKind, Result.FileName);
Alexey Samsonovd0109992014-04-18 21:36:39 +0000707 Result.FunctionName = FunctionName;
708 Result.Line = Row.Line;
709 Result.Column = Row.Column;
David Blaikieefc4eba2017-02-06 20:19:02 +0000710 Result.StartLine = StartLine;
Alexey Samsonovd0109992014-04-18 21:36:39 +0000711 Lines.push_back(std::make_pair(Row.Address, Result));
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000712 }
713
714 return Lines;
715}
716
Alexey Samsonovdce67342014-05-15 21:24:32 +0000717DIInliningInfo
718DWARFContext::getInliningInfoForAddress(uint64_t Address,
719 DILineInfoSpecifier Spec) {
Alexey Samsonov5c39fdf2014-04-18 22:22:44 +0000720 DIInliningInfo InliningInfo;
721
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000722 DWARFCompileUnit *CU = getCompileUnitForAddress(Address);
723 if (!CU)
Alexey Samsonov5c39fdf2014-04-18 22:22:44 +0000724 return InliningInfo;
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000725
Alexey Samsonov5c39fdf2014-04-18 22:22:44 +0000726 const DWARFLineTable *LineTable = nullptr;
Greg Claytonc8c10322016-12-13 18:25:19 +0000727 SmallVector<DWARFDie, 4> InlinedChain;
728 CU->getInlinedChainForAddress(Address, InlinedChain);
729 if (InlinedChain.size() == 0) {
Alexey Samsonov5c39fdf2014-04-18 22:22:44 +0000730 // If there is no DIE for address (e.g. it is in unavailable .dwo file),
731 // try to at least get file/line info from symbol table.
Alexey Samsonovdce67342014-05-15 21:24:32 +0000732 if (Spec.FLIKind != FileLineInfoKind::None) {
Alexey Samsonov5c39fdf2014-04-18 22:22:44 +0000733 DILineInfo Frame;
Frederic Rissec8a5ba2014-09-04 06:14:40 +0000734 LineTable = getLineTableForUnit(CU);
Frederic Riss101b5e22014-09-19 15:11:51 +0000735 if (LineTable &&
736 LineTable->getFileLineInfoForAddress(Address, CU->getCompilationDir(),
737 Spec.FLIKind, Frame))
Alexey Samsonov5c39fdf2014-04-18 22:22:44 +0000738 InliningInfo.addFrame(Frame);
Alexey Samsonov5c39fdf2014-04-18 22:22:44 +0000739 }
740 return InliningInfo;
741 }
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000742
Dehao Chenef700d52017-04-17 20:10:39 +0000743 uint32_t CallFile = 0, CallLine = 0, CallColumn = 0, CallDiscriminator = 0;
Greg Claytonc8c10322016-12-13 18:25:19 +0000744 for (uint32_t i = 0, n = InlinedChain.size(); i != n; i++) {
745 DWARFDie &FunctionDIE = InlinedChain[i];
Alexey Samsonovd0109992014-04-18 21:36:39 +0000746 DILineInfo Frame;
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000747 // Get function name if necessary.
Greg Claytonc8c10322016-12-13 18:25:19 +0000748 if (const char *Name = FunctionDIE.getSubroutineName(Spec.FNKind))
Alexey Samsonovdce67342014-05-15 21:24:32 +0000749 Frame.FunctionName = Name;
David Blaikieefc4eba2017-02-06 20:19:02 +0000750 if (auto DeclLineResult = FunctionDIE.getDeclLine())
751 Frame.StartLine = DeclLineResult;
Alexey Samsonovdce67342014-05-15 21:24:32 +0000752 if (Spec.FLIKind != FileLineInfoKind::None) {
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000753 if (i == 0) {
754 // For the topmost frame, initialize the line table of this
755 // compile unit and fetch file/line info from it.
Frederic Rissec8a5ba2014-09-04 06:14:40 +0000756 LineTable = getLineTableForUnit(CU);
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000757 // For the topmost routine, get file/line info from line table.
Frederic Riss101b5e22014-09-19 15:11:51 +0000758 if (LineTable)
759 LineTable->getFileLineInfoForAddress(Address, CU->getCompilationDir(),
760 Spec.FLIKind, Frame);
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000761 } else {
762 // Otherwise, use call file, call line and call column from
763 // previous DIE in inlined chain.
Frederic Riss101b5e22014-09-19 15:11:51 +0000764 if (LineTable)
765 LineTable->getFileNameByIndex(CallFile, CU->getCompilationDir(),
766 Spec.FLIKind, Frame.FileName);
Alexey Samsonovd0109992014-04-18 21:36:39 +0000767 Frame.Line = CallLine;
768 Frame.Column = CallColumn;
Dehao Chenef700d52017-04-17 20:10:39 +0000769 Frame.Discriminator = CallDiscriminator;
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000770 }
771 // Get call file/line/column of a current DIE.
772 if (i + 1 < n) {
Dehao Chenef700d52017-04-17 20:10:39 +0000773 FunctionDIE.getCallerFrame(CallFile, CallLine, CallColumn,
774 CallDiscriminator);
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000775 }
776 }
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000777 InliningInfo.addFrame(Frame);
778 }
779 return InliningInfo;
780}
781
David Blaikief9803fb2017-05-23 00:30:42 +0000782std::shared_ptr<DWARFContext>
783DWARFContext::getDWOContext(StringRef AbsolutePath) {
David Blaikie15d85fc2017-05-23 06:48:53 +0000784 if (auto S = DWP.lock()) {
David Blaikief9803fb2017-05-23 00:30:42 +0000785 DWARFContext *Ctxt = S->Context.get();
786 return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
787 }
788
David Blaikie15d85fc2017-05-23 06:48:53 +0000789 std::weak_ptr<DWOFile> *Entry = &DWOFiles[AbsolutePath];
790
791 if (auto S = Entry->lock()) {
792 DWARFContext *Ctxt = S->Context.get();
793 return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
794 }
795
796 SmallString<128> DWPName;
797 Expected<OwningBinary<ObjectFile>> Obj = [&] {
798 if (!CheckedForDWP) {
799 (getFileName() + ".dwp").toVector(DWPName);
800 auto Obj = object::ObjectFile::createObjectFile(DWPName);
801 if (Obj) {
802 Entry = &DWP;
803 return Obj;
804 } else {
805 CheckedForDWP = true;
806 // TODO: Should this error be handled (maybe in a high verbosity mode)
807 // before falling back to .dwo files?
808 consumeError(Obj.takeError());
809 }
810 }
811
812 return object::ObjectFile::createObjectFile(AbsolutePath);
813 }();
814
David Blaikief9803fb2017-05-23 00:30:42 +0000815 if (!Obj) {
816 // TODO: Actually report errors helpfully.
817 consumeError(Obj.takeError());
818 return nullptr;
819 }
David Blaikie15d85fc2017-05-23 06:48:53 +0000820
821 auto S = std::make_shared<DWOFile>();
David Blaikief9803fb2017-05-23 00:30:42 +0000822 S->File = std::move(Obj.get());
823 S->Context = llvm::make_unique<DWARFContextInMemory>(*S->File.getBinary());
David Blaikie15d85fc2017-05-23 06:48:53 +0000824 *Entry = S;
David Blaikief9803fb2017-05-23 00:30:42 +0000825 auto *Ctxt = S->Context.get();
826 return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
827}
828
George Rimar702dac62017-04-12 08:59:15 +0000829static Error createError(const Twine &Reason, llvm::Error E) {
830 return make_error<StringError>(Reason + toString(std::move(E)),
831 inconvertibleErrorCode());
832}
833
George Rimara25d3292017-05-27 18:10:23 +0000834/// SymInfo contains information about symbol: it's address
835/// and section index which is -1LL for absolute symbols.
836struct SymInfo {
837 uint64_t Address;
838 uint64_t SectionIndex;
839};
840
841/// Returns the address of symbol relocation used against and a section index.
842/// Used for futher relocations computation. Symbol's section load address is
843static Expected<SymInfo> getSymbolInfo(const object::ObjectFile &Obj,
844 const RelocationRef &Reloc,
845 const LoadedObjectInfo *L,
846 std::map<SymbolRef, SymInfo> &Cache) {
847 SymInfo Ret = {0, (uint64_t)-1LL};
George Rimar702dac62017-04-12 08:59:15 +0000848 object::section_iterator RSec = Obj.section_end();
849 object::symbol_iterator Sym = Reloc.getSymbol();
850
George Rimara25d3292017-05-27 18:10:23 +0000851 std::map<SymbolRef, SymInfo>::iterator CacheIt = Cache.end();
George Rimar702dac62017-04-12 08:59:15 +0000852 // First calculate the address of the symbol or section as it appears
853 // in the object file
854 if (Sym != Obj.symbol_end()) {
George Rimar958b01a2017-05-15 11:45:28 +0000855 bool New;
George Rimara25d3292017-05-27 18:10:23 +0000856 std::tie(CacheIt, New) = Cache.insert({*Sym, {0, 0}});
George Rimar958b01a2017-05-15 11:45:28 +0000857 if (!New)
858 return CacheIt->second;
859
George Rimar702dac62017-04-12 08:59:15 +0000860 Expected<uint64_t> SymAddrOrErr = Sym->getAddress();
861 if (!SymAddrOrErr)
George Rimar1af3cb22017-06-28 08:21:19 +0000862 return createError("failed to compute symbol address: ",
George Rimar702dac62017-04-12 08:59:15 +0000863 SymAddrOrErr.takeError());
864
865 // Also remember what section this symbol is in for later
866 auto SectOrErr = Sym->getSection();
867 if (!SectOrErr)
George Rimar1af3cb22017-06-28 08:21:19 +0000868 return createError("failed to get symbol section: ",
George Rimar702dac62017-04-12 08:59:15 +0000869 SectOrErr.takeError());
870
871 RSec = *SectOrErr;
George Rimara25d3292017-05-27 18:10:23 +0000872 Ret.Address = *SymAddrOrErr;
George Rimar702dac62017-04-12 08:59:15 +0000873 } else if (auto *MObj = dyn_cast<MachOObjectFile>(&Obj)) {
874 RSec = MObj->getRelocationSection(Reloc.getRawDataRefImpl());
George Rimara25d3292017-05-27 18:10:23 +0000875 Ret.Address = RSec->getAddress();
George Rimar702dac62017-04-12 08:59:15 +0000876 }
877
George Rimara25d3292017-05-27 18:10:23 +0000878 if (RSec != Obj.section_end())
879 Ret.SectionIndex = RSec->getIndex();
880
George Rimar702dac62017-04-12 08:59:15 +0000881 // If we are given load addresses for the sections, we need to adjust:
882 // SymAddr = (Address of Symbol Or Section in File) -
883 // (Address of Section in File) +
884 // (Load Address of Section)
885 // RSec is now either the section being targeted or the section
886 // containing the symbol being targeted. In either case,
887 // we need to perform the same computation.
888 if (L && RSec != Obj.section_end())
889 if (uint64_t SectionLoadAddress = L->getSectionLoadAddress(*RSec))
George Rimara25d3292017-05-27 18:10:23 +0000890 Ret.Address += SectionLoadAddress - RSec->getAddress();
George Rimar958b01a2017-05-15 11:45:28 +0000891
892 if (CacheIt != Cache.end())
893 CacheIt->second = Ret;
894
George Rimar702dac62017-04-12 08:59:15 +0000895 return Ret;
896}
897
898static bool isRelocScattered(const object::ObjectFile &Obj,
899 const RelocationRef &Reloc) {
George Rimard4998b02017-04-13 09:52:50 +0000900 const MachOObjectFile *MachObj = dyn_cast<MachOObjectFile>(&Obj);
901 if (!MachObj)
George Rimar702dac62017-04-12 08:59:15 +0000902 return false;
903 // MachO also has relocations that point to sections and
904 // scattered relocations.
George Rimar702dac62017-04-12 08:59:15 +0000905 auto RelocInfo = MachObj->getRelocation(Reloc.getRawDataRefImpl());
906 return MachObj->isRelocationScattered(RelocInfo);
907}
908
George Rimar2122ff642017-05-05 10:52:39 +0000909Error DWARFContextInMemory::maybeDecompress(const SectionRef &Sec,
910 StringRef Name, StringRef &Data) {
911 if (!Decompressor::isCompressed(Sec))
912 return Error::success();
913
914 Expected<Decompressor> Decompressor =
915 Decompressor::create(Name, Data, IsLittleEndian, AddressSize == 8);
916 if (!Decompressor)
917 return Decompressor.takeError();
918
919 SmallString<32> Out;
George Rimarf98b9ac2017-05-18 08:00:01 +0000920 if (auto Err = Decompressor->resizeAndDecompress(Out))
George Rimar2122ff642017-05-05 10:52:39 +0000921 return Err;
922
923 UncompressedSections.emplace_back(std::move(Out));
924 Data = UncompressedSections.back();
925
926 return Error::success();
927}
928
George Rimar1af3cb22017-06-28 08:21:19 +0000929ErrorPolicy DWARFContextInMemory::defaultErrorHandler(Error E) {
930 errs() << "error: " + toString(std::move(E)) << '\n';
931 return ErrorPolicy::Continue;
932}
933
934DWARFContextInMemory::DWARFContextInMemory(
935 const object::ObjectFile &Obj, const LoadedObjectInfo *L,
936 function_ref<ErrorPolicy(Error)> HandleError)
David Blaikie15d85fc2017-05-23 06:48:53 +0000937 : FileName(Obj.getFileName()), IsLittleEndian(Obj.isLittleEndian()),
Rafael Espindolaa04bb5b2014-07-31 20:19:36 +0000938 AddressSize(Obj.getBytesInAddress()) {
939 for (const SectionRef &Section : Obj.sections()) {
Eric Christopher7370b552012-11-12 21:40:38 +0000940 StringRef name;
Alexey Samsonov063eb3f2014-03-13 13:52:54 +0000941 Section.getName(name);
David Majnemerdac39852014-09-26 22:32:16 +0000942 // Skip BSS and Virtual sections, they aren't interesting.
Rafael Espindola80291272014-10-08 15:28:58 +0000943 bool IsBSS = Section.isBSS();
David Majnemerdac39852014-09-26 22:32:16 +0000944 if (IsBSS)
945 continue;
Rafael Espindola80291272014-10-08 15:28:58 +0000946 bool IsVirtual = Section.isVirtual();
David Majnemerdac39852014-09-26 22:32:16 +0000947 if (IsVirtual)
948 continue;
Eric Christopher7370b552012-11-12 21:40:38 +0000949 StringRef data;
Keno Fischerc780e8e2015-05-21 21:24:32 +0000950
Lang Hames2e88f4f2015-07-28 17:52:11 +0000951 section_iterator RelocatedSection = Section.getRelocatedSection();
Keno Fischerc780e8e2015-05-21 21:24:32 +0000952 // Try to obtain an already relocated version of this section.
953 // Else use the unrelocated section from the object file. We'll have to
954 // apply relocations ourselves later.
George Rimara25d3292017-05-27 18:10:23 +0000955 if (!L || !L->getLoadedSectionContents(*RelocatedSection, data))
Keno Fischerc780e8e2015-05-21 21:24:32 +0000956 Section.getContents(data);
Eric Christopher7370b552012-11-12 21:40:38 +0000957
George Rimar2122ff642017-05-05 10:52:39 +0000958 if (auto Err = maybeDecompress(Section, name, data)) {
George Rimar1af3cb22017-06-28 08:21:19 +0000959 ErrorPolicy EP = HandleError(
960 createError("failed to decompress '" + name + "', ", std::move(Err)));
961 if (EP == ErrorPolicy::Halt)
962 return;
George Rimar2122ff642017-05-05 10:52:39 +0000963 continue;
Alexey Samsonov068fc8a2013-04-23 10:17:34 +0000964 }
965
George Rimar4bf30832017-01-11 15:26:41 +0000966 // Compressed sections names in GNU style starts from ".z",
967 // at this point section is decompressed and we drop compression prefix.
968 name = name.substr(
969 name.find_first_not_of("._z")); // Skip ".", "z" and "_" prefixes.
970
Rafael Espindola77e87b32017-07-07 05:36:53 +0000971 if (StringRef *SectionData = mapSectionToMember(name)) {
Alexey Samsonov063eb3f2014-03-13 13:52:54 +0000972 *SectionData = data;
Rafael Espindola4f60a382013-05-30 03:05:14 +0000973 if (name == "debug_ranges") {
974 // FIXME: Use the other dwo range section when we emit it.
George Rimarca532112017-04-24 10:19:45 +0000975 RangeDWOSection.Data = data;
Rafael Espindola4f60a382013-05-30 03:05:14 +0000976 }
David Blaikie03c089c2013-09-23 22:44:47 +0000977 } else if (name == "debug_types") {
David Blaikie427e4352013-09-23 23:39:55 +0000978 // Find debug_types data by section rather than name as there are
979 // multiple, comdat grouped, debug_types sections.
Alexey Samsonov063eb3f2014-03-13 13:52:54 +0000980 TypesSections[Section].Data = data;
David Blaikie92d9d622014-01-09 05:08:24 +0000981 } else if (name == "debug_types.dwo") {
Alexey Samsonov063eb3f2014-03-13 13:52:54 +0000982 TypesDWOSections[Section].Data = data;
Eric Christopherda4b2192013-01-02 23:52:13 +0000983 }
Eric Christopher7370b552012-11-12 21:40:38 +0000984
Wolfgang Pieb77d3e932017-06-06 01:22:34 +0000985 // Map platform specific debug section names to DWARF standard section
986 // names.
987 name = Obj.mapDebugSectionName(name);
988
Rafael Espindolaa04bb5b2014-07-31 20:19:36 +0000989 if (RelocatedSection == Obj.section_end())
Rafael Espindola4f60a382013-05-30 03:05:14 +0000990 continue;
991
992 StringRef RelSecName;
Keno Fischerc780e8e2015-05-21 21:24:32 +0000993 StringRef RelSecData;
Rafael Espindola4f60a382013-05-30 03:05:14 +0000994 RelocatedSection->getName(RelSecName);
Keno Fischerc780e8e2015-05-21 21:24:32 +0000995
996 // If the section we're relocating was relocated already by the JIT,
997 // then we used the relocated version above, so we do not need to process
998 // relocations for it now.
George Rimara25d3292017-05-27 18:10:23 +0000999 if (L && L->getLoadedSectionContents(*RelocatedSection, RelSecData))
Keno Fischerc780e8e2015-05-21 21:24:32 +00001000 continue;
1001
Frederic Riss7bb12262015-08-23 04:44:21 +00001002 // In Mach-o files, the relocations do not need to be applied if
1003 // there is no load offset to apply. The value read at the
1004 // relocation point already factors in the section address
1005 // (actually applying the relocations will produce wrong results
1006 // as the section address will be added twice).
Craig Topper66059c92015-11-18 07:07:59 +00001007 if (!L && isa<MachOObjectFile>(&Obj))
Frederic Riss7bb12262015-08-23 04:44:21 +00001008 continue;
1009
Rafael Espindola4f60a382013-05-30 03:05:14 +00001010 RelSecName = RelSecName.substr(
David Blaikiea91885a2017-06-10 19:32:50 +00001011 RelSecName.find_first_not_of("._z")); // Skip . and _ prefixes.
Rafael Espindola4f60a382013-05-30 03:05:14 +00001012
Andrew Kaylord55d7012013-01-25 22:50:58 +00001013 // TODO: Add support for relocations in other sections as needed.
1014 // Record relocations for the debug_info and debug_line sections.
Rafael Espindola77e87b32017-07-07 05:36:53 +00001015 DWARFSection *Sec = mapNameToDWARFSection(RelSecName);
1016 RelocAddrMap *Map = Sec ? &Sec->Relocs : nullptr;
David Blaikie03c089c2013-09-23 22:44:47 +00001017 if (!Map) {
David Blaikie427e4352013-09-23 23:39:55 +00001018 // Find debug_types relocs by section rather than name as there are
1019 // multiple, comdat grouped, debug_types sections.
David Blaikie92d9d622014-01-09 05:08:24 +00001020 if (RelSecName == "debug_types")
1021 Map = &TypesSections[*RelocatedSection].Relocs;
1022 else if (RelSecName == "debug_types.dwo")
1023 Map = &TypesDWOSections[*RelocatedSection].Relocs;
1024 else
1025 continue;
David Blaikie03c089c2013-09-23 22:44:47 +00001026 }
Eric Christopher7370b552012-11-12 21:40:38 +00001027
George Rimarfed9f092017-05-17 12:10:51 +00001028 if (Section.relocation_begin() == Section.relocation_end())
1029 continue;
1030
George Rimara25d3292017-05-27 18:10:23 +00001031 // Symbol to [address, section index] cache mapping.
1032 std::map<SymbolRef, SymInfo> AddrCache;
George Rimarfed9f092017-05-17 12:10:51 +00001033 for (const RelocationRef &Reloc : Section.relocations()) {
1034 // FIXME: it's not clear how to correctly handle scattered
1035 // relocations.
1036 if (isRelocScattered(Obj, Reloc))
1037 continue;
Keno Fischerc780e8e2015-05-21 21:24:32 +00001038
George Rimara25d3292017-05-27 18:10:23 +00001039 Expected<SymInfo> SymInfoOrErr = getSymbolInfo(Obj, Reloc, L, AddrCache);
1040 if (!SymInfoOrErr) {
George Rimar1af3cb22017-06-28 08:21:19 +00001041 if (HandleError(SymInfoOrErr.takeError()) == ErrorPolicy::Halt)
1042 return;
George Rimarfed9f092017-05-17 12:10:51 +00001043 continue;
Eric Christopher7370b552012-11-12 21:40:38 +00001044 }
George Rimarfed9f092017-05-17 12:10:51 +00001045
1046 object::RelocVisitor V(Obj);
George Rimara25d3292017-05-27 18:10:23 +00001047 uint64_t Val = V.visit(Reloc.getType(), Reloc, SymInfoOrErr->Address);
George Rimarfed9f092017-05-17 12:10:51 +00001048 if (V.error()) {
1049 SmallString<32> Name;
1050 Reloc.getTypeName(Name);
George Rimar1af3cb22017-06-28 08:21:19 +00001051 ErrorPolicy EP = HandleError(
George Rimarb25a09d02017-06-29 14:05:18 +00001052 createError("failed to compute relocation: " + Name + ", ",
George Rimar1af3cb22017-06-28 08:21:19 +00001053 errorCodeToError(object_error::parse_failed)));
1054 if (EP == ErrorPolicy::Halt)
1055 return;
George Rimarfed9f092017-05-17 12:10:51 +00001056 continue;
1057 }
Eugene Zelenko2db0cfa2017-06-23 21:57:40 +00001058 RelocAddrEntry Rel = {SymInfoOrErr->SectionIndex, Val};
George Rimara25d3292017-05-27 18:10:23 +00001059 Map->insert({Reloc.getOffset(), Rel});
Eric Christopher7370b552012-11-12 21:40:38 +00001060 }
1061 }
1062}
1063
Chris Bieneman2e752db2017-01-20 19:03:14 +00001064DWARFContextInMemory::DWARFContextInMemory(
1065 const StringMap<std::unique_ptr<MemoryBuffer>> &Sections, uint8_t AddrSize,
1066 bool isLittleEndian)
1067 : IsLittleEndian(isLittleEndian), AddressSize(AddrSize) {
1068 for (const auto &SecIt : Sections) {
Rafael Espindola77e87b32017-07-07 05:36:53 +00001069 if (StringRef *SectionData = mapSectionToMember(SecIt.first()))
Chris Bieneman2e752db2017-01-20 19:03:14 +00001070 *SectionData = SecIt.second->getBuffer();
1071 }
1072}
1073
Rafael Espindola77e87b32017-07-07 05:36:53 +00001074DWARFSection *DWARFContextInMemory::mapNameToDWARFSection(StringRef Name) {
1075 return StringSwitch<DWARFSection *>(Name)
1076 .Case("debug_info", &InfoSection)
1077 .Case("debug_loc", &LocSection)
1078 .Case("debug_line", &LineSection)
1079 .Case("debug_str_offsets", &StringOffsetSection)
1080 .Case("debug_ranges", &RangeSection)
1081 .Case("debug_info.dwo", &InfoDWOSection)
1082 .Case("debug_loc.dwo", &LocDWOSection)
1083 .Case("debug_line.dwo", &LineDWOSection)
1084 .Case("debug_str_offsets.dwo", &StringOffsetDWOSection)
1085 .Case("debug_addr", &AddrSection)
1086 .Case("apple_names", &AppleNamesSection)
1087 .Case("apple_types", &AppleTypesSection)
1088 .Case("apple_namespaces", &AppleNamespacesSection)
1089 .Case("apple_namespac", &AppleNamespacesSection)
1090 .Case("apple_objc", &AppleObjCSection)
1091 .Default(nullptr);
1092}
1093
1094StringRef *DWARFContextInMemory::mapSectionToMember(StringRef Name) {
1095 if (DWARFSection *Sec = mapNameToDWARFSection(Name))
1096 return &Sec->Data;
Chris Bieneman2e752db2017-01-20 19:03:14 +00001097 return StringSwitch<StringRef *>(Name)
Chris Bieneman2e752db2017-01-20 19:03:14 +00001098 .Case("debug_abbrev", &AbbrevSection)
Chris Bieneman2e752db2017-01-20 19:03:14 +00001099 .Case("debug_aranges", &ARangeSection)
1100 .Case("debug_frame", &DebugFrameSection)
1101 .Case("eh_frame", &EHFrameSection)
1102 .Case("debug_str", &StringSection)
Chris Bieneman2e752db2017-01-20 19:03:14 +00001103 .Case("debug_macinfo", &MacinfoSection)
1104 .Case("debug_pubnames", &PubNamesSection)
1105 .Case("debug_pubtypes", &PubTypesSection)
1106 .Case("debug_gnu_pubnames", &GnuPubNamesSection)
1107 .Case("debug_gnu_pubtypes", &GnuPubTypesSection)
Chris Bieneman2e752db2017-01-20 19:03:14 +00001108 .Case("debug_abbrev.dwo", &AbbrevDWOSection)
Chris Bieneman2e752db2017-01-20 19:03:14 +00001109 .Case("debug_str.dwo", &StringDWOSection)
Chris Bieneman2e752db2017-01-20 19:03:14 +00001110 .Case("debug_cu_index", &CUIndexSection)
1111 .Case("debug_tu_index", &TUIndexSection)
1112 .Case("gdb_index", &GdbIndexSection)
1113 // Any more debug info sections go here.
1114 .Default(nullptr);
1115}
1116
Eugene Zelenko28db7e62017-03-01 01:14:23 +00001117void DWARFContextInMemory::anchor() {}