LLVM  5.0.0
DWARFContext.cpp
Go to the documentation of this file.
1 //===- DWARFContext.cpp ---------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 #include "llvm/ADT/STLExtras.h"
12 #include "llvm/ADT/SmallString.h"
13 #include "llvm/ADT/SmallVector.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/ADT/StringSwitch.h"
35 #include "llvm/Object/MachO.h"
36 #include "llvm/Object/ObjectFile.h"
38 #include "llvm/Support/Casting.h"
40 #include "llvm/Support/Error.h"
41 #include "llvm/Support/Format.h"
44 #include <algorithm>
45 #include <cstdint>
46 #include <map>
47 #include <string>
48 #include <tuple>
49 #include <utility>
50 #include <vector>
51 
52 using namespace llvm;
53 using namespace dwarf;
54 using namespace object;
55 
56 #define DEBUG_TYPE "dwarf"
57 
61 
63  const DWARFSection& Section, StringRef StringSection,
64  bool LittleEndian) {
65  DWARFDataExtractor AccelSection(Section, LittleEndian, 0);
66  DataExtractor StrData(StringSection, LittleEndian, 0);
67  OS << "\n." << Name << " contents:\n";
68  DWARFAcceleratorTable Accel(AccelSection, StrData);
69  if (!Accel.extract())
70  return;
71  Accel.dump(OS);
72 }
73 
74 static void
76  const DWARFSection &StringOffsetsSection,
77  StringRef StringSection, bool LittleEndian) {
78  DWARFDataExtractor StrOffsetExt(StringOffsetsSection, LittleEndian, 0);
79  uint32_t Offset = 0;
80  uint64_t SectionSize = StringOffsetsSection.Data.size();
81 
82  while (Offset < SectionSize) {
83  unsigned Version = 0;
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.
134  uint64_t StringOffset =
135  StrOffsetExt.getRelocatedValue(EntrySize, &Offset);
136  if (Format == DWARF32) {
137  uint32_t StringOffset32 = (uint32_t)StringOffset;
138  OS << format("%8.8x ", StringOffset32);
139  const char *S = StrData.getCStr(&StringOffset32);
140  if (S)
141  OS << format("\"%s\"", S);
142  } else
143  OS << format("%16.16" PRIx64 " ", 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.
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 
192  DIDumpType DumpType = DumpOpts.DumpType;
193  bool DumpEH = DumpOpts.DumpEH;
194  bool SummarizeTypes = DumpOpts.SummarizeTypes;
195 
196  if (DumpType == DIDT_All || DumpType == DIDT_Abbrev) {
197  OS << ".debug_abbrev contents:\n";
198  getDebugAbbrev()->dump(OS);
199  }
200 
201  if (DumpType == DIDT_All || DumpType == DIDT_AbbrevDwo)
202  if (const DWARFDebugAbbrev *D = getDebugAbbrevDWO()) {
203  OS << "\n.debug_abbrev.dwo contents:\n";
204  D->dump(OS);
205  }
206 
207  if (DumpType == DIDT_All || DumpType == DIDT_Info) {
208  OS << "\n.debug_info contents:\n";
209  for (const auto &CU : compile_units())
210  CU->dump(OS, DumpOpts);
211  }
212 
213  if ((DumpType == DIDT_All || DumpType == DIDT_InfoDwo) &&
214  getNumDWOCompileUnits()) {
215  OS << "\n.debug_info.dwo contents:\n";
216  for (const auto &DWOCU : dwo_compile_units())
217  DWOCU->dump(OS, DumpOpts);
218  }
219 
220  if ((DumpType == DIDT_All || DumpType == DIDT_Types) && getNumTypeUnits()) {
221  OS << "\n.debug_types contents:\n";
222  for (const auto &TUS : type_unit_sections())
223  for (const auto &TU : TUS)
224  TU->dump(OS, SummarizeTypes);
225  }
226 
227  if ((DumpType == DIDT_All || DumpType == DIDT_TypesDwo) &&
228  getNumDWOTypeUnits()) {
229  OS << "\n.debug_types.dwo contents:\n";
230  for (const auto &DWOTUS : dwo_type_unit_sections())
231  for (const auto &DWOTU : DWOTUS)
232  DWOTU->dump(OS, SummarizeTypes);
233  }
234 
235  if (DumpType == DIDT_All || DumpType == DIDT_Loc) {
236  OS << "\n.debug_loc contents:\n";
237  getDebugLoc()->dump(OS);
238  }
239 
240  if (DumpType == DIDT_All || DumpType == DIDT_LocDwo) {
241  OS << "\n.debug_loc.dwo contents:\n";
242  getDebugLocDWO()->dump(OS);
243  }
244 
245  if (DumpType == DIDT_All || DumpType == DIDT_Frames) {
246  OS << "\n.debug_frame contents:\n";
247  getDebugFrame()->dump(OS);
248  if (DumpEH) {
249  OS << "\n.eh_frame contents:\n";
250  getEHFrame()->dump(OS);
251  }
252  }
253 
254  if (DumpType == DIDT_All || DumpType == DIDT_Macro) {
255  OS << "\n.debug_macinfo contents:\n";
256  getDebugMacro()->dump(OS);
257  }
258 
259  uint32_t offset = 0;
260  if (DumpType == DIDT_All || DumpType == DIDT_Aranges) {
261  OS << "\n.debug_aranges contents:\n";
262  DataExtractor arangesData(getARangeSection(), isLittleEndian(), 0);
264  while (set.extract(arangesData, &offset))
265  set.dump(OS);
266  }
267 
268  uint8_t savedAddressByteSize = 0;
269  if (DumpType == DIDT_All || DumpType == DIDT_Line) {
270  OS << "\n.debug_line contents:\n";
271  for (const auto &CU : compile_units()) {
272  savedAddressByteSize = CU->getAddressByteSize();
273  auto CUDIE = CU->getUnitDIE();
274  if (!CUDIE)
275  continue;
276  if (auto StmtOffset = toSectionOffset(CUDIE.find(DW_AT_stmt_list))) {
277  DWARFDataExtractor lineData(getLineSection(), isLittleEndian(),
278  savedAddressByteSize);
279  DWARFDebugLine::LineTable LineTable;
280  uint32_t Offset = *StmtOffset;
281  LineTable.parse(lineData, &Offset);
282  LineTable.dump(OS);
283  }
284  }
285  }
286 
287  if (DumpType == DIDT_All || DumpType == DIDT_CUIndex) {
288  OS << "\n.debug_cu_index contents:\n";
289  getCUIndex().dump(OS);
290  }
291 
292  if (DumpType == DIDT_All || DumpType == DIDT_TUIndex) {
293  OS << "\n.debug_tu_index contents:\n";
294  getTUIndex().dump(OS);
295  }
296 
297  if (DumpType == DIDT_All || DumpType == DIDT_LineDwo) {
298  OS << "\n.debug_line.dwo contents:\n";
299  unsigned stmtOffset = 0;
300  DWARFDataExtractor lineData(getLineDWOSection(), isLittleEndian(),
301  savedAddressByteSize);
302  DWARFDebugLine::LineTable LineTable;
303  while (LineTable.Prologue.parse(lineData, &stmtOffset)) {
304  LineTable.dump(OS);
305  LineTable.clear();
306  }
307  }
308 
309  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  }
318  }
319 
320  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;
329  }
330  }
331 
332  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).
338  DWARFDataExtractor rangesData(getRangeSection(), isLittleEndian(),
339  savedAddressByteSize);
340  offset = 0;
341  DWARFDebugRangeList rangeList;
342  while (rangeList.extract(rangesData, &offset))
343  rangeList.dump(OS);
344  }
345 
346  if (DumpType == DIDT_All || DumpType == DIDT_Pubnames)
347  DWARFDebugPubTable(getPubNamesSection(), isLittleEndian(), false)
348  .dump("debug_pubnames", OS);
349 
350  if (DumpType == DIDT_All || DumpType == DIDT_Pubtypes)
351  DWARFDebugPubTable(getPubTypesSection(), isLittleEndian(), false)
352  .dump("debug_pubtypes", OS);
353 
354  if (DumpType == DIDT_All || DumpType == DIDT_GnuPubnames)
355  DWARFDebugPubTable(getGnuPubNamesSection(), isLittleEndian(),
356  true /* GnuStyle */)
357  .dump("debug_gnu_pubnames", OS);
358 
359  if (DumpType == DIDT_All || DumpType == DIDT_GnuPubtypes)
360  DWARFDebugPubTable(getGnuPubTypesSection(), isLittleEndian(),
361  true /* GnuStyle */)
362  .dump("debug_gnu_pubtypes", OS);
363 
364  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());
373  }
374 
375  if ((DumpType == DIDT_All || DumpType == DIDT_GdbIndex) &&
376  !getGdbIndexSection().empty()) {
377  OS << "\n.gnu_index contents:\n";
378  getGdbIndex().dump(OS);
379  }
380 
381  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());
396 }
397 
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 
408  parseCompileUnits();
409  if (auto *CU = CUs.getUnitForOffset(Offset))
410  return CU->getDIEForOffset(Offset);
411  return DWARFDie();
412 }
413 
415  bool Success = true;
416  DWARFVerifier verifier(OS, *this);
417  if (DumpType == DIDT_All || DumpType == DIDT_Info) {
418  if (!verifier.handleDebugInfo())
419  Success = false;
420  }
421  if (DumpType == DIDT_All || DumpType == DIDT_Line) {
422  if (!verifier.handleDebugLine())
423  Success = false;
424  }
425  if (DumpType == DIDT_All || DumpType == DIDT_AppleNames) {
426  if (!verifier.handleAppleNames())
427  Success = false;
428  }
429  return Success;
430 }
431 
433  if (CUIndex)
434  return *CUIndex;
435 
436  DataExtractor CUIndexData(getCUIndexSection(), isLittleEndian(), 0);
437 
438  CUIndex = llvm::make_unique<DWARFUnitIndex>(DW_SECT_INFO);
439  CUIndex->parse(CUIndexData);
440  return *CUIndex;
441 }
442 
444  if (TUIndex)
445  return *TUIndex;
446 
447  DataExtractor TUIndexData(getTUIndexSection(), isLittleEndian(), 0);
448 
449  TUIndex = llvm::make_unique<DWARFUnitIndex>(DW_SECT_TYPES);
450  TUIndex->parse(TUIndexData);
451  return *TUIndex;
452 }
453 
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 
465  if (Abbrev)
466  return Abbrev.get();
467 
468  DataExtractor abbrData(getAbbrevSection(), isLittleEndian(), 0);
469 
470  Abbrev.reset(new DWARFDebugAbbrev());
471  Abbrev->extract(abbrData);
472  return Abbrev.get();
473 }
474 
476  if (AbbrevDWO)
477  return AbbrevDWO.get();
478 
479  DataExtractor abbrData(getAbbrevDWOSection(), isLittleEndian(), 0);
480  AbbrevDWO.reset(new DWARFDebugAbbrev());
481  AbbrevDWO->extract(abbrData);
482  return AbbrevDWO.get();
483 }
484 
486  if (Loc)
487  return Loc.get();
488 
489  Loc.reset(new DWARFDebugLoc);
490  // assume all compile units have the same address byte size
491  if (getNumCompileUnits()) {
492  DWARFDataExtractor LocData(getLocSection(), isLittleEndian(),
493  getCompileUnitAtIndex(0)->getAddressByteSize());
494  Loc->parse(LocData);
495  }
496  return Loc.get();
497 }
498 
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 
510  if (Aranges)
511  return Aranges.get();
512 
513  Aranges.reset(new DWARFDebugAranges());
514  Aranges->generate(this);
515  return Aranges.get();
516 }
517 
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());
533  DebugFrame.reset(new DWARFDebugFrame(false /* IsEH */));
534  DebugFrame->parse(debugFrameData);
535  return DebugFrame.get();
536 }
537 
539  if (EHFrame)
540  return EHFrame.get();
541 
542  DataExtractor debugFrameData(getEHFrameSection(), isLittleEndian(),
543  getAddressSize());
544  DebugFrame.reset(new DWARFDebugFrame(true /* IsEH */));
545  DebugFrame->parse(debugFrameData);
546  return DebugFrame.get();
547 }
548 
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 
559 const DWARFLineTable *
561  if (!Line)
562  Line.reset(new DWARFDebugLine);
563 
564  auto UnitDIE = U->getUnitDIE();
565  if (!UnitDIE)
566  return nullptr;
567 
568  auto Offset = toSectionOffset(UnitDIE.find(DW_AT_stmt_list));
569  if (!Offset)
570  return nullptr; // No line table for this compile unit.
571 
572  uint32_t stmtOffset = *Offset + U->getLineTableOffset();
573  // See if the line table is cached.
574  if (const DWARFLineTable *lt = Line->getLineTable(stmtOffset))
575  return lt;
576 
577  // Make sure the offset is good before we try to parse.
578  if (stmtOffset >= U->getLineSection().Data.size())
579  return nullptr;
580 
581  // We have to parse it first.
582  DWARFDataExtractor lineData(U->getLineSection(), isLittleEndian(),
583  U->getAddressByteSize());
584  return Line->getOrParseLineTable(lineData, stmtOffset);
585 }
586 
587 void DWARFContext::parseCompileUnits() {
588  CUs.parse(*this, getInfoSection());
589 }
590 
591 void DWARFContext::parseTypeUnits() {
592  if (!TUs.empty())
593  return;
594  forEachTypesSections([&](const DWARFSection &S) {
595  TUs.emplace_back();
596  TUs.back().parse(*this, S);
597  });
598 }
599 
600 void DWARFContext::parseDWOCompileUnits() {
601  DWOCUs.parseDWO(*this, getInfoDWOSection());
602 }
603 
604 void DWARFContext::parseDWOTypeUnits() {
605  if (!DWOTUs.empty())
606  return;
607  forEachTypesDWOSections([&](const DWARFSection &S) {
608  DWOTUs.emplace_back();
609  DWOTUs.back().parseDWO(*this, S);
610  });
611 }
612 
613 DWARFCompileUnit *DWARFContext::getCompileUnitForOffset(uint32_t Offset) {
614  parseCompileUnits();
615  return CUs.getUnitForOffset(Offset);
616 }
617 
618 DWARFCompileUnit *DWARFContext::getCompileUnitForAddress(uint64_t Address) {
619  // First, get the offset of the compile unit.
620  uint32_t CUOffset = getDebugAranges()->findAddress(Address);
621  // Retrieve the compile unit.
622  return getCompileUnitForOffset(CUOffset);
623 }
624 
626  uint64_t Address,
628  std::string &FunctionName,
629  uint32_t &StartLine) {
630  // The address may correspond to instruction in some inlined function,
631  // so we have to build the chain of inlined functions and take the
632  // name of the topmost function in it.
633  SmallVector<DWARFDie, 4> InlinedChain;
634  CU->getInlinedChainForAddress(Address, InlinedChain);
635  if (InlinedChain.empty())
636  return false;
637 
638  const DWARFDie &DIE = InlinedChain[0];
639  bool FoundResult = false;
640  const char *Name = nullptr;
641  if (Kind != FunctionNameKind::None && (Name = DIE.getSubroutineName(Kind))) {
642  FunctionName = Name;
643  FoundResult = true;
644  }
645  if (auto DeclLineResult = DIE.getDeclLine()) {
646  StartLine = DeclLineResult;
647  FoundResult = true;
648  }
649 
650  return FoundResult;
651 }
652 
654  DILineInfoSpecifier Spec) {
655  DILineInfo Result;
656 
657  DWARFCompileUnit *CU = getCompileUnitForAddress(Address);
658  if (!CU)
659  return Result;
661  Result.FunctionName,
662  Result.StartLine);
663  if (Spec.FLIKind != FileLineInfoKind::None) {
664  if (const DWARFLineTable *LineTable = getLineTableForUnit(CU))
665  LineTable->getFileLineInfoForAddress(Address, CU->getCompilationDir(),
666  Spec.FLIKind, Result);
667  }
668  return Result;
669 }
670 
673  DILineInfoSpecifier Spec) {
674  DILineInfoTable Lines;
675  DWARFCompileUnit *CU = getCompileUnitForAddress(Address);
676  if (!CU)
677  return Lines;
678 
679  std::string FunctionName = "<invalid>";
680  uint32_t StartLine = 0;
681  getFunctionNameAndStartLineForAddress(CU, Address, Spec.FNKind, FunctionName,
682  StartLine);
683 
684  // If the Specifier says we don't need FileLineInfo, just
685  // return the top-most function at the starting address.
686  if (Spec.FLIKind == FileLineInfoKind::None) {
687  DILineInfo Result;
688  Result.FunctionName = FunctionName;
689  Result.StartLine = StartLine;
690  Lines.push_back(std::make_pair(Address, Result));
691  return Lines;
692  }
693 
694  const DWARFLineTable *LineTable = getLineTableForUnit(CU);
695 
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 
701  for (uint32_t RowIndex : RowVector) {
702  // Take file number and line/column from the row.
703  const DWARFDebugLine::Row &Row = LineTable->Rows[RowIndex];
704  DILineInfo Result;
705  LineTable->getFileNameByIndex(Row.File, CU->getCompilationDir(),
706  Spec.FLIKind, Result.FileName);
707  Result.FunctionName = FunctionName;
708  Result.Line = Row.Line;
709  Result.Column = Row.Column;
710  Result.StartLine = StartLine;
711  Lines.push_back(std::make_pair(Row.Address, Result));
712  }
713 
714  return Lines;
715 }
716 
719  DILineInfoSpecifier Spec) {
720  DIInliningInfo InliningInfo;
721 
722  DWARFCompileUnit *CU = getCompileUnitForAddress(Address);
723  if (!CU)
724  return InliningInfo;
725 
726  const DWARFLineTable *LineTable = nullptr;
727  SmallVector<DWARFDie, 4> InlinedChain;
728  CU->getInlinedChainForAddress(Address, InlinedChain);
729  if (InlinedChain.size() == 0) {
730  // 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.
732  if (Spec.FLIKind != FileLineInfoKind::None) {
733  DILineInfo Frame;
734  LineTable = getLineTableForUnit(CU);
735  if (LineTable &&
736  LineTable->getFileLineInfoForAddress(Address, CU->getCompilationDir(),
737  Spec.FLIKind, Frame))
738  InliningInfo.addFrame(Frame);
739  }
740  return InliningInfo;
741  }
742 
743  uint32_t CallFile = 0, CallLine = 0, CallColumn = 0, CallDiscriminator = 0;
744  for (uint32_t i = 0, n = InlinedChain.size(); i != n; i++) {
745  DWARFDie &FunctionDIE = InlinedChain[i];
746  DILineInfo Frame;
747  // Get function name if necessary.
748  if (const char *Name = FunctionDIE.getSubroutineName(Spec.FNKind))
749  Frame.FunctionName = Name;
750  if (auto DeclLineResult = FunctionDIE.getDeclLine())
751  Frame.StartLine = DeclLineResult;
752  if (Spec.FLIKind != FileLineInfoKind::None) {
753  if (i == 0) {
754  // For the topmost frame, initialize the line table of this
755  // compile unit and fetch file/line info from it.
756  LineTable = getLineTableForUnit(CU);
757  // For the topmost routine, get file/line info from line table.
758  if (LineTable)
759  LineTable->getFileLineInfoForAddress(Address, CU->getCompilationDir(),
760  Spec.FLIKind, Frame);
761  } else {
762  // Otherwise, use call file, call line and call column from
763  // previous DIE in inlined chain.
764  if (LineTable)
765  LineTable->getFileNameByIndex(CallFile, CU->getCompilationDir(),
766  Spec.FLIKind, Frame.FileName);
767  Frame.Line = CallLine;
768  Frame.Column = CallColumn;
769  Frame.Discriminator = CallDiscriminator;
770  }
771  // Get call file/line/column of a current DIE.
772  if (i + 1 < n) {
773  FunctionDIE.getCallerFrame(CallFile, CallLine, CallColumn,
774  CallDiscriminator);
775  }
776  }
777  InliningInfo.addFrame(Frame);
778  }
779  return InliningInfo;
780 }
781 
782 std::shared_ptr<DWARFContext>
784  if (auto S = DWP.lock()) {
785  DWARFContext *Ctxt = S->Context.get();
786  return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
787  }
788 
789  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;
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 
815  if (!Obj) {
816  // TODO: Actually report errors helpfully.
817  consumeError(Obj.takeError());
818  return nullptr;
819  }
820 
821  auto S = std::make_shared<DWOFile>();
822  S->File = std::move(Obj.get());
823  S->Context = llvm::make_unique<DWARFContextInMemory>(*S->File.getBinary());
824  *Entry = S;
825  auto *Ctxt = S->Context.get();
826  return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
827 }
828 
829 static Error createError(const Twine &Reason, llvm::Error E) {
830  return make_error<StringError>(Reason + toString(std::move(E)),
832 }
833 
834 /// SymInfo contains information about symbol: it's address
835 /// and section index which is -1LL for absolute symbols.
836 struct 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
844  const RelocationRef &Reloc,
845  const LoadedObjectInfo *L,
846  std::map<SymbolRef, SymInfo> &Cache) {
847  SymInfo Ret = {0, (uint64_t)-1LL};
849  object::symbol_iterator Sym = Reloc.getSymbol();
850 
851  std::map<SymbolRef, SymInfo>::iterator CacheIt = Cache.end();
852  // First calculate the address of the symbol or section as it appears
853  // in the object file
854  if (Sym != Obj.symbol_end()) {
855  bool New;
856  std::tie(CacheIt, New) = Cache.insert({*Sym, {0, 0}});
857  if (!New)
858  return CacheIt->second;
859 
860  Expected<uint64_t> SymAddrOrErr = Sym->getAddress();
861  if (!SymAddrOrErr)
862  return createError("failed to compute symbol address: ",
863  SymAddrOrErr.takeError());
864 
865  // Also remember what section this symbol is in for later
866  auto SectOrErr = Sym->getSection();
867  if (!SectOrErr)
868  return createError("failed to get symbol section: ",
869  SectOrErr.takeError());
870 
871  RSec = *SectOrErr;
872  Ret.Address = *SymAddrOrErr;
873  } else if (auto *MObj = dyn_cast<MachOObjectFile>(&Obj)) {
874  RSec = MObj->getRelocationSection(Reloc.getRawDataRefImpl());
875  Ret.Address = RSec->getAddress();
876  }
877 
878  if (RSec != Obj.section_end())
879  Ret.SectionIndex = RSec->getIndex();
880 
881  // 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))
890  Ret.Address += SectionLoadAddress - RSec->getAddress();
891 
892  if (CacheIt != Cache.end())
893  CacheIt->second = Ret;
894 
895  return Ret;
896 }
897 
898 static bool isRelocScattered(const object::ObjectFile &Obj,
899  const RelocationRef &Reloc) {
900  const MachOObjectFile *MachObj = dyn_cast<MachOObjectFile>(&Obj);
901  if (!MachObj)
902  return false;
903  // MachO also has relocations that point to sections and
904  // scattered relocations.
905  auto RelocInfo = MachObj->getRelocation(Reloc.getRawDataRefImpl());
906  return MachObj->isRelocationScattered(RelocInfo);
907 }
908 
909 Error 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;
920  if (auto Err = Decompressor->resizeAndDecompress(Out))
921  return Err;
922 
923  UncompressedSections.emplace_back(std::move(Out));
924  Data = UncompressedSections.back();
925 
926  return Error::success();
927 }
928 
929 ErrorPolicy DWARFContextInMemory::defaultErrorHandler(Error E) {
930  errs() << "error: " + toString(std::move(E)) << '\n';
931  return ErrorPolicy::Continue;
932 }
933 
935  const object::ObjectFile &Obj, const LoadedObjectInfo *L,
936  function_ref<ErrorPolicy(Error)> HandleError)
937  : FileName(Obj.getFileName()), IsLittleEndian(Obj.isLittleEndian()),
938  AddressSize(Obj.getBytesInAddress()) {
939  for (const SectionRef &Section : Obj.sections()) {
940  StringRef Name;
941  Section.getName(Name);
942  // Skip BSS and Virtual sections, they aren't interesting.
943  if (Section.isBSS() || Section.isVirtual())
944  continue;
945 
946  StringRef Data;
947  section_iterator RelocatedSection = Section.getRelocatedSection();
948  // Try to obtain an already relocated version of this section.
949  // Else use the unrelocated section from the object file. We'll have to
950  // apply relocations ourselves later.
951  if (!L || !L->getLoadedSectionContents(*RelocatedSection, Data))
952  Section.getContents(Data);
953 
954  if (auto Err = maybeDecompress(Section, Name, Data)) {
955  ErrorPolicy EP = HandleError(
956  createError("failed to decompress '" + Name + "', ", std::move(Err)));
957  if (EP == ErrorPolicy::Halt)
958  return;
959  continue;
960  }
961 
962  // Compressed sections names in GNU style starts from ".z",
963  // at this point section is decompressed and we drop compression prefix.
964  Name = Name.substr(
965  Name.find_first_not_of("._z")); // Skip ".", "z" and "_" prefixes.
966 
967  // Map platform specific debug section names to DWARF standard section
968  // names.
969  Name = Obj.mapDebugSectionName(Name);
970 
971  if (StringRef *SectionData = mapSectionToMember(Name)) {
972  *SectionData = Data;
973  if (Name == "debug_ranges") {
974  // FIXME: Use the other dwo range section when we emit it.
975  RangeDWOSection.Data = Data;
976  }
977  } else if (Name == "debug_types") {
978  // Find debug_types data by section rather than name as there are
979  // multiple, comdat grouped, debug_types sections.
980  TypesSections[Section].Data = Data;
981  } else if (Name == "debug_types.dwo") {
982  TypesDWOSections[Section].Data = Data;
983  }
984 
985  if (RelocatedSection == Obj.section_end())
986  continue;
987 
988  StringRef RelSecName;
989  StringRef RelSecData;
990  RelocatedSection->getName(RelSecName);
991 
992  // If the section we're relocating was relocated already by the JIT,
993  // then we used the relocated version above, so we do not need to process
994  // relocations for it now.
995  if (L && L->getLoadedSectionContents(*RelocatedSection, RelSecData))
996  continue;
997 
998  // In Mach-o files, the relocations do not need to be applied if
999  // there is no load offset to apply. The value read at the
1000  // relocation point already factors in the section address
1001  // (actually applying the relocations will produce wrong results
1002  // as the section address will be added twice).
1003  if (!L && isa<MachOObjectFile>(&Obj))
1004  continue;
1005 
1006  RelSecName = RelSecName.substr(
1007  RelSecName.find_first_not_of("._z")); // Skip . and _ prefixes.
1008 
1009  // TODO: Add support for relocations in other sections as needed.
1010  // Record relocations for the debug_info and debug_line sections.
1011  DWARFSection *Sec = mapNameToDWARFSection(RelSecName);
1012  RelocAddrMap *Map = Sec ? &Sec->Relocs : nullptr;
1013  if (!Map) {
1014  // Find debug_types relocs by section rather than name as there are
1015  // multiple, comdat grouped, debug_types sections.
1016  if (RelSecName == "debug_types")
1017  Map = &TypesSections[*RelocatedSection].Relocs;
1018  else if (RelSecName == "debug_types.dwo")
1019  Map = &TypesDWOSections[*RelocatedSection].Relocs;
1020  else
1021  continue;
1022  }
1023 
1024  if (Section.relocation_begin() == Section.relocation_end())
1025  continue;
1026 
1027  // Symbol to [address, section index] cache mapping.
1028  std::map<SymbolRef, SymInfo> AddrCache;
1029  for (const RelocationRef &Reloc : Section.relocations()) {
1030  // FIXME: it's not clear how to correctly handle scattered
1031  // relocations.
1032  if (isRelocScattered(Obj, Reloc))
1033  continue;
1034 
1035  Expected<SymInfo> SymInfoOrErr = getSymbolInfo(Obj, Reloc, L, AddrCache);
1036  if (!SymInfoOrErr) {
1037  if (HandleError(SymInfoOrErr.takeError()) == ErrorPolicy::Halt)
1038  return;
1039  continue;
1040  }
1041 
1042  object::RelocVisitor V(Obj);
1043  uint64_t Val = V.visit(Reloc.getType(), Reloc, SymInfoOrErr->Address);
1044  if (V.error()) {
1046  Reloc.getTypeName(Type);
1047  ErrorPolicy EP = HandleError(
1048  createError("failed to compute relocation: " + Type + ", ",
1049  errorCodeToError(object_error::parse_failed)));
1050  if (EP == ErrorPolicy::Halt)
1051  return;
1052  continue;
1053  }
1054  RelocAddrEntry Rel = {SymInfoOrErr->SectionIndex, Val};
1055  Map->insert({Reloc.getOffset(), Rel});
1056  }
1057  }
1058 }
1059 
1061  const StringMap<std::unique_ptr<MemoryBuffer>> &Sections, uint8_t AddrSize,
1062  bool isLittleEndian)
1063  : IsLittleEndian(isLittleEndian), AddressSize(AddrSize) {
1064  for (const auto &SecIt : Sections) {
1065  if (StringRef *SectionData = mapSectionToMember(SecIt.first()))
1066  *SectionData = SecIt.second->getBuffer();
1067  }
1068 }
1069 
1070 DWARFSection *DWARFContextInMemory::mapNameToDWARFSection(StringRef Name) {
1072  .Case("debug_info", &InfoSection)
1073  .Case("debug_loc", &LocSection)
1074  .Case("debug_line", &LineSection)
1075  .Case("debug_str_offsets", &StringOffsetSection)
1076  .Case("debug_ranges", &RangeSection)
1077  .Case("debug_info.dwo", &InfoDWOSection)
1078  .Case("debug_loc.dwo", &LocDWOSection)
1079  .Case("debug_line.dwo", &LineDWOSection)
1080  .Case("debug_str_offsets.dwo", &StringOffsetDWOSection)
1081  .Case("debug_addr", &AddrSection)
1082  .Case("apple_names", &AppleNamesSection)
1083  .Case("apple_types", &AppleTypesSection)
1084  .Case("apple_namespaces", &AppleNamespacesSection)
1085  .Case("apple_namespac", &AppleNamespacesSection)
1086  .Case("apple_objc", &AppleObjCSection)
1087  .Default(nullptr);
1088 }
1089 
1090 StringRef *DWARFContextInMemory::mapSectionToMember(StringRef Name) {
1091  if (DWARFSection *Sec = mapNameToDWARFSection(Name))
1092  return &Sec->Data;
1094  .Case("debug_abbrev", &AbbrevSection)
1095  .Case("debug_aranges", &ARangeSection)
1096  .Case("debug_frame", &DebugFrameSection)
1097  .Case("eh_frame", &EHFrameSection)
1098  .Case("debug_str", &StringSection)
1099  .Case("debug_macinfo", &MacinfoSection)
1100  .Case("debug_pubnames", &PubNamesSection)
1101  .Case("debug_pubtypes", &PubTypesSection)
1102  .Case("debug_gnu_pubnames", &GnuPubNamesSection)
1103  .Case("debug_gnu_pubtypes", &GnuPubTypesSection)
1104  .Case("debug_abbrev.dwo", &AbbrevDWOSection)
1105  .Case("debug_str.dwo", &StringDWOSection)
1106  .Case("debug_cu_index", &CUIndexSection)
1107  .Case("debug_tu_index", &TUIndexSection)
1108  .Case("gdb_index", &GdbIndexSection)
1109  // Any more debug info sections go here.
1110  .Default(nullptr);
1111 }
1112 
1113 void DWARFContextInMemory::anchor() {}
MachineLoop * L
const DWARFUnitIndex & getTUIndex()
uint32_t StartLine
Definition: DIContext.h:37
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
Create ObjectFile from path.
Definition: ObjectFile.cpp:125
void getInlinedChainForAddress(uint64_t Address, SmallVectorImpl< DWARFDie > &InlinedChain)
getInlinedChainForAddress - fetches inlined chain for a given address.
Definition: DWARFUnit.cpp:388
const DWARFDebugFrame * getEHFrame()
Get a pointer to the parsed eh frame information object.
void push_back(const T &Elt)
Definition: SmallVector.h:211
uint32_t Discriminator
Definition: DIContext.h:40
const DWARFDebugFrame * getDebugFrame()
Get a pointer to the parsed frame information object.
virtual uint64_t getSectionLoadAddress(const object::SectionRef &Sec) const
Obtain the Load Address of a section by SectionRef.
Definition: DIContext.h:207
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
virtual bool getLoadedSectionContents(const object::SectionRef &Sec, StringRef &Data) const
If conveniently available, return the content of the given Section.
Definition: DIContext.h:221
std::string FileName
Definition: DIContext.h:33
A parsed .debug_frame or .eh_frame section.
const DWARFDebugLocDWO * getDebugLocDWO()
Get a pointer to the parsed DebugLoc object.
Represents structure for holding and parsing .debug_pub* tables.
const DWARFDebugLoc * getDebugLoc()
Get a pointer to the parsed DebugLoc object.
bool parse(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr)
Parse prologue and all rows.
ErrorPolicy
Used as a return value for a error callback passed to DWARF context.
Definition: DWARFContext.h:286
DWARFDie getDIEForOffset(uint32_t Offset)
Get a DIE given an exact offset.
uint64_t Address
RelocAddrMap Relocs
Definition: DWARFSection.h:20
DWARFGdbIndex & getGdbIndex()
std::shared_ptr< DWARFContext > getDWOContext(StringRef AbsolutePath)
bool getFileNameByIndex(uint64_t FileIndex, const char *CompDir, DILineInfoSpecifier::FileLineInfoKind Kind, std::string &Result) const
Extracts filename by its index in filename table in prologue.
bool handleDebugLine()
Verify the information in the .debug_line section.
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:89
uint32_t Line
An unsigned integer indicating a source line number.
DIDumpType DumpType
Definition: DIContext.h:153
This class is the base class for all object file types.
Definition: ObjectFile.h:189
void addFrame(const DILineInfo &Frame)
Definition: DIContext.h:83
const DWARFDebugAbbrev * getDebugAbbrevDWO()
Get a pointer to the parsed dwo abbreviations object.
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
Definition: DIContext.h:99
Error takeError()
Take ownership of the stored error.
Definition: Error.h:764
LLVM_NODISCARD char back() const
back - Get the last character in the string.
Definition: StringRef.h:149
void generate(DWARFContext *CTX)
static void dumpAccelSection(raw_ostream &OS, StringRef Name, const DWARFSection &Section, StringRef StringSection, bool LittleEndian)
const char * getSubroutineName(DINameKind Kind) const
If a DIE represents a subprogram (or inlined subroutine), returns its mangled name (or short name...
Definition: DWARFDie.cpp:273
bool handleDebugInfo()
Verify the information in the .debug_info section.
DILineInfo - a format-neutral container for source line information.
Definition: DIContext.h:32
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:176
static bool getFunctionNameAndStartLineForAddress(DWARFCompileUnit *CU, uint64_t Address, FunctionNameKind Kind, std::string &FunctionName, uint32_t &StartLine)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
Definition: Dwarf.h:490
uint32_t getU32(uint32_t *offset_ptr) const
Extract a uint32_t value from *offset_ptr.
const char * getCompilationDir()
Definition: DWARFUnit.cpp:162
void getCallerFrame(uint32_t &CallFile, uint32_t &CallLine, uint32_t &CallColumn, uint32_t &CallDiscriminator) const
Retrieves values of DW_AT_call_file, DW_AT_call_line and DW_AT_call_column from DIE (or zeroes if the...
Definition: DWARFDie.cpp:298
FunctionNameKind FNKind
Definition: DIContext.h:108
void dump(StringRef Name, raw_ostream &OS) const
FileLineInfoKind FLIKind
Definition: DIContext.h:107
uint64_t Address
The program-counter value corresponding to a machine instruction generated by the compiler...
LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(const T &Value) const
Definition: StringSwitch.h:244
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
bool isValidOffsetForDataOfSize(uint32_t offset, uint32_t length) const
Test the availability of length bytes of data from offset.
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:60
content_iterator< SectionRef > section_iterator
Definition: ObjectFile.h:48
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(const char(&S)[N], const T &Value)
Definition: StringSwitch.h:74
bool parse(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr)
const DWARFDebugAranges * getDebugAranges()
Get a pointer to the parsed DebugAranges object.
uint64_t getRelocatedValue(uint32_t Size, uint32_t *Off, uint64_t *SectionIndex=nullptr) const
Extracts a value and applies a relocation to the result if one exists for the given offset...
const DWARFDebugAbbrev * getDebugAbbrev()
Get a pointer to the parsed DebugAbbrev object.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
const char * Name
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
uint64_t SectionIndex
Container for dump options that control which debug information will be dumped.
Definition: DIContext.h:152
static Expected< StringRef > getFileName(const DebugStringTableSubsectionRef &Strings, const DebugChecksumsSubsectionRef &Checksums, uint32_t FileID)
Optional< uint64_t > toSectionOffset(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an section offset.
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:43
Utility class that carries the DWARF compile/type unit and the debug info entry in an object...
Definition: DWARFDie.h:43
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
uint32_t Column
Definition: DIContext.h:36
void dump(raw_ostream &OS) const
const char * getCStr(uint32_t *offset_ptr) const
Extract a C string from *offset_ptr.
DILineInfoSpecifier - controls which fields of DILineInfo container should be filled with data...
Definition: DIContext.h:103
uint16_t File
An unsigned integer indicating the identity of the source file corresponding to a machine instruction...
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:78
const DWARFDebugMacro * getDebugMacro()
Get a pointer to the parsed DebugMacro object.
DIInliningInfo - a format-neutral container for inlined code description.
Definition: DIContext.h:63
A structured debug information entry.
Definition: DIE.h:662
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:598
DIDumpType
Selects which debug sections get dumped.
Definition: DIContext.h:116
static Error createError(const Twine &Reason, llvm::Error E)
DILineInfo getLineInfoForAddress(uint64_t Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
static void dumpStringOffsetsSection(raw_ostream &OS, StringRef SectionName, const DWARFSection &StringOffsetsSection, StringRef StringSection, bool LittleEndian, unsigned MaxVersion)
void dump(raw_ostream &OS) const
virtual basic_symbol_iterator symbol_end() const =0
static bool isRelocScattered(const object::ObjectFile &Obj, const RelocationRef &Reloc)
section_iterator_range sections() const
Definition: ObjectFile.h:272
LLVM_NODISCARD size_t find_first_not_of(char C, size_t From=0) const
Find the first character in the string that is not C or npos if not found.
Definition: StringRef.cpp:265
void dump(raw_ostream &OS) const
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:593
uint64_t getU64(uint32_t *offset_ptr) const
Extract a uint64_t value from *offset_ptr.
Standard .debug_line state machine structure.
DWARFContextInMemory(const object::ObjectFile &Obj, const LoadedObjectInfo *L=nullptr, function_ref< ErrorPolicy(Error)> HandleError=defaultErrorHandler)
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
Expected< uint64_t > getAddress() const
Returns the symbol virtual address (i.e.
Definition: ObjectFile.h:343
bool verify(raw_ostream &OS, DIDumpType DumpType=DIDT_All) override
DWARFCompileUnit * getDWOCompileUnitForHash(uint64_t Hash)
uint16_t Column
An unsigned integer indicating a column number within a source line.
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
Definition: DWARFUnit.h:275
static ErrorSuccess success()
Create a success value.
Definition: Error.h:311
#define E
Definition: LargeTest.cpp:27
uint64_t getDeclLine() const
Returns the declaration line (start line) for a DIE, assuming it specifies a subprogram.
Definition: DWARFDie.cpp:294
uint32_t Line
Definition: DIContext.h:35
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
DIInliningInfo getInliningInfoForAddress(uint64_t Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
static Expected< SymInfo > getSymbolInfo(const object::ObjectFile &Obj, const RelocationRef &Reloc, const LoadedObjectInfo *L, std::map< SymbolRef, SymInfo > &Cache)
Returns the address of symbol relocation used against and a section index.
std::string FunctionName
Definition: DIContext.h:34
bool extract(DataExtractor data, uint32_t *offset_ptr)
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
Definition: DWARFContext.h:52
void dump(raw_ostream &OS) const
bool lookupAddressRange(uint64_t Address, uint64_t Size, std::vector< uint32_t > &Result) const
reference get()
Returns a reference to the stored T value.
Definition: Error.h:744
const DWARFSection & getLineSection() const
Definition: DWARFUnit.h:178
uint16_t getU16(uint32_t *offset_ptr) const
Extract a uint16_t value from *offset_ptr.
Optional< const char * > toString(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:220
An inferface for inquiring the load address of a loaded object file to be used by the DIContext imple...
Definition: DIContext.h:192
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
Expected< section_iterator > getSection() const
Get section this symbol is defined in reference to.
Definition: ObjectFile.h:359
#define Success
DILineInfoTable getLineInfoForAddressRange(uint64_t Address, uint64_t Size, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
RelocAddrEntry contains relocated value and section index.
Definition: DWARFRelocMap.h:20
void emplace_back(ArgTypes &&...Args)
Definition: SmallVector.h:653
A class that verifies DWARF debug information given a DWARF Context.
Definition: DWARFVerifier.h:27
virtual section_iterator section_end() const =0
virtual StringRef mapDebugSectionName(StringRef Name) const
Maps a debug section name to a standard DWARF section name.
Definition: ObjectFile.h:297
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:135
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
bool getFileLineInfoForAddress(uint64_t Address, const char *CompDir, DILineInfoSpecifier::FileLineInfoKind Kind, DILineInfo &Result) const
Fills the Result argument with the file and line information corresponding to Address.
const DWARFUnitIndex & getCUIndex()
uint8_t getAddressByteSize() const
Definition: DWARFUnit.h:229
uint32_t getLineTableOffset() const
Definition: DWARFUnit.h:339
SymInfo contains information about symbol: it's address and section index which is -1LL for absolute ...
const unsigned Kind
bool handleAppleNames()
Verify the information in the .apple_names accelerator table.
DINameKind FunctionNameKind
Definition: DIContext.h:105
static void dumpDWARFv5StringOffsetsSection(raw_ostream &OS, StringRef SectionName, const DWARFSection &StringOffsetsSection, StringRef StringSection, bool LittleEndian)
const DWARFDebugLine::LineTable * getLineTableForUnit(DWARFUnit *cu)
Get a pointer to a parsed line table corresponding to a compile unit.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
const char SectionName[]
Definition: AMDGPUPTNote.h:24
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
std::string Hash(const Unit &U)
Definition: FuzzerSHA1.cpp:216
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
void dump(raw_ostream &OS, DIDumpOptions DumpOpts) override
const uint64_t Version
Definition: InstrProf.h:864
bool extract(const DWARFDataExtractor &data, uint32_t *offset_ptr)
uint64_t visit(uint32_t Rel, RelocationRef R, uint64_t Value=0)
Definition: RelocVisitor.h:43
#define D
Definition: LargeTest.cpp:26
Base class for object file relocation visitors.
Definition: RelocVisitor.h:36
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:73