1 //===-- Symbolize.h --------------------------------------------- C++ -----===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Header for LLVM symbolization library.
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZE_H
14 #define LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZE_H
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/DebugInfo/DIContext.h"
18 #include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
19 #include "llvm/Object/MachOUniversal.h"
20 #include "llvm/Object/ObjectFile.h"
21 #include "llvm/Support/MemoryBuffer.h"
29 using namespace object;
30 using FunctionNameKind = DILineInfoSpecifier::FunctionNameKind;
32 class LLVMSymbolizer {
35 FunctionNameKind PrintFunctions;
36 bool UseSymbolTable : 1;
38 bool RelativeAddresses : 1;
39 std::string DefaultArch;
40 std::vector<std::string> DsymHints;
41 Options(FunctionNameKind PrintFunctions = FunctionNameKind::LinkageName,
42 bool UseSymbolTable = true, bool Demangle = true,
43 bool RelativeAddresses = false, std::string DefaultArch = "")
44 : PrintFunctions(PrintFunctions), UseSymbolTable(UseSymbolTable),
45 Demangle(Demangle), RelativeAddresses(RelativeAddresses),
46 DefaultArch(DefaultArch) {}
49 LLVMSymbolizer(const Options &Opts = Options()) : Opts(Opts) {}
54 // Returns the result of symbolization for module name/offset as
55 // a string (possibly containing newlines).
57 symbolizeCode(const std::string &ModuleName, uint64_t ModuleOffset);
58 std::string symbolizeInlinedCode(const std::string &ModuleName,
59 uint64_t ModuleOffset);
61 symbolizeData(const std::string &ModuleName, uint64_t ModuleOffset);
63 static std::string DemangleName(const std::string &Name,
64 const SymbolizableModule *ModInfo);
67 typedef std::pair<ObjectFile*, ObjectFile*> ObjectPair;
69 SymbolizableModule *getOrCreateModuleInfo(const std::string &ModuleName);
70 ObjectFile *lookUpDsymFile(const std::string &Path,
71 const MachOObjectFile *ExeObj,
72 const std::string &ArchName);
74 /// \brief Returns pair of pointers to object and debug object.
75 ObjectPair getOrCreateObjects(const std::string &Path,
76 const std::string &ArchName);
77 /// \brief Returns a parsed object file for a given architecture in a
78 /// universal binary (or the binary itself if it is an object file).
79 ObjectFile *getObjectFileFromBinary(Binary *Bin, const std::string &ArchName);
81 std::string printDILineInfo(DILineInfo LineInfo,
82 const SymbolizableModule *ModInfo) const;
83 std::string printDIInliningInfo(DIInliningInfo InlinedContext,
84 const SymbolizableModule *ModInfo) const;
85 std::string printDIGlobal(DIGlobal Global,
86 const SymbolizableModule *ModInfo) const;
88 // Owns all the parsed binaries and object files.
89 SmallVector<std::unique_ptr<Binary>, 4> ParsedBinariesAndObjects;
90 SmallVector<std::unique_ptr<MemoryBuffer>, 4> MemoryBuffers;
91 void addOwningBinary(OwningBinary<Binary> OwningBin) {
92 std::unique_ptr<Binary> Bin;
93 std::unique_ptr<MemoryBuffer> MemBuf;
94 std::tie(Bin, MemBuf) = OwningBin.takeBinary();
95 ParsedBinariesAndObjects.push_back(std::move(Bin));
96 MemoryBuffers.push_back(std::move(MemBuf));
99 std::map<std::string, std::unique_ptr<SymbolizableModule>> Modules;
100 std::map<std::pair<MachOUniversalBinary *, std::string>, ObjectFile *>
102 std::map<std::pair<std::string, std::string>, ObjectPair>
103 ObjectPairForPathArch;
106 static const char kBadString[];
109 } // namespace symbolize