LLVM  12.0.0git
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(
55  ModuleOffset, DILineInfoSpecifier(Opts.PathStyle, Opts.PrintFunctions),
56  Opts.UseSymbolTable);
57  if (Opts.Demangle)
58  LineInfo.FunctionName = DemangleName(LineInfo.FunctionName, Info);
59  return LineInfo;
60 }
61 
62 Expected<DILineInfo>
64  object::SectionedAddress ModuleOffset) {
65  StringRef ModuleName = Obj.getFileName();
66  auto I = Modules.find(ModuleName);
67  if (I != Modules.end())
68  return symbolizeCodeCommon(I->second.get(), ModuleOffset);
69 
70  std::unique_ptr<DIContext> Context = DWARFContext::create(Obj);
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, DILineInfoSpecifier(Opts.PathStyle, Opts.PrintFunctions),
108  Opts.UseSymbolTable);
109  if (Opts.Demangle) {
110  for (int i = 0, n = InlinedContext.getNumberOfFrames(); i < n; i++) {
111  auto *Frame = InlinedContext.getMutableFrame(i);
112  Frame->FunctionName = DemangleName(Frame->FunctionName, Info);
113  }
114  }
115  return InlinedContext;
116 }
117 
119 LLVMSymbolizer::symbolizeData(const std::string &ModuleName,
120  object::SectionedAddress ModuleOffset) {
122  if (auto InfoOrErr = getOrCreateModuleInfo(ModuleName))
123  Info = InfoOrErr.get();
124  else
125  return InfoOrErr.takeError();
126 
127  // A null module means an error has already been reported. Return an empty
128  // result.
129  if (!Info)
130  return DIGlobal();
131 
132  // If the user is giving us relative addresses, add the preferred base of
133  // the object to the offset before we do the query. It's what DIContext
134  // expects.
135  if (Opts.RelativeAddresses)
136  ModuleOffset.Address += Info->getModulePreferredBase();
137 
138  DIGlobal Global = Info->symbolizeData(ModuleOffset);
139  if (Opts.Demangle)
140  Global.Name = DemangleName(Global.Name, Info);
141  return Global;
142 }
143 
145 LLVMSymbolizer::symbolizeFrame(const std::string &ModuleName,
146  object::SectionedAddress ModuleOffset) {
148  if (auto InfoOrErr = getOrCreateModuleInfo(ModuleName))
149  Info = InfoOrErr.get();
150  else
151  return InfoOrErr.takeError();
152 
153  // A null module means an error has already been reported. Return an empty
154  // result.
155  if (!Info)
156  return std::vector<DILocal>();
157 
158  // If the user is giving us relative addresses, add the preferred base of
159  // the object to the offset before we do the query. It's what DIContext
160  // expects.
161  if (Opts.RelativeAddresses)
162  ModuleOffset.Address += Info->getModulePreferredBase();
163 
164  return Info->symbolizeFrame(ModuleOffset);
165 }
166 
168  ObjectForUBPathAndArch.clear();
169  BinaryForPath.clear();
170  ObjectPairForPathArch.clear();
171  Modules.clear();
172 }
173 
174 namespace {
175 
176 // For Path="/path/to/foo" and Basename="foo" assume that debug info is in
177 // /path/to/foo.dSYM/Contents/Resources/DWARF/foo.
178 // For Path="/path/to/bar.dSYM" and Basename="foo" assume that debug info is in
179 // /path/to/bar.dSYM/Contents/Resources/DWARF/foo.
180 std::string getDarwinDWARFResourceForPath(
181  const std::string &Path, const std::string &Basename) {
182  SmallString<16> ResourceName = StringRef(Path);
183  if (sys::path::extension(Path) != ".dSYM") {
184  ResourceName += ".dSYM";
185  }
186  sys::path::append(ResourceName, "Contents", "Resources", "DWARF");
187  sys::path::append(ResourceName, Basename);
188  return std::string(ResourceName.str());
189 }
190 
191 bool checkFileCRC(StringRef Path, uint32_t CRCHash) {
194  if (!MB)
195  return false;
196  return CRCHash == llvm::crc32(arrayRefFromStringRef(MB.get()->getBuffer()));
197 }
198 
199 bool findDebugBinary(const std::string &OrigPath,
200  const std::string &DebuglinkName, uint32_t CRCHash,
201  const std::string &FallbackDebugPath,
202  std::string &Result) {
203  SmallString<16> OrigDir(OrigPath);
205  SmallString<16> DebugPath = OrigDir;
206  // Try relative/path/to/original_binary/debuglink_name
207  llvm::sys::path::append(DebugPath, DebuglinkName);
208  if (checkFileCRC(DebugPath, CRCHash)) {
209  Result = std::string(DebugPath.str());
210  return true;
211  }
212  // Try relative/path/to/original_binary/.debug/debuglink_name
213  DebugPath = OrigDir;
214  llvm::sys::path::append(DebugPath, ".debug", DebuglinkName);
215  if (checkFileCRC(DebugPath, CRCHash)) {
216  Result = std::string(DebugPath.str());
217  return true;
218  }
219  // Make the path absolute so that lookups will go to
220  // "/usr/lib/debug/full/path/to/debug", not
221  // "/usr/lib/debug/to/debug"
223  if (!FallbackDebugPath.empty()) {
224  // Try <FallbackDebugPath>/absolute/path/to/original_binary/debuglink_name
225  DebugPath = FallbackDebugPath;
226  } else {
227 #if defined(__NetBSD__)
228  // Try /usr/libdata/debug/absolute/path/to/original_binary/debuglink_name
229  DebugPath = "/usr/libdata/debug";
230 #else
231  // Try /usr/lib/debug/absolute/path/to/original_binary/debuglink_name
232  DebugPath = "/usr/lib/debug";
233 #endif
234  }
236  DebuglinkName);
237  if (checkFileCRC(DebugPath, CRCHash)) {
238  Result = std::string(DebugPath.str());
239  return true;
240  }
241  return false;
242 }
243 
244 bool getGNUDebuglinkContents(const ObjectFile *Obj, std::string &DebugName,
245  uint32_t &CRCHash) {
246  if (!Obj)
247  return false;
248  for (const SectionRef &Section : Obj->sections()) {
249  StringRef Name;
250  if (Expected<StringRef> NameOrErr = Section.getName())
251  Name = *NameOrErr;
252  else
253  consumeError(NameOrErr.takeError());
254 
255  Name = Name.substr(Name.find_first_not_of("._"));
256  if (Name == "gnu_debuglink") {
257  Expected<StringRef> ContentsOrErr = Section.getContents();
258  if (!ContentsOrErr) {
259  consumeError(ContentsOrErr.takeError());
260  return false;
261  }
262  DataExtractor DE(*ContentsOrErr, Obj->isLittleEndian(), 0);
263  uint64_t Offset = 0;
264  if (const char *DebugNameStr = DE.getCStr(&Offset)) {
265  // 4-byte align the offset.
266  Offset = (Offset + 3) & ~0x3;
267  if (DE.isValidOffsetForDataOfSize(Offset, 4)) {
268  DebugName = DebugNameStr;
269  CRCHash = DE.getU32(&Offset);
270  return true;
271  }
272  }
273  break;
274  }
275  }
276  return false;
277 }
278 
279 bool darwinDsymMatchesBinary(const MachOObjectFile *DbgObj,
280  const MachOObjectFile *Obj) {
281  ArrayRef<uint8_t> dbg_uuid = DbgObj->getUuid();
282  ArrayRef<uint8_t> bin_uuid = Obj->getUuid();
283  if (dbg_uuid.empty() || bin_uuid.empty())
284  return false;
285  return !memcmp(dbg_uuid.data(), bin_uuid.data(), dbg_uuid.size());
286 }
287 
288 template <typename ELFT>
289 Optional<ArrayRef<uint8_t>> getBuildID(const ELFFile<ELFT> *Obj) {
290  if (!Obj)
291  return {};
292  auto PhdrsOrErr = Obj->program_headers();
293  if (!PhdrsOrErr) {
294  consumeError(PhdrsOrErr.takeError());
295  return {};
296  }
297  for (const auto &P : *PhdrsOrErr) {
298  if (P.p_type != ELF::PT_NOTE)
299  continue;
300  Error Err = Error::success();
301  for (auto N : Obj->notes(P, Err))
302  if (N.getType() == ELF::NT_GNU_BUILD_ID && N.getName() == ELF::ELF_NOTE_GNU)
303  return N.getDesc();
304  consumeError(std::move(Err));
305  }
306  return {};
307 }
308 
309 Optional<ArrayRef<uint8_t>> getBuildID(const ELFObjectFileBase *Obj) {
311  if (auto *O = dyn_cast<ELFObjectFile<ELF32LE>>(Obj))
312  BuildID = getBuildID(O->getELFFile());
313  else if (auto *O = dyn_cast<ELFObjectFile<ELF32BE>>(Obj))
314  BuildID = getBuildID(O->getELFFile());
315  else if (auto *O = dyn_cast<ELFObjectFile<ELF64LE>>(Obj))
316  BuildID = getBuildID(O->getELFFile());
317  else if (auto *O = dyn_cast<ELFObjectFile<ELF64BE>>(Obj))
318  BuildID = getBuildID(O->getELFFile());
319  else
320  llvm_unreachable("unsupported file format");
321  return BuildID;
322 }
323 
324 bool findDebugBinary(const std::vector<std::string> &DebugFileDirectory,
325  const ArrayRef<uint8_t> BuildID,
326  std::string &Result) {
327  auto getDebugPath = [&](StringRef Directory) {
328  SmallString<128> Path{Directory};
329  sys::path::append(Path, ".build-id",
330  llvm::toHex(BuildID[0], /*LowerCase=*/true),
331  llvm::toHex(BuildID.slice(1), /*LowerCase=*/true));
332  Path += ".debug";
333  return Path;
334  };
335  if (DebugFileDirectory.empty()) {
336  SmallString<128> Path = getDebugPath(
337 #if defined(__NetBSD__)
338  // Try /usr/libdata/debug/.build-id/../...
339  "/usr/libdata/debug"
340 #else
341  // Try /usr/lib/debug/.build-id/../...
342  "/usr/lib/debug"
343 #endif
344  );
345  if (llvm::sys::fs::exists(Path)) {
346  Result = std::string(Path.str());
347  return true;
348  }
349  } else {
350  for (const auto &Directory : DebugFileDirectory) {
351  // Try <debug-file-directory>/.build-id/../...
352  SmallString<128> Path = getDebugPath(Directory);
353  if (llvm::sys::fs::exists(Path)) {
354  Result = std::string(Path.str());
355  return true;
356  }
357  }
358  }
359  return false;
360 }
361 
362 } // end anonymous namespace
363 
364 ObjectFile *LLVMSymbolizer::lookUpDsymFile(const std::string &ExePath,
365  const MachOObjectFile *MachExeObj, const std::string &ArchName) {
366  // On Darwin we may find DWARF in separate object file in
367  // resource directory.
368  std::vector<std::string> DsymPaths;
369  StringRef Filename = sys::path::filename(ExePath);
370  DsymPaths.push_back(
371  getDarwinDWARFResourceForPath(ExePath, std::string(Filename)));
372  for (const auto &Path : Opts.DsymHints) {
373  DsymPaths.push_back(
374  getDarwinDWARFResourceForPath(Path, std::string(Filename)));
375  }
376  for (const auto &Path : DsymPaths) {
377  auto DbgObjOrErr = getOrCreateObject(Path, ArchName);
378  if (!DbgObjOrErr) {
379  // Ignore errors, the file might not exist.
380  consumeError(DbgObjOrErr.takeError());
381  continue;
382  }
383  ObjectFile *DbgObj = DbgObjOrErr.get();
384  if (!DbgObj)
385  continue;
386  const MachOObjectFile *MachDbgObj = dyn_cast<const MachOObjectFile>(DbgObj);
387  if (!MachDbgObj)
388  continue;
389  if (darwinDsymMatchesBinary(MachDbgObj, MachExeObj))
390  return DbgObj;
391  }
392  return nullptr;
393 }
394 
395 ObjectFile *LLVMSymbolizer::lookUpDebuglinkObject(const std::string &Path,
396  const ObjectFile *Obj,
397  const std::string &ArchName) {
398  std::string DebuglinkName;
399  uint32_t CRCHash;
400  std::string DebugBinaryPath;
401  if (!getGNUDebuglinkContents(Obj, DebuglinkName, CRCHash))
402  return nullptr;
403  if (!findDebugBinary(Path, DebuglinkName, CRCHash, Opts.FallbackDebugPath,
404  DebugBinaryPath))
405  return nullptr;
406  auto DbgObjOrErr = getOrCreateObject(DebugBinaryPath, ArchName);
407  if (!DbgObjOrErr) {
408  // Ignore errors, the file might not exist.
409  consumeError(DbgObjOrErr.takeError());
410  return nullptr;
411  }
412  return DbgObjOrErr.get();
413 }
414 
415 ObjectFile *LLVMSymbolizer::lookUpBuildIDObject(const std::string &Path,
416  const ELFObjectFileBase *Obj,
417  const std::string &ArchName) {
418  auto BuildID = getBuildID(Obj);
419  if (!BuildID)
420  return nullptr;
421  if (BuildID->size() < 2)
422  return nullptr;
423  std::string DebugBinaryPath;
424  if (!findDebugBinary(Opts.DebugFileDirectory, *BuildID, DebugBinaryPath))
425  return nullptr;
426  auto DbgObjOrErr = getOrCreateObject(DebugBinaryPath, ArchName);
427  if (!DbgObjOrErr) {
428  consumeError(DbgObjOrErr.takeError());
429  return nullptr;
430  }
431  return DbgObjOrErr.get();
432 }
433 
435 LLVMSymbolizer::getOrCreateObjectPair(const std::string &Path,
436  const std::string &ArchName) {
437  auto I = ObjectPairForPathArch.find(std::make_pair(Path, ArchName));
438  if (I != ObjectPairForPathArch.end())
439  return I->second;
440 
441  auto ObjOrErr = getOrCreateObject(Path, ArchName);
442  if (!ObjOrErr) {
443  ObjectPairForPathArch.emplace(std::make_pair(Path, ArchName),
444  ObjectPair(nullptr, nullptr));
445  return ObjOrErr.takeError();
446  }
447 
448  ObjectFile *Obj = ObjOrErr.get();
449  assert(Obj != nullptr);
450  ObjectFile *DbgObj = nullptr;
451 
452  if (auto MachObj = dyn_cast<const MachOObjectFile>(Obj))
453  DbgObj = lookUpDsymFile(Path, MachObj, ArchName);
454  else if (auto ELFObj = dyn_cast<const ELFObjectFileBase>(Obj))
455  DbgObj = lookUpBuildIDObject(Path, ELFObj, ArchName);
456  if (!DbgObj)
457  DbgObj = lookUpDebuglinkObject(Path, Obj, ArchName);
458  if (!DbgObj)
459  DbgObj = Obj;
460  ObjectPair Res = std::make_pair(Obj, DbgObj);
461  ObjectPairForPathArch.emplace(std::make_pair(Path, ArchName), Res);
462  return Res;
463 }
464 
466 LLVMSymbolizer::getOrCreateObject(const std::string &Path,
467  const std::string &ArchName) {
468  Binary *Bin;
469  auto Pair = BinaryForPath.emplace(Path, OwningBinary<Binary>());
470  if (!Pair.second) {
471  Bin = Pair.first->second.getBinary();
472  } else {
474  if (!BinOrErr)
475  return BinOrErr.takeError();
476  Pair.first->second = std::move(BinOrErr.get());
477  Bin = Pair.first->second.getBinary();
478  }
479 
480  if (!Bin)
481  return static_cast<ObjectFile *>(nullptr);
482 
483  if (MachOUniversalBinary *UB = dyn_cast_or_null<MachOUniversalBinary>(Bin)) {
484  auto I = ObjectForUBPathAndArch.find(std::make_pair(Path, ArchName));
485  if (I != ObjectForUBPathAndArch.end())
486  return I->second.get();
487 
489  UB->getMachOObjectForArch(ArchName);
490  if (!ObjOrErr) {
491  ObjectForUBPathAndArch.emplace(std::make_pair(Path, ArchName),
492  std::unique_ptr<ObjectFile>());
493  return ObjOrErr.takeError();
494  }
495  ObjectFile *Res = ObjOrErr->get();
496  ObjectForUBPathAndArch.emplace(std::make_pair(Path, ArchName),
497  std::move(ObjOrErr.get()));
498  return Res;
499  }
500  if (Bin->isObject()) {
501  return cast<ObjectFile>(Bin);
502  }
503  return errorCodeToError(object_error::arch_not_found);
504 }
505 
507 LLVMSymbolizer::createModuleInfo(const ObjectFile *Obj,
508  std::unique_ptr<DIContext> Context,
509  StringRef ModuleName) {
510  auto InfoOrErr = SymbolizableObjectFile::create(Obj, std::move(Context),
511  Opts.UntagAddresses);
512  std::unique_ptr<SymbolizableModule> SymMod;
513  if (InfoOrErr)
514  SymMod = std::move(*InfoOrErr);
515  auto InsertResult = Modules.insert(
516  std::make_pair(std::string(ModuleName), std::move(SymMod)));
517  assert(InsertResult.second);
518  if (!InfoOrErr)
519  return InfoOrErr.takeError();
520  return InsertResult.first->second.get();
521 }
522 
524 LLVMSymbolizer::getOrCreateModuleInfo(const std::string &ModuleName) {
525  auto I = Modules.find(ModuleName);
526  if (I != Modules.end())
527  return I->second.get();
528 
529  std::string BinaryName = ModuleName;
530  std::string ArchName = Opts.DefaultArch;
531  size_t ColonPos = ModuleName.find_last_of(':');
532  // Verify that substring after colon form a valid arch name.
533  if (ColonPos != std::string::npos) {
534  std::string ArchStr = ModuleName.substr(ColonPos + 1);
535  if (Triple(ArchStr).getArch() != Triple::UnknownArch) {
536  BinaryName = ModuleName.substr(0, ColonPos);
537  ArchName = ArchStr;
538  }
539  }
540  auto ObjectsOrErr = getOrCreateObjectPair(BinaryName, ArchName);
541  if (!ObjectsOrErr) {
542  // Failed to find valid object file.
543  Modules.emplace(ModuleName, std::unique_ptr<SymbolizableModule>());
544  return ObjectsOrErr.takeError();
545  }
546  ObjectPair Objects = ObjectsOrErr.get();
547 
548  std::unique_ptr<DIContext> Context;
549  // If this is a COFF object containing PDB info, use a PDBContext to
550  // symbolize. Otherwise, use DWARF.
551  if (auto CoffObject = dyn_cast<COFFObjectFile>(Objects.first)) {
552  const codeview::DebugInfo *DebugInfo;
553  StringRef PDBFileName;
554  auto EC = CoffObject->getDebugPDBInfo(DebugInfo, PDBFileName);
555  if (!EC && DebugInfo != nullptr && !PDBFileName.empty()) {
556  using namespace pdb;
557  std::unique_ptr<IPDBSession> Session;
558  PDB_ReaderType ReaderType = Opts.UseNativePDBReader
559  ? PDB_ReaderType::Native
560  : PDB_ReaderType::DIA;
561  if (auto Err = loadDataForEXE(ReaderType, Objects.first->getFileName(),
562  Session)) {
563  Modules.emplace(ModuleName, std::unique_ptr<SymbolizableModule>());
564  // Return along the PDB filename to provide more context
565  return createFileError(PDBFileName, std::move(Err));
566  }
567  Context.reset(new PDBContext(*CoffObject, std::move(Session)));
568  }
569  }
570  if (!Context)
571  Context = DWARFContext::create(*Objects.second, nullptr, Opts.DWPName);
572  return createModuleInfo(Objects.first, std::move(Context), ModuleName);
573 }
574 
575 namespace {
576 
577 // Undo these various manglings for Win32 extern "C" functions:
578 // cdecl - _foo
579 // stdcall - _foo@12
580 // fastcall - @foo@12
581 // vectorcall - foo@@12
582 // These are all different linkage names for 'foo'.
583 StringRef demanglePE32ExternCFunc(StringRef SymbolName) {
584  // Remove any '_' or '@' prefix.
585  char Front = SymbolName.empty() ? '\0' : SymbolName[0];
586  if (Front == '_' || Front == '@')
587  SymbolName = SymbolName.drop_front();
588 
589  // Remove any '@[0-9]+' suffix.
590  if (Front != '?') {
591  size_t AtPos = SymbolName.rfind('@');
592  if (AtPos != StringRef::npos &&
593  std::all_of(SymbolName.begin() + AtPos + 1, SymbolName.end(),
594  [](char C) { return C >= '0' && C <= '9'; })) {
595  SymbolName = SymbolName.substr(0, AtPos);
596  }
597  }
598 
599  // Remove any ending '@' for vectorcall.
600  if (SymbolName.endswith("@"))
601  SymbolName = SymbolName.drop_back();
602 
603  return SymbolName;
604 }
605 
606 } // end anonymous namespace
607 
608 std::string
610  const SymbolizableModule *DbiModuleDescriptor) {
611  // We can spoil names of symbols with C linkage, so use an heuristic
612  // approach to check if the name should be demangled.
613  if (Name.substr(0, 2) == "_Z") {
614  int status = 0;
615  char *DemangledName = itaniumDemangle(Name.c_str(), nullptr, nullptr, &status);
616  if (status != 0)
617  return Name;
618  std::string Result = DemangledName;
619  free(DemangledName);
620  return Result;
621  }
622 
623  if (!Name.empty() && Name.front() == '?') {
624  // Only do MSVC C++ demangling on symbols starting with '?'.
625  int status = 0;
626  char *DemangledName = microsoftDemangle(
627  Name.c_str(), nullptr, nullptr, nullptr, &status,
630  if (status != 0)
631  return Name;
632  std::string Result = DemangledName;
633  free(DemangledName);
634  return Result;
635  }
636 
637  if (DbiModuleDescriptor && DbiModuleDescriptor->isWin32Module())
638  return std::string(demanglePE32ExternCFunc(Name));
639  return Name;
640 }
641 
642 } // namespace symbolize
643 } // 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
LLVM_NODISCARD std::enable_if_t< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast(const Y &Val)
Definition: Casting.h:334
DILineInfo * getMutableFrame(unsigned Index)
Definition: DIContext.h:93
char * itaniumDemangle(const char *mangled_name, char *buf, size_t *n, int *status)
LLVMContext & Context
static Expected< std::unique_ptr< SymbolizableObjectFile > > create(const object::ObjectFile *Obj, std::unique_ptr< DIContext > DICtx, bool UntagAddresses)
LLVM_NODISCARD bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
Definition: StringRef.h:300
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:274
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:378
Expected< DILineInfo > symbolizeCode(const ObjectFile &Obj, object::SectionedAddress ModuleOffset)
Definition: Symbolize.cpp:63
PDB_ReaderType
Specifies which PDB reader implementation is to be used.
Definition: PDBTypes.h:80
This class is the base class for all object file types.
Definition: ObjectFile.h:225
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:1491
Error takeError()
Take ownership of the stored error.
Definition: Error.h:557
virtual bool isWin32Module() const =0
Expected< Elf_Phdr_Range > program_headers() const
Iterate over program header table.
Definition: ELF.h:204
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:654
void make_absolute(const Twine &current_directory, SmallVectorImpl< char > &path)
Make path an absolute path.
Definition: Path.cpp:891
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
Expected< DIGlobal > symbolizeData(const std::string &ModuleName, object::SectionedAddress ModuleOffset)
Definition: Symbolize.cpp:119
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:612
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:156
static constexpr size_t npos
Definition: StringRef.h:59
StringRef str() const
Explicit conversion to StringRef.
Definition: SmallString.h:266
section_iterator_range sections() const
Definition: ObjectFile.h:319
uint32_t getNumberOfFrames() const
Definition: DIContext.h:98
Analysis containing CSE Info
Definition: CSEInfo.cpp:25
#define P(N)
virtual DIInliningInfo symbolizeInlinedCode(object::SectionedAddress ModuleOffset, DILineInfoSpecifier LineInfoSpecifier, bool UseSymbolTable) const =0
Error loadDataForEXE(PDB_ReaderType Type, StringRef Path, std::unique_ptr< IPDBSession > &Session)
Definition: PDB.cpp:36
Controls which fields of DILineInfo container should be filled with data.
Definition: DIContext.h:136
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:156
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:82
std::vector< std::string > DsymHints
Definition: Symbolize.h:48
MSDemangleFlags
Definition: Demangle.h:35
Expected< std::vector< DILocal > > symbolizeFrame(const std::string &ModuleName, object::SectionedAddress ModuleOffset)
Definition: Symbolize.cpp:145
Expected< DIInliningInfo > symbolizeInlinedCode(const std::string &ModuleName, object::SectionedAddress ModuleOffset)
Definition: Symbolize.cpp:88
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1006
#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:153
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
static std::unique_ptr< DWARFContext > create(const object::ObjectFile &Obj, const LoadedObjectInfo *L=nullptr, std::string DWPName="", std::function< void(Error)> RecoverableErrorHandler=WithColor::defaultErrorHandler, std::function< void(Error)> WarningHandler=WithColor::defaultWarningHandler)
static ErrorSuccess success()
Create a success value.
Definition: Error.h:332
static std::string DemangleName(const std::string &Name, const SymbolizableModule *DbiModuleDescriptor)
Definition: Symbolize.cpp:609
virtual std::vector< DILocal > symbolizeFrame(object::SectionedAddress ModuleOffset) const =0
ArrayRef< uint8_t > getUuid() const
std::string Name
Definition: DIContext.h:113
std::string FunctionName
Definition: DIContext.h:37
char * microsoftDemangle(const char *mangled_name, size_t *n_read, char *buf, size_t *n_buf, int *status, MSDemangleFlags Flags=MSDF_None)
Demangles the Microsoft symbol pointed at by mangled_name and returns it.
reference get()
Returns a reference to the stored T value.
Definition: Error.h:537
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:186
iterator begin() const
Definition: StringRef.h:131
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:1531
Merge contiguous icmps into a memcmp
Definition: MergeICmps.cpp:928
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
Definition: Path.cpp:577
#define I(x, y, z)
Definition: MD5.cpp:59
#define N
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:1278
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:662
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:57
std::string toHex(StringRef Input, bool LowerCase=false)
Convert buffer Input to its hexadecimal representation.
Definition: StringExtras.h:149
bool exists(const basic_file_status &status)
Does file exist?
Definition: Path.cpp:1063
iterator end() const
Definition: StringRef.h:133
virtual DIGlobal symbolizeData(object::SectionedAddress ModuleOffset) const =0
reference get()
Definition: ErrorOr.h:150
Container for description of a global variable.
Definition: DIContext.h:112
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:151
This is a value type class that represents a single section in the list of sections in the object fil...
Definition: ObjectFile.h:80
StringRef extension(StringRef path, Style style=Style::native)
Get extension.
Definition: Path.cpp:592
std::vector< std::string > DebugFileDirectory
Definition: Symbolize.h:51