LLVM  14.0.0git
DWARFContext.cpp
Go to the documentation of this file.
1 //===- DWARFContext.cpp ---------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include "llvm/ADT/STLExtras.h"
11 #include "llvm/ADT/SmallString.h"
12 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/ADT/StringSwitch.h"
35 #include "llvm/MC/MCRegisterInfo.h"
36 #include "llvm/MC/TargetRegistry.h"
38 #include "llvm/Object/MachO.h"
39 #include "llvm/Object/ObjectFile.h"
41 #include "llvm/Support/Casting.h"
43 #include "llvm/Support/Error.h"
44 #include "llvm/Support/Format.h"
45 #include "llvm/Support/LEB128.h"
47 #include "llvm/Support/Path.h"
49 #include <algorithm>
50 #include <cstdint>
51 #include <deque>
52 #include <map>
53 #include <string>
54 #include <utility>
55 #include <vector>
56 
57 using namespace llvm;
58 using namespace dwarf;
59 using namespace object;
60 
61 #define DEBUG_TYPE "dwarf"
62 
66 
67 DWARFContext::DWARFContext(std::unique_ptr<const DWARFObject> DObj,
68  std::string DWPName,
69  std::function<void(Error)> RecoverableErrorHandler,
70  std::function<void(Error)> WarningHandler)
71  : DIContext(CK_DWARF), DWPName(std::move(DWPName)),
72  RecoverableErrorHandler(RecoverableErrorHandler),
73  WarningHandler(WarningHandler), DObj(std::move(DObj)) {}
74 
75 DWARFContext::~DWARFContext() = default;
76 
77 /// Dump the UUID load command.
78 static void dumpUUID(raw_ostream &OS, const ObjectFile &Obj) {
79  auto *MachO = dyn_cast<MachOObjectFile>(&Obj);
80  if (!MachO)
81  return;
82  for (auto LC : MachO->load_commands()) {
84  if (LC.C.cmd == MachO::LC_UUID) {
85  if (LC.C.cmdsize < sizeof(UUID) + sizeof(LC.C)) {
86  OS << "error: UUID load command is too short.\n";
87  return;
88  }
89  OS << "UUID: ";
90  memcpy(&UUID, LC.Ptr+sizeof(LC.C), sizeof(UUID));
91  OS.write_uuid(UUID);
92  Triple T = MachO->getArchTriple();
93  OS << " (" << T.getArchName() << ')';
94  OS << ' ' << MachO->getFileName() << '\n';
95  }
96  }
97 }
98 
100  std::vector<Optional<StrOffsetsContributionDescriptor>>;
101 
102 // Collect all the contributions to the string offsets table from all units,
103 // sort them by their starting offsets and remove duplicates.
106  ContributionCollection Contributions;
107  for (const auto &U : Units)
108  if (const auto &C = U->getStringOffsetsTableContribution())
109  Contributions.push_back(C);
110  // Sort the contributions so that any invalid ones are placed at
111  // the start of the contributions vector. This way they are reported
112  // first.
113  llvm::sort(Contributions,
116  if (L && R)
117  return L->Base < R->Base;
118  return R.hasValue();
119  });
120 
121  // Uniquify contributions, as it is possible that units (specifically
122  // type units in dwo or dwp files) share contributions. We don't want
123  // to report them more than once.
124  Contributions.erase(
125  std::unique(Contributions.begin(), Contributions.end(),
128  if (L && R)
129  return L->Base == R->Base && L->Size == R->Size;
130  return false;
131  }),
132  Contributions.end());
133  return Contributions;
134 }
135 
136 // Dump a DWARF string offsets section. This may be a DWARF v5 formatted
137 // string offsets section, where each compile or type unit contributes a
138 // number of entries (string offsets), with each contribution preceded by
139 // a header containing size and version number. Alternatively, it may be a
140 // monolithic series of string offsets, as generated by the pre-DWARF v5
141 // implementation of split DWARF; however, in that case we still need to
142 // collect contributions of units because the size of the offsets (4 or 8
143 // bytes) depends on the format of the referencing unit (DWARF32 or DWARF64).
146  const DWARFObject &Obj,
147  const DWARFSection &StringOffsetsSection,
148  StringRef StringSection,
150  bool LittleEndian) {
151  auto Contributions = collectContributionData(Units);
152  DWARFDataExtractor StrOffsetExt(Obj, StringOffsetsSection, LittleEndian, 0);
153  DataExtractor StrData(StringSection, LittleEndian, 0);
154  uint64_t SectionSize = StringOffsetsSection.Data.size();
155  uint64_t Offset = 0;
156  for (auto &Contribution : Contributions) {
157  // Report an ill-formed contribution.
158  if (!Contribution) {
159  OS << "error: invalid contribution to string offsets table in section ."
160  << SectionName << ".\n";
161  return;
162  }
163 
164  dwarf::DwarfFormat Format = Contribution->getFormat();
165  int OffsetDumpWidth = 2 * dwarf::getDwarfOffsetByteSize(Format);
166  uint16_t Version = Contribution->getVersion();
167  uint64_t ContributionHeader = Contribution->Base;
168  // In DWARF v5 there is a contribution header that immediately precedes
169  // the string offsets base (the location we have previously retrieved from
170  // the CU DIE's DW_AT_str_offsets attribute). The header is located either
171  // 8 or 16 bytes before the base, depending on the contribution's format.
172  if (Version >= 5)
173  ContributionHeader -= Format == DWARF32 ? 8 : 16;
174 
175  // Detect overlapping contributions.
176  if (Offset > ContributionHeader) {
179  "overlapping contributions to string offsets table in section .%s.",
180  SectionName.data()));
181  }
182  // Report a gap in the table.
183  if (Offset < ContributionHeader) {
184  OS << format("0x%8.8" PRIx64 ": Gap, length = ", Offset);
185  OS << (ContributionHeader - Offset) << "\n";
186  }
187  OS << format("0x%8.8" PRIx64 ": ", ContributionHeader);
188  // In DWARF v5 the contribution size in the descriptor does not equal
189  // the originally encoded length (it does not contain the length of the
190  // version field and the padding, a total of 4 bytes). Add them back in
191  // for reporting.
192  OS << "Contribution size = " << (Contribution->Size + (Version < 5 ? 0 : 4))
193  << ", Format = " << dwarf::FormatString(Format)
194  << ", Version = " << Version << "\n";
195 
196  Offset = Contribution->Base;
197  unsigned EntrySize = Contribution->getDwarfOffsetByteSize();
198  while (Offset - Contribution->Base < Contribution->Size) {
199  OS << format("0x%8.8" PRIx64 ": ", Offset);
200  uint64_t StringOffset =
201  StrOffsetExt.getRelocatedValue(EntrySize, &Offset);
202  OS << format("%0*" PRIx64 " ", OffsetDumpWidth, StringOffset);
203  const char *S = StrData.getCStr(&StringOffset);
204  if (S)
205  OS << format("\"%s\"", S);
206  OS << "\n";
207  }
208  }
209  // Report a gap at the end of the table.
210  if (Offset < SectionSize) {
211  OS << format("0x%8.8" PRIx64 ": Gap, length = ", Offset);
212  OS << (SectionSize - Offset) << "\n";
213  }
214 }
215 
216 // Dump the .debug_addr section.
217 static void dumpAddrSection(raw_ostream &OS, DWARFDataExtractor &AddrData,
218  DIDumpOptions DumpOpts, uint16_t Version,
219  uint8_t AddrSize) {
220  uint64_t Offset = 0;
221  while (AddrData.isValidOffset(Offset)) {
222  DWARFDebugAddrTable AddrTable;
223  uint64_t TableOffset = Offset;
224  if (Error Err = AddrTable.extract(AddrData, &Offset, Version, AddrSize,
225  DumpOpts.WarningHandler)) {
226  DumpOpts.RecoverableErrorHandler(std::move(Err));
227  // Keep going after an error, if we can, assuming that the length field
228  // could be read. If it couldn't, stop reading the section.
229  if (auto TableLength = AddrTable.getFullLength()) {
230  Offset = TableOffset + *TableLength;
231  continue;
232  }
233  break;
234  }
235  AddrTable.dump(OS, DumpOpts);
236  }
237 }
238 
239 // Dump the .debug_rnglists or .debug_rnglists.dwo section (DWARF v5).
241  raw_ostream &OS, DWARFDataExtractor &rnglistData,
243  LookupPooledAddress,
244  DIDumpOptions DumpOpts) {
245  uint64_t Offset = 0;
246  while (rnglistData.isValidOffset(Offset)) {
248  uint64_t TableOffset = Offset;
249  if (Error Err = Rnglists.extract(rnglistData, &Offset)) {
250  DumpOpts.RecoverableErrorHandler(std::move(Err));
251  uint64_t Length = Rnglists.length();
252  // Keep going after an error, if we can, assuming that the length field
253  // could be read. If it couldn't, stop reading the section.
254  if (Length == 0)
255  break;
256  Offset = TableOffset + Length;
257  } else {
258  Rnglists.dump(rnglistData, OS, LookupPooledAddress, DumpOpts);
259  }
260  }
261 }
262 
263 std::unique_ptr<DWARFDebugMacro>
264 DWARFContext::parseMacroOrMacinfo(MacroSecType SectionType) {
265  auto Macro = std::make_unique<DWARFDebugMacro>();
266  auto ParseAndDump = [&](DWARFDataExtractor &Data, bool IsMacro) {
267  if (Error Err = IsMacro ? Macro->parseMacro(SectionType == MacroSection
268  ? compile_units()
269  : dwo_compile_units(),
270  SectionType == MacroSection
273  Data)
274  : Macro->parseMacinfo(Data)) {
275  RecoverableErrorHandler(std::move(Err));
276  Macro = nullptr;
277  }
278  };
279  switch (SectionType) {
280  case MacinfoSection: {
281  DWARFDataExtractor Data(DObj->getMacinfoSection(), isLittleEndian(), 0);
282  ParseAndDump(Data, /*IsMacro=*/false);
283  break;
284  }
285  case MacinfoDwoSection: {
286  DWARFDataExtractor Data(DObj->getMacinfoDWOSection(), isLittleEndian(), 0);
287  ParseAndDump(Data, /*IsMacro=*/false);
288  break;
289  }
290  case MacroSection: {
291  DWARFDataExtractor Data(*DObj, DObj->getMacroSection(), isLittleEndian(),
292  0);
293  ParseAndDump(Data, /*IsMacro=*/true);
294  break;
295  }
296  case MacroDwoSection: {
297  DWARFDataExtractor Data(DObj->getMacroDWOSection(), isLittleEndian(), 0);
298  ParseAndDump(Data, /*IsMacro=*/true);
299  break;
300  }
301  }
302  return Macro;
303 }
304 
307  const MCRegisterInfo *MRI,
308  const DWARFObject &Obj,
309  Optional<uint64_t> DumpOffset) {
310  uint64_t Offset = 0;
311 
312  while (Data.isValidOffset(Offset)) {
313  DWARFListTableHeader Header(".debug_loclists", "locations");
314  if (Error E = Header.extract(Data, &Offset)) {
316  return;
317  }
318 
319  Header.dump(Data, OS, DumpOpts);
320 
321  uint64_t EndOffset = Header.length() + Header.getHeaderOffset();
322  Data.setAddressSize(Header.getAddrSize());
323  DWARFDebugLoclists Loc(Data, Header.getVersion());
324  if (DumpOffset) {
325  if (DumpOffset >= Offset && DumpOffset < EndOffset) {
326  Offset = *DumpOffset;
327  Loc.dumpLocationList(&Offset, OS, /*BaseAddr=*/None, MRI, Obj, nullptr,
328  DumpOpts, /*Indent=*/0);
329  OS << "\n";
330  return;
331  }
332  } else {
333  Loc.dumpRange(Offset, EndOffset - Offset, OS, MRI, Obj, DumpOpts);
334  }
335  Offset = EndOffset;
336  }
337 }
338 
340  DWARFDataExtractor Data, bool GnuStyle) {
341  DWARFDebugPubTable Table;
342  Table.extract(Data, GnuStyle, DumpOpts.RecoverableErrorHandler);
343  Table.dump(OS);
344 }
345 
347  raw_ostream &OS, DIDumpOptions DumpOpts,
348  std::array<Optional<uint64_t>, DIDT_ID_Count> DumpOffsets) {
349  uint64_t DumpType = DumpOpts.DumpType;
350 
351  StringRef Extension = sys::path::extension(DObj->getFileName());
352  bool IsDWO = (Extension == ".dwo") || (Extension == ".dwp");
353 
354  // Print UUID header.
355  const auto *ObjFile = DObj->getFile();
356  if (DumpType & DIDT_UUID)
357  dumpUUID(OS, *ObjFile);
358 
359  // Print a header for each explicitly-requested section.
360  // Otherwise just print one for non-empty sections.
361  // Only print empty .dwo section headers when dumping a .dwo file.
362  bool Explicit = DumpType != DIDT_All && !IsDWO;
363  bool ExplicitDWO = Explicit && IsDWO;
364  auto shouldDump = [&](bool Explicit, const char *Name, unsigned ID,
366  unsigned Mask = 1U << ID;
367  bool Should = (DumpType & Mask) && (Explicit || !Section.empty());
368  if (!Should)
369  return nullptr;
370  OS << "\n" << Name << " contents:\n";
371  return &DumpOffsets[ID];
372  };
373 
374  // Dump individual sections.
375  if (shouldDump(Explicit, ".debug_abbrev", DIDT_ID_DebugAbbrev,
376  DObj->getAbbrevSection()))
377  getDebugAbbrev()->dump(OS);
378  if (shouldDump(ExplicitDWO, ".debug_abbrev.dwo", DIDT_ID_DebugAbbrev,
379  DObj->getAbbrevDWOSection()))
380  getDebugAbbrevDWO()->dump(OS);
381 
382  auto dumpDebugInfo = [&](const char *Name, unit_iterator_range Units) {
383  OS << '\n' << Name << " contents:\n";
384  if (auto DumpOffset = DumpOffsets[DIDT_ID_DebugInfo])
385  for (const auto &U : Units)
386  U->getDIEForOffset(DumpOffset.getValue())
387  .dump(OS, 0, DumpOpts.noImplicitRecursion());
388  else
389  for (const auto &U : Units)
390  U->dump(OS, DumpOpts);
391  };
392  if ((DumpType & DIDT_DebugInfo)) {
393  if (Explicit || getNumCompileUnits())
394  dumpDebugInfo(".debug_info", info_section_units());
395  if (ExplicitDWO || getNumDWOCompileUnits())
396  dumpDebugInfo(".debug_info.dwo", dwo_info_section_units());
397  }
398 
399  auto dumpDebugType = [&](const char *Name, unit_iterator_range Units) {
400  OS << '\n' << Name << " contents:\n";
401  for (const auto &U : Units)
402  if (auto DumpOffset = DumpOffsets[DIDT_ID_DebugTypes])
403  U->getDIEForOffset(*DumpOffset)
404  .dump(OS, 0, DumpOpts.noImplicitRecursion());
405  else
406  U->dump(OS, DumpOpts);
407  };
408  if ((DumpType & DIDT_DebugTypes)) {
409  if (Explicit || getNumTypeUnits())
410  dumpDebugType(".debug_types", types_section_units());
411  if (ExplicitDWO || getNumDWOTypeUnits())
412  dumpDebugType(".debug_types.dwo", dwo_types_section_units());
413  }
414 
415  DIDumpOptions LLDumpOpts = DumpOpts;
416  if (LLDumpOpts.Verbose)
417  LLDumpOpts.DisplayRawContents = true;
418 
419  if (const auto *Off = shouldDump(Explicit, ".debug_loc", DIDT_ID_DebugLoc,
420  DObj->getLocSection().Data)) {
421  getDebugLoc()->dump(OS, getRegisterInfo(), *DObj, LLDumpOpts, *Off);
422  }
423  if (const auto *Off =
424  shouldDump(Explicit, ".debug_loclists", DIDT_ID_DebugLoclists,
425  DObj->getLoclistsSection().Data)) {
426  DWARFDataExtractor Data(*DObj, DObj->getLoclistsSection(), isLittleEndian(),
427  0);
428  dumpLoclistsSection(OS, LLDumpOpts, Data, getRegisterInfo(), *DObj, *Off);
429  }
430  if (const auto *Off =
431  shouldDump(ExplicitDWO, ".debug_loclists.dwo", DIDT_ID_DebugLoclists,
432  DObj->getLoclistsDWOSection().Data)) {
433  DWARFDataExtractor Data(*DObj, DObj->getLoclistsDWOSection(),
434  isLittleEndian(), 0);
435  dumpLoclistsSection(OS, LLDumpOpts, Data, getRegisterInfo(), *DObj, *Off);
436  }
437 
438  if (const auto *Off =
439  shouldDump(ExplicitDWO, ".debug_loc.dwo", DIDT_ID_DebugLoc,
440  DObj->getLocDWOSection().Data)) {
441  DWARFDataExtractor Data(*DObj, DObj->getLocDWOSection(), isLittleEndian(),
442  4);
443  DWARFDebugLoclists Loc(Data, /*Version=*/4);
444  if (*Off) {
445  uint64_t Offset = **Off;
446  Loc.dumpLocationList(&Offset, OS,
447  /*BaseAddr=*/None, getRegisterInfo(), *DObj, nullptr,
448  LLDumpOpts, /*Indent=*/0);
449  OS << "\n";
450  } else {
451  Loc.dumpRange(0, Data.getData().size(), OS, getRegisterInfo(), *DObj,
452  LLDumpOpts);
453  }
454  }
455 
456  if (const Optional<uint64_t> *Off =
457  shouldDump(Explicit, ".debug_frame", DIDT_ID_DebugFrame,
458  DObj->getFrameSection().Data)) {
460  (*DF)->dump(OS, DumpOpts, getRegisterInfo(), *Off);
461  else
462  RecoverableErrorHandler(DF.takeError());
463  }
464 
465  if (const Optional<uint64_t> *Off =
466  shouldDump(Explicit, ".eh_frame", DIDT_ID_DebugFrame,
467  DObj->getEHFrameSection().Data)) {
469  (*DF)->dump(OS, DumpOpts, getRegisterInfo(), *Off);
470  else
471  RecoverableErrorHandler(DF.takeError());
472  }
473 
474  if (shouldDump(Explicit, ".debug_macro", DIDT_ID_DebugMacro,
475  DObj->getMacroSection().Data)) {
476  if (auto Macro = getDebugMacro())
477  Macro->dump(OS);
478  }
479 
480  if (shouldDump(Explicit, ".debug_macro.dwo", DIDT_ID_DebugMacro,
481  DObj->getMacroDWOSection())) {
482  if (auto MacroDWO = getDebugMacroDWO())
483  MacroDWO->dump(OS);
484  }
485 
486  if (shouldDump(Explicit, ".debug_macinfo", DIDT_ID_DebugMacro,
487  DObj->getMacinfoSection())) {
488  if (auto Macinfo = getDebugMacinfo())
489  Macinfo->dump(OS);
490  }
491 
492  if (shouldDump(Explicit, ".debug_macinfo.dwo", DIDT_ID_DebugMacro,
493  DObj->getMacinfoDWOSection())) {
494  if (auto MacinfoDWO = getDebugMacinfoDWO())
495  MacinfoDWO->dump(OS);
496  }
497 
498  if (shouldDump(Explicit, ".debug_aranges", DIDT_ID_DebugAranges,
499  DObj->getArangesSection())) {
500  uint64_t offset = 0;
501  DWARFDataExtractor arangesData(DObj->getArangesSection(), isLittleEndian(),
502  0);
504  while (arangesData.isValidOffset(offset)) {
505  if (Error E =
506  set.extract(arangesData, &offset, DumpOpts.WarningHandler)) {
507  RecoverableErrorHandler(std::move(E));
508  break;
509  }
510  set.dump(OS);
511  }
512  }
513 
514  auto DumpLineSection = [&](DWARFDebugLine::SectionParser Parser,
515  DIDumpOptions DumpOpts,
516  Optional<uint64_t> DumpOffset) {
517  while (!Parser.done()) {
518  if (DumpOffset && Parser.getOffset() != *DumpOffset) {
519  Parser.skip(DumpOpts.WarningHandler, DumpOpts.WarningHandler);
520  continue;
521  }
522  OS << "debug_line[" << format("0x%8.8" PRIx64, Parser.getOffset())
523  << "]\n";
524  Parser.parseNext(DumpOpts.WarningHandler, DumpOpts.WarningHandler, &OS,
525  DumpOpts.Verbose);
526  }
527  };
528 
529  auto DumpStrSection = [&](StringRef Section) {
530  DataExtractor StrData(Section, isLittleEndian(), 0);
531  uint64_t Offset = 0;
532  uint64_t StrOffset = 0;
533  while (StrData.isValidOffset(Offset)) {
534  Error Err = Error::success();
535  const char *CStr = StrData.getCStr(&Offset, &Err);
536  if (Err) {
537  DumpOpts.WarningHandler(std::move(Err));
538  return;
539  }
540  OS << format("0x%8.8" PRIx64 ": \"", StrOffset);
541  OS.write_escaped(CStr);
542  OS << "\"\n";
543  StrOffset = Offset;
544  }
545  };
546 
547  if (const auto *Off = shouldDump(Explicit, ".debug_line", DIDT_ID_DebugLine,
548  DObj->getLineSection().Data)) {
549  DWARFDataExtractor LineData(*DObj, DObj->getLineSection(), isLittleEndian(),
550  0);
551  DWARFDebugLine::SectionParser Parser(LineData, *this, normal_units());
552  DumpLineSection(Parser, DumpOpts, *Off);
553  }
554 
555  if (const auto *Off =
556  shouldDump(ExplicitDWO, ".debug_line.dwo", DIDT_ID_DebugLine,
557  DObj->getLineDWOSection().Data)) {
558  DWARFDataExtractor LineData(*DObj, DObj->getLineDWOSection(),
559  isLittleEndian(), 0);
560  DWARFDebugLine::SectionParser Parser(LineData, *this, dwo_units());
561  DumpLineSection(Parser, DumpOpts, *Off);
562  }
563 
564  if (shouldDump(Explicit, ".debug_cu_index", DIDT_ID_DebugCUIndex,
565  DObj->getCUIndexSection())) {
566  getCUIndex().dump(OS);
567  }
568 
569  if (shouldDump(Explicit, ".debug_tu_index", DIDT_ID_DebugTUIndex,
570  DObj->getTUIndexSection())) {
571  getTUIndex().dump(OS);
572  }
573 
574  if (shouldDump(Explicit, ".debug_str", DIDT_ID_DebugStr,
575  DObj->getStrSection()))
576  DumpStrSection(DObj->getStrSection());
577 
578  if (shouldDump(ExplicitDWO, ".debug_str.dwo", DIDT_ID_DebugStr,
579  DObj->getStrDWOSection()))
580  DumpStrSection(DObj->getStrDWOSection());
581 
582  if (shouldDump(Explicit, ".debug_line_str", DIDT_ID_DebugLineStr,
583  DObj->getLineStrSection()))
584  DumpStrSection(DObj->getLineStrSection());
585 
586  if (shouldDump(Explicit, ".debug_addr", DIDT_ID_DebugAddr,
587  DObj->getAddrSection().Data)) {
588  DWARFDataExtractor AddrData(*DObj, DObj->getAddrSection(),
589  isLittleEndian(), 0);
590  dumpAddrSection(OS, AddrData, DumpOpts, getMaxVersion(), getCUAddrSize());
591  }
592 
593  if (shouldDump(Explicit, ".debug_ranges", DIDT_ID_DebugRanges,
594  DObj->getRangesSection().Data)) {
595  uint8_t savedAddressByteSize = getCUAddrSize();
596  DWARFDataExtractor rangesData(*DObj, DObj->getRangesSection(),
597  isLittleEndian(), savedAddressByteSize);
598  uint64_t offset = 0;
599  DWARFDebugRangeList rangeList;
600  while (rangesData.isValidOffset(offset)) {
601  if (Error E = rangeList.extract(rangesData, &offset)) {
602  DumpOpts.RecoverableErrorHandler(std::move(E));
603  break;
604  }
605  rangeList.dump(OS);
606  }
607  }
608 
609  auto LookupPooledAddress = [&](uint32_t Index) -> Optional<SectionedAddress> {
610  const auto &CUs = compile_units();
611  auto I = CUs.begin();
612  if (I == CUs.end())
613  return None;
614  return (*I)->getAddrOffsetSectionItem(Index);
615  };
616 
617  if (shouldDump(Explicit, ".debug_rnglists", DIDT_ID_DebugRnglists,
618  DObj->getRnglistsSection().Data)) {
619  DWARFDataExtractor RnglistData(*DObj, DObj->getRnglistsSection(),
620  isLittleEndian(), 0);
621  dumpRnglistsSection(OS, RnglistData, LookupPooledAddress, DumpOpts);
622  }
623 
624  if (shouldDump(ExplicitDWO, ".debug_rnglists.dwo", DIDT_ID_DebugRnglists,
625  DObj->getRnglistsDWOSection().Data)) {
626  DWARFDataExtractor RnglistData(*DObj, DObj->getRnglistsDWOSection(),
627  isLittleEndian(), 0);
628  dumpRnglistsSection(OS, RnglistData, LookupPooledAddress, DumpOpts);
629  }
630 
631  if (shouldDump(Explicit, ".debug_pubnames", DIDT_ID_DebugPubnames,
632  DObj->getPubnamesSection().Data)) {
633  DWARFDataExtractor PubTableData(*DObj, DObj->getPubnamesSection(),
634  isLittleEndian(), 0);
635  dumpPubTableSection(OS, DumpOpts, PubTableData, /*GnuStyle=*/false);
636  }
637 
638  if (shouldDump(Explicit, ".debug_pubtypes", DIDT_ID_DebugPubtypes,
639  DObj->getPubtypesSection().Data)) {
640  DWARFDataExtractor PubTableData(*DObj, DObj->getPubtypesSection(),
641  isLittleEndian(), 0);
642  dumpPubTableSection(OS, DumpOpts, PubTableData, /*GnuStyle=*/false);
643  }
644 
645  if (shouldDump(Explicit, ".debug_gnu_pubnames", DIDT_ID_DebugGnuPubnames,
646  DObj->getGnuPubnamesSection().Data)) {
647  DWARFDataExtractor PubTableData(*DObj, DObj->getGnuPubnamesSection(),
648  isLittleEndian(), 0);
649  dumpPubTableSection(OS, DumpOpts, PubTableData, /*GnuStyle=*/true);
650  }
651 
652  if (shouldDump(Explicit, ".debug_gnu_pubtypes", DIDT_ID_DebugGnuPubtypes,
653  DObj->getGnuPubtypesSection().Data)) {
654  DWARFDataExtractor PubTableData(*DObj, DObj->getGnuPubtypesSection(),
655  isLittleEndian(), 0);
656  dumpPubTableSection(OS, DumpOpts, PubTableData, /*GnuStyle=*/true);
657  }
658 
659  if (shouldDump(Explicit, ".debug_str_offsets", DIDT_ID_DebugStrOffsets,
660  DObj->getStrOffsetsSection().Data))
662  OS, DumpOpts, "debug_str_offsets", *DObj, DObj->getStrOffsetsSection(),
663  DObj->getStrSection(), normal_units(), isLittleEndian());
664  if (shouldDump(ExplicitDWO, ".debug_str_offsets.dwo", DIDT_ID_DebugStrOffsets,
665  DObj->getStrOffsetsDWOSection().Data))
666  dumpStringOffsetsSection(OS, DumpOpts, "debug_str_offsets.dwo", *DObj,
667  DObj->getStrOffsetsDWOSection(),
668  DObj->getStrDWOSection(), dwo_units(),
669  isLittleEndian());
670 
671  if (shouldDump(Explicit, ".gdb_index", DIDT_ID_GdbIndex,
672  DObj->getGdbIndexSection())) {
673  getGdbIndex().dump(OS);
674  }
675 
676  if (shouldDump(Explicit, ".apple_names", DIDT_ID_AppleNames,
677  DObj->getAppleNamesSection().Data))
678  getAppleNames().dump(OS);
679 
680  if (shouldDump(Explicit, ".apple_types", DIDT_ID_AppleTypes,
681  DObj->getAppleTypesSection().Data))
682  getAppleTypes().dump(OS);
683 
684  if (shouldDump(Explicit, ".apple_namespaces", DIDT_ID_AppleNamespaces,
685  DObj->getAppleNamespacesSection().Data))
686  getAppleNamespaces().dump(OS);
687 
688  if (shouldDump(Explicit, ".apple_objc", DIDT_ID_AppleObjC,
689  DObj->getAppleObjCSection().Data))
690  getAppleObjC().dump(OS);
691  if (shouldDump(Explicit, ".debug_names", DIDT_ID_DebugNames,
692  DObj->getNamesSection().Data))
693  getDebugNames().dump(OS);
694 }
695 
697  bool IsDWO) {
698  parseDWOUnits(LazyParse);
699 
700  if (const auto &TUI = getTUIndex()) {
701  if (const auto *R = TUI.getFromHash(Hash))
702  return dyn_cast_or_null<DWARFTypeUnit>(
703  DWOUnits.getUnitForIndexEntry(*R));
704  return nullptr;
705  }
706 
707  struct UnitContainers {
708  const DWARFUnitVector &Units;
710  };
711  UnitContainers Units = IsDWO ? UnitContainers{DWOUnits, DWOTypeUnits}
712  : UnitContainers{NormalUnits, NormalTypeUnits};
713  if (!Units.Map) {
714  Units.Map.emplace();
715  for (const auto &U : IsDWO ? dwo_units() : normal_units()) {
716  if (DWARFTypeUnit *TU = dyn_cast<DWARFTypeUnit>(U.get()))
717  (*Units.Map)[TU->getTypeHash()] = TU;
718  }
719  }
720 
721  return (*Units.Map)[Hash];
722 }
723 
725  parseDWOUnits(LazyParse);
726 
727  if (const auto &CUI = getCUIndex()) {
728  if (const auto *R = CUI.getFromHash(Hash))
729  return dyn_cast_or_null<DWARFCompileUnit>(
730  DWOUnits.getUnitForIndexEntry(*R));
731  return nullptr;
732  }
733 
734  // If there's no index, just search through the CUs in the DWO - there's
735  // probably only one unless this is something like LTO - though an in-process
736  // built/cached lookup table could be used in that case to improve repeated
737  // lookups of different CUs in the DWO.
738  for (const auto &DWOCU : dwo_compile_units()) {
739  // Might not have parsed DWO ID yet.
740  if (!DWOCU->getDWOId()) {
741  if (Optional<uint64_t> DWOId =
742  toUnsigned(DWOCU->getUnitDIE().find(DW_AT_GNU_dwo_id)))
743  DWOCU->setDWOId(*DWOId);
744  else
745  // No DWO ID?
746  continue;
747  }
748  if (DWOCU->getDWOId() == Hash)
749  return dyn_cast<DWARFCompileUnit>(DWOCU.get());
750  }
751  return nullptr;
752 }
753 
755  parseNormalUnits();
756  if (auto *CU = NormalUnits.getUnitForOffset(Offset))
757  return CU->getDIEForOffset(Offset);
758  return DWARFDie();
759 }
760 
762  bool Success = true;
763  DWARFVerifier verifier(OS, *this, DumpOpts);
764 
765  Success &= verifier.handleDebugAbbrev();
766  if (DumpOpts.DumpType & DIDT_DebugInfo)
767  Success &= verifier.handleDebugInfo();
768  if (DumpOpts.DumpType & DIDT_DebugLine)
769  Success &= verifier.handleDebugLine();
770  Success &= verifier.handleAccelTables();
771  return Success;
772 }
773 
775  if (CUIndex)
776  return *CUIndex;
777 
778  DataExtractor CUIndexData(DObj->getCUIndexSection(), isLittleEndian(), 0);
779 
780  CUIndex = std::make_unique<DWARFUnitIndex>(DW_SECT_INFO);
781  CUIndex->parse(CUIndexData);
782  return *CUIndex;
783 }
784 
786  if (TUIndex)
787  return *TUIndex;
788 
789  DataExtractor TUIndexData(DObj->getTUIndexSection(), isLittleEndian(), 0);
790 
791  TUIndex = std::make_unique<DWARFUnitIndex>(DW_SECT_EXT_TYPES);
792  TUIndex->parse(TUIndexData);
793  return *TUIndex;
794 }
795 
797  if (GdbIndex)
798  return *GdbIndex;
799 
800  DataExtractor GdbIndexData(DObj->getGdbIndexSection(), true /*LE*/, 0);
801  GdbIndex = std::make_unique<DWARFGdbIndex>();
802  GdbIndex->parse(GdbIndexData);
803  return *GdbIndex;
804 }
805 
807  if (Abbrev)
808  return Abbrev.get();
809 
810  DataExtractor abbrData(DObj->getAbbrevSection(), isLittleEndian(), 0);
811 
812  Abbrev.reset(new DWARFDebugAbbrev());
813  Abbrev->extract(abbrData);
814  return Abbrev.get();
815 }
816 
818  if (AbbrevDWO)
819  return AbbrevDWO.get();
820 
821  DataExtractor abbrData(DObj->getAbbrevDWOSection(), isLittleEndian(), 0);
822  AbbrevDWO.reset(new DWARFDebugAbbrev());
823  AbbrevDWO->extract(abbrData);
824  return AbbrevDWO.get();
825 }
826 
828  if (Loc)
829  return Loc.get();
830 
831  // Assume all units have the same address byte size.
832  auto LocData =
834  ? DWARFDataExtractor(*DObj, DObj->getLocSection(), isLittleEndian(),
835  getUnitAtIndex(0)->getAddressByteSize())
837  Loc.reset(new DWARFDebugLoc(std::move(LocData)));
838  return Loc.get();
839 }
840 
842  if (Aranges)
843  return Aranges.get();
844 
845  Aranges.reset(new DWARFDebugAranges());
846  Aranges->generate(this);
847  return Aranges.get();
848 }
849 
851  if (DebugFrame)
852  return DebugFrame.get();
853 
854  const DWARFSection &DS = DObj->getFrameSection();
855 
856  // There's a "bug" in the DWARFv3 standard with respect to the target address
857  // size within debug frame sections. While DWARF is supposed to be independent
858  // of its container, FDEs have fields with size being "target address size",
859  // which isn't specified in DWARF in general. It's only specified for CUs, but
860  // .eh_frame can appear without a .debug_info section. Follow the example of
861  // other tools (libdwarf) and extract this from the container (ObjectFile
862  // provides this information). This problem is fixed in DWARFv4
863  // See this dwarf-discuss discussion for more details:
864  // http://lists.dwarfstd.org/htdig.cgi/dwarf-discuss-dwarfstd.org/2011-December/001173.html
865  DWARFDataExtractor DebugFrameData(*DObj, DS, isLittleEndian(),
866  DObj->getAddressSize());
867  auto DF =
868  std::make_unique<DWARFDebugFrame>(getArch(), /*IsEH=*/false, DS.Address);
869  if (Error E = DF->parse(DebugFrameData))
870  return std::move(E);
871 
872  DebugFrame.swap(DF);
873  return DebugFrame.get();
874 }
875 
877  if (EHFrame)
878  return EHFrame.get();
879 
880  const DWARFSection &DS = DObj->getEHFrameSection();
881  DWARFDataExtractor DebugFrameData(*DObj, DS, isLittleEndian(),
882  DObj->getAddressSize());
883 
884  auto DF =
885  std::make_unique<DWARFDebugFrame>(getArch(), /*IsEH=*/true, DS.Address);
886  if (Error E = DF->parse(DebugFrameData))
887  return std::move(E);
888  DebugFrame.swap(DF);
889  return DebugFrame.get();
890 }
891 
893  if (!Macro)
894  Macro = parseMacroOrMacinfo(MacroSection);
895  return Macro.get();
896 }
897 
899  if (!MacroDWO)
900  MacroDWO = parseMacroOrMacinfo(MacroDwoSection);
901  return MacroDWO.get();
902 }
903 
905  if (!Macinfo)
906  Macinfo = parseMacroOrMacinfo(MacinfoSection);
907  return Macinfo.get();
908 }
909 
911  if (!MacinfoDWO)
912  MacinfoDWO = parseMacroOrMacinfo(MacinfoDwoSection);
913  return MacinfoDWO.get();
914 }
915 
916 template <typename T>
917 static T &getAccelTable(std::unique_ptr<T> &Cache, const DWARFObject &Obj,
918  const DWARFSection &Section, StringRef StringSection,
919  bool IsLittleEndian) {
920  if (Cache)
921  return *Cache;
922  DWARFDataExtractor AccelSection(Obj, Section, IsLittleEndian, 0);
923  DataExtractor StrData(StringSection, IsLittleEndian, 0);
924  Cache.reset(new T(AccelSection, StrData));
925  if (Error E = Cache->extract())
927  return *Cache;
928 }
929 
931  return getAccelTable(Names, *DObj, DObj->getNamesSection(),
932  DObj->getStrSection(), isLittleEndian());
933 }
934 
936  return getAccelTable(AppleNames, *DObj, DObj->getAppleNamesSection(),
937  DObj->getStrSection(), isLittleEndian());
938 }
939 
941  return getAccelTable(AppleTypes, *DObj, DObj->getAppleTypesSection(),
942  DObj->getStrSection(), isLittleEndian());
943 }
944 
946  return getAccelTable(AppleNamespaces, *DObj,
947  DObj->getAppleNamespacesSection(),
948  DObj->getStrSection(), isLittleEndian());
949 }
950 
952  return getAccelTable(AppleObjC, *DObj, DObj->getAppleObjCSection(),
953  DObj->getStrSection(), isLittleEndian());
954 }
955 
959  getLineTableForUnit(U, WarningHandler);
960  if (!ExpectedLineTable) {
961  WarningHandler(ExpectedLineTable.takeError());
962  return nullptr;
963  }
964  return *ExpectedLineTable;
965 }
966 
968  DWARFUnit *U, function_ref<void(Error)> RecoverableErrorHandler) {
969  if (!Line)
970  Line.reset(new DWARFDebugLine);
971 
972  auto UnitDIE = U->getUnitDIE();
973  if (!UnitDIE)
974  return nullptr;
975 
976  auto Offset = toSectionOffset(UnitDIE.find(DW_AT_stmt_list));
977  if (!Offset)
978  return nullptr; // No line table for this compile unit.
979 
980  uint64_t stmtOffset = *Offset + U->getLineTableOffset();
981  // See if the line table is cached.
982  if (const DWARFLineTable *lt = Line->getLineTable(stmtOffset))
983  return lt;
984 
985  // Make sure the offset is good before we try to parse.
986  if (stmtOffset >= U->getLineSection().Data.size())
987  return nullptr;
988 
989  // We have to parse it first.
990  DWARFDataExtractor lineData(*DObj, U->getLineSection(), isLittleEndian(),
991  U->getAddressByteSize());
992  return Line->getOrParseLineTable(lineData, stmtOffset, *this, U,
993  RecoverableErrorHandler);
994 }
995 
996 void DWARFContext::parseNormalUnits() {
997  if (!NormalUnits.empty())
998  return;
999  DObj->forEachInfoSections([&](const DWARFSection &S) {
1000  NormalUnits.addUnitsForSection(*this, S, DW_SECT_INFO);
1001  });
1002  NormalUnits.finishedInfoUnits();
1003  DObj->forEachTypesSections([&](const DWARFSection &S) {
1004  NormalUnits.addUnitsForSection(*this, S, DW_SECT_EXT_TYPES);
1005  });
1006 }
1007 
1008 void DWARFContext::parseDWOUnits(bool Lazy) {
1009  if (!DWOUnits.empty())
1010  return;
1011  DObj->forEachInfoDWOSections([&](const DWARFSection &S) {
1012  DWOUnits.addUnitsForDWOSection(*this, S, DW_SECT_INFO, Lazy);
1013  });
1014  DWOUnits.finishedInfoUnits();
1015  DObj->forEachTypesDWOSections([&](const DWARFSection &S) {
1016  DWOUnits.addUnitsForDWOSection(*this, S, DW_SECT_EXT_TYPES, Lazy);
1017  });
1018 }
1019 
1021  parseNormalUnits();
1022  return dyn_cast_or_null<DWARFCompileUnit>(
1023  NormalUnits.getUnitForOffset(Offset));
1024 }
1025 
1027  // First, get the offset of the compile unit.
1029  // Retrieve the compile unit.
1030  return getCompileUnitForOffset(CUOffset);
1031 }
1032 
1034  DIEsForAddress Result;
1035 
1037  if (!CU)
1038  return Result;
1039 
1040  Result.CompileUnit = CU;
1041  Result.FunctionDIE = CU->getSubroutineForAddress(Address);
1042 
1043  std::vector<DWARFDie> Worklist;
1044  Worklist.push_back(Result.FunctionDIE);
1045  while (!Worklist.empty()) {
1046  DWARFDie DIE = Worklist.back();
1047  Worklist.pop_back();
1048 
1049  if (!DIE.isValid())
1050  continue;
1051 
1052  if (DIE.getTag() == DW_TAG_lexical_block &&
1053  DIE.addressRangeContainsAddress(Address)) {
1054  Result.BlockDIE = DIE;
1055  break;
1056  }
1057 
1058  append_range(Worklist, DIE);
1059  }
1060 
1061  return Result;
1062 }
1063 
1064 /// TODO: change input parameter from "uint64_t Address"
1065 /// into "SectionedAddress Address"
1069  std::string &FunctionName, std::string &StartFile, uint32_t &StartLine,
1070  Optional<uint64_t> &StartAddress) {
1071  // The address may correspond to instruction in some inlined function,
1072  // so we have to build the chain of inlined functions and take the
1073  // name of the topmost function in it.
1074  SmallVector<DWARFDie, 4> InlinedChain;
1075  CU->getInlinedChainForAddress(Address, InlinedChain);
1076  if (InlinedChain.empty())
1077  return false;
1078 
1079  const DWARFDie &DIE = InlinedChain[0];
1080  bool FoundResult = false;
1081  const char *Name = nullptr;
1082  if (Kind != FunctionNameKind::None && (Name = DIE.getSubroutineName(Kind))) {
1083  FunctionName = Name;
1084  FoundResult = true;
1085  }
1086  std::string DeclFile = DIE.getDeclFile(FileNameKind);
1087  if (!DeclFile.empty()) {
1088  StartFile = DeclFile;
1089  FoundResult = true;
1090  }
1091  if (auto DeclLineResult = DIE.getDeclLine()) {
1092  StartLine = DeclLineResult;
1093  FoundResult = true;
1094  }
1095  if (auto LowPcAddr = toSectionedAddress(DIE.find(DW_AT_low_pc)))
1096  StartAddress = LowPcAddr->Address;
1097  return FoundResult;
1098 }
1099 
1101  if (auto SizeAttr = Type.find(DW_AT_byte_size))
1102  if (Optional<uint64_t> Size = SizeAttr->getAsUnsignedConstant())
1103  return Size;
1104 
1105  switch (Type.getTag()) {
1106  case DW_TAG_pointer_type:
1107  case DW_TAG_reference_type:
1108  case DW_TAG_rvalue_reference_type:
1109  return PointerSize;
1110  case DW_TAG_ptr_to_member_type: {
1111  if (DWARFDie BaseType = Type.getAttributeValueAsReferencedDie(DW_AT_type))
1112  if (BaseType.getTag() == DW_TAG_subroutine_type)
1113  return 2 * PointerSize;
1114  return PointerSize;
1115  }
1116  case DW_TAG_const_type:
1117  case DW_TAG_immutable_type:
1118  case DW_TAG_volatile_type:
1119  case DW_TAG_restrict_type:
1120  case DW_TAG_typedef: {
1121  if (DWARFDie BaseType = Type.getAttributeValueAsReferencedDie(DW_AT_type))
1122  return getTypeSize(BaseType, PointerSize);
1123  break;
1124  }
1125  case DW_TAG_array_type: {
1126  DWARFDie BaseType = Type.getAttributeValueAsReferencedDie(DW_AT_type);
1127  if (!BaseType)
1128  return Optional<uint64_t>();
1130  if (!BaseSize)
1131  return Optional<uint64_t>();
1132  uint64_t Size = *BaseSize;
1133  for (DWARFDie Child : Type) {
1134  if (Child.getTag() != DW_TAG_subrange_type)
1135  continue;
1136 
1137  if (auto ElemCountAttr = Child.find(DW_AT_count))
1138  if (Optional<uint64_t> ElemCount =
1139  ElemCountAttr->getAsUnsignedConstant())
1140  Size *= *ElemCount;
1141  if (auto UpperBoundAttr = Child.find(DW_AT_upper_bound))
1142  if (Optional<int64_t> UpperBound =
1143  UpperBoundAttr->getAsSignedConstant()) {
1144  int64_t LowerBound = 0;
1145  if (auto LowerBoundAttr = Child.find(DW_AT_lower_bound))
1146  LowerBound = LowerBoundAttr->getAsSignedConstant().getValueOr(0);
1147  Size *= *UpperBound - LowerBound + 1;
1148  }
1149  }
1150  return Size;
1151  }
1152  default:
1153  break;
1154  }
1155  return Optional<uint64_t>();
1156 }
1157 
1158 static Optional<int64_t>
1160  Optional<unsigned> FrameBaseReg) {
1161  if (!Expr.empty() &&
1162  (Expr[0] == DW_OP_fbreg ||
1163  (FrameBaseReg && Expr[0] == DW_OP_breg0 + *FrameBaseReg))) {
1164  unsigned Count;
1165  int64_t Offset = decodeSLEB128(Expr.data() + 1, &Count, Expr.end());
1166  // A single DW_OP_fbreg or DW_OP_breg.
1167  if (Expr.size() == Count + 1)
1168  return Offset;
1169  // Same + DW_OP_deref (Fortran arrays look like this).
1170  if (Expr.size() == Count + 2 && Expr[Count + 1] == DW_OP_deref)
1171  return Offset;
1172  // Fallthrough. Do not accept ex. (DW_OP_breg W29, DW_OP_stack_value)
1173  }
1174  return None;
1175 }
1176 
1177 void DWARFContext::addLocalsForDie(DWARFCompileUnit *CU, DWARFDie Subprogram,
1178  DWARFDie Die, std::vector<DILocal> &Result) {
1179  if (Die.getTag() == DW_TAG_variable ||
1180  Die.getTag() == DW_TAG_formal_parameter) {
1181  DILocal Local;
1182  if (const char *Name = Subprogram.getSubroutineName(DINameKind::ShortName))
1183  Local.FunctionName = Name;
1184 
1185  Optional<unsigned> FrameBaseReg;
1186  if (auto FrameBase = Subprogram.find(DW_AT_frame_base))
1187  if (Optional<ArrayRef<uint8_t>> Expr = FrameBase->getAsBlock())
1188  if (!Expr->empty() && (*Expr)[0] >= DW_OP_reg0 &&
1189  (*Expr)[0] <= DW_OP_reg31) {
1190  FrameBaseReg = (*Expr)[0] - DW_OP_reg0;
1191  }
1192 
1193  if (Expected<std::vector<DWARFLocationExpression>> Loc =
1194  Die.getLocations(DW_AT_location)) {
1195  for (const auto &Entry : *Loc) {
1196  if (Optional<int64_t> FrameOffset =
1197  getExpressionFrameOffset(Entry.Expr, FrameBaseReg)) {
1198  Local.FrameOffset = *FrameOffset;
1199  break;
1200  }
1201  }
1202  } else {
1203  // FIXME: missing DW_AT_location is OK here, but other errors should be
1204  // reported to the user.
1205  consumeError(Loc.takeError());
1206  }
1207 
1208  if (auto TagOffsetAttr = Die.find(DW_AT_LLVM_tag_offset))
1209  Local.TagOffset = TagOffsetAttr->getAsUnsignedConstant();
1210 
1211  if (auto Origin =
1212  Die.getAttributeValueAsReferencedDie(DW_AT_abstract_origin))
1213  Die = Origin;
1214  if (auto NameAttr = Die.find(DW_AT_name))
1215  if (Optional<const char *> Name = dwarf::toString(*NameAttr))
1216  Local.Name = *Name;
1217  if (auto Type = Die.getAttributeValueAsReferencedDie(DW_AT_type))
1218  Local.Size = getTypeSize(Type, getCUAddrSize());
1219  if (auto DeclFileAttr = Die.find(DW_AT_decl_file)) {
1220  if (const auto *LT = CU->getContext().getLineTableForUnit(CU))
1221  LT->getFileNameByIndex(
1222  DeclFileAttr->getAsUnsignedConstant().getValue(),
1223  CU->getCompilationDir(),
1225  Local.DeclFile);
1226  }
1227  if (auto DeclLineAttr = Die.find(DW_AT_decl_line))
1228  Local.DeclLine = DeclLineAttr->getAsUnsignedConstant().getValue();
1229 
1230  Result.push_back(Local);
1231  return;
1232  }
1233 
1234  if (Die.getTag() == DW_TAG_inlined_subroutine)
1235  if (auto Origin =
1236  Die.getAttributeValueAsReferencedDie(DW_AT_abstract_origin))
1237  Subprogram = Origin;
1238 
1239  for (auto Child : Die)
1240  addLocalsForDie(CU, Subprogram, Child, Result);
1241 }
1242 
1243 std::vector<DILocal>
1245  std::vector<DILocal> Result;
1247  if (!CU)
1248  return Result;
1249 
1250  DWARFDie Subprogram = CU->getSubroutineForAddress(Address.Address);
1251  if (Subprogram.isValid())
1252  addLocalsForDie(CU, Subprogram, Subprogram, Result);
1253  return Result;
1254 }
1255 
1257  DILineInfoSpecifier Spec) {
1258  DILineInfo Result;
1259 
1261  if (!CU)
1262  return Result;
1263 
1265  CU, Address.Address, Spec.FNKind, Spec.FLIKind, Result.FunctionName,
1266  Result.StartFileName, Result.StartLine, Result.StartAddress);
1267  if (Spec.FLIKind != FileLineInfoKind::None) {
1268  if (const DWARFLineTable *LineTable = getLineTableForUnit(CU)) {
1269  LineTable->getFileLineInfoForAddress(
1270  {Address.Address, Address.SectionIndex}, CU->getCompilationDir(),
1271  Spec.FLIKind, Result);
1272  }
1273  }
1274  return Result;
1275 }
1276 
1279  DILineInfoTable Lines;
1281  if (!CU)
1282  return Lines;
1283 
1284  uint32_t StartLine = 0;
1285  std::string StartFileName;
1286  std::string FunctionName(DILineInfo::BadString);
1287  Optional<uint64_t> StartAddress;
1289  Spec.FLIKind, FunctionName,
1290  StartFileName, StartLine, StartAddress);
1291 
1292  // If the Specifier says we don't need FileLineInfo, just
1293  // return the top-most function at the starting address.
1294  if (Spec.FLIKind == FileLineInfoKind::None) {
1295  DILineInfo Result;
1296  Result.FunctionName = FunctionName;
1297  Result.StartFileName = StartFileName;
1298  Result.StartLine = StartLine;
1299  Result.StartAddress = StartAddress;
1300  Lines.push_back(std::make_pair(Address.Address, Result));
1301  return Lines;
1302  }
1303 
1304  const DWARFLineTable *LineTable = getLineTableForUnit(CU);
1305 
1306  // Get the index of row we're looking for in the line table.
1307  std::vector<uint32_t> RowVector;
1308  if (!LineTable->lookupAddressRange({Address.Address, Address.SectionIndex},
1309  Size, RowVector)) {
1310  return Lines;
1311  }
1312 
1313  for (uint32_t RowIndex : RowVector) {
1314  // Take file number and line/column from the row.
1315  const DWARFDebugLine::Row &Row = LineTable->Rows[RowIndex];
1316  DILineInfo Result;
1317  LineTable->getFileNameByIndex(Row.File, CU->getCompilationDir(),
1318  Spec.FLIKind, Result.FileName);
1319  Result.FunctionName = FunctionName;
1320  Result.Line = Row.Line;
1321  Result.Column = Row.Column;
1322  Result.StartFileName = StartFileName;
1323  Result.StartLine = StartLine;
1324  Result.StartAddress = StartAddress;
1325  Lines.push_back(std::make_pair(Row.Address.Address, Result));
1326  }
1327 
1328  return Lines;
1329 }
1330 
1333  DILineInfoSpecifier Spec) {
1334  DIInliningInfo InliningInfo;
1335 
1337  if (!CU)
1338  return InliningInfo;
1339 
1340  const DWARFLineTable *LineTable = nullptr;
1341  SmallVector<DWARFDie, 4> InlinedChain;
1342  CU->getInlinedChainForAddress(Address.Address, InlinedChain);
1343  if (InlinedChain.size() == 0) {
1344  // If there is no DIE for address (e.g. it is in unavailable .dwo file),
1345  // try to at least get file/line info from symbol table.
1346  if (Spec.FLIKind != FileLineInfoKind::None) {
1347  DILineInfo Frame;
1348  LineTable = getLineTableForUnit(CU);
1349  if (LineTable && LineTable->getFileLineInfoForAddress(
1350  {Address.Address, Address.SectionIndex},
1351  CU->getCompilationDir(), Spec.FLIKind, Frame))
1352  InliningInfo.addFrame(Frame);
1353  }
1354  return InliningInfo;
1355  }
1356 
1357  uint32_t CallFile = 0, CallLine = 0, CallColumn = 0, CallDiscriminator = 0;
1358  for (uint32_t i = 0, n = InlinedChain.size(); i != n; i++) {
1359  DWARFDie &FunctionDIE = InlinedChain[i];
1360  DILineInfo Frame;
1361  // Get function name if necessary.
1362  if (const char *Name = FunctionDIE.getSubroutineName(Spec.FNKind))
1363  Frame.FunctionName = Name;
1364  if (auto DeclLineResult = FunctionDIE.getDeclLine())
1365  Frame.StartLine = DeclLineResult;
1366  Frame.StartFileName = FunctionDIE.getDeclFile(Spec.FLIKind);
1367  if (auto LowPcAddr = toSectionedAddress(FunctionDIE.find(DW_AT_low_pc)))
1368  Frame.StartAddress = LowPcAddr->Address;
1369  if (Spec.FLIKind != FileLineInfoKind::None) {
1370  if (i == 0) {
1371  // For the topmost frame, initialize the line table of this
1372  // compile unit and fetch file/line info from it.
1373  LineTable = getLineTableForUnit(CU);
1374  // For the topmost routine, get file/line info from line table.
1375  if (LineTable)
1376  LineTable->getFileLineInfoForAddress(
1377  {Address.Address, Address.SectionIndex}, CU->getCompilationDir(),
1378  Spec.FLIKind, Frame);
1379  } else {
1380  // Otherwise, use call file, call line and call column from
1381  // previous DIE in inlined chain.
1382  if (LineTable)
1383  LineTable->getFileNameByIndex(CallFile, CU->getCompilationDir(),
1384  Spec.FLIKind, Frame.FileName);
1385  Frame.Line = CallLine;
1386  Frame.Column = CallColumn;
1387  Frame.Discriminator = CallDiscriminator;
1388  }
1389  // Get call file/line/column of a current DIE.
1390  if (i + 1 < n) {
1391  FunctionDIE.getCallerFrame(CallFile, CallLine, CallColumn,
1392  CallDiscriminator);
1393  }
1394  }
1395  InliningInfo.addFrame(Frame);
1396  }
1397  return InliningInfo;
1398 }
1399 
1400 std::shared_ptr<DWARFContext>
1402  if (auto S = DWP.lock()) {
1403  DWARFContext *Ctxt = S->Context.get();
1404  return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
1405  }
1406 
1407  std::weak_ptr<DWOFile> *Entry = &DWOFiles[AbsolutePath];
1408 
1409  if (auto S = Entry->lock()) {
1410  DWARFContext *Ctxt = S->Context.get();
1411  return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
1412  }
1413 
1415  if (!CheckedForDWP) {
1416  SmallString<128> DWPName;
1418  this->DWPName.empty()
1419  ? (DObj->getFileName() + ".dwp").toStringRef(DWPName)
1420  : StringRef(this->DWPName));
1421  if (Obj) {
1422  Entry = &DWP;
1423  return Obj;
1424  } else {
1425  CheckedForDWP = true;
1426  // TODO: Should this error be handled (maybe in a high verbosity mode)
1427  // before falling back to .dwo files?
1428  consumeError(Obj.takeError());
1429  }
1430  }
1431 
1432  return object::ObjectFile::createObjectFile(AbsolutePath);
1433  }();
1434 
1435  if (!Obj) {
1436  // TODO: Actually report errors helpfully.
1437  consumeError(Obj.takeError());
1438  return nullptr;
1439  }
1440 
1441  auto S = std::make_shared<DWOFile>();
1442  S->File = std::move(Obj.get());
1443  S->Context = DWARFContext::create(*S->File.getBinary(),
1445  *Entry = S;
1446  auto *Ctxt = S->Context.get();
1447  return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
1448 }
1449 
1450 static Error createError(const Twine &Reason, llvm::Error E) {
1451  return make_error<StringError>(Reason + toString(std::move(E)),
1453 }
1454 
1455 /// SymInfo contains information about symbol: it's address
1456 /// and section index which is -1LL for absolute symbols.
1457 struct SymInfo {
1460 };
1461 
1462 /// Returns the address of symbol relocation used against and a section index.
1463 /// Used for futher relocations computation. Symbol's section load address is
1465  const RelocationRef &Reloc,
1466  const LoadedObjectInfo *L,
1467  std::map<SymbolRef, SymInfo> &Cache) {
1468  SymInfo Ret = {0, (uint64_t)-1LL};
1470  object::symbol_iterator Sym = Reloc.getSymbol();
1471 
1472  std::map<SymbolRef, SymInfo>::iterator CacheIt = Cache.end();
1473  // First calculate the address of the symbol or section as it appears
1474  // in the object file
1475  if (Sym != Obj.symbol_end()) {
1476  bool New;
1477  std::tie(CacheIt, New) = Cache.insert({*Sym, {0, 0}});
1478  if (!New)
1479  return CacheIt->second;
1480 
1481  Expected<uint64_t> SymAddrOrErr = Sym->getAddress();
1482  if (!SymAddrOrErr)
1483  return createError("failed to compute symbol address: ",
1484  SymAddrOrErr.takeError());
1485 
1486  // Also remember what section this symbol is in for later
1487  auto SectOrErr = Sym->getSection();
1488  if (!SectOrErr)
1489  return createError("failed to get symbol section: ",
1490  SectOrErr.takeError());
1491 
1492  RSec = *SectOrErr;
1493  Ret.Address = *SymAddrOrErr;
1494  } else if (auto *MObj = dyn_cast<MachOObjectFile>(&Obj)) {
1495  RSec = MObj->getRelocationSection(Reloc.getRawDataRefImpl());
1496  Ret.Address = RSec->getAddress();
1497  }
1498 
1499  if (RSec != Obj.section_end())
1500  Ret.SectionIndex = RSec->getIndex();
1501 
1502  // If we are given load addresses for the sections, we need to adjust:
1503  // SymAddr = (Address of Symbol Or Section in File) -
1504  // (Address of Section in File) +
1505  // (Load Address of Section)
1506  // RSec is now either the section being targeted or the section
1507  // containing the symbol being targeted. In either case,
1508  // we need to perform the same computation.
1509  if (L && RSec != Obj.section_end())
1510  if (uint64_t SectionLoadAddress = L->getSectionLoadAddress(*RSec))
1511  Ret.Address += SectionLoadAddress - RSec->getAddress();
1512 
1513  if (CacheIt != Cache.end())
1514  CacheIt->second = Ret;
1515 
1516  return Ret;
1517 }
1518 
1519 static bool isRelocScattered(const object::ObjectFile &Obj,
1520  const RelocationRef &Reloc) {
1521  const MachOObjectFile *MachObj = dyn_cast<MachOObjectFile>(&Obj);
1522  if (!MachObj)
1523  return false;
1524  // MachO also has relocations that point to sections and
1525  // scattered relocations.
1526  auto RelocInfo = MachObj->getRelocation(Reloc.getRawDataRefImpl());
1527  return MachObj->isRelocationScattered(RelocInfo);
1528 }
1529 
1530 namespace {
1531 struct DWARFSectionMap final : public DWARFSection {
1532  RelocAddrMap Relocs;
1533 };
1534 
1535 class DWARFObjInMemory final : public DWARFObject {
1536  bool IsLittleEndian;
1537  uint8_t AddressSize;
1538  StringRef FileName;
1539  const object::ObjectFile *Obj = nullptr;
1540  std::vector<SectionName> SectionNames;
1541 
1542  using InfoSectionMap = MapVector<object::SectionRef, DWARFSectionMap,
1543  std::map<object::SectionRef, unsigned>>;
1544 
1545  InfoSectionMap InfoSections;
1546  InfoSectionMap TypesSections;
1547  InfoSectionMap InfoDWOSections;
1548  InfoSectionMap TypesDWOSections;
1549 
1550  DWARFSectionMap LocSection;
1551  DWARFSectionMap LoclistsSection;
1552  DWARFSectionMap LoclistsDWOSection;
1553  DWARFSectionMap LineSection;
1554  DWARFSectionMap RangesSection;
1555  DWARFSectionMap RnglistsSection;
1556  DWARFSectionMap StrOffsetsSection;
1557  DWARFSectionMap LineDWOSection;
1558  DWARFSectionMap FrameSection;
1559  DWARFSectionMap EHFrameSection;
1560  DWARFSectionMap LocDWOSection;
1561  DWARFSectionMap StrOffsetsDWOSection;
1562  DWARFSectionMap RangesDWOSection;
1563  DWARFSectionMap RnglistsDWOSection;
1564  DWARFSectionMap AddrSection;
1565  DWARFSectionMap AppleNamesSection;
1566  DWARFSectionMap AppleTypesSection;
1567  DWARFSectionMap AppleNamespacesSection;
1568  DWARFSectionMap AppleObjCSection;
1569  DWARFSectionMap NamesSection;
1570  DWARFSectionMap PubnamesSection;
1571  DWARFSectionMap PubtypesSection;
1572  DWARFSectionMap GnuPubnamesSection;
1573  DWARFSectionMap GnuPubtypesSection;
1574  DWARFSectionMap MacroSection;
1575 
1576  DWARFSectionMap *mapNameToDWARFSection(StringRef Name) {
1578  .Case("debug_loc", &LocSection)
1579  .Case("debug_loclists", &LoclistsSection)
1580  .Case("debug_loclists.dwo", &LoclistsDWOSection)
1581  .Case("debug_line", &LineSection)
1582  .Case("debug_frame", &FrameSection)
1583  .Case("eh_frame", &EHFrameSection)
1584  .Case("debug_str_offsets", &StrOffsetsSection)
1585  .Case("debug_ranges", &RangesSection)
1586  .Case("debug_rnglists", &RnglistsSection)
1587  .Case("debug_loc.dwo", &LocDWOSection)
1588  .Case("debug_line.dwo", &LineDWOSection)
1589  .Case("debug_names", &NamesSection)
1590  .Case("debug_rnglists.dwo", &RnglistsDWOSection)
1591  .Case("debug_str_offsets.dwo", &StrOffsetsDWOSection)
1592  .Case("debug_addr", &AddrSection)
1593  .Case("apple_names", &AppleNamesSection)
1594  .Case("debug_pubnames", &PubnamesSection)
1595  .Case("debug_pubtypes", &PubtypesSection)
1596  .Case("debug_gnu_pubnames", &GnuPubnamesSection)
1597  .Case("debug_gnu_pubtypes", &GnuPubtypesSection)
1598  .Case("apple_types", &AppleTypesSection)
1599  .Case("apple_namespaces", &AppleNamespacesSection)
1600  .Case("apple_namespac", &AppleNamespacesSection)
1601  .Case("apple_objc", &AppleObjCSection)
1602  .Case("debug_macro", &MacroSection)
1603  .Default(nullptr);
1604  }
1605 
1606  StringRef AbbrevSection;
1607  StringRef ArangesSection;
1608  StringRef StrSection;
1609  StringRef MacinfoSection;
1610  StringRef MacinfoDWOSection;
1611  StringRef MacroDWOSection;
1612  StringRef AbbrevDWOSection;
1613  StringRef StrDWOSection;
1614  StringRef CUIndexSection;
1615  StringRef GdbIndexSection;
1616  StringRef TUIndexSection;
1617  StringRef LineStrSection;
1618 
1619  // A deque holding section data whose iterators are not invalidated when
1620  // new decompressed sections are inserted at the end.
1621  std::deque<SmallString<0>> UncompressedSections;
1622 
1623  StringRef *mapSectionToMember(StringRef Name) {
1624  if (DWARFSection *Sec = mapNameToDWARFSection(Name))
1625  return &Sec->Data;
1627  .Case("debug_abbrev", &AbbrevSection)
1628  .Case("debug_aranges", &ArangesSection)
1629  .Case("debug_str", &StrSection)
1630  .Case("debug_macinfo", &MacinfoSection)
1631  .Case("debug_macinfo.dwo", &MacinfoDWOSection)
1632  .Case("debug_macro.dwo", &MacroDWOSection)
1633  .Case("debug_abbrev.dwo", &AbbrevDWOSection)
1634  .Case("debug_str.dwo", &StrDWOSection)
1635  .Case("debug_cu_index", &CUIndexSection)
1636  .Case("debug_tu_index", &TUIndexSection)
1637  .Case("gdb_index", &GdbIndexSection)
1638  .Case("debug_line_str", &LineStrSection)
1639  // Any more debug info sections go here.
1640  .Default(nullptr);
1641  }
1642 
1643  /// If Sec is compressed section, decompresses and updates its contents
1644  /// provided by Data. Otherwise leaves it unchanged.
1645  Error maybeDecompress(const object::SectionRef &Sec, StringRef Name,
1646  StringRef &Data) {
1647  if (!Decompressor::isCompressed(Sec))
1648  return Error::success();
1649 
1650  Expected<Decompressor> Decompressor =
1651  Decompressor::create(Name, Data, IsLittleEndian, AddressSize == 8);
1652  if (!Decompressor)
1653  return Decompressor.takeError();
1654 
1655  SmallString<0> Out;
1656  if (auto Err = Decompressor->resizeAndDecompress(Out))
1657  return Err;
1658 
1659  UncompressedSections.push_back(std::move(Out));
1660  Data = UncompressedSections.back();
1661 
1662  return Error::success();
1663  }
1664 
1665 public:
1666  DWARFObjInMemory(const StringMap<std::unique_ptr<MemoryBuffer>> &Sections,
1667  uint8_t AddrSize, bool IsLittleEndian)
1668  : IsLittleEndian(IsLittleEndian) {
1669  for (const auto &SecIt : Sections) {
1670  if (StringRef *SectionData = mapSectionToMember(SecIt.first()))
1671  *SectionData = SecIt.second->getBuffer();
1672  else if (SecIt.first() == "debug_info")
1673  // Find debug_info and debug_types data by section rather than name as
1674  // there are multiple, comdat grouped, of these sections.
1675  InfoSections[SectionRef()].Data = SecIt.second->getBuffer();
1676  else if (SecIt.first() == "debug_info.dwo")
1677  InfoDWOSections[SectionRef()].Data = SecIt.second->getBuffer();
1678  else if (SecIt.first() == "debug_types")
1679  TypesSections[SectionRef()].Data = SecIt.second->getBuffer();
1680  else if (SecIt.first() == "debug_types.dwo")
1681  TypesDWOSections[SectionRef()].Data = SecIt.second->getBuffer();
1682  }
1683  }
1684  DWARFObjInMemory(const object::ObjectFile &Obj, const LoadedObjectInfo *L,
1685  function_ref<void(Error)> HandleError,
1686  function_ref<void(Error)> HandleWarning,
1688  : IsLittleEndian(Obj.isLittleEndian()),
1689  AddressSize(Obj.getBytesInAddress()), FileName(Obj.getFileName()),
1690  Obj(&Obj) {
1691 
1692  StringMap<unsigned> SectionAmountMap;
1693  for (const SectionRef &Section : Obj.sections()) {
1694  StringRef Name;
1695  if (auto NameOrErr = Section.getName())
1696  Name = *NameOrErr;
1697  else
1698  consumeError(NameOrErr.takeError());
1699 
1700  ++SectionAmountMap[Name];
1701  SectionNames.push_back({ Name, true });
1702 
1703  // Skip BSS and Virtual sections, they aren't interesting.
1704  if (Section.isBSS() || Section.isVirtual())
1705  continue;
1706 
1707  // Skip sections stripped by dsymutil.
1708  if (Section.isStripped())
1709  continue;
1710 
1711  StringRef Data;
1712  Expected<section_iterator> SecOrErr = Section.getRelocatedSection();
1713  if (!SecOrErr) {
1714  HandleError(createError("failed to get relocated section: ",
1715  SecOrErr.takeError()));
1716  continue;
1717  }
1718 
1719  // Try to obtain an already relocated version of this section.
1720  // Else use the unrelocated section from the object file. We'll have to
1721  // apply relocations ourselves later.
1722  section_iterator RelocatedSection =
1723  Obj.isRelocatableObject() ? *SecOrErr : Obj.section_end();
1724  if (!L || !L->getLoadedSectionContents(*RelocatedSection, Data)) {
1725  Expected<StringRef> E = Section.getContents();
1726  if (E)
1727  Data = *E;
1728  else
1729  // maybeDecompress below will error.
1730  consumeError(E.takeError());
1731  }
1732 
1733  if (auto Err = maybeDecompress(Section, Name, Data)) {
1734  HandleError(createError("failed to decompress '" + Name + "', ",
1735  std::move(Err)));
1736  continue;
1737  }
1738 
1739  // Compressed sections names in GNU style starts from ".z",
1740  // at this point section is decompressed and we drop compression prefix.
1741  Name = Name.substr(
1742  Name.find_first_not_of("._z")); // Skip ".", "z" and "_" prefixes.
1743 
1744  // Map platform specific debug section names to DWARF standard section
1745  // names.
1746  Name = Obj.mapDebugSectionName(Name);
1747 
1748  if (StringRef *SectionData = mapSectionToMember(Name)) {
1749  *SectionData = Data;
1750  if (Name == "debug_ranges") {
1751  // FIXME: Use the other dwo range section when we emit it.
1752  RangesDWOSection.Data = Data;
1753  } else if (Name == "debug_frame" || Name == "eh_frame") {
1754  if (DWARFSection *S = mapNameToDWARFSection(Name))
1755  S->Address = Section.getAddress();
1756  }
1757  } else if (InfoSectionMap *Sections =
1759  .Case("debug_info", &InfoSections)
1760  .Case("debug_info.dwo", &InfoDWOSections)
1761  .Case("debug_types", &TypesSections)
1762  .Case("debug_types.dwo", &TypesDWOSections)
1763  .Default(nullptr)) {
1764  // Find debug_info and debug_types data by section rather than name as
1765  // there are multiple, comdat grouped, of these sections.
1766  DWARFSectionMap &S = (*Sections)[Section];
1767  S.Data = Data;
1768  }
1769 
1770  if (RelocatedSection != Obj.section_end() && Name.contains(".dwo"))
1771  HandleWarning(
1772  createError("Unexpected relocations for dwo section " + Name));
1773 
1774  if (RelocatedSection == Obj.section_end() ||
1776  continue;
1777 
1778  StringRef RelSecName;
1779  if (auto NameOrErr = RelocatedSection->getName())
1780  RelSecName = *NameOrErr;
1781  else
1782  consumeError(NameOrErr.takeError());
1783 
1784  // If the section we're relocating was relocated already by the JIT,
1785  // then we used the relocated version above, so we do not need to process
1786  // relocations for it now.
1787  StringRef RelSecData;
1788  if (L && L->getLoadedSectionContents(*RelocatedSection, RelSecData))
1789  continue;
1790 
1791  // In Mach-o files, the relocations do not need to be applied if
1792  // there is no load offset to apply. The value read at the
1793  // relocation point already factors in the section address
1794  // (actually applying the relocations will produce wrong results
1795  // as the section address will be added twice).
1796  if (!L && isa<MachOObjectFile>(&Obj))
1797  continue;
1798 
1799  RelSecName = RelSecName.substr(
1800  RelSecName.find_first_not_of("._z")); // Skip . and _ prefixes.
1801 
1802  // TODO: Add support for relocations in other sections as needed.
1803  // Record relocations for the debug_info and debug_line sections.
1804  DWARFSectionMap *Sec = mapNameToDWARFSection(RelSecName);
1805  RelocAddrMap *Map = Sec ? &Sec->Relocs : nullptr;
1806  if (!Map) {
1807  // Find debug_info and debug_types relocs by section rather than name
1808  // as there are multiple, comdat grouped, of these sections.
1809  if (RelSecName == "debug_info")
1810  Map = &static_cast<DWARFSectionMap &>(InfoSections[*RelocatedSection])
1811  .Relocs;
1812  else if (RelSecName == "debug_types")
1813  Map =
1814  &static_cast<DWARFSectionMap &>(TypesSections[*RelocatedSection])
1815  .Relocs;
1816  else
1817  continue;
1818  }
1819 
1820  if (Section.relocation_begin() == Section.relocation_end())
1821  continue;
1822 
1823  // Symbol to [address, section index] cache mapping.
1824  std::map<SymbolRef, SymInfo> AddrCache;
1825  SupportsRelocation Supports;
1827  std::tie(Supports, Resolver) = getRelocationResolver(Obj);
1828  for (const RelocationRef &Reloc : Section.relocations()) {
1829  // FIXME: it's not clear how to correctly handle scattered
1830  // relocations.
1831  if (isRelocScattered(Obj, Reloc))
1832  continue;
1833 
1834  Expected<SymInfo> SymInfoOrErr =
1835  getSymbolInfo(Obj, Reloc, L, AddrCache);
1836  if (!SymInfoOrErr) {
1837  HandleError(SymInfoOrErr.takeError());
1838  continue;
1839  }
1840 
1841  // Check if Resolver can handle this relocation type early so as not to
1842  // handle invalid cases in DWARFDataExtractor.
1843  //
1844  // TODO Don't store Resolver in every RelocAddrEntry.
1845  if (Supports && Supports(Reloc.getType())) {
1846  auto I = Map->try_emplace(
1847  Reloc.getOffset(),
1848  RelocAddrEntry{SymInfoOrErr->SectionIndex, Reloc,
1849  SymInfoOrErr->Address,
1850  Optional<object::RelocationRef>(), 0, Resolver});
1851  // If we didn't successfully insert that's because we already had a
1852  // relocation for that offset. Store it as a second relocation in the
1853  // same RelocAddrEntry instead.
1854  if (!I.second) {
1855  RelocAddrEntry &entry = I.first->getSecond();
1856  if (entry.Reloc2) {
1857  HandleError(createError(
1858  "At most two relocations per offset are supported"));
1859  }
1860  entry.Reloc2 = Reloc;
1861  entry.SymbolValue2 = SymInfoOrErr->Address;
1862  }
1863  } else {
1865  Reloc.getTypeName(Type);
1866  // FIXME: Support more relocations & change this to an error
1867  HandleWarning(
1868  createError("failed to compute relocation: " + Type + ", ",
1869  errorCodeToError(object_error::parse_failed)));
1870  }
1871  }
1872  }
1873 
1874  for (SectionName &S : SectionNames)
1875  if (SectionAmountMap[S.Name] > 1)
1876  S.IsNameUnique = false;
1877  }
1878 
1880  uint64_t Pos) const override {
1881  auto &Sec = static_cast<const DWARFSectionMap &>(S);
1882  RelocAddrMap::const_iterator AI = Sec.Relocs.find(Pos);
1883  if (AI == Sec.Relocs.end())
1884  return None;
1885  return AI->second;
1886  }
1887 
1888  const object::ObjectFile *getFile() const override { return Obj; }
1889 
1890  ArrayRef<SectionName> getSectionNames() const override {
1891  return SectionNames;
1892  }
1893 
1894  bool isLittleEndian() const override { return IsLittleEndian; }
1895  StringRef getAbbrevDWOSection() const override { return AbbrevDWOSection; }
1896  const DWARFSection &getLineDWOSection() const override {
1897  return LineDWOSection;
1898  }
1899  const DWARFSection &getLocDWOSection() const override {
1900  return LocDWOSection;
1901  }
1902  StringRef getStrDWOSection() const override { return StrDWOSection; }
1903  const DWARFSection &getStrOffsetsDWOSection() const override {
1904  return StrOffsetsDWOSection;
1905  }
1906  const DWARFSection &getRangesDWOSection() const override {
1907  return RangesDWOSection;
1908  }
1909  const DWARFSection &getRnglistsDWOSection() const override {
1910  return RnglistsDWOSection;
1911  }
1912  const DWARFSection &getLoclistsDWOSection() const override {
1913  return LoclistsDWOSection;
1914  }
1915  const DWARFSection &getAddrSection() const override { return AddrSection; }
1916  StringRef getCUIndexSection() const override { return CUIndexSection; }
1917  StringRef getGdbIndexSection() const override { return GdbIndexSection; }
1918  StringRef getTUIndexSection() const override { return TUIndexSection; }
1919 
1920  // DWARF v5
1921  const DWARFSection &getStrOffsetsSection() const override {
1922  return StrOffsetsSection;
1923  }
1924  StringRef getLineStrSection() const override { return LineStrSection; }
1925 
1926  // Sections for DWARF5 split dwarf proposal.
1927  void forEachInfoDWOSections(
1928  function_ref<void(const DWARFSection &)> F) const override {
1929  for (auto &P : InfoDWOSections)
1930  F(P.second);
1931  }
1932  void forEachTypesDWOSections(
1933  function_ref<void(const DWARFSection &)> F) const override {
1934  for (auto &P : TypesDWOSections)
1935  F(P.second);
1936  }
1937 
1938  StringRef getAbbrevSection() const override { return AbbrevSection; }
1939  const DWARFSection &getLocSection() const override { return LocSection; }
1940  const DWARFSection &getLoclistsSection() const override { return LoclistsSection; }
1941  StringRef getArangesSection() const override { return ArangesSection; }
1942  const DWARFSection &getFrameSection() const override {
1943  return FrameSection;
1944  }
1945  const DWARFSection &getEHFrameSection() const override {
1946  return EHFrameSection;
1947  }
1948  const DWARFSection &getLineSection() const override { return LineSection; }
1949  StringRef getStrSection() const override { return StrSection; }
1950  const DWARFSection &getRangesSection() const override { return RangesSection; }
1951  const DWARFSection &getRnglistsSection() const override {
1952  return RnglistsSection;
1953  }
1954  const DWARFSection &getMacroSection() const override { return MacroSection; }
1955  StringRef getMacroDWOSection() const override { return MacroDWOSection; }
1956  StringRef getMacinfoSection() const override { return MacinfoSection; }
1957  StringRef getMacinfoDWOSection() const override { return MacinfoDWOSection; }
1958  const DWARFSection &getPubnamesSection() const override { return PubnamesSection; }
1959  const DWARFSection &getPubtypesSection() const override { return PubtypesSection; }
1960  const DWARFSection &getGnuPubnamesSection() const override {
1961  return GnuPubnamesSection;
1962  }
1963  const DWARFSection &getGnuPubtypesSection() const override {
1964  return GnuPubtypesSection;
1965  }
1966  const DWARFSection &getAppleNamesSection() const override {
1967  return AppleNamesSection;
1968  }
1969  const DWARFSection &getAppleTypesSection() const override {
1970  return AppleTypesSection;
1971  }
1972  const DWARFSection &getAppleNamespacesSection() const override {
1973  return AppleNamespacesSection;
1974  }
1975  const DWARFSection &getAppleObjCSection() const override {
1976  return AppleObjCSection;
1977  }
1978  const DWARFSection &getNamesSection() const override {
1979  return NamesSection;
1980  }
1981 
1982  StringRef getFileName() const override { return FileName; }
1983  uint8_t getAddressSize() const override { return AddressSize; }
1984  void forEachInfoSections(
1985  function_ref<void(const DWARFSection &)> F) const override {
1986  for (auto &P : InfoSections)
1987  F(P.second);
1988  }
1989  void forEachTypesSections(
1990  function_ref<void(const DWARFSection &)> F) const override {
1991  for (auto &P : TypesSections)
1992  F(P.second);
1993  }
1994 };
1995 } // namespace
1996 
1997 std::unique_ptr<DWARFContext>
1999  ProcessDebugRelocations RelocAction,
2000  const LoadedObjectInfo *L, std::string DWPName,
2001  std::function<void(Error)> RecoverableErrorHandler,
2002  std::function<void(Error)> WarningHandler) {
2003  auto DObj = std::make_unique<DWARFObjInMemory>(
2004  Obj, L, RecoverableErrorHandler, WarningHandler, RelocAction);
2005  return std::make_unique<DWARFContext>(std::move(DObj), std::move(DWPName),
2006  RecoverableErrorHandler,
2007  WarningHandler);
2008 }
2009 
2010 std::unique_ptr<DWARFContext>
2011 DWARFContext::create(const StringMap<std::unique_ptr<MemoryBuffer>> &Sections,
2012  uint8_t AddrSize, bool isLittleEndian,
2013  std::function<void(Error)> RecoverableErrorHandler,
2014  std::function<void(Error)> WarningHandler) {
2015  auto DObj =
2016  std::make_unique<DWARFObjInMemory>(Sections, AddrSize, isLittleEndian);
2017  return std::make_unique<DWARFContext>(
2018  std::move(DObj), "", RecoverableErrorHandler, WarningHandler);
2019 }
2020 
2022  // Detect the architecture from the object file. We usually don't need OS
2023  // info to lookup a target and create register info.
2024  Triple TT;
2025  TT.setArch(Triple::ArchType(Obj.getArch()));
2026  TT.setVendor(Triple::UnknownVendor);
2027  TT.setOS(Triple::UnknownOS);
2028  std::string TargetLookupError;
2029  const Target *TheTarget =
2030  TargetRegistry::lookupTarget(TT.str(), TargetLookupError);
2031  if (!TargetLookupError.empty())
2033  TargetLookupError.c_str());
2034  RegInfo.reset(TheTarget->createMCRegInfo(TT.str()));
2035  return Error::success();
2036 }
2037 
2039  // In theory, different compile units may have different address byte
2040  // sizes, but for simplicity we just use the address byte size of the
2041  // first compile unit. In practice the address size field is repeated across
2042  // various DWARF headers (at least in version 5) to make it easier to dump
2043  // them independently, not to enable varying the address size.
2044  auto CUs = compile_units();
2045  return CUs.empty() ? 0 : (*CUs.begin())->getAddressByteSize();
2046 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::StringSwitch::Case
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:67
i
i
Definition: README.txt:29
llvm::DWARFDebugRangeList
Definition: DWARFDebugRangeList.h:22
MemoryBuffer.h
llvm::DWARFSection
Definition: DWARFSection.h:16
set
We currently generate a but we really shouldn eax ecx xorl edx divl ecx eax divl ecx movl eax ret A similar code sequence works for division We currently compile i32 v2 eax eax jo LBB1_2 atomic and others It is also currently not done for read modify write instructions It is also current not done if the OF or CF flags are needed The shift operators have the complication that when the shift count is EFLAGS is not set
Definition: README.txt:1277
DWARFFormValue.h
llvm::DWARFContext::getDebugNames
const DWARFDebugNames & getDebugNames()
Get a reference to the parsed accelerator table object.
Definition: DWARFContext.cpp:930
llvm::errc::invalid_argument
@ invalid_argument
llvm::DWARFContext::getLineTableForUnit
const DWARFDebugLine::LineTable * getLineTableForUnit(DWARFUnit *U)
Get a pointer to a parsed line table corresponding to a compile unit.
Definition: DWARFContext.cpp:957
llvm::DWARFDie::isValid
bool isValid() const
Definition: DWARFDie.h:51
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::DWARFVerifier
A class that verifies DWARF debug information given a DWARF Context.
Definition: DWARFVerifier.h:34
DWARFCompileUnit.h
llvm::DWARFContext::types_section_units
unit_iterator_range types_section_units()
Get units from .debug_types in this context.
Definition: DWARFContext.h:167
llvm::DWARFDebugLine::SectionParser::getOffset
uint64_t getOffset() const
Get the offset the parser has reached.
Definition: DWARFDebugLine.h:351
llvm::LoadedObjectInfo::getLoadedSectionContents
virtual bool getLoadedSectionContents(const object::SectionRef &Sec, StringRef &Data) const
If conveniently available, return the content of the given Section.
Definition: DIContext.h:283
llvm::DWARFContext::create
static std::unique_ptr< DWARFContext > create(const object::ObjectFile &Obj, ProcessDebugRelocations RelocAction=ProcessDebugRelocations::Process, const LoadedObjectInfo *L=nullptr, std::string DWPName="", std::function< void(Error)> RecoverableErrorHandler=WithColor::defaultErrorHandler, std::function< void(Error)> WarningHandler=WithColor::defaultWarningHandler)
Definition: DWARFContext.cpp:1998
llvm::sys::path::extension
StringRef extension(StringRef path, Style style=Style::native)
Get extension.
Definition: Path.cpp:591
llvm::DWARFContext::getEHFrame
Expected< const DWARFDebugFrame * > getEHFrame()
Get a pointer to the parsed eh frame information object.
Definition: DWARFContext.cpp:876
DWARFGdbIndex.h
DWARFAcceleratorTable.h
llvm::object::RelocationResolver
uint64_t(*)(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t LocData, int64_t Addend) RelocationResolver
Definition: RelocationResolver.h:37
llvm::DWARFDebugAranges::findAddress
uint64_t findAddress(uint64_t Address) const
Definition: DWARFDebugAranges.cpp:121
DWARFDebugMacro.h
llvm::DWARFDebugPubTable::dump
void dump(raw_ostream &OS) const
Definition: DWARFDebugPubTable.cpp:93
dumpLoclistsSection
static void dumpLoclistsSection(raw_ostream &OS, DIDumpOptions DumpOpts, DWARFDataExtractor Data, const MCRegisterInfo *MRI, const DWARFObject &Obj, Optional< uint64_t > DumpOffset)
Definition: DWARFContext.cpp:305
T
llvm::DIInliningInfo
A format-neutral container for inlined code description.
Definition: DIContext.h:87
llvm::DILineInfoSpecifier
Controls which fields of DILineInfo container should be filled with data.
Definition: DIContext.h:135
StringRef.h
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::DWARFContext::getAppleNames
const AppleAcceleratorTable & getAppleNames()
Get a reference to the parsed accelerator table object.
Definition: DWARFContext.cpp:935
llvm::DWARFDebugLine::SectionParser::done
bool done() const
Indicates if the parser has parsed as much as possible.
Definition: DWARFDebugLine.h:348
llvm::StringSwitch::Default
LLVM_NODISCARD R Default(T Value)
Definition: StringSwitch.h:181
llvm::DIDumpOptions::DumpType
unsigned DumpType
Definition: DIContext.h:181
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:137
llvm::toString
std::string toString(Error E)
Write all error messages (if any) in E to a string.
Definition: Error.h:1029
llvm::AppleAcceleratorTable::dump
void dump(raw_ostream &OS) const override
Definition: DWARFAcceleratorTable.cpp:203
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1175
Path.h
getTypeSize
static Optional< uint64_t > getTypeSize(DWARFDie Type, uint64_t PointerSize)
Definition: DWARFContext.cpp:1100
llvm::DWARFContext::getNumTypeUnits
unsigned getNumTypeUnits()
Get the number of type units in this context.
Definition: DWARFContext.h:228
llvm::raw_ostream::write_escaped
raw_ostream & write_escaped(StringRef Str, bool UseHexEscapes=false)
Output Str, turning '\', '\t', ' ', '"', and anything that doesn't satisfy llvm::isPrint into an esca...
Definition: raw_ostream.cpp:162
llvm::DWARFContext::getDWOCompileUnitForHash
DWARFCompileUnit * getDWOCompileUnitForHash(uint64_t Hash)
Definition: DWARFContext.cpp:724
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:330
llvm::DWARFContext::getLineInfoForAddressRange
DILineInfoTable getLineInfoForAddressRange(object::SectionedAddress Address, uint64_t Size, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
Definition: DWARFContext.cpp:1277
DWARFDebugLine.h
DWARFContext.h
llvm::dwarf::toSectionedAddress
Optional< object::SectionedAddress > toSectionedAddress(const Optional< DWARFFormValue > &V)
Definition: DWARFFormValue.h:295
Error.h
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
llvm::DILineInfo::BadString
static constexpr const char *const BadString
Definition: DIContext.h:33
llvm::DWARFListTableHeader::getVersion
uint16_t getVersion() const
Definition: DWARFListTable.h:96
llvm::DWARFContext::getStringExtractor
DataExtractor getStringExtractor() const
Definition: DWARFContext.h:342
llvm::DWARFUnitVector::addUnitsForSection
void addUnitsForSection(DWARFContext &C, const DWARFSection &Section, DWARFSectionKind SectionKind)
Read units from a .debug_info or .debug_types section.
Definition: DWARFUnit.cpp:35
llvm::DenseMapIterator
Definition: DenseMap.h:56
llvm::DWARFContext::info_section_units
unit_iterator_range info_section_units()
Get units from .debug_info in this context.
Definition: DWARFContext.h:154
llvm::DWARFUnitVector::addUnitsForDWOSection
void addUnitsForDWOSection(DWARFContext &C, const DWARFSection &DWOSection, DWARFSectionKind SectionKind, bool Lazy=false)
Read units from a .debug_info.dwo or .debug_types.dwo section.
Definition: DWARFUnit.cpp:46
llvm::DWARFContext
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
Definition: DWARFContext.h:53
llvm::DIDumpOptions::WarningHandler
std::function< void(Error)> WarningHandler
Definition: DIContext.h:214
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::StrOffsetsContributionDescriptor::Base
uint64_t Base
Definition: DWARFUnit.h:180
getSymbolInfo
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.
Definition: DWARFContext.cpp:1464
llvm::DWARFListTableHeader::dump
void dump(DataExtractor Data, raw_ostream &OS, DIDumpOptions DumpOpts={}) const
Definition: DWARFListTable.cpp:78
llvm::object::ObjectFile::getArch
virtual Triple::ArchType getArch() const =0
llvm::Optional
Definition: APInt.h:33
getAccelTable
static T & getAccelTable(std::unique_ptr< T > &Cache, const DWARFObject &Obj, const DWARFSection &Section, StringRef StringSection, bool IsLittleEndian)
Definition: DWARFContext.cpp:917
llvm::MapVector
This class implements a map that also provides access to all stored values in a deterministic order.
Definition: MapVector.h:37
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:80
llvm::DWARFContext::getDebugAbbrevDWO
const DWARFDebugAbbrev * getDebugAbbrevDWO()
Get a pointer to the parsed dwo abbreviations object.
Definition: DWARFContext.cpp:817
llvm::DWARFUnitIndex::dump
void dump(raw_ostream &OS) const
Definition: DWARFUnitIndex.cpp:214
llvm::DIE
A structured debug information entry.
Definition: DIE.h:739
DWARFDebugArangeSet.h
llvm::DWARFDebugAddrTable::extract
Error extract(const DWARFDataExtractor &Data, uint64_t *OffsetPtr, uint16_t CUVersion, uint8_t CUAddrSize, std::function< void(Error)> WarnCallback)
Extract the entire table, including all addresses.
Definition: DWARFDebugAddr.cpp:121
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:116
llvm::DWARFDebugAddrTable::getFullLength
Optional< uint64_t > getFullLength() const
Return the full length of this table, including the length field.
Definition: DWARFDebugAddr.cpp:179
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::DWARFContext::dwo_types_section_units
unit_iterator_range dwo_types_section_units()
Get units from .debug_types.dwo in the DWO context.
Definition: DWARFContext.h:200
STLExtras.h
llvm::DWARFListTableBase::dump
void dump(DWARFDataExtractor Data, raw_ostream &OS, llvm::function_ref< Optional< object::SectionedAddress >(uint32_t)> LookupPooledAddress, DIDumpOptions DumpOpts={}) const
Definition: DWARFListTable.h:252
llvm::DIE::getTag
dwarf::Tag getTag() const
Definition: DIE.h:775
llvm::DWARFDataExtractor
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
Definition: DWARFDataExtractor.h:21
llvm::DWARFDebugLine::LineTable::getFileLineInfoForAddress
bool getFileLineInfoForAddress(object::SectionedAddress Address, const char *CompDir, DILineInfoSpecifier::FileLineInfoKind Kind, DILineInfo &Result) const
Fills the Result argument with the file and line information corresponding to Address.
Definition: DWARFDebugLine.cpp:1398
getExpressionFrameOffset
static Optional< int64_t > getExpressionFrameOffset(ArrayRef< uint8_t > Expr, Optional< unsigned > FrameBaseReg)
Definition: DWARFContext.cpp:1159
llvm::DWARFVerifier::handleDebugInfo
bool handleDebugInfo()
Verify the information in the .debug_info and .debug_types sections.
Definition: DWARFVerifier.cpp:384
BaseType
Format.h
llvm::TargetRegistry::lookupTarget
static const Target * lookupTarget(const std::string &Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
Definition: TargetRegistry.cpp:62
llvm::BitmaskEnumDetail::Mask
std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:80
llvm::DWARFContext::getLocalsForAddress
std::vector< DILocal > getLocalsForAddress(object::SectionedAddress Address) override
Definition: DWARFContext.cpp:1244
llvm::DWARFListTableHeader::length
uint64_t length() const
Returns the length of the table, including the length field, or 0 if the length has not been determin...
Definition: DWARFListTable.cpp:105
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1044
llvm::DWARFContext::getDebugMacroDWO
const DWARFDebugMacro * getDebugMacroDWO()
Get a pointer to the parsed DebugMacroDWO information object.
Definition: DWARFContext.cpp:898
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:158
llvm::ArrayRef::data
const T * data() const
Definition: ArrayRef.h:160
F
#define F(x, y, z)
Definition: MD5.cpp:55
getFunctionNameAndStartLineForAddress
static bool getFunctionNameAndStartLineForAddress(DWARFCompileUnit *CU, uint64_t Address, FunctionNameKind Kind, DILineInfoSpecifier::FileLineInfoKind FileNameKind, std::string &FunctionName, std::string &StartFile, uint32_t &StartLine, Optional< uint64_t > &StartAddress)
TODO: change input parameter from "uint64_t Address" into "SectionedAddress Address".
Definition: DWARFContext.cpp:1066
MachO.h
llvm::DWARFContext::getInliningInfoForAddress
DIInliningInfo getInliningInfoForAddress(object::SectionedAddress Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
Definition: DWARFContext.cpp:1332
llvm::DILineInfo::FunctionName
std::string FunctionName
Definition: DIContext.h:37
llvm::DWARFContext::getAppleObjC
const AppleAcceleratorTable & getAppleObjC()
Get a reference to the parsed accelerator table object.
Definition: DWARFContext.cpp:951
llvm::AArch64CC::LT
@ LT
Definition: AArch64BaseInfo.h:266
llvm::DWARFUnit::getUnitDIE
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
Definition: DWARFUnit.h:390
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:82
llvm::Resolver
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Definition: Record.h:2012
llvm::StringRef::substr
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:610
llvm::Target::createMCRegInfo
MCRegisterInfo * createMCRegInfo(StringRef TT) const
createMCRegInfo - Create a MCRegisterInfo implementation.
Definition: TargetRegistry.h:420
SymInfo::SectionIndex
uint64_t SectionIndex
Definition: DWARFContext.cpp:1459
llvm::object::SymbolicFile::symbol_end
virtual basic_symbol_iterator symbol_end() const =0
llvm::DWARFContext::getDebugMacinfo
const DWARFDebugMacro * getDebugMacinfo()
Get a pointer to the parsed DebugMacinfo information object.
Definition: DWARFContext.cpp:904
llvm::DILineInfo::Column
uint32_t Column
Definition: DIContext.h:41
llvm::DWARFContext::getDebugAranges
const DWARFDebugAranges * getDebugAranges()
Get a pointer to the parsed DebugAranges object.
Definition: DWARFContext.cpp:841
dumpAddrSection
static void dumpAddrSection(raw_ostream &OS, DWARFDataExtractor &AddrData, DIDumpOptions DumpOpts, uint16_t Version, uint8_t AddrSize)
Definition: DWARFContext.cpp:217
DWARFDebugRangeList.h
DWARFVerifier.h
llvm::DWARFDebugLine::Row
Standard .debug_line state machine structure.
Definition: DWARFDebugLine.h:136
llvm::object::ObjectFile::isRelocatableObject
virtual bool isRelocatableObject() const =0
True if this is a relocatable object (.o/.obj).
llvm::DIDumpOptions::Verbose
bool Verbose
Definition: DIContext.h:191
llvm::Triple::ArchType
ArchType
Definition: Triple.h:46
llvm::DINameKind
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
Definition: DIContext.h:131
llvm::DWARFDebugLoclists
Definition: DWARFDebugLoc.h:123
llvm::DWARFDataExtractor::getRelocatedValue
uint64_t getRelocatedValue(uint32_t Size, uint64_t *Off, uint64_t *SectionIndex=nullptr, Error *Err=nullptr) const
Extracts a value and applies a relocation to the result if one exists for the given offset.
Definition: DWARFDataExtractor.cpp:46
llvm::msgpack::Type::Map
@ Map
llvm::object::ObjectFile::section_end
virtual section_iterator section_end() const =0
DWARFDebugFrame.h
SmallString.h
llvm::DWARFContext::dwo_info_section_units
unit_iterator_range dwo_info_section_units()
Get units from .debug_info..dwo in the DWO context.
Definition: DWARFContext.h:188
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::DWARFContext::getDebugMacinfoDWO
const DWARFDebugMacro * getDebugMacinfoDWO()
Get a pointer to the parsed DebugMacinfoDWO information object.
Definition: DWARFContext.cpp:910
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::DWARFDebugAbbrev
Definition: DWARFDebugAbbrev.h:56
llvm::errorCodeToError
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:90
llvm::DWARFUnitIndex
Definition: DWARFUnitIndex.h:80
llvm::DIInliningInfo::addFrame
void addFrame(const DILineInfo &Frame)
Definition: DIContext.h:105
DWARFSection.h
llvm::DWARFContext::getMaxVersion
unsigned getMaxVersion()
Definition: DWARFContext.h:266
llvm::ms_demangle::QualifierMangleMode::Result
@ Result
llvm::DWARFLocationTable::dumpLocationList
bool dumpLocationList(uint64_t *Offset, raw_ostream &OS, Optional< object::SectionedAddress > BaseAddr, const MCRegisterInfo *MRI, const DWARFObject &Obj, DWARFUnit *U, DIDumpOptions DumpOpts, unsigned Indent) const
Dump the location list at the given Offset.
Definition: DWARFDebugLoc.cpp:119
llvm::DIContext
Definition: DIContext.h:217
getFileName
static Expected< StringRef > getFileName(const DebugStringTableSubsectionRef &Strings, const DebugChecksumsSubsectionRef &Checksums, uint32_t FileID)
Definition: CodeViewYAMLDebugSections.cpp:555
llvm::DWARFContext::getNumCompileUnits
unsigned getNumCompileUnits()
Get the number of compile units in this context.
Definition: DWARFContext.h:222
DWARFDie.h
llvm::dwarf::Index
Index
Definition: Dwarf.h:467
llvm::createError
static Error createError(const Twine &Err)
Definition: APFloat.cpp:232
DWARFDebugLoc.h
llvm::DWARFDie::getCallerFrame
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:1055
llvm::DWARFContext::getArch
Triple::ArchType getArch() const
Definition: DWARFContext.h:447
dumpUUID
static void dumpUUID(raw_ostream &OS, const ObjectFile &Obj)
Dump the UUID load command.
Definition: DWARFContext.cpp:78
llvm::DWARFDie::getDeclFile
std::string getDeclFile(DILineInfoSpecifier::FileLineInfoKind Kind) const
Definition: DWARFDie.cpp:1048
llvm::DWARFListTableBase::length
uint64_t length()
Definition: DWARFListTable.h:198
llvm::dwarf::FormatString
StringRef FormatString(DwarfFormat Format)
Definition: Dwarf.cpp:790
llvm::dwarf::toSectionOffset
Optional< uint64_t > toSectionOffset(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an section offset.
Definition: DWARFFormValue.h:316
llvm::DWARFVerifier::handleDebugLine
bool handleDebugLine()
Verify the information in the .debug_line section.
Definition: DWARFVerifier.cpp:884
llvm::DWARFDebugLine::LineTable::Rows
RowVector Rows
Definition: DWARFDebugLine.h:289
llvm::DW_SECT_EXT_TYPES
@ DW_SECT_EXT_TYPES
Definition: DWARFUnitIndex.h:62
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::DWARFObject
Definition: DWARFObject.h:25
llvm::DILineInfo::StartLine
uint32_t StartLine
Definition: DIContext.h:42
llvm::DWARFDebugLine::SectionParser::parseNext
LineTable parseNext(function_ref< void(Error)> RecoverableErrorHandler, function_ref< void(Error)> UnrecoverableErrorHandler, raw_ostream *OS=nullptr, bool Verbose=false)
Get the next line table from the section.
Definition: DWARFDebugLine.cpp:1443
llvm::DWARFUnit::getLineTableOffset
uint32_t getLineTableOffset() const
Definition: DWARFUnit.h:490
llvm::DWARFContext::getStringDWOExtractor
DataExtractor getStringDWOExtractor() const
Definition: DWARFContext.h:345
llvm::DWARFUnit::getLineSection
const DWARFSection & getLineSection() const
Definition: DWARFUnit.h:299
llvm::dwarf::DwarfFormat
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
Definition: Dwarf.h:92
SymInfo::Address
uint64_t Address
Definition: DWARFContext.cpp:1458
llvm::None
const NoneType None
Definition: None.h:23
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::DWARFContext::ProcessDebugRelocations::Ignore
@ Ignore
llvm::DWARFDebugLine::LineTable::lookupAddressRange
bool lookupAddressRange(object::SectionedAddress Address, uint64_t Size, std::vector< uint32_t > &Result) const
Definition: DWARFDebugLine.cpp:1265
llvm::DWARFContext::compile_units
compile_unit_range compile_units()
Get compile units in this context.
Definition: DWARFContext.h:174
DF
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
llvm::DWARFVerifier::handleAccelTables
bool handleAccelTables()
Verify the information in accelerator tables, if they exist.
Definition: DWARFVerifier.cpp:1532
llvm::DWARFDebugLine
Definition: DWARFDebugLine.h:32
llvm::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:108
llvm::SmallString< 128 >
ContributionCollection
std::vector< Optional< StrOffsetsContributionDescriptor > > ContributionCollection
Definition: DWARFContext.cpp:100
llvm::DWARFContext::getDebugMacro
const DWARFDebugMacro * getDebugMacro()
Get a pointer to the parsed DebugMacro information object.
Definition: DWARFContext.cpp:892
llvm::DWARFContext::dwo_units
unit_iterator_range dwo_units()
Get all units in the DWO context.
Definition: DWARFContext.h:216
llvm::DWARFContext::verify
bool verify(raw_ostream &OS, DIDumpOptions DumpOpts={}) override
Definition: DWARFContext.cpp:761
llvm::DWARFCompileUnit
Definition: DWARFCompileUnit.h:17
llvm::object::SectionRef
This is a value type class that represents a single section in the list of sections in the object fil...
Definition: ObjectFile.h:79
llvm::object::SupportsRelocation
bool(*)(uint64_t) SupportsRelocation
Definition: RelocationResolver.h:34
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:223
DWARFDebugPubTable.h
llvm::DWARFDebugRangeList::extract
Error extract(const DWARFDataExtractor &data, uint64_t *offset_ptr)
Definition: DWARFDebugRangeList.cpp:31
llvm::DWARFGdbIndex::dump
void dump(raw_ostream &OS)
Definition: DWARFGdbIndex.cpp:98
collectContributionData
static ContributionCollection collectContributionData(DWARFContext::unit_iterator_range Units)
Definition: DWARFContext.cpp:105
DWARFDebugAranges.h
llvm::DWARFGdbIndex
Definition: DWARFGdbIndex.h:22
llvm::DIDT_ID_Count
@ DIDT_ID_Count
Definition: DIContext.h:163
llvm::DILineInfo::Line
uint32_t Line
Definition: DIContext.h:40
llvm::DWARFContext::getTypeUnitForHash
DWARFTypeUnit * getTypeUnitForHash(uint16_t Version, uint64_t Hash, bool IsDWO)
Definition: DWARFContext.cpp:696
llvm::DINameKind::ShortName
@ ShortName
llvm::object::SymbolRef::getSection
Expected< section_iterator > getSection() const
Get section this symbol is defined in reference to.
Definition: ObjectFile.h:408
object
bar al al movzbl eax ret Missed when stored in a memory object
Definition: README.txt:1411
dumpPubTableSection
static void dumpPubTableSection(raw_ostream &OS, DIDumpOptions DumpOpts, DWARFDataExtractor Data, bool GnuStyle)
Definition: DWARFContext.cpp:339
llvm::DWARFContext::getNumDWOTypeUnits
unsigned getNumDWOTypeUnits()
Get the number of type units in the DWO context.
Definition: DWARFContext.h:240
llvm::LoadedObjectInfo::getSectionLoadAddress
virtual uint64_t getSectionLoadAddress(const object::SectionRef &Sec) const
Obtain the Load Address of a section by SectionRef.
Definition: DIContext.h:268
llvm::DWARFDebugLine::LineTable::getFileNameByIndex
bool getFileNameByIndex(uint64_t FileIndex, StringRef CompDir, DILineInfoSpecifier::FileLineInfoKind Kind, std::string &Result) const
Extracts filename by its index in filename table in prologue.
Definition: DWARFDebugLine.h:261
Index
uint32_t Index
Definition: ELFObjHandler.cpp:83
llvm::DWARFDebugLoc
Definition: DWARFDebugLoc.h:86
llvm::DWARFDebugRnglistTable
Definition: DWARFDebugRnglists.h:60
uint64_t
llvm::object::symbol_iterator
Definition: ObjectFile.h:206
llvm::DWARFDebugLine::SectionParser
Helper to allow for parsing of an entire .debug_line section in sequence.
Definition: DWARFDebugLine.h:312
llvm::DWARFVerifier::handleDebugAbbrev
bool handleDebugAbbrev()
Verify the information in any of the following sections, if available: .debug_abbrev,...
Definition: DWARFVerifier.cpp:308
llvm::DWARFDie::getDeclLine
uint64_t getDeclLine() const
Returns the declaration line (start line) for a DIE, assuming it specifies a subprogram.
Definition: DWARFDie.cpp:1043
llvm::find
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1669
llvm::DWARFDebugAddrTable
A class representing an address table as specified in DWARF v5.
Definition: DWARFDebugAddr.h:29
llvm::DWARFContext::getDebugAbbrev
const DWARFDebugAbbrev * getDebugAbbrev()
Get a pointer to the parsed DebugAbbrev object.
Definition: DWARFContext.cpp:806
llvm::DWARFListTableHeader::getHeaderOffset
uint64_t getHeaderOffset() const
Definition: DWARFListTable.h:93
LEB128.h
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::DenseMap
Definition: DenseMap.h:714
llvm::DWARFContext::getCUAddrSize
uint8_t getCUAddrSize()
Get address size from CUs.
Definition: DWARFContext.cpp:2038
llvm::DWARFContext::dwo_compile_units
compile_unit_range dwo_compile_units()
Get compile units in the DWO context.
Definition: DWARFContext.h:207
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::DILineInfo
A format-neutral container for source line information.
Definition: DIContext.h:31
llvm::DWARFDie::find
Optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
Definition: DWARFDie.cpp:821
MCRegisterInfo.h
llvm::DILineInfoSpecifier::FileLineInfoKind
FileLineInfoKind
Definition: DIContext.h:136
DWARFDebugRnglists.h
llvm::HighlightColor::Address
@ Address
llvm::DataExtractor::isValidOffset
bool isValidOffset(uint64_t offset) const
Test the validity of offset.
Definition: DataExtractor.h:665
llvm::object::ObjectFile::createObjectFile
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
Definition: ObjectFile.cpp:186
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1707
ObjectFile.h
memcpy
<%struct.s * > cast struct s *S to sbyte *< sbyte * > sbyte uint cast struct s *agg result to sbyte *< sbyte * > sbyte uint cast struct s *memtmp to sbyte *< sbyte * > sbyte uint ret void llc ends up issuing two memcpy or custom lower memcpy(of small size) to be ldmia/stmia. I think option 2 is better but the current register allocator cannot allocate a chunk of registers at a time. A feasible temporary solution is to use specific physical registers at the lowering time for small(<
llvm::DWARFDebugArangeSet
Definition: DWARFDebugArangeSet.h:22
llvm::object::content_iterator
Definition: SymbolicFile.h:67
llvm::DWARFContext::getUnitAtIndex
DWARFUnit * getUnitAtIndex(unsigned index)
Get the unit at the specified index.
Definition: DWARFContext.h:246
llvm::StringRef::find_first_not_of
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:241
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
UUID
std::pair< llvm::MachO::Target, std::string > UUID
Definition: TextStubCommon.h:23
dumpStringOffsetsSection
static void dumpStringOffsetsSection(raw_ostream &OS, DIDumpOptions DumpOpts, StringRef SectionName, const DWARFObject &Obj, const DWARFSection &StringOffsetsSection, StringRef StringSection, DWARFContext::unit_iterator_range Units, bool LittleEndian)
Definition: DWARFContext.cpp:144
llvm::DILineInfo::Discriminator
uint32_t Discriminator
Definition: DIContext.h:46
llvm::DWARFContext::getTUIndex
const DWARFUnitIndex & getTUIndex()
Definition: DWARFContext.cpp:785
llvm::object::getRelocationResolver
std::pair< SupportsRelocation, RelocationResolver > getRelocationResolver(const ObjectFile &Obj)
Definition: RelocationResolver.cpp:645
llvm::DWARFContext::getDIEsForAddress
DIEsForAddress getDIEsForAddress(uint64_t Address)
Get the compilation unit, the function DIE and lexical block DIE for the given address where applicab...
Definition: DWARFContext.cpp:1033
llvm::DWARFContext::getGdbIndex
DWARFGdbIndex & getGdbIndex()
Definition: DWARFContext.cpp:796
llvm::DWARFContext::getDWOContext
std::shared_ptr< DWARFContext > getDWOContext(StringRef AbsolutePath)
Definition: DWARFContext.cpp:1401
llvm::DIDT_All
@ DIDT_All
Definition: DIContext.h:170
llvm::dwarf::toString
Optional< const char * > toString(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
Definition: DWARFFormValue.h:175
llvm::DWARFContext::~DWARFContext
~DWARFContext()
llvm::DWARFUnitVector::getUnitForIndexEntry
DWARFUnit * getUnitForIndexEntry(const DWARFUnitIndex::Entry &E)
Definition: DWARFUnit.cpp:144
llvm::DWARFDie::getLocations
Expected< DWARFLocationExpressionsVector > getLocations(dwarf::Attribute Attr) const
Definition: DWARFDie.cpp:980
llvm::RelocAddrEntry
RelocAddrEntry contains relocated value and section index.
Definition: DWARFRelocMap.h:20
RelocationResolver.h
llvm::DataExtractor::getCStr
const char * getCStr(uint64_t *OffsetPtr, Error *Err=nullptr) const
Extract a C string from *offset_ptr.
Definition: DataExtractor.h:129
Extension
Definition: AArch64AsmParser.cpp:3250
llvm::DWARFContext::getDebugFrame
Expected< const DWARFDebugFrame * > getDebugFrame()
Get a pointer to the parsed frame information object.
Definition: DWARFContext.cpp:850
llvm::ArrayRef< uint8_t >
llvm::DWARFContext::isLittleEndian
bool isLittleEndian() const
Definition: DWARFContext.h:379
llvm::DWARFContext::getDebugLoc
const DWARFDebugLoc * getDebugLoc()
Get a pointer to the parsed DebugLoc object.
Definition: DWARFContext.cpp:827
llvm::object::section_iterator
content_iterator< SectionRef > section_iterator
Definition: ObjectFile.h:46
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
Dwarf.h
llvm::object::ObjectFile
This class is the base class for all object file types.
Definition: ObjectFile.h:227
llvm::DWARFUnitVector::getUnitForOffset
DWARFUnit * getUnitForOffset(uint64_t Offset) const
Definition: DWARFUnit.cpp:131
llvm::Expected::get
reference get()
Returns a reference to the stored T value.
Definition: Error.h:568
uint32_t
llvm::append_range
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
Definition: STLExtras.h:1846
llvm::COFF::SectionSize
@ SectionSize
Definition: COFF.h:61
llvm::DWARFContext::normal_units
unit_iterator_range normal_units()
Get all normal compile/type units in this context.
Definition: DWARFContext.h:182
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
dumpRnglistsSection
static void dumpRnglistsSection(raw_ostream &OS, DWARFDataExtractor &rnglistData, llvm::function_ref< Optional< object::SectionedAddress >(uint32_t)> LookupPooledAddress, DIDumpOptions DumpOpts)
Definition: DWARFContext.cpp:240
llvm::Triple::UnknownVendor
@ UnknownVendor
Definition: Triple.h:152
llvm::AppleAcceleratorTable
This implements the Apple accelerator table format, a precursor of the DWARF 5 accelerator table form...
Definition: DWARFAcceleratorTable.h:83
llvm::format
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
llvm::DWARFContext::getNumDWOCompileUnits
unsigned getNumDWOCompileUnits()
Get the number of compile units in the DWO context.
Definition: DWARFContext.h:234
llvm::DWARFDebugMacro
Definition: DWARFDebugMacro.h:23
llvm::MCRegisterInfo
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Definition: MCRegisterInfo.h:135
llvm::DIDT_UUID
@ DIDT_UUID
Definition: DIContext.h:175
llvm::DWARFDebugLoc::dump
void dump(raw_ostream &OS, const MCRegisterInfo *RegInfo, const DWARFObject &Obj, DIDumpOptions DumpOpts, Optional< uint64_t > Offset) const
Print the location lists found within the debug_loc section.
Definition: DWARFDebugLoc.cpp:183
llvm::DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath
@ AbsoluteFilePath
llvm::DILineInfoSpecifier::FNKind
FunctionNameKind FNKind
Definition: DIContext.h:149
Decompressor.h
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::DWARFDebugPubTable
Represents structure for holding and parsing .debug_pub* tables.
Definition: DWARFDebugPubTable.h:25
llvm::DWARFContext::getDIEForOffset
DWARFDie getDIEForOffset(uint64_t Offset)
Get a DIE given an exact offset.
Definition: DWARFContext.cpp:754
llvm::DWARFContext::getCUIndex
const DWARFUnitIndex & getCUIndex()
Definition: DWARFContext.cpp:774
llvm::pdb::PDB_DataKind::Local
@ Local
llvm::DWARFContext::getLineInfoForAddress
DILineInfo getLineInfoForAddress(object::SectionedAddress Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
Definition: DWARFContext.cpp:1256
llvm::StringRef::size
constexpr LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:156
llvm::DWARFListTableHeader
A class representing the header of a list table such as the range list table in the ....
Definition: DWARFListTable.h:56
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::DWARFListTableBase::extract
Error extract(DWARFDataExtractor Data, uint64_t *OffsetPtr)
Extract an entire table, including all list entries.
Definition: DWARFListTable.h:202
llvm::DWARFUnit::getAddressByteSize
uint8_t getAddressByteSize() const
Definition: DWARFUnit.h:286
llvm::createStringError
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1240
llvm::DWARFDebugAddrTable::dump
void dump(raw_ostream &OS, DIDumpOptions DumpOpts={}) const
Definition: DWARFDebugAddr.cpp:135
llvm::DWARFTypeUnit
Definition: DWARFTypeUnit.h:25
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
std
Definition: BitVector.h:850
llvm::inconvertibleErrorCode
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:77
uint16_t
llvm::DWARFContext::getRegisterInfo
const MCRegisterInfo * getRegisterInfo() const
Definition: DWARFContext.h:411
DWARFDebugAbbrev.h
llvm::DWARFUnit
Definition: DWARFUnit.h:203
llvm::SIInstrFlags::DS
@ DS
Definition: SIDefines.h:60
llvm::SectionName
Definition: DWARFSection.h:21
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
Success
#define Success
Definition: AArch64Disassembler.cpp:266
llvm::DWARFDebugNames::dump
void dump(raw_ostream &OS) const override
Definition: DWARFAcceleratorTable.cpp:791
Casting.h
llvm::DWARFContext::getCompileUnitForOffset
DWARFCompileUnit * getCompileUnitForOffset(uint64_t Offset)
Return the compile unit that includes an offset (relative to .debug_info).
Definition: DWARFContext.cpp:1020
DataExtractor.h
llvm::DWARFUnitVector::finishedInfoUnits
void finishedInfoUnits()
Indicate that parsing .debug_info[.dwo] is done, and remaining units will be from ....
Definition: DWARFUnit.h:166
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1590
llvm::DILocal
Definition: DIContext.h:119
llvm::DIDumpOptions::DisplayRawContents
bool DisplayRawContents
Definition: DIContext.h:192
llvm::TargetStackID::Default
@ Default
Definition: TargetFrameLowering.h:28
llvm::DILineInfo::StartAddress
Optional< uint64_t > StartAddress
Definition: DIContext.h:43
llvm::unique
auto unique(Range &&R, Predicate P)
Definition: STLExtras.h:1802
StringSwitch.h
llvm::LoadedObjectInfo
An inferface for inquiring the load address of a loaded object file to be used by the DIContext imple...
Definition: DIContext.h:253
DWARFUnitIndex.h
llvm::dwarf::toUnsigned
Optional< uint64_t > toUnsigned(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an unsigned constant.
Definition: DWARFFormValue.h:223
llvm::DWARFDebugPubTable::extract
void extract(DWARFDataExtractor Data, bool GnuStyle, function_ref< void(Error)> RecoverableErrorHandler)
Definition: DWARFDebugPubTable.cpp:22
llvm::object::ObjectFile::mapDebugSectionName
virtual StringRef mapDebugSectionName(StringRef Name) const
Maps a debug section name to a standard DWARF section name.
Definition: ObjectFile.h:342
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition: Error.h:598
llvm::DWARFDie::getAttributeValueAsReferencedDie
DWARFDie getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE as the referenced DIE.
Definition: DWARFDie.cpp:878
llvm::decodeSLEB128
int64_t decodeSLEB128(const uint8_t *p, unsigned *n=nullptr, const uint8_t *end=nullptr, const char **error=nullptr)
Utility function to decode a SLEB128 value.
Definition: LEB128.h:161
llvm::DILineInfo::FileName
std::string FileName
Definition: DIContext.h:36
llvm::DataExtractor
Definition: DataExtractor.h:41
llvm::DWARFDie::getTag
dwarf::Tag getTag() const
Definition: DWARFDie.h:72
Version
uint64_t Version
Definition: RawMemProfReader.cpp:25
SmallVector.h
llvm::DILineInfoSpecifier::FunctionNameKind
DINameKind FunctionNameKind
Definition: DIContext.h:146
llvm::DWARFDebugLine::SectionParser::skip
void skip(function_ref< void(Error)> RecoverableErrorHandler, function_ref< void(Error)> UnrecoverableErrorHandler)
Skip the current line table and go to the following line table (if present) immediately.
Definition: DWARFDebugLine.cpp:1459
llvm::DWARFDebugLoclists::dumpRange
void dumpRange(uint64_t StartOffset, uint64_t Size, raw_ostream &OS, const MCRegisterInfo *MRI, const DWARFObject &Obj, DIDumpOptions DumpOpts)
Dump all location lists within the given range.
Definition: DWARFDebugLoc.cpp:385
llvm::object::SectionedAddress
Definition: ObjectFile.h:143
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:163
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
llvm::object::ObjectFile::sections
section_iterator_range sections() const
Definition: ObjectFile.h:321
llvm::DWARFDebugLine::LineTable
Definition: DWARFDebugLine.h:229
SymInfo
SymInfo contains information about symbol: it's address and section index which is -1LL for absolute ...
Definition: DWARFContext.cpp:1457
llvm::DWARFContext::getCompileUnitForAddress
DWARFCompileUnit * getCompileUnitForAddress(uint64_t Address)
Return the compile unit which contains instruction with provided address.
Definition: DWARFContext.cpp:1026
llvm::StringSwitch
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:42
llvm::DIDumpOptions::noImplicitRecursion
DIDumpOptions noImplicitRecursion() const
Return the options with RecurseDepth set to 0 unless explicitly required.
Definition: DIContext.h:203
llvm::raw_ostream::uuid_t
uint8_t[16] uuid_t
Output a formatted UUID with dash separators.
Definition: raw_ostream.h:272
llvm::DWARFDie
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
Definition: DWARFDie.h:43
llvm::DWARFDebugNames
.debug_names section consists of one or more units.
Definition: DWARFAcceleratorTable.h:231
llvm::DILineInfoSpecifier::FLIKind
FileLineInfoKind FLIKind
Definition: DIContext.h:148
llvm::DWARFContext::DWARFContext
DWARFContext(std::unique_ptr< const DWARFObject > DObj, std::string DWPName="", std::function< void(Error)> RecoverableErrorHandler=WithColor::defaultErrorHandler, std::function< void(Error)> WarningHandler=WithColor::defaultWarningHandler)
Definition: DWARFContext.cpp:67
llvm::Triple::UnknownOS
@ UnknownOS
Definition: Triple.h:171
llvm::DWARFDebugAbbrev::dump
void dump(raw_ostream &OS) const
Definition: DWARFDebugAbbrev.cpp:128
llvm::DWARFContext::DIEsForAddress
Wraps the returned DIEs for a given address.
Definition: DWARFContext.h:353
raw_ostream.h
llvm::dwarf::getDwarfOffsetByteSize
uint8_t getDwarfOffsetByteSize(DwarfFormat Format)
The size of a reference determined by the DWARF 32/64-bit format.
Definition: Dwarf.h:635
n
The same transformation can work with an even modulo with the addition of a and shrink the compare RHS by the same amount Unless the target supports that transformation probably isn t worthwhile The transformation can also easily be made to work with non zero equality for n
Definition: README.txt:685
isRelocScattered
static bool isRelocScattered(const object::ObjectFile &Obj, const RelocationRef &Reloc)
Definition: DWARFContext.cpp:1519
DWARFDebugAddr.h
llvm::DWARFListTableHeader::getAddrSize
uint8_t getAddrSize() const
Definition: DWARFListTable.h:94
llvm::DWARFContext::ProcessDebugRelocations
ProcessDebugRelocations
Definition: DWARFContext.h:419
llvm::DWARFDebugAranges
Definition: DWARFDebugAranges.h:21
TargetRegistry.h
llvm::DWARFSection::Data
StringRef Data
Definition: DWARFSection.h:17
CU
Definition: AArch64AsmBackend.cpp:504
llvm::DWARFContext::getAppleTypes
const AppleAcceleratorTable & getAppleTypes()
Get a reference to the parsed accelerator table object.
Definition: DWARFContext.cpp:940
llvm::DWARFContext::dump
void dump(raw_ostream &OS, DIDumpOptions DumpOpts, std::array< Optional< uint64_t >, DIDT_ID_Count > DumpOffsets)
Dump a textual representation to OS.
Definition: DWARFContext.cpp:346
llvm::raw_ostream::write_uuid
raw_ostream & write_uuid(const uuid_t UUID)
Definition: raw_ostream.cpp:152
llvm::object::SymbolRef::getAddress
Expected< uint64_t > getAddress() const
Returns the symbol virtual address (i.e.
Definition: ObjectFile.h:392
llvm::DWARFContext::getAppleNamespaces
const AppleAcceleratorTable & getAppleNamespaces()
Get a reference to the parsed accelerator table object.
Definition: DWARFContext.cpp:945
llvm::ArrayRef::end
iterator end() const
Definition: ArrayRef.h:152
entry
print Instructions which execute on loop entry
Definition: MustExecute.cpp:339
llvm::DWARFContext::loadRegisterInfo
Error loadRegisterInfo(const object::ObjectFile &Obj)
Loads register info for the architecture of the provided object file.
Definition: DWARFContext.cpp:2021
llvm::DWARFDebugRangeList::dump
void dump(raw_ostream &OS) const
Definition: DWARFDebugRangeList.cpp:67
llvm::MachO::SectionType
SectionType
These are the section type and attributes fields.
Definition: MachO.h:120
llvm::dwarf::DWARF32
@ DWARF32
Definition: Dwarf.h:92
llvm::DWARFDie::getSubroutineName
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:1010
llvm::DWARFListTableHeader::extract
Error extract(DWARFDataExtractor Data, uint64_t *OffsetPtr)
Extract the table header and the array of offsets.
Definition: DWARFListTable.cpp:19
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38
llvm::DIDumpOptions
Container for dump options that control which debug information will be dumped.
Definition: DIContext.h:180
llvm::DIDumpOptions::RecoverableErrorHandler
std::function< void(Error)> RecoverableErrorHandler
Definition: DIContext.h:212
llvm::DWARFUnitVector
Describe a collection of units.
Definition: DWARFUnit.h:120
llvm::DILineInfo::StartFileName
std::string StartFileName
Definition: DIContext.h:38