Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef ABSL_DEBUGGING_INTERNAL_ELF_MEM_IMAGE_H_
00020 #define ABSL_DEBUGGING_INTERNAL_ELF_MEM_IMAGE_H_
00021
00022
00023
00024 #include <climits>
00025
00026
00027
00028 #ifdef ABSL_HAVE_ELF_MEM_IMAGE
00029 #error ABSL_HAVE_ELF_MEM_IMAGE cannot be directly set
00030 #endif
00031
00032 #if defined(__ELF__) && defined(__GLIBC__) && !defined(__native_client__) && \
00033 !defined(__asmjs__) && !defined(__wasm__)
00034 #define ABSL_HAVE_ELF_MEM_IMAGE 1
00035 #endif
00036
00037 #if ABSL_HAVE_ELF_MEM_IMAGE
00038
00039 #include <link.h>
00040
00041 namespace absl {
00042 namespace debugging_internal {
00043
00044
00045 class ElfMemImage {
00046 private:
00047
00048 static const int kInvalidBaseSentinel;
00049
00050 public:
00051
00052 static constexpr const void *const kInvalidBase =
00053 static_cast<const void*>(&kInvalidBaseSentinel);
00054
00055
00056
00057
00058 struct SymbolInfo {
00059 const char *name;
00060 const char *version;
00061
00062 const void *address;
00063 const ElfW(Sym) *symbol;
00064 };
00065
00066
00067 class SymbolIterator {
00068 public:
00069 friend class ElfMemImage;
00070 const SymbolInfo *operator->() const;
00071 const SymbolInfo &operator*() const;
00072 SymbolIterator& operator++();
00073 bool operator!=(const SymbolIterator &rhs) const;
00074 bool operator==(const SymbolIterator &rhs) const;
00075 private:
00076 SymbolIterator(const void *const image, int index);
00077 void Update(int incr);
00078 SymbolInfo info_;
00079 int index_;
00080 const void *const image_;
00081 };
00082
00083
00084 explicit ElfMemImage(const void *base);
00085 void Init(const void *base);
00086 bool IsPresent() const { return ehdr_ != nullptr; }
00087 const ElfW(Phdr)* GetPhdr(int index) const;
00088 const ElfW(Sym)* GetDynsym(int index) const;
00089 const ElfW(Versym)* GetVersym(int index) const;
00090 const ElfW(Verdef)* GetVerdef(int index) const;
00091 const ElfW(Verdaux)* GetVerdefAux(const ElfW(Verdef) *verdef) const;
00092 const char* GetDynstr(ElfW(Word) offset) const;
00093 const void* GetSymAddr(const ElfW(Sym) *sym) const;
00094 const char* GetVerstr(ElfW(Word) offset) const;
00095 int GetNumSymbols() const;
00096
00097 SymbolIterator begin() const;
00098 SymbolIterator end() const;
00099
00100
00101
00102
00103
00104 bool LookupSymbol(const char *name, const char *version,
00105 int symbol_type, SymbolInfo *info_out) const;
00106
00107
00108
00109
00110
00111 bool LookupSymbolByAddress(const void *address, SymbolInfo *info_out) const;
00112
00113 private:
00114 const ElfW(Ehdr) *ehdr_;
00115 const ElfW(Sym) *dynsym_;
00116 const ElfW(Versym) *versym_;
00117 const ElfW(Verdef) *verdef_;
00118 const ElfW(Word) *hash_;
00119 const char *dynstr_;
00120 size_t strsize_;
00121 size_t verdefnum_;
00122 ElfW(Addr) link_base_;
00123 };
00124
00125 }
00126 }
00127
00128 #endif // ABSL_HAVE_ELF_MEM_IMAGE
00129
00130 #endif // ABSL_DEBUGGING_INTERNAL_ELF_MEM_IMAGE_H_