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 #ifndef __Type_h__
00032 #define __Type_h__
00033
00034 #include "Serialization.h"
00035 #include "Annotatable.h"
00036 #include "symutil.h"
00037
00038 namespace Dyninst{
00039 namespace SymtabAPI{
00040
00041 class Module;
00042 class Symtab;
00043 class Symbol;
00044 class Type;
00045 class typeEnum;
00046 class typePointer;
00047 class typeFunction;
00048 class typeSubrange;
00049 class typeArray;
00050 class typeStruct;
00051 class typeUnion;
00052 class typeScalar;
00053 class typeCommon;
00054 class typeTypedef;
00055 class typeRef;
00056 class CBlock;
00057 class typeCollection;
00058 class fieldListType;
00059 class TypeMemManager;
00060
00061
00062
00063
00064 typedef enum {dataEnum,
00065 dataPointer,
00066 dataFunction,
00067 dataSubrange,
00068 dataArray,
00069 dataStructure,
00070 dataUnion,
00071 dataCommon,
00072 dataScalar,
00073 dataTypedef,
00074 dataReference,
00075 dataUnknownType,
00076 dataNullType,
00077 dataTypeClass
00078 } dataClass;
00079
00080 SYMTAB_EXPORT const char *dataClass2Str(dataClass dc);
00081
00082 typedef int typeId_t;
00083
00084 typedef enum {
00085 visPrivate,
00086 visProtected,
00087 visPublic,
00088 visUnknown
00089 } visibility_t;
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 SYMTAB_EXPORT const char *visibility2Str(visibility_t v);
00102
00103 #define FIELD_ANNOTATABLE_CLASS AnnotatableDense
00104
00105 class Field : public Serializable, public FIELD_ANNOTATABLE_CLASS
00106 {
00107 friend class typeStruct;
00108 friend class typeUnion;
00109 friend class typeCommon;
00110 friend class CBlock;
00111
00112 std::string fieldName_;
00113 Type *type_;
00114 visibility_t vis_;
00115 int offset_;
00116
00117
00118 protected:
00119 void copy(Field &);
00120
00121 public:
00122 SYMTAB_EXPORT Field();
00123 SYMTAB_EXPORT Field(std::string name, Type *typ, int offsetVal = -1,
00124 visibility_t vis = visUnknown);
00125
00126
00127 SYMTAB_EXPORT Field(Field &f);
00128 SYMTAB_EXPORT ~Field();
00129
00130 SYMTAB_EXPORT std::string &getName();
00131 SYMTAB_EXPORT Type *getType();
00132 SYMTAB_EXPORT visibility_t getVisibility();
00133 SYMTAB_EXPORT unsigned int getSize();
00134 SYMTAB_EXPORT int getOffset();
00135
00136 SYMTAB_EXPORT void fixupUnknown(Module *);
00137 SYMTAB_EXPORT Serializable * serialize_impl(SerializerBase *sb,
00138 const char *tag="Field") THROW_SPEC(SerializerError);
00139 SYMTAB_EXPORT virtual bool operator==(const Field &) const;
00140 };
00141
00142 #define TYPE_ANNOTATABLE_CLASS AnnotatableDense
00143
00144 class Type : public Serializable, public TYPE_ANNOTATABLE_CLASS
00145 {
00146 friend class typeCollection;
00147 friend std::string parseStabString(Module *, int linenum, char *, int,
00148 typeCommon *);
00149 static Type* upgradePlaceholder(Type *placeholder, Type *new_type);
00150
00151 public:
00152
00153 SYMTAB_EXPORT virtual void serialize_specific(SerializerBase *)
00154 THROW_SPEC(SerializerError) {}
00155
00156 SYMTAB_EXPORT Serializable * serialize_impl(SerializerBase *,
00157 const char * = "Type") THROW_SPEC (SerializerError);
00158
00159 protected:
00160 typeId_t ID_;
00161 std::string name_;
00162 unsigned int size_;
00163 dataClass type_;
00164
00165
00166
00167
00168
00169
00170
00171
00172 bool updatingSize;
00173
00174 static typeId_t USER_TYPE_ID;
00175
00176
00177 unsigned int refCount;
00178
00179 protected:
00180 SYMTAB_EXPORT virtual void updateSize() {}
00181
00182 SYMTAB_EXPORT virtual void merge( Type * ) { }
00183
00184 public:
00185 SYMTAB_EXPORT virtual bool operator==(const Type &) const;
00186 SYMTAB_EXPORT virtual bool isCompatible(Type *oType);
00187 SYMTAB_EXPORT virtual void fixupUnknowns(Module *);
00188
00189 SYMTAB_EXPORT Type(std::string name, typeId_t ID, dataClass dataTyp = dataNullType);
00190 SYMTAB_EXPORT Type(std::string name, dataClass dataTyp = dataNullType);
00191
00192 SYMTAB_EXPORT Type();
00193 SYMTAB_EXPORT virtual ~Type();
00194
00195
00196 SYMTAB_EXPORT static Type *createFake(std::string name);
00197
00198 SYMTAB_EXPORT static Type *createPlaceholder(typeId_t ID, std::string name = "");
00199
00200 SYMTAB_EXPORT typeId_t getID() const;
00201 SYMTAB_EXPORT unsigned int getSize();
00202 SYMTAB_EXPORT bool setSize(unsigned int size);
00203 SYMTAB_EXPORT std::string &getName();
00204 SYMTAB_EXPORT bool setName(std::string);
00205 SYMTAB_EXPORT dataClass getDataClass() const;
00206
00207
00208 SYMTAB_EXPORT void incrRefCount();
00209 SYMTAB_EXPORT void decrRefCount();
00210
00211
00212 SYMTAB_EXPORT typeEnum *getEnumType();
00213 SYMTAB_EXPORT typePointer *getPointerType();
00214 SYMTAB_EXPORT typeFunction *getFunctionType();
00215 SYMTAB_EXPORT typeSubrange *getSubrangeType();
00216 SYMTAB_EXPORT typeArray *getArrayType();
00217 SYMTAB_EXPORT typeStruct *getStructType();
00218 SYMTAB_EXPORT typeUnion *getUnionType();
00219 SYMTAB_EXPORT typeScalar *getScalarType();
00220 SYMTAB_EXPORT typeCommon *getCommonType();
00221 SYMTAB_EXPORT typeTypedef *getTypedefType();
00222 SYMTAB_EXPORT typeRef *getRefType();
00223 SYMTAB_EXPORT std::string specificType();
00224 };
00225
00226
00227
00228
00229
00230 class fieldListInterface {
00231 public:
00232 SYMTAB_EXPORT virtual ~fieldListInterface() {};
00233 SYMTAB_EXPORT virtual std::vector<Field *> *getComponents() const = 0;
00234 };
00235
00236 class rangedInterface {
00237 public:
00238 SYMTAB_EXPORT virtual ~rangedInterface() {};
00239 SYMTAB_EXPORT virtual unsigned long getLow() const = 0;
00240 SYMTAB_EXPORT virtual unsigned long getHigh() const = 0;
00241 };
00242
00243 class derivedInterface{
00244 public:
00245 SYMTAB_EXPORT virtual ~derivedInterface() {};
00246 SYMTAB_EXPORT virtual Type *getConstituentType() const = 0;
00247 };
00248
00249
00250
00251 class fieldListType : public Type, public fieldListInterface
00252 {
00253 private:
00254 void fixupComponents();
00255 protected:
00256 std::vector<Field *> fieldList;
00257 std::vector<Field *> *derivedFieldList;
00258 SYMTAB_EXPORT fieldListType(std::string &name, typeId_t ID, dataClass typeDes);
00259
00260 public:
00261 SYMTAB_EXPORT fieldListType();
00262 SYMTAB_EXPORT ~fieldListType();
00263 SYMTAB_EXPORT bool operator==(const Type &) const;
00264 SYMTAB_EXPORT std::vector<Field *> *getComponents() const;
00265
00266 SYMTAB_EXPORT std::vector<Field *> *getFields() const;
00267
00268 SYMTAB_EXPORT virtual void postFieldInsert(int nsize) = 0;
00269
00270
00271 SYMTAB_EXPORT void addField(std::string fieldname, Type *type, int offsetVal = -1, visibility_t vis = visUnknown);
00272 SYMTAB_EXPORT void addField(unsigned num, std::string fieldname, Type *type, int offsetVal = -1, visibility_t vis = visUnknown);
00273 SYMTAB_EXPORT void addField(Field *fld);
00274 SYMTAB_EXPORT void addField(unsigned num, Field *fld);
00275
00276 SYMTAB_EXPORT void serialize_fieldlist(Dyninst::SerializerBase *,
00277 const char * = "fieldListType") THROW_SPEC (SerializerError);
00278
00279
00280 };
00281
00282 class rangedType : public Type, public rangedInterface {
00283 protected:
00284 unsigned long low_;
00285 unsigned long hi_;
00286 protected:
00287
00288 SYMTAB_EXPORT rangedType(std::string &name, typeId_t ID, dataClass typeDes, int size, unsigned long low, unsigned long hi);
00289 SYMTAB_EXPORT rangedType(std::string &name, dataClass typeDes, int size, unsigned long low, unsigned long hi);
00290 SYMTAB_EXPORT void serialize_ranged(SerializerBase *,
00291 const char * = "rangedType") THROW_SPEC (SerializerError);
00292 public:
00293 SYMTAB_EXPORT rangedType();
00294 SYMTAB_EXPORT ~rangedType();
00295 SYMTAB_EXPORT bool operator==(const Type &) const;
00296 SYMTAB_EXPORT unsigned long getLow() const { return low_; }
00297 SYMTAB_EXPORT unsigned long getHigh() const { return hi_; }
00298 };
00299
00300 class derivedType : public Type, public derivedInterface {
00301 protected:
00302 Type *baseType_;
00303 protected:
00304 SYMTAB_EXPORT derivedType(std::string &name, typeId_t id, int size, dataClass typeDes);
00305 SYMTAB_EXPORT derivedType(std::string &name, int size, dataClass typeDes);
00306 public:
00307 SYMTAB_EXPORT derivedType();
00308 SYMTAB_EXPORT ~derivedType();
00309 SYMTAB_EXPORT bool operator==(const Type &) const;
00310 SYMTAB_EXPORT Type *getConstituentType() const;
00311 SYMTAB_EXPORT void serialize_derived(SerializerBase *,
00312 const char * = "derivedType") THROW_SPEC(SerializerError);
00313 };
00314
00315
00316
00317 class typeEnum : public Type {
00318 private:
00319 std::vector<std::pair<std::string, int> > consts;
00320 public:
00321 SYMTAB_EXPORT typeEnum();
00322 SYMTAB_EXPORT typeEnum(typeId_t ID, std::string name = "");
00323 SYMTAB_EXPORT typeEnum(std::string name);
00324 SYMTAB_EXPORT static typeEnum *create(std::string &name, std::vector<std::pair<std::string, int> *>&elements,
00325 Symtab *obj = NULL);
00326 SYMTAB_EXPORT static typeEnum *create(std::string &name, std::vector<std::string> &constNames, Symtab *obj);
00327 SYMTAB_EXPORT bool addConstant(const std::string &fieldname,int value);
00328 SYMTAB_EXPORT std::vector<std::pair<std::string, int> > &getConstants();
00329 SYMTAB_EXPORT bool setName(const char *name);
00330 SYMTAB_EXPORT bool isCompatible(Type *otype);
00331 SYMTAB_EXPORT void serialize_specific(SerializerBase *) THROW_SPEC(SerializerError);
00332 };
00333
00334 class typeFunction : public Type {
00335 protected:
00336 SYMTAB_EXPORT void fixupUnknowns(Module *);
00337 private:
00338 Type *retType_;
00339 std::vector<Type *> params_;
00340 public:
00341 SYMTAB_EXPORT typeFunction();
00342 SYMTAB_EXPORT typeFunction(typeId_t ID, Type *retType, std::string name = "");
00343 SYMTAB_EXPORT typeFunction(Type *retType, std::string name = "");
00344 SYMTAB_EXPORT static typeFunction *create(std::string &name, Type *retType,
00345 std::vector<Type *> ¶mTypes, Symtab *obj = NULL);
00346 SYMTAB_EXPORT ~typeFunction();
00347 SYMTAB_EXPORT bool addParam( Type *type);
00348 SYMTAB_EXPORT Type *getReturnType() const;
00349 SYMTAB_EXPORT bool setRetType(Type *rtype);
00350
00351 SYMTAB_EXPORT std::vector<Type *> &getParams();
00352 SYMTAB_EXPORT bool isCompatible(Type *otype);
00353 SYMTAB_EXPORT void serialize_specific(SerializerBase *) THROW_SPEC(SerializerError);
00354 };
00355
00356 class typeScalar : public Type {
00357 private:
00358 bool isSigned_;
00359 public:
00360 SYMTAB_EXPORT typeScalar();
00361 SYMTAB_EXPORT typeScalar(typeId_t ID, unsigned int size, std::string name = "", bool isSigned = false);
00362 SYMTAB_EXPORT typeScalar(unsigned int size, std::string name = "", bool isSigned = false);
00363 SYMTAB_EXPORT static typeScalar *create(std::string &name, int size, Symtab *obj = NULL);
00364 SYMTAB_EXPORT bool isSigned();
00365 SYMTAB_EXPORT bool isCompatible(Type *otype);
00366 SYMTAB_EXPORT void serialize_specific(SerializerBase *) THROW_SPEC(SerializerError);
00367 };
00368
00369 class typeCommon : public fieldListType {
00370 private:
00371 std::vector<CBlock *> cblocks;
00372 protected:
00373 SYMTAB_EXPORT void postFieldInsert(int nsize) { size_ += nsize; }
00374
00375 SYMTAB_EXPORT void fixupUnknowns(Module *);
00376 public:
00377 SYMTAB_EXPORT typeCommon();
00378 SYMTAB_EXPORT typeCommon(typeId_t ID, std::string name = "");
00379 SYMTAB_EXPORT typeCommon(std::string name);
00380 SYMTAB_EXPORT static typeCommon *create(std::string &name, Symtab *obj = NULL);
00381 SYMTAB_EXPORT std::vector<CBlock *> *getCblocks() const;
00382 SYMTAB_EXPORT void beginCommonBlock();
00383 SYMTAB_EXPORT void endCommonBlock(Symbol *, void *baseAddr);
00384 SYMTAB_EXPORT void serialize_specific(SerializerBase *) THROW_SPEC(SerializerError);
00385 };
00386
00387 class CBlock : public Serializable, public AnnotatableSparse
00388 {
00389 friend class typeCommon;
00390 private:
00391
00392 std::vector<Field *> fieldList;
00393
00394
00395
00396 std::vector<Symbol *> functions;
00397
00398 public:
00399 SYMTAB_EXPORT std::vector<Field *> *getComponents();
00400 SYMTAB_EXPORT std::vector<Symbol *> *getFunctions();
00401
00402 SYMTAB_EXPORT void fixupUnknowns(Module *);
00403
00404 SYMTAB_EXPORT Serializable * serialize_impl(SerializerBase *,
00405 const char *tag="CBlock") THROW_SPEC(SerializerError);
00406 };
00407
00408 class typeStruct : public fieldListType {
00409 protected:
00410 SYMTAB_EXPORT void updateSize();
00411 SYMTAB_EXPORT void postFieldInsert(int nsize);
00412 SYMTAB_EXPORT void fixupUnknowns(Module *);
00413 SYMTAB_EXPORT void merge(Type *other);
00414 public:
00415 SYMTAB_EXPORT typeStruct();
00416 SYMTAB_EXPORT typeStruct(typeId_t ID, std::string name = "");
00417 SYMTAB_EXPORT typeStruct(std::string name);
00418 SYMTAB_EXPORT static typeStruct *create(std::string &name, std::vector< std::pair<std::string, Type *> *> &flds,
00419
00420 Symtab *obj = NULL);
00421 SYMTAB_EXPORT static typeStruct *create(std::string &name, std::vector<Field *> &fields,
00422 Symtab *obj = NULL);
00423
00424 SYMTAB_EXPORT bool isCompatible(Type *otype);
00425 SYMTAB_EXPORT void serialize_specific(SerializerBase *) THROW_SPEC(SerializerError);
00426 };
00427
00428 class typeUnion : public fieldListType {
00429 protected:
00430 SYMTAB_EXPORT void updateSize();
00431 SYMTAB_EXPORT void postFieldInsert(int nsize);
00432 SYMTAB_EXPORT void merge(Type *other);
00433 SYMTAB_EXPORT void fixupUnknowns(Module *);
00434 public:
00435 SYMTAB_EXPORT typeUnion();
00436 SYMTAB_EXPORT typeUnion(typeId_t ID, std::string name = "");
00437 SYMTAB_EXPORT typeUnion(std::string name);
00438 SYMTAB_EXPORT static typeUnion *create(std::string &name, std::vector<std::pair<std::string, Type *> *> &fieldNames,
00439 Symtab *obj = NULL);
00440 SYMTAB_EXPORT static typeUnion *create(std::string &name, std::vector<Field *> &fields,
00441 Symtab *obj = NULL);
00442 SYMTAB_EXPORT bool isCompatible(Type *otype);
00443 SYMTAB_EXPORT void serialize_specific(SerializerBase *) THROW_SPEC(SerializerError);
00444 };
00445
00446 class typePointer : public derivedType {
00447 protected:
00448 SYMTAB_EXPORT void fixupUnknowns(Module *);
00449 public:
00450 SYMTAB_EXPORT typePointer();
00451 SYMTAB_EXPORT typePointer(typeId_t ID, Type *ptr, std::string name = "");
00452 SYMTAB_EXPORT typePointer(Type *ptr, std::string name = "");
00453 SYMTAB_EXPORT static typePointer *create(std::string &name, Type *ptr, Symtab *obj = NULL);
00454 SYMTAB_EXPORT static typePointer *create(std::string &name, Type *ptr, int size,
00455 Symtab *obj = NULL);
00456 SYMTAB_EXPORT bool isCompatible(Type *otype);
00457 SYMTAB_EXPORT bool setPtr(Type *ptr);
00458 SYMTAB_EXPORT void serialize_specific(SerializerBase *) THROW_SPEC(SerializerError);
00459 };
00460
00461 class typeTypedef: public derivedType {
00462 private:
00463 unsigned int sizeHint_;
00464
00465 protected:
00466 SYMTAB_EXPORT void updateSize();
00467 SYMTAB_EXPORT void fixupUnknowns(Module *);
00468
00469 public:
00470 SYMTAB_EXPORT typeTypedef();
00471 SYMTAB_EXPORT typeTypedef(typeId_t ID, Type *base, std::string name, unsigned int sizeHint = 0);
00472 SYMTAB_EXPORT typeTypedef(Type *base, std::string name, unsigned int sizeHint = 0);
00473
00474 SYMTAB_EXPORT static typeTypedef *create(std::string &name, Type *ptr, Symtab *obj = NULL);
00475 SYMTAB_EXPORT bool isCompatible(Type *otype);
00476 SYMTAB_EXPORT bool operator==(const Type &otype) const;
00477 SYMTAB_EXPORT void serialize_specific(SerializerBase *) THROW_SPEC(SerializerError);
00478 };
00479
00480 class typeRef : public derivedType {
00481 protected:
00482 SYMTAB_EXPORT void fixupUnknowns(Module *);
00483 public:
00484 SYMTAB_EXPORT typeRef();
00485 SYMTAB_EXPORT typeRef(typeId_t ID, Type *refType, std::string name);
00486 SYMTAB_EXPORT typeRef(Type *refType, std::string name);
00487 SYMTAB_EXPORT static typeRef *create(std::string &name, Type *ptr, Symtab * obj = NULL);
00488 SYMTAB_EXPORT bool isCompatible(Type *otype);
00489 SYMTAB_EXPORT bool operator==(const Type &otype) const;
00490 SYMTAB_EXPORT void serialize_specific(SerializerBase *) THROW_SPEC(SerializerError);
00491 };
00492
00493 class typeSubrange : public rangedType {
00494 private:
00495
00496 public:
00497 SYMTAB_EXPORT typeSubrange();
00498 SYMTAB_EXPORT typeSubrange(typeId_t ID, int size, long low, long hi, std::string name);
00499 SYMTAB_EXPORT typeSubrange( int size, long low, long hi, std::string name);
00500 SYMTAB_EXPORT static typeSubrange *create(std::string &name, int size, long low, long hi, Symtab *obj = NULL);
00501 SYMTAB_EXPORT bool isCompatible(Type *otype);
00502 SYMTAB_EXPORT void serialize_specific(SerializerBase *) THROW_SPEC(SerializerError);
00503 };
00504
00505 class typeArray : public rangedType {
00506 private:
00507 Type *arrayElem;
00508 unsigned int sizeHint_;
00509 protected:
00510 SYMTAB_EXPORT void updateSize();
00511 SYMTAB_EXPORT void merge(Type *other);
00512 public:
00513 SYMTAB_EXPORT typeArray();
00514 SYMTAB_EXPORT typeArray(typeId_t ID, Type *base, long low, long hi, std::string name, unsigned int sizeHint = 0);
00515 SYMTAB_EXPORT typeArray(Type *base, long low, long hi, std::string name, unsigned int sizeHint = 0);
00516 SYMTAB_EXPORT static typeArray *create(std::string &name, Type *typ, long low, long hi, Symtab *obj = NULL);
00517 SYMTAB_EXPORT Type *getBaseType() const;
00518 SYMTAB_EXPORT bool isCompatible(Type *otype);
00519 SYMTAB_EXPORT bool operator==(const Type &otype) const;
00520 SYMTAB_EXPORT void fixupUnknowns(Module *);
00521 SYMTAB_EXPORT void serialize_specific(SerializerBase *) THROW_SPEC(SerializerError);
00522 };
00523
00524 }
00525 }
00526 #endif
00527