LLVM  14.0.0git
DwarfTransformer.cpp
Go to the documentation of this file.
1 //===- DwarfTransformer.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 
9 #include <thread>
10 #include <unordered_set>
11 
14 #include "llvm/Support/Error.h"
17 
23 
24 using namespace llvm;
25 using namespace gsym;
26 
29  const char *CompDir;
30  std::vector<uint32_t> FileCache;
32  uint8_t AddrSize = 0;
33 
36  CompDir = CU->getCompilationDir();
37  FileCache.clear();
38  if (LineTable)
39  FileCache.assign(LineTable->Prologue.FileNames.size() + 1, UINT32_MAX);
40  DWARFDie Die = CU->getUnitDIE();
41  Language = dwarf::toUnsigned(Die.find(dwarf::DW_AT_language), 0);
42  AddrSize = CU->getAddressByteSize();
43  }
44 
45  /// Return true if Addr is the highest address for a given compile unit. The
46  /// highest address is encoded as -1, of all ones in the address. These high
47  /// addresses are used by some linkers to indicate that a function has been
48  /// dead stripped or didn't end up in the linked executable.
50  if (AddrSize == 4)
51  return Addr == UINT32_MAX;
52  else if (AddrSize == 8)
53  return Addr == UINT64_MAX;
54  return false;
55  }
56 
57  /// Convert a DWARF compile unit file index into a GSYM global file index.
58  ///
59  /// Each compile unit in DWARF has its own file table in the line table
60  /// prologue. GSYM has a single large file table that applies to all files
61  /// from all of the info in a GSYM file. This function converts between the
62  /// two and caches and DWARF CU file index that has already been converted so
63  /// the first client that asks for a compile unit file index will end up
64  /// doing the conversion, and subsequent clients will get the cached GSYM
65  /// index.
67  if (!LineTable)
68  return 0;
69  assert(DwarfFileIdx < FileCache.size());
70  uint32_t &GsymFileIdx = FileCache[DwarfFileIdx];
71  if (GsymFileIdx != UINT32_MAX)
72  return GsymFileIdx;
73  std::string File;
74  if (LineTable->getFileNameByIndex(
75  DwarfFileIdx, CompDir,
77  GsymFileIdx = Gsym.insertFile(File);
78  else
79  GsymFileIdx = 0;
80  return GsymFileIdx;
81  }
82 };
83 
84 
86  if (DWARFDie SpecDie =
87  Die.getAttributeValueAsReferencedDie(dwarf::DW_AT_specification)) {
88  if (DWARFDie SpecParent = GetParentDeclContextDIE(SpecDie))
89  return SpecParent;
90  }
91  if (DWARFDie AbstDie =
92  Die.getAttributeValueAsReferencedDie(dwarf::DW_AT_abstract_origin)) {
93  if (DWARFDie AbstParent = GetParentDeclContextDIE(AbstDie))
94  return AbstParent;
95  }
96 
97  // We never want to follow parent for inlined subroutine - that would
98  // give us information about where the function is inlined, not what
99  // function is inlined
100  if (Die.getTag() == dwarf::DW_TAG_inlined_subroutine)
101  return DWARFDie();
102 
103  DWARFDie ParentDie = Die.getParent();
104  if (!ParentDie)
105  return DWARFDie();
106 
107  switch (ParentDie.getTag()) {
108  case dwarf::DW_TAG_namespace:
109  case dwarf::DW_TAG_structure_type:
110  case dwarf::DW_TAG_union_type:
111  case dwarf::DW_TAG_class_type:
112  case dwarf::DW_TAG_subprogram:
113  return ParentDie; // Found parent decl context DIE
114  case dwarf::DW_TAG_lexical_block:
115  return GetParentDeclContextDIE(ParentDie);
116  default:
117  break;
118  }
119 
120  return DWARFDie();
121 }
122 
123 /// Get the GsymCreator string table offset for the qualified name for the
124 /// DIE passed in. This function will avoid making copies of any strings in
125 /// the GsymCreator when possible. We don't need to copy a string when the
126 /// string comes from our .debug_str section or is an inlined string in the
127 /// .debug_info. If we create a qualified name string in this function by
128 /// combining multiple strings in the DWARF string table or info, we will make
129 /// a copy of the string when we add it to the string table.
132  GsymCreator &Gsym) {
133  // If the dwarf has mangled name, use mangled name
134  if (auto LinkageName =
135  dwarf::toString(Die.findRecursively({dwarf::DW_AT_MIPS_linkage_name,
136  dwarf::DW_AT_linkage_name}),
137  nullptr))
138  return Gsym.insertString(LinkageName, /* Copy */ false);
139 
141  if (ShortName.empty())
142  return llvm::None;
143 
144  // For C++ and ObjC, prepend names of all parent declaration contexts
145  if (!(Language == dwarf::DW_LANG_C_plus_plus ||
146  Language == dwarf::DW_LANG_C_plus_plus_03 ||
147  Language == dwarf::DW_LANG_C_plus_plus_11 ||
148  Language == dwarf::DW_LANG_C_plus_plus_14 ||
149  Language == dwarf::DW_LANG_ObjC_plus_plus ||
150  // This should not be needed for C, but we see C++ code marked as C
151  // in some binaries. This should hurt, so let's do it for C as well
152  Language == dwarf::DW_LANG_C))
153  return Gsym.insertString(ShortName, /* Copy */ false);
154 
155  // Some GCC optimizations create functions with names ending with .isra.<num>
156  // or .part.<num> and those names are just DW_AT_name, not DW_AT_linkage_name
157  // If it looks like it could be the case, don't add any prefix
158  if (ShortName.startswith("_Z") &&
159  (ShortName.contains(".isra.") || ShortName.contains(".part.")))
160  return Gsym.insertString(ShortName, /* Copy */ false);
161 
162  DWARFDie ParentDeclCtxDie = GetParentDeclContextDIE(Die);
163  if (ParentDeclCtxDie) {
164  std::string Name = ShortName.str();
165  while (ParentDeclCtxDie) {
166  StringRef ParentName(ParentDeclCtxDie.getName(DINameKind::ShortName));
167  if (!ParentName.empty()) {
168  // "lambda" names are wrapped in < >. Replace with { }
169  // to be consistent with demangled names and not to confuse with
170  // templates
171  if (ParentName.front() == '<' && ParentName.back() == '>')
172  Name = "{" + ParentName.substr(1, ParentName.size() - 2).str() + "}" +
173  "::" + Name;
174  else
175  Name = ParentName.str() + "::" + Name;
176  }
177  ParentDeclCtxDie = GetParentDeclContextDIE(ParentDeclCtxDie);
178  }
179  // Copy the name since we created a new name in a std::string.
180  return Gsym.insertString(Name, /* Copy */ true);
181  }
182  // Don't copy the name since it exists in the DWARF object file.
183  return Gsym.insertString(ShortName, /* Copy */ false);
184 }
185 
187  bool CheckChildren = true;
188  switch (Die.getTag()) {
189  case dwarf::DW_TAG_subprogram:
190  // Don't look into functions within functions.
191  CheckChildren = Depth == 0;
192  break;
193  case dwarf::DW_TAG_inlined_subroutine:
194  return true;
195  default:
196  break;
197  }
198  if (!CheckChildren)
199  return false;
200  for (DWARFDie ChildDie : Die.children()) {
201  if (hasInlineInfo(ChildDie, Depth + 1))
202  return true;
203  }
204  return false;
205 }
206 
207 static void parseInlineInfo(GsymCreator &Gsym, CUInfo &CUI, DWARFDie Die,
209  InlineInfo &parent) {
210  if (!hasInlineInfo(Die, Depth))
211  return;
212 
213  dwarf::Tag Tag = Die.getTag();
214  if (Tag == dwarf::DW_TAG_inlined_subroutine) {
215  // create new InlineInfo and append to parent.children
216  InlineInfo II;
217  DWARFAddressRange FuncRange =
220  if (RangesOrError) {
221  for (const DWARFAddressRange &Range : RangesOrError.get()) {
222  // Check that the inlined function is within the range of the function
223  // info, it might not be in case of split functions
224  if (FuncRange.LowPC <= Range.LowPC && Range.HighPC <= FuncRange.HighPC)
225  II.Ranges.insert(AddressRange(Range.LowPC, Range.HighPC));
226  }
227  }
228  if (II.Ranges.empty())
229  return;
230 
231  if (auto NameIndex = getQualifiedNameIndex(Die, CUI.Language, Gsym))
232  II.Name = *NameIndex;
234  Gsym, dwarf::toUnsigned(Die.find(dwarf::DW_AT_call_file), 0));
235  II.CallLine = dwarf::toUnsigned(Die.find(dwarf::DW_AT_call_line), 0);
236  // parse all children and append to parent
237  for (DWARFDie ChildDie : Die.children())
238  parseInlineInfo(Gsym, CUI, ChildDie, Depth + 1, FI, II);
239  parent.Children.emplace_back(std::move(II));
240  return;
241  }
242  if (Tag == dwarf::DW_TAG_subprogram || Tag == dwarf::DW_TAG_lexical_block) {
243  // skip this Die and just recurse down
244  for (DWARFDie ChildDie : Die.children())
245  parseInlineInfo(Gsym, CUI, ChildDie, Depth + 1, FI, parent);
246  }
247 }
248 
250  DWARFDie Die, GsymCreator &Gsym,
251  FunctionInfo &FI) {
252  std::vector<uint32_t> RowVector;
253  const uint64_t StartAddress = FI.startAddress();
254  const uint64_t EndAddress = FI.endAddress();
255  const uint64_t RangeSize = EndAddress - StartAddress;
256  const object::SectionedAddress SecAddress{
258 
259 
260  if (!CUI.LineTable->lookupAddressRange(SecAddress, RangeSize, RowVector)) {
261  // If we have a DW_TAG_subprogram but no line entries, fall back to using
262  // the DW_AT_decl_file an d DW_AT_decl_line if we have both attributes.
263  std::string FilePath = Die.getDeclFile(
265  if (FilePath.empty())
266  return;
267  if (auto Line =
268  dwarf::toUnsigned(Die.findRecursively({dwarf::DW_AT_decl_line}))) {
269  LineEntry LE(StartAddress, Gsym.insertFile(FilePath), *Line);
270  FI.OptLineTable = LineTable();
271  FI.OptLineTable->push(LE);
272  }
273  return;
274  }
275 
276  FI.OptLineTable = LineTable();
277  DWARFDebugLine::Row PrevRow;
278  for (uint32_t RowIndex : RowVector) {
279  // Take file number and line/column from the row.
280  const DWARFDebugLine::Row &Row = CUI.LineTable->Rows[RowIndex];
281  const uint32_t FileIdx = CUI.DWARFToGSYMFileIndex(Gsym, Row.File);
282  uint64_t RowAddress = Row.Address.Address;
283  // Watch out for a RowAddress that is in the middle of a line table entry
284  // in the DWARF. If we pass an address in between two line table entries
285  // we will get a RowIndex for the previous valid line table row which won't
286  // be contained in our function. This is usually a bug in the DWARF due to
287  // linker problems or LTO or other DWARF re-linking so it is worth emitting
288  // an error, but not worth stopping the creation of the GSYM.
289  if (!FI.Range.contains(RowAddress)) {
290  if (RowAddress < FI.Range.Start) {
291  Log << "error: DIE has a start address whose LowPC is between the "
292  "line table Row[" << RowIndex << "] with address "
293  << HEX64(RowAddress) << " and the next one.\n";
294  Die.dump(Log, 0, DIDumpOptions::getForSingleDIE());
295  RowAddress = FI.Range.Start;
296  } else {
297  continue;
298  }
299  }
300 
301  LineEntry LE(RowAddress, FileIdx, Row.Line);
302  if (RowIndex != RowVector[0] && Row.Address < PrevRow.Address) {
303  // We have seen full duplicate line tables for functions in some
304  // DWARF files. Watch for those here by checking the the last
305  // row was the function's end address (HighPC) and that the
306  // current line table entry's address is the same as the first
307  // line entry we already have in our "function_info.Lines". If
308  // so break out after printing a warning.
309  auto FirstLE = FI.OptLineTable->first();
310  if (FirstLE && *FirstLE == LE) {
311  if (!Gsym.isQuiet()) {
312  Log << "warning: duplicate line table detected for DIE:\n";
313  Die.dump(Log, 0, DIDumpOptions::getForSingleDIE());
314  }
315  } else {
316  // Print out (ignore if os == nulls as this is expensive)
317  Log << "error: line table has addresses that do not "
318  << "monotonically increase:\n";
319  for (uint32_t RowIndex2 : RowVector) {
320  CUI.LineTable->Rows[RowIndex2].dump(Log);
321  }
322  Die.dump(Log, 0, DIDumpOptions::getForSingleDIE());
323  }
324  break;
325  }
326 
327  // Skip multiple line entries for the same file and line.
328  auto LastLE = FI.OptLineTable->last();
329  if (LastLE && LastLE->File == FileIdx && LastLE->Line == Row.Line)
330  continue;
331  // Only push a row if it isn't an end sequence. End sequence markers are
332  // included for the last address in a function or the last contiguous
333  // address in a sequence.
334  if (Row.EndSequence) {
335  // End sequence means that the next line entry could have a lower address
336  // that the previous entries. So we clear the previous row so we don't
337  // trigger the line table error about address that do not monotonically
338  // increase.
339  PrevRow = DWARFDebugLine::Row();
340  } else {
341  FI.OptLineTable->push(LE);
342  PrevRow = Row;
343  }
344  }
345  // If not line table rows were added, clear the line table so we don't encode
346  // on in the GSYM file.
347  if (FI.OptLineTable->empty())
349 }
350 
351 void DwarfTransformer::handleDie(raw_ostream &OS, CUInfo &CUI, DWARFDie Die) {
352  switch (Die.getTag()) {
353  case dwarf::DW_TAG_subprogram: {
355  if (!RangesOrError) {
356  consumeError(RangesOrError.takeError());
357  break;
358  }
359  const DWARFAddressRangesVector &Ranges = RangesOrError.get();
360  if (Ranges.empty())
361  break;
362  auto NameIndex = getQualifiedNameIndex(Die, CUI.Language, Gsym);
363  if (!NameIndex) {
364  OS << "error: function at " << HEX64(Die.getOffset())
365  << " has no name\n ";
366  Die.dump(OS, 0, DIDumpOptions::getForSingleDIE());
367  break;
368  }
369 
370  // Create a function_info for each range
371  for (const DWARFAddressRange &Range : Ranges) {
372  // The low PC must be less than the high PC. Many linkers don't remove
373  // DWARF for functions that don't get linked into the final executable.
374  // If both the high and low pc have relocations, linkers will often set
375  // the address values for both to the same value to indicate the function
376  // has been remove. Other linkers have been known to set the one or both
377  // PC values to a UINT32_MAX for 4 byte addresses and UINT64_MAX for 8
378  // byte addresses to indicate the function isn't valid. The check below
379  // tries to watch for these cases and abort if it runs into them.
380  if (Range.LowPC >= Range.HighPC || CUI.isHighestAddress(Range.LowPC))
381  break;
382 
383  // Many linkers can't remove DWARF and might set the LowPC to zero. Since
384  // high PC can be an offset from the low PC in more recent DWARF versions
385  // we need to watch for a zero'ed low pc which we do using
386  // ValidTextRanges below.
387  if (!Gsym.IsValidTextAddress(Range.LowPC)) {
388  // We expect zero and -1 to be invalid addresses in DWARF depending
389  // on the linker of the DWARF. This indicates a function was stripped
390  // and the debug info wasn't able to be stripped from the DWARF. If
391  // the LowPC isn't zero or -1, then we should emit an error.
392  if (Range.LowPC != 0) {
393  if (!Gsym.isQuiet()) {
394  // Unexpected invalid address, emit a warning
395  OS << "warning: DIE has an address range whose start address is "
396  "not in any executable sections ("
397  << *Gsym.GetValidTextRanges()
398  << ") and will not be processed:\n";
399  Die.dump(OS, 0, DIDumpOptions::getForSingleDIE());
400  }
401  }
402  break;
403  }
404 
405  FunctionInfo FI;
406  FI.setStartAddress(Range.LowPC);
407  FI.setEndAddress(Range.HighPC);
408  FI.Name = *NameIndex;
409  if (CUI.LineTable) {
410  convertFunctionLineTable(OS, CUI, Die, Gsym, FI);
411  }
412  if (hasInlineInfo(Die, 0)) {
413  FI.Inline = InlineInfo();
414  FI.Inline->Name = *NameIndex;
415  FI.Inline->Ranges.insert(FI.Range);
416  parseInlineInfo(Gsym, CUI, Die, 0, FI, *FI.Inline);
417  }
418  Gsym.addFunctionInfo(std::move(FI));
419  }
420  } break;
421  default:
422  break;
423  }
424  for (DWARFDie ChildDie : Die.children())
425  handleDie(OS, CUI, ChildDie);
426 }
427 
429  size_t NumBefore = Gsym.getNumFunctionInfos();
430  if (NumThreads == 1) {
431  // Parse all DWARF data from this thread, use the same string/file table
432  // for everything
433  for (const auto &CU : DICtx.compile_units()) {
434  DWARFDie Die = CU->getUnitDIE(false);
435  CUInfo CUI(DICtx, dyn_cast<DWARFCompileUnit>(CU.get()));
436  handleDie(Log, CUI, Die);
437  }
438  } else {
439  // LLVM Dwarf parser is not thread-safe and we need to parse all DWARF up
440  // front before we start accessing any DIEs since there might be
441  // cross compile unit references in the DWARF. If we don't do this we can
442  // end up crashing.
443 
444  // We need to call getAbbreviations sequentially first so that getUnitDIE()
445  // only works with its local data.
446  for (const auto &CU : DICtx.compile_units())
447  CU->getAbbreviations();
448 
449  // Now parse all DIEs in case we have cross compile unit references in a
450  // thread pool.
451  ThreadPool pool(hardware_concurrency(NumThreads));
452  for (const auto &CU : DICtx.compile_units())
453  pool.async([&CU]() { CU->getUnitDIE(false /*CUDieOnly*/); });
454  pool.wait();
455 
456  // Now convert all DWARF to GSYM in a thread pool.
457  std::mutex LogMutex;
458  for (const auto &CU : DICtx.compile_units()) {
459  DWARFDie Die = CU->getUnitDIE(false /*CUDieOnly*/);
460  if (Die) {
461  CUInfo CUI(DICtx, dyn_cast<DWARFCompileUnit>(CU.get()));
462  pool.async([this, CUI, &LogMutex, Die]() mutable {
463  std::string ThreadLogStorage;
464  raw_string_ostream ThreadOS(ThreadLogStorage);
465  handleDie(ThreadOS, CUI, Die);
466  ThreadOS.flush();
467  if (!ThreadLogStorage.empty()) {
468  // Print ThreadLogStorage lines into an actual stream under a lock
469  std::lock_guard<std::mutex> guard(LogMutex);
470  Log << ThreadLogStorage;
471  }
472  });
473  }
474  }
475  pool.wait();
476  }
477  size_t FunctionsAddedCount = Gsym.getNumFunctionInfos() - NumBefore;
478  Log << "Loaded " << FunctionsAddedCount << " functions from DWARF.\n";
479  return Error::success();
480 }
481 
483  Log << "Verifying GSYM file \"" << GsymPath << "\":\n";
484 
485  auto Gsym = GsymReader::openFile(GsymPath);
486  if (!Gsym)
487  return Gsym.takeError();
488 
489  auto NumAddrs = Gsym->getNumAddresses();
490  DILineInfoSpecifier DLIS(
493  std::string gsymFilename;
494  for (uint32_t I = 0; I < NumAddrs; ++I) {
495  auto FuncAddr = Gsym->getAddress(I);
496  if (!FuncAddr)
497  return createStringError(std::errc::invalid_argument,
498  "failed to extract address[%i]", I);
499 
500  auto FI = Gsym->getFunctionInfo(*FuncAddr);
501  if (!FI)
502  return createStringError(std::errc::invalid_argument,
503  "failed to extract function info for address 0x%"
504  PRIu64, *FuncAddr);
505 
506  for (auto Addr = *FuncAddr; Addr < *FuncAddr + FI->size(); ++Addr) {
507  const object::SectionedAddress SectAddr{
509  auto LR = Gsym->lookup(Addr);
510  if (!LR)
511  return LR.takeError();
512 
513  auto DwarfInlineInfos =
514  DICtx.getInliningInfoForAddress(SectAddr, DLIS);
515  uint32_t NumDwarfInlineInfos = DwarfInlineInfos.getNumberOfFrames();
516  if (NumDwarfInlineInfos == 0) {
517  DwarfInlineInfos.addFrame(
518  DICtx.getLineInfoForAddress(SectAddr, DLIS));
519  }
520 
521  // Check for 1 entry that has no file and line info
522  if (NumDwarfInlineInfos == 1 &&
523  DwarfInlineInfos.getFrame(0).FileName == "<invalid>") {
524  DwarfInlineInfos = DIInliningInfo();
525  NumDwarfInlineInfos = 0;
526  }
527  if (NumDwarfInlineInfos > 0 &&
528  NumDwarfInlineInfos != LR->Locations.size()) {
529  Log << "error: address " << HEX64(Addr) << " has "
530  << NumDwarfInlineInfos << " DWARF inline frames and GSYM has "
531  << LR->Locations.size() << "\n";
532  Log << " " << NumDwarfInlineInfos << " DWARF frames:\n";
533  for (size_t Idx = 0; Idx < NumDwarfInlineInfos; ++Idx) {
534  const auto dii = DwarfInlineInfos.getFrame(Idx);
535  Log << " [" << Idx << "]: " << dii.FunctionName << " @ "
536  << dii.FileName << ':' << dii.Line << '\n';
537  }
538  Log << " " << LR->Locations.size() << " GSYM frames:\n";
539  for (size_t Idx = 0, count = LR->Locations.size();
540  Idx < count; ++Idx) {
541  const auto &gii = LR->Locations[Idx];
542  Log << " [" << Idx << "]: " << gii.Name << " @ " << gii.Dir
543  << '/' << gii.Base << ':' << gii.Line << '\n';
544  }
545  DwarfInlineInfos = DICtx.getInliningInfoForAddress(SectAddr, DLIS);
546  Gsym->dump(Log, *FI);
547  continue;
548  }
549 
550  for (size_t Idx = 0, count = LR->Locations.size(); Idx < count;
551  ++Idx) {
552  const auto &gii = LR->Locations[Idx];
553  if (Idx < NumDwarfInlineInfos) {
554  const auto dii = DwarfInlineInfos.getFrame(Idx);
555  gsymFilename = LR->getSourceFile(Idx);
556  // Verify function name
557  if (dii.FunctionName.find(gii.Name.str()) != 0)
558  Log << "error: address " << HEX64(Addr) << " DWARF function \""
559  << dii.FunctionName.c_str()
560  << "\" doesn't match GSYM function \"" << gii.Name << "\"\n";
561  // Verify source file path
562  if (dii.FileName != gsymFilename)
563  Log << "error: address " << HEX64(Addr) << " DWARF path \""
564  << dii.FileName.c_str() << "\" doesn't match GSYM path \""
565  << gsymFilename.c_str() << "\"\n";
566  // Verify source file line
567  if (dii.Line != gii.Line)
568  Log << "error: address " << HEX64(Addr) << " DWARF line "
569  << dii.Line << " != GSYM line " << gii.Line << "\n";
570  }
571  }
572  }
573  }
574  return Error::success();
575 }
llvm::StringRef::back
LLVM_NODISCARD char back() const
back - Get the last character in the string.
Definition: StringRef.h:168
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:929
llvm::hardware_concurrency
ThreadPoolStrategy hardware_concurrency(unsigned ThreadCount=0)
Returns a default thread strategy where all available hardware resources are to be used,...
Definition: Threading.h:188
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::gsym::FunctionInfo::size
uint64_t size() const
Definition: FunctionInfo.h:175
InlineInfo.h
llvm::StringRef::empty
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:153
llvm::gsym::FunctionInfo::Name
uint32_t Name
String table offset in the string table.
Definition: FunctionInfo.h:91
parseInlineInfo
static void parseInlineInfo(GsymCreator &Gsym, CUInfo &CUI, DWARFDie Die, uint32_t Depth, FunctionInfo &FI, InlineInfo &parent)
Definition: DwarfTransformer.cpp:207
llvm::gsym::GsymReader::openFile
static llvm::Expected< GsymReader > openFile(StringRef Path)
Construct a GsymReader from a file on disk.
Definition: GsymReader.cpp:34
llvm::gsym::CUInfo::DWARFToGSYMFileIndex
uint32_t DWARFToGSYMFileIndex(GsymCreator &Gsym, uint32_t DwarfFileIdx)
Convert a DWARF compile unit file index into a GSYM global file index.
Definition: DwarfTransformer.cpp:66
llvm::ThreadPool
A ThreadPool for asynchronous parallel execution on a defined number of threads.
Definition: ThreadPool.h:37
llvm::gsym::GsymCreator
GsymCreator is used to emit GSYM data to a stand alone file or section within a file.
Definition: GsymCreator.h:133
llvm::DIInliningInfo
A format-neutral container for inlined code description.
Definition: DIContext.h:87
DwarfTransformer.h
llvm::DILineInfoSpecifier
Controls which fields of DILineInfo container should be filled with data.
Definition: DIContext.h:135
llvm::gsym::AddressRanges::insert
void insert(AddressRange Range)
Definition: Range.cpp:19
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:625
llvm::gsym::LineTable::size
size_t size() const
Definition: LineTable.h:193
llvm::gsym::LineEntry
Line entries are used to encode the line tables in FunctionInfo objects.
Definition: LineEntry.h:22
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
pool
Implement PPCInstrInfo::isLoadFromStackSlot isStoreToStackSlot for vector to generate better spill code The first should be a single lvx from the constant pool
Definition: README_ALTIVEC.txt:8
DWARFContext.h
Error.h
llvm::gsym::FunctionInfo::OptLineTable
llvm::Optional< LineTable > OptLineTable
Definition: FunctionInfo.h:92
llvm::Depth
@ Depth
Definition: SIMachineScheduler.h:36
llvm::DWARFContext
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
Definition: DWARFContext.h:53
hasInlineInfo
static bool hasInlineInfo(DWARFDie Die, uint32_t Depth)
Definition: DwarfTransformer.cpp:186
llvm::gsym::CUInfo::FileCache
std::vector< uint32_t > FileCache
Definition: DwarfTransformer.cpp:30
llvm::Optional< uint32_t >
llvm::gsym::GsymCreator::IsValidTextAddress
bool IsValidTextAddress(uint64_t Addr) const
Check if an address is a valid code address.
Definition: GsymCreator.cpp:353
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
FunctionInfo.h
llvm::gsym::InlineInfo::CallFile
uint32_t CallFile
1 based file index in the file table.
Definition: InlineInfo.h:64
llvm::dwarf::Tag
Tag
Definition: Dwarf.h:104
llvm::DINameKind::LinkageName
@ LinkageName
llvm::DWARFDie::children
iterator_range< iterator > children() const
Definition: DWARFDie.h:385
llvm::DWARFAddressRange::LowPC
uint64_t LowPC
Definition: DWARFAddressRange.h:23
llvm::gsym::AddressRange::Start
uint64_t Start
Definition: Range.h:34
llvm::gsym::InlineInfo
Inline information stores the name of the inline function along with an array of address ranges.
Definition: InlineInfo.h:61
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1035
llvm::gsym::CUInfo
Definition: DwarfTransformer.cpp:27
llvm::DWARFContext::getInliningInfoForAddress
DIInliningInfo getInliningInfoForAddress(object::SectionedAddress Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
Definition: DWARFContext.cpp:1303
llvm::StringRef::substr
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:611
llvm::gsym::CUInfo::CUInfo
CUInfo(DWARFContext &DICtx, DWARFCompileUnit *CU)
Definition: DwarfTransformer.cpp:34
llvm::gsym::InlineInfo::CallLine
uint32_t CallLine
Source line number.
Definition: InlineInfo.h:65
llvm::DWARFDebugLine::Row
Standard .debug_line state machine structure.
Definition: DWARFDebugLine.h:136
llvm::DIDumpOptions::getForSingleDIE
static DIDumpOptions getForSingleDIE()
Return default option set for printing a single DIE without children.
Definition: DIContext.h:195
llvm::AMDGPU::HSAMD::Kernel::Key::Language
constexpr char Language[]
Key for Kernel::Metadata::mLanguage.
Definition: AMDGPUMetadata.h:383
UINT64_MAX
#define UINT64_MAX
Definition: DataTypes.h:77
llvm::gsym::FunctionInfo::startAddress
uint64_t startAddress() const
Definition: FunctionInfo.h:173
llvm::DWARFDie::getDeclFile
std::string getDeclFile(DILineInfoSpecifier::FileLineInfoKind Kind) const
Definition: DWARFDie.cpp:809
llvm::DWARFDebugLine::LineTable::Rows
RowVector Rows
Definition: DWARFDebugLine.h:289
InlineInfo
@ InlineInfo
Definition: FunctionInfo.cpp:24
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::AArch64CC::LE
@ LE
Definition: AArch64BaseInfo.h:268
llvm::raw_ostream::flush
void flush()
Definition: raw_ostream.h:186
llvm::gsym::AddressRanges::empty
bool empty() const
Definition: Range.h:90
llvm::gsym::FunctionInfo::Range
AddressRange Range
Definition: FunctionInfo.h:90
llvm::gsym::FunctionInfo::Inline
llvm::Optional< InlineInfo > Inline
Definition: FunctionInfo.h:93
llvm::StringRef::str
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:245
llvm::None
const NoneType None
Definition: None.h:23
llvm::gsym::LineTable
LineTable class contains deserialized versions of line tables for each function's address ranges.
Definition: LineTable.h:118
llvm::DWARFDebugLine::LineTable::lookupAddressRange
bool lookupAddressRange(object::SectionedAddress Address, uint64_t Size, std::vector< uint32_t > &Result) const
Definition: DWARFDebugLine.cpp:1265
llvm::DWARFContext::compile_units
compile_unit_range compile_units()
Get compile units in this context.
Definition: DWARFContext.h:167
llvm::gsym::FunctionInfo
Function information in GSYM files encodes information for one contiguous address range.
Definition: FunctionInfo.h:89
llvm::DWARFDie::dump
void dump(raw_ostream &OS, unsigned indent=0, DIDumpOptions DumpOpts=DIDumpOptions()) const
Dump the DIE and all of its attributes to the supplied stream.
Definition: DWARFDie.cpp:837
llvm::DWARFCompileUnit
Definition: DWARFCompileUnit.h:17
llvm::gsym::GsymCreator::GetValidTextRanges
const Optional< AddressRanges > GetValidTextRanges() const
Get the valid text ranges.
Definition: GsymCreator.h:252
ThreadPool.h
llvm::DINameKind::ShortName
@ ShortName
llvm::gsym::InlineInfo::Name
uint32_t Name
String table offset in the string table.
Definition: InlineInfo.h:63
llvm::DWARFAddressRange::HighPC
uint64_t HighPC
Definition: DWARFAddressRange.h:24
llvm::count
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
Definition: STLExtras.h:1634
llvm::gsym::CUInfo::Language
uint64_t Language
Definition: DwarfTransformer.cpp:31
uint64_t
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:80
llvm::DWARFDie::getAddressRanges
Expected< DWARFAddressRangesVector > getAddressRanges() const
Get the address ranges for this DIE.
Definition: DWARFDie.cpp:710
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::object::SectionedAddress::UndefSection
const static uint64_t UndefSection
Definition: ObjectFile.h:145
llvm::gsym::DwarfTransformer::convert
llvm::Error convert(uint32_t NumThreads)
Extract the DWARF from the supplied object file and convert it into the Gsym format in the GsymCreato...
Definition: DwarfTransformer.cpp:428
llvm::StringRef::front
LLVM_NODISCARD char front() const
front - Get the first character in the string.
Definition: StringRef.h:161
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::DWARFDie::find
Optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
Definition: DWARFDie.cpp:596
llvm::DWARFDie::getOffset
uint64_t getOffset() const
Get the absolute offset into the debug info or types section.
Definition: DWARFDie.h:67
llvm::gsym::CUInfo::AddrSize
uint8_t AddrSize
Definition: DwarfTransformer.cpp:32
llvm::gsym::FunctionInfo::endAddress
uint64_t endAddress() const
Definition: FunctionInfo.h:174
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::DWARFDie::findRecursively
Optional< DWARFFormValue > findRecursively(ArrayRef< dwarf::Attribute > Attrs) const
Extract the first value of any attribute in Attrs from this DIE and recurse into any DW_AT_specificat...
Definition: DWARFDie.cpp:620
llvm::gsym::DwarfTransformer::verify
llvm::Error verify(StringRef GsymPath)
Definition: DwarfTransformer.cpp:482
llvm::gsym::FunctionInfo::setEndAddress
void setEndAddress(uint64_t Addr)
Definition: FunctionInfo.h:177
llvm::dwarf::toString
Optional< const char * > toString(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
Definition: DWARFFormValue.h:175
llvm::gsym::GsymCreator::getNumFunctionInfos
size_t getNumFunctionInfos() const
Get the current number of FunctionInfo objects contained in this object.
Definition: GsymCreator.cpp:348
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::gsym::GsymCreator::addFunctionInfo
void addFunctionInfo(FunctionInfo &&FI)
Add a function info to this GSYM creator.
Definition: GsymCreator.cpp:324
llvm::Expected::get
reference get()
Returns a reference to the stored T value.
Definition: Error.h:569
uint32_t
llvm::DWARFDie::getName
const char * getName(DINameKind Kind) const
Return the DIE name resolving DW_AT_specification or DW_AT_abstract_origin references if necessary.
Definition: DWARFDie.cpp:777
llvm::gsym::CUInfo::CompDir
const char * CompDir
Definition: DwarfTransformer.cpp:29
llvm::gsym::GsymCreator::insertString
uint32_t insertString(StringRef S, bool Copy=true)
Insert a string into the GSYM string table.
Definition: GsymCreator.cpp:303
GsymReader.h
llvm::DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath
@ AbsoluteFilePath
llvm::DWARFContext::getLineInfoForAddress
DILineInfo getLineInfoForAddress(object::SectionedAddress Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
Definition: DWARFContext.cpp:1227
llvm::DWARFDie::getParent
DWARFDie getParent() const
Get the parent of this DIE object.
Definition: DWARFDie.cpp:893
llvm::gsym::AddressRange
A class that represents an address range.
Definition: Range.h:33
DIContext.h
llvm::gsym::CUInfo::LineTable
const DWARFDebugLine::LineTable * LineTable
Definition: DwarfTransformer.cpp:28
llvm::createStringError
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1231
llvm::DWARFAddressRangesVector
std::vector< DWARFAddressRange > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
Definition: DWARFAddressRange.h:83
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::gsym::FunctionInfo::setStartAddress
void setStartAddress(uint64_t Addr)
Definition: FunctionInfo.h:176
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::gsym::CUInfo::isHighestAddress
bool isHighestAddress(uint64_t Addr) const
Return true if Addr is the highest address for a given compile unit.
Definition: DwarfTransformer.cpp:49
llvm::DWARFDebugLine::Row::Address
object::SectionedAddress Address
The program-counter value corresponding to a machine instruction generated by the compiler and sectio...
Definition: DWARFDebugLine.h:156
llvm::gsym::GsymCreator::insertFile
uint32_t insertFile(StringRef Path, sys::path::Style Style=sys::path::Style::native)
Insert a file into this GSYM creator.
Definition: GsymCreator.cpp:28
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:210
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition: Error.h:589
llvm::gsym::GsymCreator::isQuiet
bool isQuiet() const
Whether the transformation should be quiet, i.e. not output warnings.
Definition: GsymCreator.h:293
llvm::DWARFDie::getAttributeValueAsReferencedDie
DWARFDie getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE as the referenced DIE.
Definition: DWARFDie.cpp:653
llvm::gsym::InlineInfo::Ranges
AddressRanges Ranges
Definition: InlineInfo.h:66
llvm::DWARFDie::getTag
dwarf::Tag getTag() const
Definition: DWARFDie.h:72
llvm::gsym::AddressRange::contains
bool contains(uint64_t Addr) const
Definition: Range.h:39
llvm::object::SectionedAddress
Definition: ObjectFile.h:144
convertFunctionLineTable
static void convertFunctionLineTable(raw_ostream &Log, CUInfo &CUI, DWARFDie Die, GsymCreator &Gsym, FunctionInfo &FI)
Definition: DwarfTransformer.cpp:249
llvm::DWARFDebugLine::LineTable
Definition: DWARFDebugLine.h:229
llvm::DWARFDie
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
Definition: DWARFDie.h:43
llvm::DWARFAddressRange
Definition: DWARFAddressRange.h:22
getQualifiedNameIndex
static Optional< uint32_t > getQualifiedNameIndex(DWARFDie &Die, uint64_t Language, GsymCreator &Gsym)
Get the GsymCreator string table offset for the qualified name for the DIE passed in.
Definition: DwarfTransformer.cpp:130
raw_ostream.h
llvm::StringRef::size
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:157
GsymCreator.h
CU
Definition: AArch64AsmBackend.cpp:501
HEX64
#define HEX64(v)
Definition: Range.h:21
File
Instrumentation for Order File
Definition: InstrOrderFile.cpp:205
llvm::gsym::InlineInfo::Children
std::vector< InlineInfo > Children
Definition: InlineInfo.h:67
GetParentDeclContextDIE
static DWARFDie GetParentDeclContextDIE(DWARFDie &Die)
Definition: DwarfTransformer.cpp:85