]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/llvm/tools/llvm-symbolizer/LLVMSymbolize.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / llvm / tools / llvm-symbolizer / LLVMSymbolize.h
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), PrintFunctions(PrintFunctions),
41           PrintInlining(PrintInlining), Demangle(Demangle) {
42     }
43   };
44
45   LLVMSymbolizer(const Options &Opts = Options()) : Opts(Opts) {}
46
47   // Returns the result of symbolization for module name/offset as
48   // a string (possibly containing newlines).
49   std::string
50   symbolizeCode(const std::string &ModuleName, uint64_t ModuleOffset);
51   std::string
52   symbolizeData(const std::string &ModuleName, uint64_t ModuleOffset);
53   void flush();
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;
62   static const char kBadString[];
63 };
64
65 class ModuleInfo {
66 public:
67   ModuleInfo(ObjectFile *Obj, DIContext *DICtx);
68
69   DILineInfo symbolizeCode(uint64_t ModuleOffset,
70                            const LLVMSymbolizer::Options &Opts) const;
71   DIInliningInfo symbolizeInlinedCode(
72       uint64_t ModuleOffset, const LLVMSymbolizer::Options &Opts) const;
73   bool symbolizeData(uint64_t ModuleOffset, std::string &Name, uint64_t &Start,
74                      uint64_t &Size) const;
75
76 private:
77   bool getNameFromSymbolTable(SymbolRef::Type Type, uint64_t Address,
78                               std::string &Name, uint64_t &Addr,
79                               uint64_t &Size) const;
80   OwningPtr<ObjectFile> Module;
81   OwningPtr<DIContext> DebugInfoContext;
82
83   struct SymbolDesc {
84     uint64_t Addr;
85     uint64_t AddrEnd;
86     friend bool operator<(const SymbolDesc &s1, const SymbolDesc &s2) {
87       return s1.AddrEnd <= s2.Addr;
88     }
89   };
90   typedef std::map<SymbolDesc, StringRef> SymbolMapTy;
91   SymbolMapTy Functions;
92   SymbolMapTy Objects;
93 };
94
95 } // namespace symbolize
96 } // namespace llvm
97
98 #endif // LLVM_SYMBOLIZE_H