00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #if !defined(_Symbol_h_)
00037 #define _Symbol_h_
00038
00039
00040
00041
00042
00043
00044 #include "symutil.h"
00045 #include "Annotatable.h"
00046 #include "Serialization.h"
00047
00048 #ifndef CASE_RETURN_STR
00049 #define CASE_RETURN_STR(x) case x: return #x
00050 #endif
00051
00052
00053 namespace Dyninst{
00054 namespace SymtabAPI{
00055
00056 class Module;
00057 class typeCommon;
00058 class localVarCollection;
00059 class Region;
00060 class Aggregate;
00061 class Function;
00062 class Variable;
00063 class Type;
00064 class typeCollection;
00065 class Symtab;
00066
00067
00068
00069
00070
00071 class Symbol : public Serializable,
00072 public AnnotatableSparse
00073 {
00074 friend class typeCommon;
00075 friend class Symtab;
00076 friend class AObject;
00077 friend class Object;
00078 friend class Aggregate;
00079 friend class relocationEntry;
00080
00081 friend std::string parseStabString(Module *, int linenum, char *, int,
00082 typeCommon *);
00083
00084 public:
00085
00086 enum SymbolType {
00087 ST_UNKNOWN,
00088 ST_FUNCTION,
00089 ST_OBJECT,
00090 ST_MODULE,
00091 ST_SECTION,
00092 ST_TLS,
00093 ST_DELETED,
00094 ST_INDIRECT,
00095 ST_NOTYPE
00096 };
00097
00098 static const char *symbolType2Str(SymbolType t);
00099
00100 enum SymbolLinkage {
00101 SL_UNKNOWN,
00102 SL_GLOBAL,
00103 SL_LOCAL,
00104 SL_WEAK
00105 };
00106
00107 static const char *symbolLinkage2Str(SymbolLinkage t);
00108
00109 enum SymbolTag {
00110 TAG_UNKNOWN,
00111 TAG_USER,
00112 TAG_LIBRARY,
00113 TAG_INTERNAL
00114 };
00115
00116 static const char *symbolTag2Str(SymbolTag t);
00117
00118 enum SymbolVisibility {
00119 SV_UNKNOWN,
00120 SV_DEFAULT,
00121 SV_INTERNAL,
00122 SV_HIDDEN,
00123 SV_PROTECTED
00124 };
00125 static const char *symbolVisibility2Str(SymbolVisibility t);
00126
00127 SYMTAB_EXPORT Symbol();
00128
00129 SYMTAB_EXPORT static Symbol *magicEmitElfSymbol();
00130
00131 SYMTAB_EXPORT Symbol (const std::string& name,
00132 SymbolType t,
00133 SymbolLinkage l,
00134 SymbolVisibility v,
00135 Offset o,
00136 Module *module = NULL,
00137 Region *r = NULL,
00138 unsigned s = 0,
00139 bool d = false,
00140 bool a = false,
00141 int index= -1,
00142 int strindex = -1,
00143 bool cs = false);
00144 SYMTAB_EXPORT ~Symbol();
00145
00146 SYMTAB_EXPORT bool operator== (const Symbol &) const;
00147
00148
00149
00150
00151 SYMTAB_EXPORT const std::string& getMangledName () const;
00152 SYMTAB_EXPORT const std::string& getPrettyName() const;
00153 SYMTAB_EXPORT const std::string& getTypedName() const;
00154
00155 SYMTAB_EXPORT Module *getModule() const { return module_; }
00156 SYMTAB_EXPORT Symtab *getSymtab() const;
00157 SYMTAB_EXPORT SymbolType getType () const { return type_; }
00158 SYMTAB_EXPORT SymbolLinkage getLinkage () const { return linkage_; }
00159 SYMTAB_EXPORT Offset getOffset() const { return offset_; }
00160 SYMTAB_EXPORT Offset getPtrOffset() const { return ptr_offset_; }
00161 SYMTAB_EXPORT Offset getLocalTOC() const { return localTOC_; }
00162 SYMTAB_EXPORT unsigned getSize() const { return size_; }
00163 SYMTAB_EXPORT Region *getRegion() const { return region_; }
00164
00165 SYMTAB_EXPORT bool isInDynSymtab() const { return (type_ != ST_DELETED) && isDynamic_; }
00166 SYMTAB_EXPORT bool isInSymtab() const { return (type_ != ST_DELETED) && !isDynamic_; }
00167 SYMTAB_EXPORT bool isAbsolute() const { return isAbsolute_; }
00168 SYMTAB_EXPORT bool isCommonStorage() const { return isCommonStorage_; }
00169
00170 SYMTAB_EXPORT bool isFunction() const;
00171 SYMTAB_EXPORT bool setFunction(Function * func);
00172 SYMTAB_EXPORT Function * getFunction() const;
00173
00174 SYMTAB_EXPORT bool isVariable() const;
00175 SYMTAB_EXPORT bool setVariable(Variable *var);
00176 SYMTAB_EXPORT Variable * getVariable() const;
00177
00178 SYMTAB_EXPORT SymbolVisibility getVisibility() const { return visibility_; }
00179
00180 SYMTAB_EXPORT int getIndex() const { return index_; }
00181 SYMTAB_EXPORT bool setIndex(int index) { index_ = index; return true; }
00182 SYMTAB_EXPORT int getStrIndex() const { return strindex_; }
00183 SYMTAB_EXPORT bool setStrIndex(int strindex) { strindex_ = strindex; return true; }
00184 SYMTAB_EXPORT void setReferringSymbol (Symbol *referringSymbol);
00185 SYMTAB_EXPORT Symbol* getReferringSymbol ();
00186
00187
00188 SYMTAB_EXPORT bool setOffset (Offset newOffset);
00189 SYMTAB_EXPORT bool setPtrOffset (Offset newOffset);
00190 SYMTAB_EXPORT bool setLocalTOC (Offset localTOC);
00191 SYMTAB_EXPORT bool setSize(unsigned ns);
00192 SYMTAB_EXPORT bool setRegion(Region *r);
00193 SYMTAB_EXPORT bool setModule(Module *mod);
00194
00195 SYMTAB_EXPORT bool setMangledName(std::string name);
00196
00197 SYMTAB_EXPORT bool setSymbolType(SymbolType sType);
00198
00199 SYMTAB_EXPORT SymbolTag tag () const;
00200 SYMTAB_EXPORT bool setDynamic(bool d) { isDynamic_ = d; return true;}
00201 SYMTAB_EXPORT bool setAbsolute(bool a) { isAbsolute_ = a; return true; }
00202 SYMTAB_EXPORT bool setCommonStorage(bool cs) { isCommonStorage_ = cs; return true; }
00203
00204 SYMTAB_EXPORT bool setVersionFileName(std::string &fileName);
00205 SYMTAB_EXPORT bool setVersions(std::vector<std::string> &vers);
00206 SYMTAB_EXPORT bool setVersionNum(unsigned verNum);
00207 SYMTAB_EXPORT void setVersionHidden() { versionHidden_ = true; }
00208
00209 SYMTAB_EXPORT bool getVersionFileName(std::string &fileName);
00210 SYMTAB_EXPORT bool getVersions(std::vector<std::string> *&vers);
00211 SYMTAB_EXPORT bool getVersionNum(unsigned &verNum);
00212 SYMTAB_EXPORT bool getVersionHidden() { return versionHidden_; }
00213
00214 friend
00215 std::ostream& operator<< (std::ostream &os, const Symbol &s);
00216
00217 public:
00218 static std::string emptyString;
00219 int getInternalType() { return internal_type_; }
00220 void setInternalType(int i) { internal_type_ = i; }
00221
00222 private:
00223
00224 Module* module_;
00225 SymbolType type_;
00226 int internal_type_;
00227 SymbolLinkage linkage_;
00228 SymbolVisibility visibility_;
00229 Offset offset_;
00230 Offset ptr_offset_;
00231 Offset localTOC_;
00232 Region* region_;
00233 Symbol* referring_;
00234 unsigned size_;
00235
00236 bool isDynamic_;
00237 bool isAbsolute_;
00238
00239 Aggregate * aggregate_;
00240
00241 std::string mangledName_;
00242 std::string prettyName_;
00243 std::string typedName_;
00244
00245 SymbolTag tag_;
00246 int index_;
00247 int strindex_;
00248
00249 bool isCommonStorage_;
00250
00251 std::vector<std::string> verNames_;
00252
00253 bool versionHidden_;
00254
00255 void restore_module_and_region(SerializerBase *,
00256 std::string &, Offset) THROW_SPEC (SerializerError);
00257
00258 public:
00259
00260 SYMTAB_EXPORT Serializable * serialize_impl(SerializerBase *,
00261 const char *tag = "Symbol") THROW_SPEC (SerializerError);
00262 };
00263
00264 class LookupInterface
00265 {
00266 public:
00267 SYMTAB_EXPORT LookupInterface();
00268 SYMTAB_EXPORT virtual bool getAllSymbolsByType(std::vector<Symbol *> &ret,
00269 Symbol::SymbolType sType) = 0;
00270 SYMTAB_EXPORT virtual bool findSymbol(std::vector<Symbol *> &ret,
00271 const std::string& name,
00272 Symbol::SymbolType sType = Symbol::ST_UNKNOWN,
00273 NameType nameType = anyName,
00274 bool isRegex = false,
00275 bool checkCase = false,
00276 bool includeUndefined = false) = 0;
00277 SYMTAB_EXPORT virtual bool findType(Type *&type, std::string name) = 0;
00278 SYMTAB_EXPORT virtual bool findVariableType(Type *&type, std::string name)= 0;
00279
00280 SYMTAB_EXPORT virtual ~LookupInterface();
00281 };
00282
00283 std::ostream& operator<< (std::ostream &os, const Symbol &s);
00284
00285 }
00286 }
00287
00288 #endif