windows build fixes and some more work on symtab serialization
[dyninst.git] / dyninstAPI / h / BPatch_type.h
1 /*
2  * Copyright (c) 1996-2004 Barton P. Miller
3  * 
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.
10  * 
11  * This license is for research uses.  For such uses, there is no
12  * charge. We define "research use" to mean you may freely use it
13  * inside your organization for whatever purposes you see fit. But you
14  * may not re-distribute Paradyn or parts of Paradyn, in any form
15  * source or binary (including derivatives), electronic or otherwise,
16  * to any other organization or entity without our permission.
17  * 
18  * (for other uses, please contact us at paradyn@cs.wisc.edu)
19  * 
20  * All warranties, including without limitation, any warranty of
21  * merchantability or fitness for a particular purpose, are hereby
22  * excluded.
23  * 
24  * By your use of Paradyn, you understand and agree that we (or any
25  * other person or entity with proprietary rights in Paradyn) are
26  * under no obligation to provide either maintenance services,
27  * update services, notices of latent defects, or correction of
28  * defects for Paradyn.
29  * 
30  * Even if advised of the possibility of such damages, under no
31  * circumstances shall we (or any other person or entity with
32  * proprietary rights in the software licensed hereunder) be liable
33  * to you or any third party for direct, indirect, or consequential
34  * damages of any character regardless of type of action, including,
35  * without limitation, loss of profits, loss of use, loss of good
36  * will, or computer failure or malfunction.  You agree to indemnify
37  * us (and any other person or entity with proprietary rights in the
38  * software licensed hereunder) for any and all liability it may
39  * incur to third parties resulting from your use of Paradyn.
40  */
41
42 #ifndef _BPatch_type_h_
43 #define _BPatch_type_h_
44
45 #include "BPatch_dll.h"
46 #include "BPatch_Vector.h"
47 #include "BPatch_eventLock.h"
48 #include <string.h>     
49
50 #include "Type.h"
51 #include "Variable.h"
52
53 typedef enum {BPatchSymLocalVar,  BPatchSymGlobalVar, BPatchSymRegisterVar,
54               BPatchSymStaticLocalVar, BPatchSymStaticGlobal,
55               BPatchSymLocalFunc, BPatchSymGlobalFunc, BPatchSymFuncParam,
56               BPatchSymTypeName, BPatchSymAggType, BPatchSymTypeTag}symDescr_t;
57
58 /*
59  * Symbol Descriptors:
60  * BPatchSymLocalVar       - local variable- gnu sun-(empty)
61  * BPatchSymGlobalVar      - global variable- gnu sun-'G'
62  * BPatchSymRegisterVar    - register variable- gnu sun-'r'
63  * BPatchSymStaticLocalVar - static local variable- gnu sun-'V'
64  * BPatchSymStaticGlobal   - static global variable- gnu- sun'S'
65  * BPatchSymLocalFunc      - local function- gnu sun-'f'
66  * BPatchSymGlobalFunc     - global function- gnu- sun'F'
67  * BPatchSymFuncParam      - function paramater - gnu- sun'p'
68  * BPatchSymTypeName       - type name- gnu sun-'t'
69  * BPatchSymAggType        - aggregate type-struct,union, enum- gnu sun-'T'
70  * BPatchSymTypeTag        - C++ type name and tag combination
71  */
72
73 #if defined (IBM_BPATCH_COMPAT)
74 #define BPatch_dataBuilt_inType BPatch_dataUnknownType
75 #endif
76
77 typedef enum {BPatch_dataScalar, 
78               BPatch_dataEnumerated,
79               BPatch_dataTypeClass,
80               BPatch_dataStructure, 
81               BPatch_dataUnion, 
82               BPatch_dataArray, 
83               BPatch_dataPointer, 
84               BPatch_dataReferance, 
85               BPatch_dataFunction,
86               BPatch_dataTypeAttrib,
87               BPatch_dataReference,
88               BPatch_dataUnknownType,
89               BPatchSymTypeRange,
90               BPatch_dataMethod,
91               BPatch_dataCommon,
92               BPatch_dataPrimitive,
93               BPatch_dataTypeNumber,
94               BPatch_dataTypeDefine,
95               BPatch_dataNullType
96 } BPatch_dataClass;
97
98
99 #define BPatch_scalar   BPatch_dataScalar
100 #define BPatch_enumerated       BPatch_dataEnumerated
101 #define BPatch_typeClass        BPatch_dataTypeClass
102 #define BPatch_structure        BPatch_dataStructure 
103 #define BPatch_union    BPatch_dataUnion 
104 #define BPatch_array    BPatch_dataArray 
105 #define BPatch_pointer  BPatch_dataPointer 
106 #define BPatch_reference        BPatch_dataReferance 
107 #define BPatch_typeAttrib       BPatch_dataTypeAttrib
108 #define BPatch_unknownType      BPatch_dataUnknownType
109 #define BPatch_typeDefine       BPatch_dataTypeDefine
110
111 /*
112  * Type Descriptors:
113  * BPatchSymTypeReference - type reference- gnu sun-(empty)
114  * BPatch_dataArray - array type- gnu sun-'a'
115  * BPatch_dataEnumerated - enumerated type- gnu sun-'e'
116  * BPatch_dataTypeClass - Class type
117  * BPatch_dataFunction - function type- gnu sun-'f'
118  * BPatchSymTypeRange - range type- gnu sun-'r'
119  * BPatch_dataStructure - structure type- gnu sun-'s'
120  * BPatch_dataUnion - union specification- gnu sun-'u'
121  * BPatch_dataPointer - pointer type- gnu sun-'*'
122  * BPatch_dataReferance - referance type- gnu sun-'*'
123  * BPatch_dataTypeAttrib - type attribute (C++)- gnu sun- '@'
124  * BPatch_dataReference - C++ reference to another type- gnu sun- '&'
125  * BPatch_dataMethod - C++ class method
126  */
127
128 typedef enum {BPatch_private, BPatch_protected, BPatch_public,
129               BPatch_optimized=9,BPatch_visUnknown}BPatch_visibility;
130 /*
131  * BPatch_visibility: Accessibility of member data and functions
132  * These values follow the 'field_name:' after the '/' identifier.
133  * BPatch_private   == 0 gnu Sun -- private
134  * BPatch_protected == 1 gnu Sun -- protected
135  * BPatch_public    == 2 gnu Sun -- public
136  * BPatch_optimized == 9 gnu Sun -- field optimized out and is public
137  * BPatch_visUnknown visibility not known or doesn't apply(ANSIC), the default
138  *
139  */
140
141 typedef enum {
142     BPatch_storageAddr,
143     BPatch_storageAddrRef,
144     BPatch_storageReg,
145     BPatch_storageRegRef,
146     BPatch_storageRegOffset,
147     BPatch_storageFrameOffset
148 } BPatch_storageClass;
149
150 /*
151  * BPatch_storageClass: Encodes how a variable is stored.
152  * 
153  * BPatch_storageAddr           - Absolute address of variable.
154  * BPatch_storageAddrRef        - Address of pointer to variable.
155  * BPatch_storageReg            - Register which holds variable value.
156  * BPatch_storageRegRef         - Register which holds pointer to variable.
157  * BPatch_storageRegOffset      - Address of variable = $reg + address.
158  * BPatch_storageFrameOffset    - Address of variable = $fp  + address.
159  */
160
161 class BPatch_type;
162 class BPatch_function;
163 class BPatch_module;
164
165 /*
166  * A BPatch_field is equivalent to a field in a enum, struct, or union.
167  * A field can be an atomic type, i.e, int, char, or more complex like a
168  * union or struct.
169  */
170
171 #ifdef DYNINST_CLASS_NAME
172 #undef DYNINST_CLASS_NAME
173 #endif
174 #define DYNINST_CLASS_NAME BPatch_field
175
176 class BPATCH_DLL_EXPORT BPatch_field : public BPatch_eventLock{
177   friend class BPatch_variableExpr;
178   friend class BPatch_cblock;
179   
180   BPatch_dataClass   typeDes;
181   /* For Enums */
182   int          value;
183
184   /* For structs and unions */
185   int         size;
186   
187   //Symtab field
188   Dyninst::SymtabAPI::Field *fld;
189
190   protected:
191   void copy(BPatch_field &);
192   void fixupUnknown(BPatch_module *);
193
194   public:
195 /*  
196   // Enum constructor
197   API_EXPORT_CTOR(Enum, (fName, _typeDes, eValue),
198   BPatch_field,(const char * fName,  BPatch_dataClass _typeDes, int eValue));
199   // C++ version for Enum constructor
200   API_EXPORT_CTOR(EnumCpp, (fName, _typeDes, eValue, _vis),
201   BPatch_field, (const char * fName,  BPatch_dataClass _typeDes, int eValue,
202                BPatch_visibility _vis));            
203   // Struct or Union construct
204   API_EXPORT_CTOR(SU, (fName, _typeDes, suType, suOffset, suSize),
205   BPatch_field,(const char * fName,  BPatch_dataClass _typeDes, 
206                BPatch_type *suType, int suOffset, int suSize));
207   // C++ version for Struct or Union construct
208   API_EXPORT_CTOR(SUCpp, (fName, _typeDes, suType, suOffset, suSize, _vis),
209   BPatch_field,(const char * fName,  BPatch_dataClass _typeDes, 
210                BPatch_type *suType, int suOffset, int suSize,
211                BPatch_visibility _vis));
212 */
213
214   // Copy constructor
215   BPatch_field(BPatch_field &f);
216   BPatch_field(Dyninst::SymtabAPI::Field *fld_, BPatch_dataClass typeDescriptor = BPatch_dataUnknownType, int value_ = 0, int size_ = 0);
217
218   API_EXPORT_DTOR(_dtor,(),
219   ~,BPatch_field,());
220   
221   API_EXPORT_OPER(_equals, (src),
222   BPatch_field &,operator=,(BPatch_field &src));
223
224 #ifdef NOTDEF
225   API_EXPORT_OPER(_equals_equals, (src),
226   bool ,operator==,(const BPatch_field &src));
227 #endif
228                               
229   API_EXPORT(Int, (),
230   const char *,getName,()); 
231
232   API_EXPORT(Int, (),
233   BPatch_type *,getType,());
234
235   API_EXPORT(Int, (),
236   int,getValue,());
237
238   API_EXPORT(Int, (),
239   BPatch_visibility,getVisibility,());
240
241   API_EXPORT(Int, (),
242   BPatch_dataClass,getTypeDesc,());
243
244   API_EXPORT(Int, (),
245   int,getSize,());
246
247   API_EXPORT(Int, (),
248   int,getOffset,());
249 }; 
250
251 //
252 // Define an instance of a Common block.  Each subroutine can have its own
253 //   version of the common block.
254 //
255 #ifdef DYNINST_CLASS_NAME
256 #undef DYNINST_CLASS_NAME
257 #endif
258 #define DYNINST_CLASS_NAME BPatch_cblock
259 class BPATCH_DLL_EXPORT BPatch_cblock : public BPatch_eventLock{
260 private:
261   // the list of fields
262   BPatch_Vector<BPatch_field *> fieldList;
263
264   // which functions use this list
265   BPatch_Vector<BPatch_function *> functions;
266
267   Dyninst::SymtabAPI::CBlock *cBlk;
268
269   void fixupUnknowns(BPatch_module *);
270 public:
271   BPatch_cblock(Dyninst::SymtabAPI::CBlock *cBlk_);
272   
273   API_EXPORT(Int, (),
274   BPatch_Vector<BPatch_field *> *,getComponents,());
275   API_EXPORT(Int, (),
276   BPatch_Vector<BPatch_function *> *,getFunctions,());
277 };
278
279 #ifdef DYNINST_CLASS_NAME
280 #undef DYNINST_CLASS_NAME
281 #endif
282 #define DYNINST_CLASS_NAME BPatch_type
283 class BPATCH_DLL_EXPORT BPatch_type : public BPatch_eventLock{
284     friend class BPatch;
285     friend class BPatch_module;
286     friend class BPatch_function;
287     friend class BPatch_typeCollection;
288     friend class BPatch_localVar;
289     friend class BPatch_field;
290     friend class BPatch_addressSpace;
291     
292 protected:
293   int           ID;                /* unique ID of type */
294   static std::map<Dyninst::SymtabAPI::Type*, BPatch_type *> type_map;
295   BPatch_dataClass   type_;
296
297   //Symtab type
298   Dyninst::SymtabAPI::Type *typ;
299
300   /* For common blocks */
301
302   static int USER_BPATCH_TYPE_ID;
303
304   // INTERNAL DATA MEMBERS
305
306   unsigned int refCount;
307
308  protected:
309   // Simple Destructor
310   virtual ~BPatch_type();
311   BPatch_type(const char *name = NULL, int _ID = 0, BPatch_dataClass = BPatch_dataNullType);
312   static BPatch_type *findOrCreateType(Dyninst::SymtabAPI::Type *type);
313   
314   // A few convenience functions
315   BPatch_dataClass convertToBPatchdataClass(Dyninst::SymtabAPI::dataClass type);
316   Dyninst::SymtabAPI::dataClass convertToSymtabType(BPatch_dataClass type);
317
318   static BPatch_type *createFake(const char *_name);
319   /* Placeholder for real type, to be filled in later */
320   static BPatch_type *createPlaceholder(int _ID, const char *_name = NULL) 
321          { return new BPatch_type(_name, _ID, BPatch_dataUnknownType); }
322
323 public:
324   BPatch_type(Dyninst::SymtabAPI::Type *typ_);
325   virtual bool operator==(const BPatch_type &) const;
326
327   int  getID() const { return ID;}
328
329   API_EXPORT(Int, (),
330   unsigned int,getSize,());
331
332   Dyninst::SymtabAPI::Type *getSymtabType() const;
333
334 //Define all of these in .C 
335   const char *getName() const;
336
337 #ifdef IBM_BPATCH_COMPAT
338   char *getName(char *buffer, int max) const; 
339   BPatch_dataClass type() const { return type_; }
340 #endif
341   BPatch_dataClass getDataClass() const { return type_; }
342
343   //TODO - implement these functions later -- giri
344   const char *getLow() const;
345   const char *getHigh() const;
346   BPatch_Vector<BPatch_field *> * getComponents() const;
347   API_EXPORT(Int, (otype),
348         bool, isCompatible, (BPatch_type * otype));
349   BPatch_type *getConstituentType() const;
350   BPatch_Vector<BPatch_cblock *> *getCblocks() const;
351
352   // INTERNAL METHODS
353
354   void incrRefCount() { ++refCount; }
355   void decrRefCount() { assert(refCount > 0); if (!--refCount) delete this; }
356   void fixupUnknowns(BPatch_module *) { }
357 };
358
359 //
360 // This class stores information about local variables.
361 // It is desgined store information about a variable in a function.
362 // Scope needs to be addressed in this class.
363
364 #ifdef DYNINST_CLASS_NAME
365 #undef DYNINST_CLASS_NAME
366 #endif
367 #define DYNINST_CLASS_NAME BPatch_localVar
368 class process;
369 class BPATCH_DLL_EXPORT BPatch_localVar : public BPatch_eventLock{
370     friend class BPatch;
371     friend class BPatch_function;
372
373     BPatch_type *type;
374     BPatch_storageClass storageClass;
375     // scope_t scope;
376
377     Dyninst::SymtabAPI::localVar *lVar;
378
379 public:
380     //  Internal use only
381     BPatch_localVar(Dyninst::SymtabAPI::localVar *lVar_);
382     ~BPatch_localVar();
383
384     void fixupUnknown(BPatch_module *);
385     Dyninst::SymtabAPI::localVar *getSymtabVar();
386     BPatch_storageClass convertToBPatchStorage(Dyninst::SymtabAPI::VariableLocation *loc);
387
388 public:
389     //  end of functions for nternal use only
390     const char *        getName();
391     BPatch_type *       getType();
392     int                 getLineNum();
393     long                getFrameOffset();
394     int                 getRegister();
395     BPatch_storageClass getStorageClass();
396
397 };
398
399 #endif /* _BPatch_type_h_ */