2019-07-29 01:08:52 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** Allow to quickly find symbol name from address.
|
|
|
|
* Used as a replacement for "dladdr" function which is extremely slow.
|
|
|
|
*/
|
|
|
|
class SymbolIndex
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct Symbol
|
|
|
|
{
|
|
|
|
const void * address_begin;
|
|
|
|
const void * address_end;
|
|
|
|
const char * object;
|
2019-07-29 17:14:53 +00:00
|
|
|
std::string name; /// demangled NOTE Can use Arena for strings
|
2019-07-29 18:38:04 +00:00
|
|
|
};
|
2019-07-29 01:08:52 +00:00
|
|
|
|
2019-07-29 18:38:04 +00:00
|
|
|
struct Object
|
|
|
|
{
|
|
|
|
const void * address_begin;
|
|
|
|
const void * address_end;
|
|
|
|
std::string name;
|
2019-07-29 01:08:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SymbolIndex() { update(); }
|
|
|
|
void update();
|
|
|
|
|
2019-07-29 18:38:04 +00:00
|
|
|
const Symbol * findSymbol(const void * address) const;
|
|
|
|
const Object * findObject(const void * address) const;
|
2019-07-29 01:08:52 +00:00
|
|
|
|
2019-07-29 18:38:04 +00:00
|
|
|
const std::vector<Symbol> & symbols() const { return data.symbols; }
|
|
|
|
const std::vector<Object> & objects() const { return data.objects; }
|
2019-07-29 01:08:52 +00:00
|
|
|
|
2019-07-29 18:38:04 +00:00
|
|
|
struct Data
|
|
|
|
{
|
|
|
|
std::vector<Symbol> symbols;
|
|
|
|
std::vector<Object> objects;
|
|
|
|
};
|
2019-07-29 01:08:52 +00:00
|
|
|
private:
|
2019-07-29 18:38:04 +00:00
|
|
|
Data data;
|
2019-07-29 01:08:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|