LLVM  10.0.0
Symbolize.cpp
Go to the documentation of this file.
1 //===-- LLVMSymbolize.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 // Implementation for LLVM symbolization library.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 
15 #include "SymbolizableObjectFile.h"
16 
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/BinaryFormat/COFF.h"
20 #include "llvm/DebugInfo/PDB/PDB.h"
22 #include "llvm/Demangle/Demangle.h"
23 #include "llvm/Object/COFF.h"
24 #include "llvm/Object/MachO.h"
26 #include "llvm/Support/CRC.h"
27 #include "llvm/Support/Casting.h"
30 #include "llvm/Support/Errc.h"
33 #include "llvm/Support/Path.h"
34 #include <algorithm>
35 #include <cassert>
36 #include <cstring>
37 
38 namespace llvm {
39 namespace symbolize {
40 
41 Expected<DILineInfo>
42 LLVMSymbolizer::symbolizeCodeCommon(SymbolizableModule *Info,
43  object::SectionedAddress ModuleOffset) {
44  // A null module means an error has already been reported. Return an empty
45  // result.
46  if (!Info)
47  return DILineInfo();
48 
49  // If the user is giving us relative addresses, add the preferred base of the
50  // object to the offset before we do the query. It's what DIContext expects.
51  if (Opts.RelativeAddresses)
52  ModuleOffset.Address += Info->getModulePreferredBase();
53 
54  DILineInfo LineInfo = Info->symbolizeCode(ModuleOffset, Opts.PrintFunctions,
55  Opts.UseSymbolTable);
56  if (Opts.Demangle)
57  LineInfo.FunctionName = DemangleName(LineInfo.FunctionName, Info);
58  return LineInfo;
59 }
60 
61 Expected<DILineInfo>
63  object::SectionedAddress ModuleOffset) {
64  StringRef ModuleName = Obj.getFileName();
65  auto I = Modules.find(ModuleName);
66  if (I != Modules.end())
67  return symbolizeCodeCommon(I->second.get(), ModuleOffset);
68 
69  std::unique_ptr<DIContext> Context =
72  createModuleInfo(&Obj, std::move(Context), ModuleName);
73  if (!InfoOrErr)
74  return InfoOrErr.takeError();
75  return symbolizeCodeCommon(*InfoOrErr, ModuleOffset);
76 }
77 
79 LLVMSymbolizer::symbolizeCode(const std::string &ModuleName,
80  object::SectionedAddress ModuleOffset) {
81  Expected<SymbolizableModule *> InfoOrErr = getOrCreateModuleInfo(ModuleName);
82  if (!InfoOrErr)
83  return InfoOrErr.takeError();
84  return symbolizeCodeCommon(*InfoOrErr, ModuleOffset);
85 }
86 
88 LLVMSymbolizer::symbolizeInlinedCode(const std::string &ModuleName,
89  object::SectionedAddress ModuleOffset) {
91  if (auto InfoOrErr = getOrCreateModuleInfo(ModuleName))
92  Info = InfoOrErr.get();
93  else
94  return InfoOrErr.takeError();
95 
96  // A null module means an error has already been reported. Return an empty
97  // result.
98  if (!Info)
99  return DIInliningInfo();
100 
101  // If the user is giving us relative addresses, add the preferred base of the
102  // object to the offset before we do the query. It's what DIContext expects.
103  if (Opts.RelativeAddresses)
104  ModuleOffset.Address += Info->getModulePreferredBase();
105 
106  DIInliningInfo InlinedContext = Info->symbolizeInlinedCode(
107  ModuleOffset, Opts.PrintFunctions, Opts.UseSymbolTable);
108  if (Opts.Demangle) {
109  for (int i = 0, n = InlinedContext.getNumberOfFrames(); i < n; i++) {
110  auto *Frame = InlinedContext.getMutableFrame(i);
111  Frame->FunctionName = DemangleName(Frame->FunctionName, Info);
112  }
113  }
114  return InlinedContext;
115 }
116 
118 LLVMSymbolizer::symbolizeData(const std::string &ModuleName,
119  object::SectionedAddress ModuleOffset) {
121  if (auto InfoOrErr = getOrCreateModuleInfo(ModuleName))
122  Info = InfoOrErr.get();
123  else
124  return InfoOrErr.takeError();
125 
126  // A null module means an error has already been reported. Return an empty
127  // result.
128  if (!Info)
129  return DIGlobal();
130 
131  // If the user is giving us relative addresses, add the preferred base of
132  // the object to the offset before we do the query. It's what DIContext
133  // expects.
134  if (Opts.RelativeAddresses)
135  ModuleOffset.Address += Info->getModulePreferredBase();
136 
137  DIGlobal Global = Info->symbolizeData(ModuleOffset);
138  if (Opts.Demangle)
139  Global.Name = DemangleName(Global.Name, Info);
140  return Global;
141 }
142 
144 LLVMSymbolizer::symbolizeFrame(const std::string &ModuleName,
145  object::SectionedAddress ModuleOffset) {
147  if (auto InfoOrErr = getOrCreateModuleInfo(ModuleName))
148  Info = InfoOrErr.get();
149  else
150  return InfoOrErr.takeError();
151 
152  // A null module means an error has already been reported. Return an empty
153  // result.
154  if (!Info)
155  return std::vector<DILocal>();
156 
157  // If the user is giving us relative addresses, add the preferred base of
158  // the object to the offset before we do the query. It's what DIContext
159  // expects.
160  if (Opts.RelativeAddresses)
161  ModuleOffset.Address += Info->getModulePreferredBase();
162 
163  return Info->symbolizeFrame(ModuleOffset);
164 }
165 
167  ObjectForUBPathAndArch.clear();
168  BinaryForPath.clear();
169  ObjectPairForPathArch.clear();
170  Modules.clear();
171 }
172 
173 namespace {
174 
175 // For Path="/path/to/foo" and Basename="foo" assume that debug info is in
176 // /path/to/foo.dSYM/Contents/Resources/DWARF/foo.
177 // For Path="/path/to/bar.dSYM" and Basename="foo" assume that debug info is in
178 // /path/to/bar.dSYM/Contents/Resources/DWARF/foo.
179 std::string getDarwinDWARFResourceForPath(
180  const std::string &Path, const std::string &Basename) {
181  SmallString<16> ResourceName = StringRef(Path);
182  if (sys::path::extension(Path) != ".dSYM") {
183  ResourceName += ".dSYM";
184  }
185  sys::path::append(ResourceName, "Contents", "Resources", "DWARF");
186  sys::path::append(ResourceName, Basename);
187  return ResourceName.str();
188 }
189 
190 bool checkFileCRC(StringRef Path, uint32_t CRCHash) {
193  if (!MB)
194  return false;
195  return CRCHash == llvm::crc32(arrayRefFromStringRef(MB.get()->getBuffer()));
196 }
197 
198 bool findDebugBinary(const std::string &OrigPath,
199  const std::string &DebuglinkName, uint32_t CRCHash,
200  const std::string &FallbackDebugPath,
201  std::string &Result) {
202  SmallString<16> OrigDir(OrigPath);
204  SmallString<16> DebugPath = OrigDir;
205  // Try relative/path/to/original_binary/debuglink_name
206  llvm::sys::path::append(DebugPath, DebuglinkName);
207  if (checkFileCRC(DebugPath, CRCHash)) {
208  Result = DebugPath.str();
209  return true;
210  }
211  // Try relative/path/to/original_binary/.debug/debuglink_name
212  DebugPath = OrigDir;
213  llvm::sys::path::append(DebugPath, ".debug", DebuglinkName);
214  if (checkFileCRC(DebugPath, CRCHash)) {
215  Result = DebugPath.str();
216  return true;
217  }
218  // Make the path absolute so that lookups will go to
219  // "/usr/lib/debug/full/path/to/debug", not
220  // "/usr/lib/debug/to/debug"
222  if (!FallbackDebugPath.empty()) {
223  // Try <FallbackDebugPath>/absolute/path/to/original_binary/debuglink_name
224  DebugPath = FallbackDebugPath;
225  } else {
226 #if defined(__NetBSD__)
227  // Try /usr/libdata/debug/absolute/path/to/original_binary/debuglink_name
228  DebugPath = "/usr/libdata/debug";
229 #else
230  // Try /usr/lib/debug/absolute/path/to/original_binary/debuglink_name
231  DebugPath = "/usr/lib/debug";
232 #endif
233  }
235  DebuglinkName);
236  if (checkFileCRC(DebugPath, CRCHash)) {
237  Result = DebugPath.str();
238  return true;
239  }
240  return false;
241 }
242 
243 bool getGNUDebuglinkContents(const ObjectFile *Obj, std::string &DebugName,
244  uint32_t &CRCHash) {
245  if (!Obj)
246  return false;
247  for (const SectionRef &Section : Obj->sections()) {
248  StringRef Name;
249  if (Expected<StringRef> NameOrErr = Section.getName())
250  Name = *NameOrErr;
251  else
252  consumeError(NameOrErr.takeError());
253 
254  Name = Name.substr(Name.find_first_not_of("._"));
255  if (Name == "gnu_debuglink") {
256  Expected<StringRef> ContentsOrErr = Section.getContents();
257  if (!ContentsOrErr) {
258  consumeError(ContentsOrErr.takeError());
259  return false;
260  }
261  DataExtractor DE(*ContentsOrErr, Obj->isLittleEndian(), 0);
262  uint64_t Offset = 0;
263  if (const char *DebugNameStr = DE.getCStr(&Offset)) {
264  // 4-byte align the offset.
265  Offset = (Offset + 3) & ~0x3;
266  if (DE.isValidOffsetForDataOfSize(Offset, 4)) {
267  DebugName = DebugNameStr;
268  CRCHash = DE.getU32(&Offset);
269  return true;
270  }
271  }
272  break;
273  }
274  }
275  return false;
276 }
277 
278 bool darwinDsymMatchesBinary(const MachOObjectFile *DbgObj,
279  const MachOObjectFile *Obj) {
280  ArrayRef<uint8_t> dbg_uuid = DbgObj->getUuid();
281  ArrayRef<uint8_t> bin_uuid = Obj->getUuid();
282  if (dbg_uuid.empty() || bin_uuid.empty())
283  return false;
284  return !memcmp(dbg_uuid.data(), bin_uuid.data(), dbg_uuid.size());
285 }
286 
287 template <typename ELFT>
288 Optional<ArrayRef<uint8_t>> getBuildID(const ELFFile<ELFT> *Obj) {
289  if (!Obj)
290  return {};
291  auto PhdrsOrErr = Obj->program_headers();
292  if (!PhdrsOrErr) {
293  consumeError(PhdrsOrErr.takeError());
294  return {};
295  }
296  for (const auto &P : *PhdrsOrErr) {
297  if (P.p_type != ELF::PT_NOTE)
298  continue;
299  Error Err = Error::success();
300  for (auto N : Obj->notes(P, Err))
301  if (N.getType() == ELF::NT_GNU_BUILD_ID && N.getName() == ELF::ELF_NOTE_GNU)
302  return N.getDesc();
303  }
304  return {};
305 }
306 
307 Optional<ArrayRef<uint8_t>> getBuildID(const ELFObjectFileBase *Obj) {
309  if (auto *O = dyn_cast<ELFObjectFile<ELF32LE>>(Obj))
310  BuildID = getBuildID(O->getELFFile());
311  else if (auto *O = dyn_cast<ELFObjectFile<ELF32BE>>(Obj))
312  BuildID = getBuildID(O->getELFFile());
313  else if (auto *O = dyn_cast<ELFObjectFile<ELF64LE>>(Obj))
314  BuildID = getBuildID(O->getELFFile());
315  else if (auto *O = dyn_cast<ELFObjectFile<ELF64BE>>(Obj))
316  BuildID = getBuildID(O->getELFFile());
317  else
318  llvm_unreachable("unsupported file format");
319  return BuildID;
320 }
321 
322 bool findDebugBinary(const std::vector<std::string> &DebugFileDirectory,
323  const ArrayRef<uint8_t> BuildID,
324  std::string &Result) {
325  auto getDebugPath = [&](StringRef Directory) {
326  SmallString<128> Path{Directory};
327  sys::path::append(Path, ".build-id",
328  llvm::toHex(BuildID[0], /*LowerCase=*/true),
329  llvm::toHex(BuildID.slice(1), /*LowerCase=*/true));
330  Path += ".debug";
331  return Path;
332  };
333  if (DebugFileDirectory.empty()) {
334  SmallString<128> Path = getDebugPath(
335 #if defined(__NetBSD__)
336  // Try /usr/libdata/debug/.build-id/../...
337  "/usr/libdata/debug"
338 #else
339  // Try /usr/lib/debug/.build-id/../...
340  "/usr/lib/debug"
341 #endif
342  );
343  if (llvm::sys::fs::exists(Path)) {
344  Result = Path.str();
345  return true;
346  }
347  } else {
348  for (const auto &Directory : DebugFileDirectory) {
349  // Try <debug-file-directory>/.build-id/../...
350  SmallString<128> Path = getDebugPath(Directory);
351  if (llvm::sys::fs::exists(Path)) {
352  Result = Path.str();
353  return true;
354  }
355  }
356  }
357  return false;
358 }
359 
360 } // end anonymous namespace
361 
362 ObjectFile *LLVMSymbolizer::lookUpDsymFile(const std::string &ExePath,
363  const MachOObjectFile *MachExeObj, const std::string &ArchName) {
364  // On Darwin we may find DWARF in separate object file in
365  // resource directory.
366  std::vector<std::string> DsymPaths;
367  StringRef Filename = sys::path::filename(ExePath);
368  DsymPaths.push_back(getDarwinDWARFResourceForPath(ExePath, Filename));
369  for (const auto &Path : Opts.DsymHints) {
370  DsymPaths.push_back(getDarwinDWARFResourceForPath(Path, Filename));
371  }
372  for (const auto &Path : DsymPaths) {
373  auto DbgObjOrErr = getOrCreateObject(Path, ArchName);
374  if (!DbgObjOrErr) {
375  // Ignore errors, the file might not exist.
376  consumeError(DbgObjOrErr.takeError());
377  continue;
378  }
379  ObjectFile *DbgObj = DbgObjOrErr.get();
380  if (!DbgObj)
381  continue;
382  const MachOObjectFile *MachDbgObj = dyn_cast<const MachOObjectFile>(DbgObj);
383  if (!MachDbgObj)
384  continue;
385  if (darwinDsymMatchesBinary(MachDbgObj, MachExeObj))
386  return DbgObj;
387  }
388  return nullptr;
389 }
390 
391 ObjectFile *LLVMSymbolizer::lookUpDebuglinkObject(const std::string &Path,
392  const ObjectFile *Obj,
393  const std::string &ArchName) {
394  std::string DebuglinkName;
395  uint32_t CRCHash;
396  std::string DebugBinaryPath;
397  if (!getGNUDebuglinkContents(Obj, DebuglinkName, CRCHash))
398  return nullptr;
399  if (!findDebugBinary(Path, DebuglinkName, CRCHash, Opts.FallbackDebugPath,
400  DebugBinaryPath))
401  return nullptr;
402  auto DbgObjOrErr = getOrCreateObject(DebugBinaryPath, ArchName);
403  if (!DbgObjOrErr) {
404  // Ignore errors, the file might not exist.
405  consumeError(DbgObjOrErr.takeError());
406  return nullptr;
407  }
408  return DbgObjOrErr.get();
409 }
410 
411 ObjectFile *LLVMSymbolizer::lookUpBuildIDObject(const std::string &Path,
412  const ELFObjectFileBase *Obj,
413  const std::string &ArchName) {
414  auto BuildID = getBuildID(Obj);
415  if (!BuildID)
416  return nullptr;
417  if (BuildID->size() < 2)
418  return nullptr;
419  std::string DebugBinaryPath;
420  if (!findDebugBinary(Opts.DebugFileDirectory, *BuildID, DebugBinaryPath))
421  return nullptr;
422  auto DbgObjOrErr = getOrCreateObject(DebugBinaryPath, ArchName);
423  if (!DbgObjOrErr) {
424  consumeError(DbgObjOrErr.takeError());
425  return nullptr;
426  }
427  return DbgObjOrErr.get();
428 }
429 
431 LLVMSymbolizer::getOrCreateObjectPair(const std::string &Path,
432  const std::string &ArchName) {
433  auto I = ObjectPairForPathArch.find(std::make_pair(Path, ArchName));
434  if (I != ObjectPairForPathArch.end())
435  return I->second;
436 
437  auto ObjOrErr = getOrCreateObject(Path, ArchName);
438  if (!ObjOrErr) {
439  ObjectPairForPathArch.emplace(std::make_pair(Path, ArchName),
440  ObjectPair(nullptr, nullptr));
441  return ObjOrErr.takeError();
442  }
443 
444  ObjectFile *Obj = ObjOrErr.get();
445  assert(Obj != nullptr);
446  ObjectFile *DbgObj = nullptr;
447 
448  if (auto MachObj = dyn_cast<const MachOObjectFile>(Obj))
449  DbgObj = lookUpDsymFile(Path, MachObj, ArchName);
450  else if (auto ELFObj = dyn_cast<const ELFObjectFileBase>(Obj))
451  DbgObj = lookUpBuildIDObject(Path, ELFObj, ArchName);
452  if (!DbgObj)
453  DbgObj = lookUpDebuglinkObject(Path, Obj, ArchName);
454  if (!DbgObj)
455  DbgObj = Obj;
456  ObjectPair Res = std::make_pair(Obj, DbgObj);
457  ObjectPairForPathArch.emplace(std::make_pair(Path, ArchName), Res);
458  return Res;
459 }
460 
462 LLVMSymbolizer::getOrCreateObject(const std::string &Path,
463  const std::string &ArchName) {
464  Binary *Bin;
465  auto Pair = BinaryForPath.emplace(Path, OwningBinary<Binary>());
466  if (!Pair.second) {
467  Bin = Pair.first->second.getBinary();
468  } else {
470  if (!BinOrErr)
471  return BinOrErr.takeError();
472  Pair.first->second = std::move(BinOrErr.get());
473  Bin = Pair.first->second.getBinary();
474  }
475 
476  if (!Bin)
477  return static_cast<ObjectFile *>(nullptr);
478 
479  if (MachOUniversalBinary *UB = dyn_cast_or_null<MachOUniversalBinary>(Bin)) {
480  auto I = ObjectForUBPathAndArch.find(std::make_pair(Path, ArchName));
481  if (I != ObjectForUBPathAndArch.end())
482  return I->second.get();
483 
485  UB->getMachOObjectForArch(ArchName);
486  if (!ObjOrErr) {
487  ObjectForUBPathAndArch.emplace(std::make_pair(Path, ArchName),
488  std::unique_ptr<ObjectFile>());
489  return ObjOrErr.takeError();
490  }
491  ObjectFile *Res = ObjOrErr->get();
492  ObjectForUBPathAndArch.emplace(std::make_pair(Path, ArchName),
493  std::move(ObjOrErr.get()));
494  return Res;
495  }
496  if (Bin->isObject()) {
497  return cast<ObjectFile>(Bin);
498  }
499  return errorCodeToError(object_error::arch_not_found);
500 }
501 
503 LLVMSymbolizer::createModuleInfo(const ObjectFile *Obj,
504  std::unique_ptr<DIContext> Context,
505  StringRef ModuleName) {
506  auto InfoOrErr = SymbolizableObjectFile::create(Obj, std::move(Context),
507  Opts.UntagAddresses);
508  std::unique_ptr<SymbolizableModule> SymMod;
509  if (InfoOrErr)
510  SymMod = std::move(*InfoOrErr);
511  auto InsertResult =
512  Modules.insert(std::make_pair(ModuleName, std::move(SymMod)));
513  assert(InsertResult.second);
514  if (std::error_code EC = InfoOrErr.getError())
515  return errorCodeToError(EC);
516  return InsertResult.first->second.get();
517 }
518 
520 LLVMSymbolizer::getOrCreateModuleInfo(const std::string &ModuleName) {
521  auto I = Modules.find(ModuleName);
522  if (I != Modules.end())
523  return I->second.get();
524 
525  std::string BinaryName = ModuleName;
526  std::string ArchName = Opts.DefaultArch;
527  size_t ColonPos = ModuleName.find_last_of(':');
528  // Verify that substring after colon form a valid arch name.
529  if (ColonPos != std::string::npos) {
530  std::string ArchStr = ModuleName.substr(ColonPos + 1);
531  if (Triple(ArchStr).getArch() != Triple::UnknownArch) {
532  BinaryName = ModuleName.substr(0, ColonPos);
533  ArchName = ArchStr;
534  }
535  }
536  auto ObjectsOrErr = getOrCreateObjectPair(BinaryName, ArchName);
537  if (!ObjectsOrErr) {
538  // Failed to find valid object file.
539  Modules.emplace(ModuleName, std::unique_ptr<SymbolizableModule>());
540  return ObjectsOrErr.takeError();
541  }
542  ObjectPair Objects = ObjectsOrErr.get();
543 
544  std::unique_ptr<DIContext> Context;
545  // If this is a COFF object containing PDB info, use a PDBContext to
546  // symbolize. Otherwise, use DWARF.
547  if (auto CoffObject = dyn_cast<COFFObjectFile>(Objects.first)) {
548  const codeview::DebugInfo *DebugInfo;
549  StringRef PDBFileName;
550  auto EC = CoffObject->getDebugPDBInfo(DebugInfo, PDBFileName);
551  if (!EC && DebugInfo != nullptr && !PDBFileName.empty()) {
552  using namespace pdb;
553  std::unique_ptr<IPDBSession> Session;
554  if (auto Err = loadDataForEXE(PDB_ReaderType::DIA,
555  Objects.first->getFileName(), Session)) {
556  Modules.emplace(ModuleName, std::unique_ptr<SymbolizableModule>());
557  // Return along the PDB filename to provide more context
558  return createFileError(PDBFileName, std::move(Err));
559  }
560  Context.reset(new PDBContext(*CoffObject, std::move(Session)));
561  }
562  }
563  if (!Context)
564  Context =
565  DWARFContext::create(*Objects.second, nullptr,
566  DWARFContext::defaultErrorHandler, Opts.DWPName);
567  return createModuleInfo(Objects.first, std::move(Context), ModuleName);
568 }
569 
570 namespace {
571 
572 // Undo these various manglings for Win32 extern "C" functions:
573 // cdecl - _foo
574 // stdcall - _foo@12
575 // fastcall - @foo@12
576 // vectorcall - foo@@12
577 // These are all different linkage names for 'foo'.
578 StringRef demanglePE32ExternCFunc(StringRef SymbolName) {
579  // Remove any '_' or '@' prefix.
580  char Front = SymbolName.empty() ? '\0' : SymbolName[0];
581  if (Front == '_' || Front == '@')
582  SymbolName = SymbolName.drop_front();
583 
584  // Remove any '@[0-9]+' suffix.
585  if (Front != '?') {
586  size_t AtPos = SymbolName.rfind('@');
587  if (AtPos != StringRef::npos &&
588  std::all_of(SymbolName.begin() + AtPos + 1, SymbolName.end(),
589  [](char C) { return C >= '0' && C <= '9'; })) {
590  SymbolName = SymbolName.substr(0, AtPos);
591  }
592  }
593 
594  // Remove any ending '@' for vectorcall.
595  if (SymbolName.endswith("@"))
596  SymbolName = SymbolName.drop_back();
597 
598  return SymbolName;
599 }
600 
601 } // end anonymous namespace
602 
603 std::string
605  const SymbolizableModule *DbiModuleDescriptor) {
606  // We can spoil names of symbols with C linkage, so use an heuristic
607  // approach to check if the name should be demangled.
608  if (Name.substr(0, 2) == "_Z") {
609  int status = 0;
610  char *DemangledName = itaniumDemangle(Name.c_str(), nullptr, nullptr, &status);
611  if (status != 0)
612  return Name;
613  std::string Result = DemangledName;
614  free(DemangledName);
615  return Result;
616  }
617 
618  if (!Name.empty() && Name.front() == '?') {
619  // Only do MSVC C++ demangling on symbols starting with '?'.
620  int status = 0;
621  char *DemangledName = microsoftDemangle(
622  Name.c_str(), nullptr, nullptr, &status,
625  if (status != 0)
626  return Name;
627  std::string Result = DemangledName;
628  free(DemangledName);
629  return Result;
630  }
631 
632  if (DbiModuleDescriptor && DbiModuleDescriptor->isWin32Module())
633  return std::string(demanglePE32ExternCFunc(Name));
634  return Name;
635 }
636 
637 } // namespace symbolize
638 } // namespace llvm
uint32_t crc32(ArrayRef< uint8_t > Data)
Definition: CRC.cpp:101
uint64_t CallInst * C
Represents either an error or a value T.
Definition: ErrorOr.h:56
void remove_filename(SmallVectorImpl< char > &path, Style style=Style::native)
Remove the last component from path unless it is the root dir.
Definition: Path.cpp:474
DILineInfo * getMutableFrame(unsigned Index)
Definition: DIContext.h:92
char * itaniumDemangle(const char *mangled_name, char *buf, size_t *n, int *status)
LLVMContext & Context
LLVM_NODISCARD bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
Definition: StringRef.h:288
iterator_range< Elf_Note_Iterator > notes(const Elf_Phdr &Phdr, Error &Err) const
Get an iterator range over notes of a program header.
Definition: ELF.h:261
This class represents lattice values for constants.
Definition: AllocatorList.h:23
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
StringRef getFileName() const
Definition: Binary.cpp:42
LLVM_NODISCARD size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
Definition: StringRef.h:366
Expected< DILineInfo > symbolizeCode(const ObjectFile &Obj, object::SectionedAddress ModuleOffset)
Definition: Symbolize.cpp:62
This class is the base class for all object file types.
Definition: ObjectFile.h:223
ArrayRef< uint8_t > arrayRefFromStringRef(StringRef Input)
Construct a string ref from an array ref of unsigned chars.
Definition: StringExtras.h:60
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1182
Error takeError()
Take ownership of the stored error.
Definition: Error.h:552
virtual bool isWin32Module() const =0
Expected< Elf_Phdr_Range > program_headers() const
Iterate over program header table.
Definition: ELF.h:193
Expected< std::unique_ptr< Binary > > createBinary(MemoryBufferRef Source, LLVMContext *Context=nullptr)
Create a Binary from Source, autodetecting the file type.
Definition: Binary.cpp:46
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition: Path.cpp:455
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
LLVM_NODISCARD StringRef drop_front(size_t N=1) const
Return a StringRef equal to &#39;this&#39; but with the first N elements dropped.
Definition: StringRef.h:642
void make_absolute(const Twine &current_directory, SmallVectorImpl< char > &path)
Make path an absolute path.
Definition: Path.cpp:876
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
Expected< DIGlobal > symbolizeData(const std::string &ModuleName, object::SectionedAddress ModuleOffset)
Definition: Symbolize.cpp:118
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:600
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:147
StringRef str() const
Explicit conversion to StringRef.
Definition: SmallString.h:266
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:25
section_iterator_range sections() const
Definition: ObjectFile.h:312
uint32_t getNumberOfFrames() const
Definition: DIContext.h:97
Analysis containing CSE Info
Definition: CSEInfo.cpp:25
#define P(N)
Error loadDataForEXE(PDB_ReaderType Type, StringRef Path, std::unique_ptr< IPDBSession > &Session)
Definition: PDB.cpp:43
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:158
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:87
A format-neutral container for inlined code description.
Definition: DIContext.h:81
std::vector< std::string > DsymHints
Definition: Symbolize.h:45
static ErrorPolicy defaultErrorHandler(Error E)
Function used to handle default error reporting policy.
MSDemangleFlags
Definition: Demangle.h:35
Expected< std::vector< DILocal > > symbolizeFrame(const std::string &ModuleName, object::SectionedAddress ModuleOffset)
Definition: Symbolize.cpp:144
Expected< DIInliningInfo > symbolizeInlinedCode(const std::string &ModuleName, object::SectionedAddress ModuleOffset)
Definition: Symbolize.cpp:88
virtual DIInliningInfo symbolizeInlinedCode(object::SectionedAddress ModuleOffset, FunctionNameKind FNKind, bool UseSymbolTable) const =0
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1001
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isLittleEndian() const
Definition: Binary.h:146
const T * data() const
Definition: ArrayRef.h:155
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:43
static std::unique_ptr< DWARFContext > create(const object::ObjectFile &Obj, const LoadedObjectInfo *L=nullptr, function_ref< ErrorPolicy(Error)> HandleError=defaultErrorHandler, std::string DWPName="")
static ErrorSuccess success()
Create a success value.
Definition: Error.h:326
static std::string DemangleName(const std::string &Name, const SymbolizableModule *DbiModuleDescriptor)
Definition: Symbolize.cpp:604
virtual std::vector< DILocal > symbolizeFrame(object::SectionedAddress ModuleOffset) const =0
ArrayRef< uint8_t > getUuid() const
std::string Name
Definition: DIContext.h:112
std::string FunctionName
Definition: DIContext.h:36
reference get()
Returns a reference to the stored T value.
Definition: Error.h:532
bool isObject() const
Definition: Binary.h:102
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array...
Definition: ArrayRef.h:188
iterator begin() const
Definition: StringRef.h:122
virtual uint64_t getModulePreferredBase() const =0
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
constexpr const char * ELF_NOTE_GNU
Definition: ELF.h:1523
Merge contiguous icmps into a memcmp
Definition: MergeICmps.cpp:928
static const size_t npos
Definition: StringRef.h:56
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
Definition: Path.cpp:588
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:332
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef relative_path(StringRef path, Style style=Style::native)
Get relative path.
Definition: Path.cpp:412
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
Definition: Error.h:1273
LLVM_NODISCARD StringRef drop_back(size_t N=1) const
Return a StringRef equal to &#39;this&#39; but with the last N elements dropped.
Definition: StringRef.h:650
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:54
static ErrorOr< std::unique_ptr< SymbolizableObjectFile > > create(const object::ObjectFile *Obj, std::unique_ptr< DIContext > DICtx, bool UntagAddresses)
std::string toHex(StringRef Input, bool LowerCase=false)
Convert buffer Input to its hexadecimal representation.
Definition: StringExtras.h:141
bool exists(const basic_file_status &status)
Does file exist?
Definition: Path.cpp:1048
iterator end() const
Definition: StringRef.h:124
virtual DIGlobal symbolizeData(object::SectionedAddress ModuleOffset) const =0
char * microsoftDemangle(const char *mangled_name, char *buf, size_t *n, int *status, MSDemangleFlags Flags=MSDF_None)
reference get()
Definition: ErrorOr.h:156
Container for description of a global variable.
Definition: DIContext.h:111
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:153
This is a value type class that represents a single section in the list of sections in the object fil...
Definition: ObjectFile.h:81
StringRef extension(StringRef path, Style style=Style::native)
Get extension.
Definition: Path.cpp:603
std::vector< std::string > DebugFileDirectory
Definition: Symbolize.h:48