7c138d3e4683a12e27c66daf315e34ddb504e25f
[oota-llvm.git] / lib / DebugInfo / Symbolize / SymbolizableObjectFile.h
1 //===-- SymbolizableObjectFile.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 // This file declares the SymbolizableObjectFile class.
11 //
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H
14 #define LLVM_LIB_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H
15
16 #include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
17 #include <map>
18
19 namespace llvm {
20 class DataExtractor;
21 }
22
23 namespace llvm {
24 namespace symbolize {
25
26 class SymbolizableObjectFile : public SymbolizableModule {
27 public:
28   static ErrorOr<std::unique_ptr<SymbolizableObjectFile>>
29   create(object::ObjectFile *Obj, std::unique_ptr<DIContext> DICtx);
30
31   DILineInfo symbolizeCode(uint64_t ModuleOffset, FunctionNameKind FNKind,
32                            bool UseSymbolTable) const override;
33   DIInliningInfo symbolizeInlinedCode(uint64_t ModuleOffset,
34                                       FunctionNameKind FNKind,
35                                       bool UseSymbolTable) const override;
36   bool symbolizeData(uint64_t ModuleOffset, std::string &Name, uint64_t &Start,
37                      uint64_t &Size) const override;
38
39   // Return true if this is a 32-bit x86 PE COFF module.
40   bool isWin32Module() const override;
41
42   // Returns the preferred base of the module, i.e. where the loader would place
43   // it in memory assuming there were no conflicts.
44   uint64_t getModulePreferredBase() const override;
45
46 private:
47   bool getNameFromSymbolTable(object::SymbolRef::Type Type, uint64_t Address,
48                               std::string &Name, uint64_t &Addr,
49                               uint64_t &Size) const;
50   // For big-endian PowerPC64 ELF, OpdAddress is the address of the .opd
51   // (function descriptor) section and OpdExtractor refers to its contents.
52   std::error_code addSymbol(const object::SymbolRef &Symbol,
53                             uint64_t SymbolSize,
54                             DataExtractor *OpdExtractor = nullptr,
55                             uint64_t OpdAddress = 0);
56   std::error_code addCoffExportSymbols(const object::COFFObjectFile *CoffObj);
57
58   object::ObjectFile *Module;
59   std::unique_ptr<DIContext> DebugInfoContext;
60
61   struct SymbolDesc {
62     uint64_t Addr;
63     // If size is 0, assume that symbol occupies the whole memory range up to
64     // the following symbol.
65     uint64_t Size;
66     friend bool operator<(const SymbolDesc &s1, const SymbolDesc &s2) {
67       return s1.Addr < s2.Addr;
68     }
69   };
70   std::map<SymbolDesc, StringRef> Functions;
71   std::map<SymbolDesc, StringRef> Objects;
72
73   SymbolizableObjectFile(object::ObjectFile *Obj,
74                          std::unique_ptr<DIContext> DICtx);
75 };
76
77 }  // namespace symbolize
78 }  // namespace llvm
79
80 #endif  // LLVM_LIB_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H