#pragma once #ifdef __ELF__ #include #include #include #include namespace DB { /** Allow to quickly find symbol name from address. * Used as a replacement for "dladdr" function which is extremely slow. * It works better than "dladdr" because it also allows to search private symbols, that are not participated in shared linking. */ class SymbolIndex : public ext::singleton { protected: friend class ext::singleton; SymbolIndex() { update(); } public: struct Symbol { const void * address_begin; const void * address_end; const char * name; }; struct Object { const void * address_begin; const void * address_end; std::string name; std::unique_ptr elf; }; const Symbol * findSymbol(const void * address) const; const Object * findObject(const void * address) const; const std::vector & symbols() const { return data.symbols; } const std::vector & objects() const { return data.objects; } struct Data { std::vector symbols; std::vector objects; }; private: Data data; void update(); }; } #endif