2 * Copyright (c) 1996-2009 Barton P. Miller
4 * We provide the Paradyn Parallel Performance Tools (below
5 * described as "Paradyn") on an AS IS basis, and do not warrant its
6 * validity or performance. We reserve the right to update, modify,
7 * or discontinue this software at any time. We shall have no
8 * obligation to supply such updates or modifications or any other
9 * form of support to you.
11 * By your use of Paradyn, you understand and agree that we (or any
12 * other person or entity with proprietary rights in Paradyn) are
13 * under no obligation to provide either maintenance services,
14 * update services, notices of latent defects, or correction of
15 * defects for Paradyn.
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License as published by the Free Software Foundation; either
20 * version 2.1 of the License, or (at your option) any later version.
22 * This library is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * Lesser General Public License for more details.
27 * You should have received a copy of the GNU Lesser General Public
28 * License along with this library; if not, write to the Free Software
29 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
35 #include "Serialization.h"
36 #include "Annotatable.h"
60 class localVarCollection;
63 //TODO?? class BPatch(to be ??)function;
66 typedef enum {dataEnum,
82 const char *dataClass2Str(dataClass dc);
94 * visibility: Accessibility of member data and functions
95 * These values follow the 'fieldname:' after the '/' identifier.
96 * visPrivate == 0 gnu Sun -- private
97 * visProtected == 1 gnu Sun -- protected
98 * visPublic == 2 gnu Sun -- public
99 * visUnknown visibility not known or doesn't apply(ANSIC), the default
103 const char *visibility2Str(visibility_t v);
111 const char *storageClass2Str(storageClass sc);
113 * storageClass: Encodes how a variable is stored.
115 * storageAddr - Absolute address of variable.
116 * storageReg - Register which holds variable value.
117 * storageRegOffset - Address of variable = $reg + address.
126 * storageRefClass: Encodes if a variable can be accessed through a register/address.
128 * storageRef - There is a pointer to variable.
129 * storageNoRef - No reference. Value can be obtained using storageClass.
132 class SYMTAB_EXPORT Field{
133 friend class typeStruct;
134 friend class typeUnion;
135 friend class typeCommon;
138 std::string fieldName_;
149 Field(std::string name, Type *typ, int offsetVal = -1, visibility_t vis = visUnknown);
155 std::string &getName();
157 visibility_t getVisibility();
158 unsigned int getSize();
160 void *getUpPtr() const;
161 bool setUpPtr(void *);
163 void fixupUnknown(Module *);
166 class Type : public Serializable, public AnnotatableSparse {
167 friend class typeCollection;
168 friend std::string parseStabString(Module *, int linenum, char *, int,
170 static Type* upgradePlaceholder(Type *placeholder, Type *new_type);
172 SYMTAB_EXPORT void serialize(SerializerBase *, const char *);
174 typeId_t ID_; /* unique ID of type */
176 unsigned int size_; /* size of type */
180 * We set updatingSize to true when we're in the process of
181 * calculating the size of container structures. This helps avoid
182 * infinite recursion for self referencial types. Getting a
183 * self-referencial type probably signifies an error in another
184 * part of the type processing code (or an error in the binary).
188 static typeId_t USER_TYPE_ID;
190 // INTERNAL DATA MEMBERS
191 unsigned int refCount;
197 SYMTAB_EXPORT virtual void updateSize() {}
199 SYMTAB_EXPORT virtual void merge( Type * /* other */ ) { }
202 SYMTAB_EXPORT virtual bool operator==(const Type &) const;
203 SYMTAB_EXPORT virtual bool isCompatible(Type *oType);
204 SYMTAB_EXPORT virtual void fixupUnknowns(Module *);
206 SYMTAB_EXPORT Type(std::string name, typeId_t ID, dataClass dataTyp = dataNullType);
207 SYMTAB_EXPORT Type(std::string name, dataClass dataTyp = dataNullType);
209 SYMTAB_EXPORT Type();
210 SYMTAB_EXPORT virtual ~Type();
212 // A few convenience functions
213 SYMTAB_EXPORT static Type *createFake(std::string name);
214 /* Placeholder for real type, to be filled in later */
215 SYMTAB_EXPORT static Type *createPlaceholder(typeId_t ID, std::string name = "");
217 SYMTAB_EXPORT typeId_t getID() const;
218 SYMTAB_EXPORT unsigned int getSize();
219 SYMTAB_EXPORT bool setSize(unsigned int size);
220 SYMTAB_EXPORT std::string &getName();
221 SYMTAB_EXPORT bool setName(std::string);
223 SYMTAB_EXPORT bool setUpPtr(void *);
224 SYMTAB_EXPORT void *getUpPtr() const;
226 SYMTAB_EXPORT dataClass getDataClass() const;
229 SYMTAB_EXPORT void incrRefCount();
230 SYMTAB_EXPORT void decrRefCount();
231 //Methods to dynamically cast generic Type Object to specific types.
233 SYMTAB_EXPORT typeEnum *getEnumType();
234 SYMTAB_EXPORT typePointer *getPointerType();
235 SYMTAB_EXPORT typeFunction *getFunctionType();
236 SYMTAB_EXPORT typeSubrange *getSubrangeType();
237 SYMTAB_EXPORT typeArray *getArrayType();
238 SYMTAB_EXPORT typeStruct *getStructType();
239 SYMTAB_EXPORT typeUnion *getUnionType();
240 SYMTAB_EXPORT typeScalar *getScalarType();
241 SYMTAB_EXPORT typeCommon *getCommonType();
242 SYMTAB_EXPORT typeTypedef *getTypedefType();
243 SYMTAB_EXPORT typeRef *getRefType();
246 // Interfaces to be implemented by intermediate subtypes
247 // We have to do this thanks to reference types and C++'s lovely
248 // multiple inheritance
250 class fieldListInterface {
252 SYMTAB_EXPORT virtual ~fieldListInterface() {};
253 SYMTAB_EXPORT virtual std::vector<Field *> *getComponents() const = 0;
256 class rangedInterface {
258 SYMTAB_EXPORT virtual ~rangedInterface() {};
259 SYMTAB_EXPORT virtual int getLow() const = 0;
260 SYMTAB_EXPORT virtual int getHigh() const = 0;
263 class derivedInterface{
265 SYMTAB_EXPORT virtual ~derivedInterface() {};
266 SYMTAB_EXPORT virtual Type *getConstituentType() const = 0;
269 // Intermediate types (interfaces + Type)
271 class fieldListType : public Type, public fieldListInterface {
273 void fixupComponents();
275 std::vector<Field *> fieldList;
276 std::vector<Field *> *derivedFieldList;
277 SYMTAB_EXPORT fieldListType(std::string &name, typeId_t ID, dataClass typeDes);
278 /* Each subclass may need to update its size after adding a field */
280 SYMTAB_EXPORT fieldListType();
281 SYMTAB_EXPORT ~fieldListType();
282 SYMTAB_EXPORT bool operator==(const Type &) const;
283 SYMTAB_EXPORT std::vector<Field *> *getComponents() const;
285 SYMTAB_EXPORT std::vector<Field *> *getFields() const;
287 SYMTAB_EXPORT virtual void postFieldInsert(int nsize) = 0;
289 /* Add field for C++ struct or union */
290 SYMTAB_EXPORT void addField(std::string fieldname, Type *type, int offsetVal = -1, visibility_t vis = visUnknown);
291 SYMTAB_EXPORT void addField(unsigned num, std::string fieldname, Type *type, int offsetVal = -1, visibility_t vis = visUnknown);
292 SYMTAB_EXPORT void addField(Field *fld);
293 SYMTAB_EXPORT void addField(unsigned num, Field *fld);
295 // void addField(const std::string &fieldname, dataClass typeDes,
296 // Type *type, int offset, int size, visibility_t vis = visUnknown);
299 class rangedType : public Type, public rangedInterface {
306 //rangedType(const std::string &name, typeId_t ID, dataClass typeDes, int size, const char *low, const char *hi);
307 SYMTAB_EXPORT rangedType(std::string &name, typeId_t ID, dataClass typeDes, int size, int low, int hi);
308 SYMTAB_EXPORT rangedType(std::string &name, dataClass typeDes, int size, int low, int hi);
310 SYMTAB_EXPORT rangedType();
311 SYMTAB_EXPORT ~rangedType();
312 SYMTAB_EXPORT bool operator==(const Type &) const;
313 SYMTAB_EXPORT int getLow() const { return low_; }
314 SYMTAB_EXPORT int getHigh() const { return hi_; }
317 class derivedType : public Type, public derivedInterface {
321 SYMTAB_EXPORT derivedType(std::string &name, typeId_t id, int size, dataClass typeDes);
322 SYMTAB_EXPORT derivedType(std::string &name, int size, dataClass typeDes);
324 SYMTAB_EXPORT derivedType();
325 SYMTAB_EXPORT ~derivedType();
326 SYMTAB_EXPORT bool operator==(const Type &) const;
327 SYMTAB_EXPORT Type *getConstituentType() const;
330 // Derived classes from Type
332 class typeEnum : public Type {
334 std::vector<std::pair<std::string, int> *> consts;
336 SYMTAB_EXPORT typeEnum();
337 SYMTAB_EXPORT typeEnum(typeId_t ID, std::string name = "");
338 SYMTAB_EXPORT typeEnum(std::string name);
339 SYMTAB_EXPORT static typeEnum *create(std::string &name, std::vector<std::pair<std::string, int> *>&elements,
341 SYMTAB_EXPORT static typeEnum *typeEnum::create(std::string &name, std::vector<std::string> &constNames, Symtab *obj);
342 SYMTAB_EXPORT bool addConstant(const std::string &fieldname,int value);
343 SYMTAB_EXPORT std::vector<std::pair<std::string, int> *> &getConstants();
344 SYMTAB_EXPORT bool setName(const char *name);
345 SYMTAB_EXPORT bool isCompatible(Type *otype);
348 class typeFunction : public Type {
350 SYMTAB_EXPORT void fixupUnknowns(Module *);
352 Type *retType_; /* Return type of the function */
353 std::vector<Type *> params_;
355 SYMTAB_EXPORT typeFunction();
356 SYMTAB_EXPORT typeFunction(typeId_t ID, Type *retType, std::string name = "");
357 SYMTAB_EXPORT typeFunction(Type *retType, std::string name = "");
358 SYMTAB_EXPORT static typeFunction *create(std::string &name, Type *retType,
359 std::vector<Type *> ¶mTypes, Symtab *obj = NULL);
360 SYMTAB_EXPORT ~typeFunction();
361 SYMTAB_EXPORT bool addParam( Type *type);
362 SYMTAB_EXPORT Type *getReturnType() const;
363 SYMTAB_EXPORT bool setRetType(Type *rtype);
365 SYMTAB_EXPORT std::vector<Type *> &getParams();
366 SYMTAB_EXPORT bool isCompatible(Type *otype);
369 class typeScalar : public Type {
373 SYMTAB_EXPORT typeScalar();
374 SYMTAB_EXPORT typeScalar(typeId_t ID, unsigned int size, std::string name = "", bool isSigned = false);
375 SYMTAB_EXPORT typeScalar(unsigned int size, std::string name = "", bool isSigned = false);
376 SYMTAB_EXPORT static typeScalar *create(std::string &name, int size, Symtab *obj = NULL);
377 SYMTAB_EXPORT bool isSigned();
378 SYMTAB_EXPORT bool isCompatible(Type *otype);
381 class typeCommon : public fieldListType {
383 std::vector<CBlock *> cblocks;
385 SYMTAB_EXPORT void postFieldInsert(int nsize) { size_ += nsize; }
386 //void postFieldInsert(int offset, int nsize) { if ((unsigned int) (offset + nsize) > size_) size_ = offset + nsize; }
387 SYMTAB_EXPORT void fixupUnknowns(Module *);
389 SYMTAB_EXPORT typeCommon();
390 SYMTAB_EXPORT typeCommon(typeId_t ID, std::string name = "");
391 SYMTAB_EXPORT typeCommon(std::string name);
392 SYMTAB_EXPORT static typeCommon *create(std::string &name, Symtab *obj = NULL);
393 SYMTAB_EXPORT std::vector<CBlock *> *getCblocks() const;
394 SYMTAB_EXPORT void beginCommonBlock();
395 SYMTAB_EXPORT void endCommonBlock(Symbol *, void *baseAddr);
399 friend class typeCommon;
401 // the list of fields
402 std::vector<Field *> fieldList;
404 // which functions use this list
405 std::vector<Symbol *> functions;
410 SYMTAB_EXPORT std::vector<Field *> *getComponents();
411 SYMTAB_EXPORT std::vector<Symbol *> *getFunctions();
413 SYMTAB_EXPORT void fixupUnknowns(Module *);
415 SYMTAB_EXPORT void *getUpPtr() const;
416 SYMTAB_EXPORT bool setUpPtr(void *);
419 class typeStruct : public fieldListType {
421 SYMTAB_EXPORT void updateSize();
422 SYMTAB_EXPORT void postFieldInsert(int nsize);
423 SYMTAB_EXPORT void fixupUnknowns(Module *);
424 SYMTAB_EXPORT void merge(Type *other);
426 SYMTAB_EXPORT typeStruct();
427 SYMTAB_EXPORT typeStruct(typeId_t ID, std::string name = "");
428 SYMTAB_EXPORT typeStruct(std::string name);
429 SYMTAB_EXPORT static typeStruct *create(std::string &name, std::vector< std::pair<std::string, Type *> *> &flds,
432 SYMTAB_EXPORT static typeStruct *create(std::string &name, std::vector<Field *> &fields,
435 SYMTAB_EXPORT bool isCompatible(Type *otype);
438 class typeUnion : public fieldListType {
440 SYMTAB_EXPORT void updateSize();
441 SYMTAB_EXPORT void postFieldInsert(int nsize);
442 SYMTAB_EXPORT void merge(Type *other);
443 SYMTAB_EXPORT void fixupUnknowns(Module *);
445 SYMTAB_EXPORT typeUnion();
446 SYMTAB_EXPORT typeUnion(typeId_t ID, std::string name = "");
447 SYMTAB_EXPORT typeUnion(std::string name);
448 SYMTAB_EXPORT static typeUnion *create(std::string &name, std::vector<std::pair<std::string, Type *> *> &fieldNames,
450 SYMTAB_EXPORT static typeUnion *create(std::string &name, std::vector<Field *> &fields,
452 SYMTAB_EXPORT bool isCompatible(Type *otype);
455 class typePointer : public derivedType {
457 SYMTAB_EXPORT void fixupUnknowns(Module *);
459 SYMTAB_EXPORT typePointer();
460 SYMTAB_EXPORT typePointer(typeId_t ID, Type *ptr, std::string name = "");
461 SYMTAB_EXPORT typePointer(Type *ptr, std::string name = "");
462 SYMTAB_EXPORT static typePointer *create(std::string &name, Type *ptr, Symtab *obj = NULL);
463 SYMTAB_EXPORT static typePointer *create(std::string &name, Type *ptr, int size,
465 SYMTAB_EXPORT bool isCompatible(Type *otype);
466 SYMTAB_EXPORT bool setPtr(Type *ptr);
469 class typeTypedef: public derivedType {
471 unsigned int sizeHint_;
474 SYMTAB_EXPORT void updateSize();
475 SYMTAB_EXPORT void fixupUnknowns(Module *);
478 SYMTAB_EXPORT typeTypedef();
479 SYMTAB_EXPORT typeTypedef(typeId_t ID, Type *base, std::string name, unsigned int sizeHint = 0);
480 SYMTAB_EXPORT typeTypedef(Type *base, std::string name, unsigned int sizeHint = 0);
482 SYMTAB_EXPORT static typeTypedef *create(std::string &name, Type *ptr, Symtab *obj = NULL);
483 SYMTAB_EXPORT bool isCompatible(Type *otype);
484 SYMTAB_EXPORT bool operator==(const Type &otype) const;
487 class typeRef : public derivedType {
489 SYMTAB_EXPORT void fixupUnknowns(Module *);
491 SYMTAB_EXPORT typeRef();
492 SYMTAB_EXPORT typeRef(typeId_t ID, Type *refType, std::string name);
493 SYMTAB_EXPORT typeRef(Type *refType, std::string name);
494 SYMTAB_EXPORT static typeRef *create(std::string &name, Type *ptr, Symtab * obj = NULL);
495 SYMTAB_EXPORT bool isCompatible(Type *otype);
496 SYMTAB_EXPORT bool operator==(const Type &otype) const;
499 class typeSubrange : public rangedType {
501 //typeSubrange(int ID, int size, const char *low, const char *hi, const char *name);
503 SYMTAB_EXPORT typeSubrange();
504 SYMTAB_EXPORT typeSubrange(typeId_t ID, int size, int low, int hi, std::string name);
505 SYMTAB_EXPORT typeSubrange( int size, int low, int hi, std::string name);
506 SYMTAB_EXPORT static typeSubrange *create(std::string &name, int size, int low, int hi, Symtab *obj = NULL);
507 SYMTAB_EXPORT bool isCompatible(Type *otype);
510 class typeArray : public rangedType {
513 unsigned int sizeHint_;
515 SYMTAB_EXPORT void updateSize();
516 SYMTAB_EXPORT void merge(Type *other);
518 SYMTAB_EXPORT typeArray();
519 SYMTAB_EXPORT typeArray(typeId_t ID, Type *base, int low, int hi, std::string name, unsigned int sizeHint = 0);
520 SYMTAB_EXPORT typeArray(Type *base, int low, int hi, std::string name, unsigned int sizeHint = 0);
521 SYMTAB_EXPORT static typeArray *create(std::string &name, Type *typ, int low, int hi, Symtab *obj = NULL);
522 SYMTAB_EXPORT Type *getBaseType() const;
523 SYMTAB_EXPORT bool isCompatible(Type *otype);
524 SYMTAB_EXPORT bool operator==(const Type &otype) const;
525 SYMTAB_EXPORT void fixupUnknowns(Module *);
528 //location for a variable
530 storageClass stClass;
531 storageRefClass refClass;
539 class SYMTAB_EXPORT localVar
541 friend class typeCommon;
542 friend class localVarCollection;
546 std::string fileName_;
548 std::vector<loc_t *> *locs_;
556 localVar(std::string name, Type *typ, std::string fileName, int lineNum, std::vector<loc_t *> *locs = NULL);
558 localVar(localVar &lvar);
559 bool addLocation(loc_t *location);
560 bool setLocation(std::vector<loc_t *> *locs);
562 void fixupUnknown(Module *);
564 // end of functions for internal use only
565 std::string &getName();
567 bool setType(Type *newType);
569 std::string &getFileName();
570 std::vector<loc_t *> *getLocationLists();
572 void *getUpPtr() const;
573 bool setUpPtr(void *);
576 } // namespace SymtabAPI
577 } // namespace Dyninst