1 //===-- LLVMSymbolize.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_SYMBOLIZE_H
14 #define LLVM_SYMBOLIZE_H
16 #include "llvm/ADT/OwningPtr.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/DebugInfo/DIContext.h"
19 #include "llvm/Object/MachOUniversal.h"
20 #include "llvm/Object/ObjectFile.h"
21 #include "llvm/Support/MemoryBuffer.h"
27 using namespace object;
33 class LLVMSymbolizer {
36 bool UseSymbolTable : 1;
37 bool PrintFunctions : 1;
38 bool PrintInlining : 1;
40 std::string DefaultArch;
41 Options(bool UseSymbolTable = true, bool PrintFunctions = true,
42 bool PrintInlining = true, bool Demangle = true,
43 std::string DefaultArch = "")
44 : UseSymbolTable(UseSymbolTable), PrintFunctions(PrintFunctions),
45 PrintInlining(PrintInlining), Demangle(Demangle),
46 DefaultArch(DefaultArch) {
50 LLVMSymbolizer(const Options &Opts = Options()) : Opts(Opts) {}
55 // Returns the result of symbolization for module name/offset as
56 // a string (possibly containing newlines).
58 symbolizeCode(const std::string &ModuleName, uint64_t ModuleOffset);
60 symbolizeData(const std::string &ModuleName, uint64_t ModuleOffset);
62 static std::string DemangleName(const std::string &Name);
64 typedef std::pair<Binary*, Binary*> BinaryPair;
66 ModuleInfo *getOrCreateModuleInfo(const std::string &ModuleName);
67 /// \brief Returns pair of pointers to binary and debug binary.
68 BinaryPair getOrCreateBinary(const std::string &Path);
69 /// \brief Returns a parsed object file for a given architecture in a
70 /// universal binary (or the binary itself if it is an object file).
71 ObjectFile *getObjectFileFromBinary(Binary *Bin, const std::string &ArchName);
73 std::string printDILineInfo(DILineInfo LineInfo) const;
75 // Owns all the parsed binaries and object files.
76 SmallVector<Binary*, 4> ParsedBinariesAndObjects;
77 // Owns module info objects.
78 typedef std::map<std::string, ModuleInfo *> ModuleMapTy;
80 typedef std::map<std::string, BinaryPair> BinaryMapTy;
81 BinaryMapTy BinaryForPath;
82 typedef std::map<std::pair<MachOUniversalBinary *, std::string>, ObjectFile *>
83 ObjectFileForArchMapTy;
84 ObjectFileForArchMapTy ObjectFileForArch;
87 static const char kBadString[];
92 ModuleInfo(ObjectFile *Obj, DIContext *DICtx);
94 DILineInfo symbolizeCode(uint64_t ModuleOffset,
95 const LLVMSymbolizer::Options &Opts) const;
96 DIInliningInfo symbolizeInlinedCode(
97 uint64_t ModuleOffset, const LLVMSymbolizer::Options &Opts) const;
98 bool symbolizeData(uint64_t ModuleOffset, std::string &Name, uint64_t &Start,
99 uint64_t &Size) const;
102 bool getNameFromSymbolTable(SymbolRef::Type Type, uint64_t Address,
103 std::string &Name, uint64_t &Addr,
104 uint64_t &Size) const;
106 OwningPtr<DIContext> DebugInfoContext;
110 // If size is 0, assume that symbol occupies the whole memory range up to
111 // the following symbol.
113 friend bool operator<(const SymbolDesc &s1, const SymbolDesc &s2) {
114 return s1.Addr < s2.Addr;
117 typedef std::map<SymbolDesc, StringRef> SymbolMapTy;
118 SymbolMapTy Functions;
122 } // namespace symbolize
125 #endif // LLVM_SYMBOLIZE_H