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