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