42 LLVMSymbolizer::symbolizeCodeCommon(SymbolizableModule *
Info,
43 object::SectionedAddress ModuleOffset) {
52 ModuleOffset.Address += Info->getModulePreferredBase();
54 DILineInfo LineInfo = Info->symbolizeCode(ModuleOffset, Opts.
PrintFunctions,
57 LineInfo.FunctionName =
DemangleName(LineInfo.FunctionName, Info);
65 auto I = Modules.find(ModuleName);
66 if (
I != Modules.end())
67 return symbolizeCodeCommon(
I->second.get(), ModuleOffset);
69 std::unique_ptr<DIContext>
Context =
72 createModuleInfo(&Obj, std::move(Context), ModuleName);
75 return symbolizeCodeCommon(*InfoOrErr, ModuleOffset);
84 return symbolizeCodeCommon(*InfoOrErr, ModuleOffset);
91 if (
auto InfoOrErr = getOrCreateModuleInfo(ModuleName))
92 Info = InfoOrErr.get();
94 return InfoOrErr.takeError();
114 return InlinedContext;
121 if (
auto InfoOrErr = getOrCreateModuleInfo(ModuleName))
122 Info = InfoOrErr.get();
124 return InfoOrErr.takeError();
147 if (
auto InfoOrErr = getOrCreateModuleInfo(ModuleName))
148 Info = InfoOrErr.get();
150 return InfoOrErr.takeError();
155 return std::vector<DILocal>();
167 ObjectForUBPathAndArch.clear();
168 BinaryForPath.clear();
169 ObjectPairForPathArch.clear();
179 std::string getDarwinDWARFResourceForPath(
180 const std::string &Path,
const std::string &Basename) {
183 ResourceName +=
".dSYM";
187 return ResourceName.
str();
198 bool findDebugBinary(
const std::string &OrigPath,
199 const std::string &DebuglinkName,
uint32_t CRCHash,
200 const std::string &FallbackDebugPath,
201 std::string &Result) {
207 if (checkFileCRC(DebugPath, CRCHash)) {
208 Result = DebugPath.
str();
214 if (checkFileCRC(DebugPath, CRCHash)) {
215 Result = DebugPath.
str();
222 if (!FallbackDebugPath.empty()) {
224 DebugPath = FallbackDebugPath;
226 #if defined(__NetBSD__) 228 DebugPath =
"/usr/libdata/debug";
231 DebugPath =
"/usr/lib/debug";
236 if (checkFileCRC(DebugPath, CRCHash)) {
237 Result = DebugPath.
str();
243 bool getGNUDebuglinkContents(
const ObjectFile *Obj, std::string &DebugName,
254 Name = Name.
substr(Name.find_first_not_of(
"._"));
255 if (Name ==
"gnu_debuglink") {
257 if (!ContentsOrErr) {
263 if (
const char *DebugNameStr = DE.getCStr(&Offset)) {
265 Offset = (Offset + 3) & ~0x3;
266 if (DE.isValidOffsetForDataOfSize(Offset, 4)) {
267 DebugName = DebugNameStr;
268 CRCHash = DE.getU32(&Offset);
287 template <
typename ELFT>
296 for (
const auto &
P : *PhdrsOrErr) {
300 for (
auto N : Obj->
notes(
P, Err))
310 BuildID = getBuildID(
O->getELFFile());
312 BuildID = getBuildID(
O->getELFFile());
314 BuildID = getBuildID(
O->getELFFile());
316 BuildID = getBuildID(
O->getELFFile());
322 bool findDebugBinary(
const std::vector<std::string> &DebugFileDirectory,
324 std::string &Result) {
325 auto getDebugPath = [&](
StringRef Directory) {
333 if (DebugFileDirectory.empty()) {
335 #
if defined(__NetBSD__)
348 for (
const auto &Directory : DebugFileDirectory) {
362 ObjectFile *LLVMSymbolizer::lookUpDsymFile(
const std::string &ExePath,
366 std::vector<std::string> DsymPaths;
368 DsymPaths.push_back(getDarwinDWARFResourceForPath(ExePath, Filename));
369 for (
const auto &Path : Opts.
DsymHints) {
370 DsymPaths.push_back(getDarwinDWARFResourceForPath(Path, Filename));
372 for (
const auto &Path : DsymPaths) {
373 auto DbgObjOrErr = getOrCreateObject(Path, ArchName);
385 if (darwinDsymMatchesBinary(MachDbgObj, MachExeObj))
391 ObjectFile *LLVMSymbolizer::lookUpDebuglinkObject(
const std::string &Path,
393 const std::string &ArchName) {
394 std::string DebuglinkName;
396 std::string DebugBinaryPath;
397 if (!getGNUDebuglinkContents(Obj, DebuglinkName, CRCHash))
402 auto DbgObjOrErr = getOrCreateObject(DebugBinaryPath, ArchName);
408 return DbgObjOrErr.get();
411 ObjectFile *LLVMSymbolizer::lookUpBuildIDObject(
const std::string &Path,
413 const std::string &ArchName) {
414 auto BuildID = getBuildID(Obj);
417 if (BuildID->size() < 2)
419 std::string DebugBinaryPath;
422 auto DbgObjOrErr = getOrCreateObject(DebugBinaryPath, ArchName);
427 return DbgObjOrErr.get();
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())
437 auto ObjOrErr = getOrCreateObject(Path, ArchName);
439 ObjectPairForPathArch.emplace(std::make_pair(Path, ArchName),
440 ObjectPair(
nullptr,
nullptr));
441 return ObjOrErr.takeError();
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);
453 DbgObj = lookUpDebuglinkObject(Path, Obj, ArchName);
456 ObjectPair Res = std::make_pair(Obj, DbgObj);
457 ObjectPairForPathArch.emplace(std::make_pair(Path, ArchName), Res);
462 LLVMSymbolizer::getOrCreateObject(
const std::string &Path,
463 const std::string &ArchName) {
467 Bin = Pair.first->second.getBinary();
472 Pair.first->second = std::move(BinOrErr.
get());
473 Bin = Pair.first->second.getBinary();
480 auto I = ObjectForUBPathAndArch.find(std::make_pair(Path, ArchName));
481 if (
I != ObjectForUBPathAndArch.end())
482 return I->second.get();
485 UB->getMachOObjectForArch(ArchName);
487 ObjectForUBPathAndArch.emplace(std::make_pair(Path, ArchName),
488 std::unique_ptr<ObjectFile>());
492 ObjectForUBPathAndArch.emplace(std::make_pair(Path, ArchName),
493 std::move(ObjOrErr.
get()));
497 return cast<ObjectFile>(Bin);
503 LLVMSymbolizer::createModuleInfo(
const ObjectFile *Obj,
504 std::unique_ptr<DIContext>
Context,
508 std::unique_ptr<SymbolizableModule> SymMod;
510 SymMod = std::move(*InfoOrErr);
512 Modules.insert(std::make_pair(ModuleName, std::move(SymMod)));
513 assert(InsertResult.second);
514 if (std::error_code EC = InfoOrErr.getError())
516 return InsertResult.first->second.get();
520 LLVMSymbolizer::getOrCreateModuleInfo(
const std::string &ModuleName) {
521 auto I = Modules.find(ModuleName);
522 if (
I != Modules.end())
523 return I->second.get();
525 std::string BinaryName = ModuleName;
527 size_t ColonPos = ModuleName.find_last_of(
':');
529 if (ColonPos != std::string::npos) {
530 std::string ArchStr = ModuleName.substr(ColonPos + 1);
532 BinaryName = ModuleName.substr(0, ColonPos);
536 auto ObjectsOrErr = getOrCreateObjectPair(BinaryName, ArchName);
539 Modules.emplace(ModuleName, std::unique_ptr<SymbolizableModule>());
540 return ObjectsOrErr.takeError();
542 ObjectPair Objects = ObjectsOrErr.get();
544 std::unique_ptr<DIContext>
Context;
547 if (
auto CoffObject = dyn_cast<COFFObjectFile>(Objects.first)) {
550 auto EC = CoffObject->getDebugPDBInfo(DebugInfo, PDBFileName);
551 if (!EC && DebugInfo !=
nullptr && !PDBFileName.
empty()) {
553 std::unique_ptr<IPDBSession> Session;
555 Objects.first->getFileName(), Session)) {
556 Modules.emplace(ModuleName, std::unique_ptr<SymbolizableModule>());
560 Context.reset(
new PDBContext(*CoffObject, std::move(Session)));
567 return createModuleInfo(Objects.first, std::move(Context), ModuleName);
580 char Front = SymbolName.
empty() ?
'\0' : SymbolName[0];
581 if (Front ==
'_' || Front ==
'@')
586 size_t AtPos = SymbolName.
rfind(
'@');
589 [](
char C) {
return C >=
'0' &&
C <=
'9'; })) {
590 SymbolName = SymbolName.
substr(0, AtPos);
608 if (Name.substr(0, 2) ==
"_Z") {
613 std::string Result = DemangledName;
618 if (!Name.empty() && Name.front() ==
'?') {
622 Name.c_str(),
nullptr,
nullptr, &
status,
627 std::string Result = DemangledName;
632 if (DbiModuleDescriptor && DbiModuleDescriptor->
isWin32Module())
633 return std::string(demanglePE32ExternCFunc(Name));
uint32_t crc32(ArrayRef< uint8_t > Data)
Represents either an error or a value T.
void remove_filename(SmallVectorImpl< char > &path, Style style=Style::native)
Remove the last component from path unless it is the root dir.
DILineInfo * getMutableFrame(unsigned Index)
char * itaniumDemangle(const char *mangled_name, char *buf, size_t *n, int *status)
LLVM_NODISCARD bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
iterator_range< Elf_Note_Iterator > notes(const Elf_Phdr &Phdr, Error &Err) const
Get an iterator range over notes of a program header.
This class represents lattice values for constants.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
StringRef getFileName() const
LLVM_NODISCARD size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
Expected< DILineInfo > symbolizeCode(const ObjectFile &Obj, object::SectionedAddress ModuleOffset)
This class is the base class for all object file types.
ArrayRef< uint8_t > arrayRefFromStringRef(StringRef Input)
Construct a string ref from an array ref of unsigned chars.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
Error takeError()
Take ownership of the stored error.
virtual bool isWin32Module() const =0
Expected< Elf_Phdr_Range > program_headers() const
Iterate over program header table.
Expected< std::unique_ptr< Binary > > createBinary(MemoryBufferRef Source, LLVMContext *Context=nullptr)
Create a Binary from Source, autodetecting the file type.
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
LLVM_NODISCARD StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
void make_absolute(const Twine ¤t_directory, SmallVectorImpl< char > &path)
Make path an absolute path.
Tagged union holding either a T or a Error.
Expected< DIGlobal > symbolizeData(const std::string &ModuleName, object::SectionedAddress ModuleOffset)
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
StringRef str() const
Explicit conversion to StringRef.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
section_iterator_range sections() const
uint32_t getNumberOfFrames() const
Analysis containing CSE Info
Error loadDataForEXE(PDB_ReaderType Type, StringRef Path, std::unique_ptr< IPDBSession > &Session)
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.
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
A format-neutral container for inlined code description.
std::vector< std::string > DsymHints
static ErrorPolicy defaultErrorHandler(Error E)
Function used to handle default error reporting policy.
Expected< std::vector< DILocal > > symbolizeFrame(const std::string &ModuleName, object::SectionedAddress ModuleOffset)
Expected< DIInliningInfo > symbolizeInlinedCode(const std::string &ModuleName, object::SectionedAddress ModuleOffset)
virtual DIInliningInfo symbolizeInlinedCode(object::SectionedAddress ModuleOffset, FunctionNameKind FNKind, bool UseSymbolTable) const =0
FunctionNameKind PrintFunctions
void consumeError(Error Err)
Consume a Error without doing anything.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isLittleEndian() const
Triple - Helper class for working with autoconf configuration names.
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.
static std::string DemangleName(const std::string &Name, const SymbolizableModule *DbiModuleDescriptor)
virtual std::vector< DILocal > symbolizeFrame(object::SectionedAddress ModuleOffset) const =0
ArrayRef< uint8_t > getUuid() const
reference get()
Returns a reference to the stored T value.
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...
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
Merge contiguous icmps into a memcmp
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
std::string FallbackDebugPath
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef relative_path(StringRef path, Style style=Style::native)
Get relative path.
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
LLVM_NODISCARD StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
Lightweight error class with error context and mandatory checking.
StringRef - Represent a constant reference to a string, i.e.
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.
bool exists(const basic_file_status &status)
Does file exist?
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)
Container for description of a global variable.
bool empty() const
empty - Check if the array is empty.
This is a value type class that represents a single section in the list of sections in the object fil...
StringRef extension(StringRef path, Style style=Style::native)
Get extension.
std::vector< std::string > DebugFileDirectory