Alexey Samsonov | c4c7ea3 | 2013-01-22 14:21:19 +0000 | [diff] [blame] | 1 | //===-- LLVMSymbolize.h ----------------------------------------- C++ -----===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Header for LLVM symbolization library. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | #ifndef LLVM_SYMBOLIZE_H |
| 14 | #define LLVM_SYMBOLIZE_H |
| 15 | |
| 16 | #include "llvm/ADT/OwningPtr.h" |
| 17 | #include "llvm/DebugInfo/DIContext.h" |
| 18 | #include "llvm/Object/ObjectFile.h" |
| 19 | #include "llvm/Support/MemoryBuffer.h" |
| 20 | #include <map> |
| 21 | #include <string> |
| 22 | |
| 23 | namespace llvm { |
| 24 | |
| 25 | using namespace object; |
| 26 | |
| 27 | namespace symbolize { |
| 28 | |
| 29 | class ModuleInfo; |
| 30 | |
| 31 | class LLVMSymbolizer { |
| 32 | public: |
| 33 | struct Options { |
| 34 | bool UseSymbolTable : 1; |
| 35 | bool PrintFunctions : 1; |
| 36 | bool PrintInlining : 1; |
| 37 | bool Demangle : 1; |
| 38 | Options(bool UseSymbolTable = true, bool PrintFunctions = true, |
| 39 | bool PrintInlining = true, bool Demangle = true) |
| 40 | : UseSymbolTable(UseSymbolTable), |
| 41 | PrintFunctions(PrintFunctions), |
| 42 | PrintInlining(PrintInlining), |
| 43 | Demangle(Demangle) { } |
| 44 | }; |
| 45 | |
| 46 | LLVMSymbolizer(const Options &Opts = Options()) : Opts(Opts) { } |
| 47 | |
| 48 | // Returns the result of symbolization for module name/offset as |
| 49 | // a string (possibly containing newlines). |
| 50 | std::string symbolizeCode(const std::string &ModuleName, |
| 51 | uint64_t ModuleOffset); |
| 52 | std::string symbolizeData(const std::string &ModuleName, |
| 53 | uint64_t ModuleOffset); |
| 54 | private: |
| 55 | ModuleInfo *getOrCreateModuleInfo(const std::string &ModuleName); |
| 56 | std::string printDILineInfo(DILineInfo LineInfo) const; |
| 57 | void DemangleName(std::string &Name) const; |
| 58 | |
| 59 | typedef std::map<std::string, ModuleInfo*> ModuleMapTy; |
| 60 | ModuleMapTy Modules; |
| 61 | Options Opts; |
Alexey Samsonov | 638c63c | 2013-02-04 15:55:26 +0000 | [diff] [blame] | 62 | static const char kBadString[]; |
Alexey Samsonov | c4c7ea3 | 2013-01-22 14:21:19 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | class ModuleInfo { |
| 66 | OwningPtr<ObjectFile> Module; |
| 67 | OwningPtr<DIContext> DebugInfoContext; |
| 68 | public: |
| 69 | ModuleInfo(ObjectFile *Obj, DIContext *DICtx) |
| 70 | : Module(Obj), DebugInfoContext(DICtx) {} |
| 71 | |
| 72 | DILineInfo symbolizeCode( |
| 73 | uint64_t ModuleOffset, const LLVMSymbolizer::Options& Opts) const; |
| 74 | DIInliningInfo symbolizeInlinedCode( |
| 75 | uint64_t ModuleOffset, const LLVMSymbolizer::Options& Opts) const; |
| 76 | bool symbolizeData(uint64_t ModuleOffset, std::string &Name, |
| 77 | uint64_t &Start, uint64_t &Size) const; |
| 78 | |
| 79 | private: |
| 80 | bool getNameFromSymbolTable(SymbolRef::Type Type, uint64_t Address, |
| 81 | std::string &Name, uint64_t &Addr, |
| 82 | uint64_t &Size) const; |
| 83 | }; |
| 84 | |
| 85 | } // namespace symbolize |
| 86 | } // namespace llvm |
| 87 | |
| 88 | #endif // LLVM_SYMBOLIZE_H |