00001 #ifndef IG_PROF_IG_PROF_SYM_CACHE_H 00002 # define IG_PROF_IG_PROF_SYM_CACHE_H 00003 00004 # include "IgTools/IgProf/src/IgProfMacros.h" 00005 # include "IgTools/IgProf/src/IgProfBuffer.h" 00006 # include "IgTools/IgProf/src/IgProf.h" 00007 # include <limits.h> 00008 # include <stdint.h> 00009 00011 class IgProfSymCache : protected IgProfBuffer 00012 { 00013 static const unsigned int BINARY_HASH = 128; 00014 static const unsigned int SYMBOL_HASH = 128*1024; 00015 public: 00016 struct Binary; 00017 struct Symbol; 00018 struct SymCache; 00019 00021 struct Binary 00022 { 00023 Binary *next; //< The next binary in the hash bin chain. 00024 const char *name; //< Name of the executable object if known. 00025 int id; //< Reference ID in final output, -1 if unset. 00026 }; 00027 00029 struct Symbol 00030 { 00031 Symbol *next; //< The next symbol in the hash bin chain. 00032 void *address; //< Instruction pointer value. 00033 const char *name; //< Name of the symbol (function) if known. 00034 int symoffset; //< Offset from the beginning of symbol. 00035 int binoffset; //< Offset from the beginning of executable object. 00036 Binary *binary; //< The binary object containing this symbol. 00037 int id; //< Reference ID in final output, -1 if unset. 00038 }; 00039 00041 struct SymCache 00042 { 00043 SymCache *next; //< The next cache entry in the hash bin chain. 00044 void *calladdr; //< Instruction pointer value. 00045 void *symaddr; //< Address of the corresponding symbol. 00046 }; 00047 00048 IgProfSymCache(void); 00049 ~IgProfSymCache(void); 00050 00051 Symbol * get(void *address); 00052 00053 private: 00054 void * roundAddressToSymbol(void *address); 00055 Symbol * symbolForAddress(void *address); 00056 00057 Binary *bintable_[BINARY_HASH]; //< The binaries hash. 00058 Symbol *symtable_[SYMBOL_HASH]; //< The symbol hash. 00059 SymCache *symcache_[SYMBOL_HASH]; //< The symbol cache hash. 00060 00061 // Unavailable copy constructor, assignment operator 00062 IgProfSymCache(IgProfSymCache &); 00063 IgProfSymCache &operator=(IgProfSymCache &); 00064 }; 00065 00066 #endif // IG_PROF_IG_PROF_SYM_CACHE_H