2 * Copyright (c) 1996 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 * 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.
18 * (for other uses, please contact us at paradyn@cs.wisc.edu)
20 * All warranties, including without limitation, any warranty of
21 * merchantability or fitness for a particular purpose, are hereby
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.
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.
48 #include "BPatch_Vector.h"
49 #include "BPatch_type.h"
50 #include "BPatch_collections.h"
51 #include "showerror.h"
54 // This is the ID that is decremented for each type a user defines. It is
55 // Global so that every type that the user defines has a unique ID.
57 static int USER_BPATCH_TYPE_ID = -1000;
60 * BPatch_type::BPatch_type
62 * EMPTY Constructor for BPatch_type.
65 BPatch_type::BPatch_type() :
66 nullType(true), cblocks(NULL)
77 * BPatch_type::BPatch_type
79 * Constructor for BPatch_type. Creates a type object representing a type
80 * with the features given in the parameters.
82 BPatch_type::BPatch_type(const char *_name, bool _nullType) :
83 nullType(_nullType), cblocks(NULL)
99 * BPatch_type::BPatch_type
101 * Constructor for BPatch_type ENUM. Creates a type object representing a type
102 * with the features given in the parameters.
104 BPatch_type::BPatch_type(const char *_name, int _ID, BPatch_dataClass _type):
105 nullType(false), cblocks(NULL)
109 // This is just for now XXX
115 name = strdup(_name);
121 * BPatch_type::BPatch_type
123 * Constructor for BPatch_type Structs, Unions, range(size),
124 * and reference(void) and built-in type. These are the negative type
125 * numbers defined in the gdb doc. The type ID neg. type num.
126 * Creates a type object representing a type
127 * with the features given in the parameters.
128 * A collection of the built-in types is created in for the image and
129 * is gloabally accessible to all modules. This way it is only created once..
131 BPatch_type::BPatch_type(const char *_name, int _ID, BPatch_dataClass _type,
133 nullType(false), cblocks(NULL)
139 name = strdup(_name);
150 if( _type == BPatch_dataScalar) {
151 // Check that void type == void type
181 * BPatch_type::BPatch_type
183 * Constructor for BPatch_type Pointers (and Internal).
184 * Creates a type object representing a type
185 * with the features given in the parameters.
187 BPatch_type::BPatch_type(const char *_name, int _ID, BPatch_dataClass _type,
189 nullType(false), cblocks(NULL)
193 if(_type == BPatch_dataScalar){ // could be a typedef for something
195 name = strdup(_name);
199 if(_ptr->ptr) // point to whatever it points to
201 else // or just point to the oldType
205 fieldList = _ptr->fieldList;
218 name = strdup(_name);
222 size = sizeof(void *);
229 * BPatch_type::BPatch_type
231 * Constructor for BPatch_type Range with lower and upper bound.
232 * Creates a type object representing a type
233 * with the features given in the parameters.
235 BPatch_type::BPatch_type(const char *_name, int _ID, BPatch_dataClass _type,
236 const char * _low, const char * _hi):
237 nullType(false), cblocks(NULL)
243 name = strdup(_name);
247 name = strdup(_name);
250 /* need to change for smaller types, maybe case statement
251 needs to be arch. independent and there may be a lot of cases*/
257 * BPatch_type::BPatch_type
259 * Constructor for BPatch_type Array.
260 * Creates a type object representing a type
261 * with the features given in the parameters.
263 BPatch_type::BPatch_type(const char *_name, int _ID, BPatch_dataClass _type,
264 BPatch_type * _ptr, int _low, int _hi):
265 nullType(false), cblocks(NULL)
275 name = strdup(_name);
280 sprintf(temp, "%d", _low);
283 sprintf(temp, "%d", _hi);
286 /* size = sizeof(artype)*(_hi+1)
287 need to find out how big that size is first */
288 size = ((ptr->getSize())*(_hi-_low+1));
292 * BPatch_type::BPatch_type
294 * Constructor for BPatch_type typedef--pre-existing type.
295 * Creates a type object representing a type
296 * with the features given in the parameters.
298 BPatch_type::BPatch_type(const char * _name, int _ID, BPatch_type * _ptr):
299 nullType(false), cblocks(NULL)
306 name = strdup(_name);
311 low = strdup(_ptr->low);
315 hi = strdup(_ptr->hi);
328 name = strdup(_name);
333 type_ = BPatch_dataScalar;
339 * BPatch_type::BPatch_type
341 * Constructor for BPatch_type Type Attributes. These are types defined
342 * by the built-in types and use the '@' as the type identifier.
343 * Creates a type object representing a type
344 * with the features given in the parameters.
346 BPatch_type::BPatch_type(const char * _name, int _ID, BPatch_dataClass _type,
347 int _size, BPatch_type * _ptr):
348 nullType(false), cblocks(NULL)
352 b_size = _ptr->getSize();
356 if( b_size != _size) {
357 sprintf(errorLine, "Built-in Type size %d and Stabs record size %d differ"
358 " for [%d]%s: Overriding built-in type size!!",
359 b_size, _size, _ID, _name);
360 BPatch_reportError(BPatchWarning, 112, errorLine);
366 name = strdup(_name);
376 //---------------------------------------------------------------------
377 // User defined BPatch_Type Constructors
379 // These functions allow the user to create their own types and manipulate
380 // these types. The user defined types are stored with the other system
381 // types. They can be differentiated from system types by their type ID. It
382 // is less than -1000. jdd 7/29/99
385 /* USER_DEFINED BPATCH_TYPE
387 * BPatch_type::BPatch_type
389 * Constructor for BPatch_type ENUM. Creates a type object representing a type
390 * with the features given in the parameters.
392 BPatch_type::BPatch_type(const char *_name, BPatch_dataClass _type):
393 nullType(false), cblocks(NULL)
395 ID = USER_BPATCH_TYPE_ID;
396 USER_BPATCH_TYPE_ID--;
399 // This is just for now XXX jdd 8/5/99, may need to be changed later
405 name = strdup(_name);
410 /* USER_DEFINED BPATCH_TYPE
412 * BPatch_type::BPatch_type
414 * Constructor for BPatch_type Structs, Unions, range(size),
415 * and reference(void) and built-in type. These are the negative type
416 * numbers defined in the gdb doc. The type ID neg. type num.
417 * Creates a type object representing a type
418 * with the features given in the parameters.
419 * A collection of the built-in types is created in for the image and
420 * is gloabally accessible to all modules. This way it is only created once..
422 BPatch_type::BPatch_type(const char *_name, BPatch_dataClass _type,
424 nullType(false), cblocks(NULL)
426 ID =USER_BPATCH_TYPE_ID;
427 USER_BPATCH_TYPE_ID--;
432 name = strdup(_name);
441 ptr = (BPatch_type *)_size; // check this field before adding new struct, union component
442 // to see if the size needs to be computed.
448 /* USER_DEFINED BPATCH_TYPE
450 * BPatch_type::BPatch_type
452 * Constructor for BPatch_type Pointers (and Internal).
453 * Creates a type object representing a type
454 * with the features given in the parameters.
456 BPatch_type::BPatch_type(const char *_name, BPatch_type * _ptr, int size_):
457 nullType(false), cblocks(NULL)
459 ID = USER_BPATCH_TYPE_ID;
460 USER_BPATCH_TYPE_ID--;
462 type_ = BPatch_dataPointer;
466 name = strdup(_name);
471 if(_ptr->ptr) // point to whatever it points to
473 else // or just point to the oldType
475 fieldList = _ptr->fieldList;
485 /* USER_DEFINED BPATCH_TYPE
487 * BPatch_type::BPatch_type
489 * Constructor for BPatch_type Range with lower and upper bound.
490 * Creates a type object representing a type
491 * with the features given in the parameters.
493 BPatch_type::BPatch_type(const char *_name, BPatch_dataClass _type,
494 const char * _low, const char * _hi):
495 nullType(false), cblocks(NULL)
497 ID = USER_BPATCH_TYPE_ID;
498 USER_BPATCH_TYPE_ID--;
503 name = strdup(_name);
507 name = strdup(_name);
510 /* need to change for smaller types, maybe case statement
511 needs to be arch. independent and there may be a lot of cases*/
516 /* USER_DEFINED BPATCH_TYPE
518 * BPatch_type::BPatch_type
520 * Constructor for BPatch_type Array.
521 * Creates a type object representing a type
522 * with the features given in the parameters.
524 BPatch_type::BPatch_type(const char *_name, BPatch_dataClass _type,
525 BPatch_type * _ptr, int _low, int _hi):
529 ID = USER_BPATCH_TYPE_ID;
530 USER_BPATCH_TYPE_ID--;
538 name = strdup(_name);
543 sprintf(temp, "%d", _low);
546 sprintf(temp, "%d", _hi);
549 /* size = sizeof(artype)*(_hi+1)
550 need to find out how big that size is first */
551 size = ((ptr->getSize())*(_hi+1));
554 /* USER_DEFINED BPATCH_TYPE
556 * BPatch_type::BPatch_type
558 * Constructor for BPatch_type typedef--pre-existing type.
559 * Creates a type object representing a type
560 * with the features given in the parameters.
562 BPatch_type::BPatch_type(const char * _name, BPatch_type * _ptr):
566 ID = USER_BPATCH_TYPE_ID;
567 USER_BPATCH_TYPE_ID--;
572 name = strdup(_name);
577 low = strdup(_ptr->low);
581 hi = strdup(_ptr->hi);
591 ID = USER_BPATCH_TYPE_ID;
592 USER_BPATCH_TYPE_ID--;
596 name = strdup(_name);
601 type_ = BPatch_dataScalar;
606 /* USER_DEFINED BPATCH_TYPE
608 * BPatch_type::BPatch_type
610 * Constructor for BPatch_type Type Attributes. These are types defined
611 * by the built-in types and use the '@' as the type identifier.
612 * Creates a type object representing a type
613 * with the features given in the parameters.
615 BPatch_type::BPatch_type(const char * _name, BPatch_dataClass _type,
616 int _size, BPatch_type * _ptr):
621 b_size = _ptr->getSize();
622 ID = USER_BPATCH_TYPE_ID;
623 USER_BPATCH_TYPE_ID--;
625 if( b_size != _size) {
626 sprintf(errorLine, "Built-in Type size %d and Stabs record size %d differ"
627 " for [%d]%s: Overriding built-in type size!!",
628 b_size, _size, ID, _name);
629 BPatch_reportError(BPatchWarning, 112, errorLine);
635 name = strdup(_name);
645 void BPatch_type::beginCommonBlock()
647 BPatch_Vector<BPatch_field*> emptyList;
649 if (!cblocks) cblocks = new BPatch_Vector<BPatch_cblock *>;
651 // null out field list
652 fieldList = emptyList;
655 void BPatch_type::endCommonBlock(BPatch_function *func, void *baseAddr)
659 // create local variables in func's scope for each field of common block
660 for (j=0; j < fieldList.size(); j++) {
661 BPatch_localVar *locVar;
662 locVar = new BPatch_localVar((char *) fieldList[j]->getName(),
663 fieldList[j]->getType(), 0,
664 fieldList[j]->getOffset()+(Address) baseAddr, 5,
666 func->localVariables->addLocalVar( locVar);
669 // look to see if the field list matches an existing block
670 for (i=0; i < cblocks->size(); i++) {
671 BPatch_cblock *curr = (*cblocks)[i];
672 for (j=0; j < fieldList.size(); j++) {
673 if (strcmp(fieldList[j]->getName(),curr->fieldList[j]->getName()) ||
674 (fieldList[j]->getOffset() !=curr->fieldList[j]->getOffset()) ||
675 (fieldList[j]->getSize() != curr->fieldList[j]->getSize())) {
679 if (j == fieldList.size() && (j == curr->fieldList.size())) {
681 curr->functions.push_back(func);
686 // this one is unique
687 BPatch_cblock *newBlock = new BPatch_cblock();
688 newBlock->fieldList = fieldList;
689 newBlock->functions.push_back(func);
690 cblocks->push_back(newBlock);
692 // create local variables in func's scope for each field of common block
693 for (j=0; j < fieldList.size(); j++) {
694 BPatch_localVar *locVar;
695 locVar = new BPatch_localVar((char *) fieldList[j]->getName(),
696 fieldList[j]->getType(), 0,
697 fieldList[j]->getOffset()+(Address) baseAddr, 5,
699 func->localVariables->addLocalVar( locVar);
707 * BPatch_type::isCompatible
709 * Returns true of the type is compatible with the other specified type, false
710 * if it is not (if it breaks out of the case).
712 * oType The other type to check for compatibility.
714 bool BPatch_type::isCompatible(BPatch_type *otype)
717 if (nullType || otype->nullType)
720 // name, ID and type are the same them it has to be the same BPatch_type
721 if ((ID == otype->ID) && (type_ == otype->type_)) {
722 if (name && otype->name && !strcmp(name,otype->name)) {
727 if ((type_ == BPatch_dataUnknownType) || (otype->type_ == BPatch_dataUnknownType)) {
728 BPatch_reportError(BPatchWarning, 112,
729 "One or more unknown BPatch_types");
734 case BPatch_dataScalar:
735 if (!strcmp(name,otype->name) && (size == otype->size)) {
738 BPatch_reportError(BPatchWarning, 112, "scalar's not compatible");
743 case BPatchSymTypeRange:
744 if (!(strcmp(name,otype->name))&& (ID == otype->ID)&&(size == otype->size))
746 if (!(strcmp(name,otype->name))&&(size == otype->size))
750 case BPatch_dataReference:
751 if (!(strcmp(name,otype->name)) && (size == otype->size))
755 case BPatch_dataBuilt_inType:
756 if (!(strcmp(name,otype->name))&&(size == otype->size))
760 case BPatch_dataUnknownType:
761 // should be caught above
765 case BPatch_dataTypeAttrib:
766 if (!(strcmp(name,otype->name))&&(size == otype->size))
770 case BPatch_dataPointer:
772 BPatch_type *pType1, *pType2;
774 if (otype->type_ != BPatch_dataPointer) {
775 BPatch_reportError(BPatchWarning, 112,
776 "Pointer and non-Pointer are not type compatible");
779 // verify type that each one points to is compatible
782 if (!pType1 || !pType2 || !pType1->isCompatible(pType2)) {
791 case BPatch_dataFunction:
792 if (!(strcmp(name,otype->name))&&(ID == otype->ID)) {
795 BPatch_reportError(BPatchWarning, 112,
796 "function call not compatible");
801 case BPatch_dataArray:
803 BPatch_type * arType1, * arType2;
805 if (otype->type_ != BPatch_dataArray) {
806 BPatch_reportError(BPatchWarning, 112,
807 "Array and non-array are not type compatible");
811 // verify that the number of elements is the same
812 if ((atoi(this->hi) - atoi(this->low)) != (atoi(otype->hi) - atoi(otype->low))) {
814 sprintf(message, "Incompatible number of elements [%s..%s] vs. [%s..%s]",
815 this->low, this->hi, otype->low, otype->hi);
816 BPatch_reportError(BPatchWarning, 112, message);
820 // verify that elements of the array are compatible
822 arType2 = otype->ptr;
823 if (!arType1 || !arType2 || !arType1->isCompatible(arType2)) {
824 // no need to report error, recursive call will
832 case BPatch_dataEnumerated:
834 if( !strcmp( name, otype->name) && (ID == otype->ID))
836 BPatch_Vector<BPatch_field *> * fields1 = this->getComponents();
837 // BPatch_Vector<BPatch_field *> * fields2 = ((BPatch_type)otype).getComponents();
838 BPatch_Vector<BPatch_field *> * fields2 = (BPatch_Vector<BPatch_field *> *) &(otype->fieldList);
840 if( fields1->size() != fields2->size()) {
841 BPatch_reportError(BPatchWarning, 112, "enumerated type mismatch ");
845 //need to compare componment by component to verify compatibility
846 for(int i=0;i<fields1->size();i++){
847 BPatch_field * field1 = (*fields1)[i];
848 BPatch_field * field2 = (*fields2)[i];
849 if( (field1->getValue() != field2->getValue()) ||
850 (strcmp(field1->getName(), field2->getName())))
851 BPatch_reportError(BPatchWarning, 112, "enum element mismatch ");
854 // Everything matched so they are the same
859 case BPatch_dataStructure:
860 case BPatch_dataUnion:
862 if (!strcmp( name, otype->name) && (ID == otype->ID))
864 BPatch_Vector<BPatch_field *> * fields1 = this->getComponents();
865 // The line below does not work in linux.
866 // BPatch_Vector<BPatch_field *> * fields2 = ((BPatch_type)otype).getComponents();
867 BPatch_Vector<BPatch_field *> * fields2 = (BPatch_Vector<BPatch_field *> *) &(otype->fieldList);
869 if (fields1->size() != fields2->size()) {
870 BPatch_reportError(BPatchWarning, 112,
871 "struct/union numer of elements mismatch ");
875 //need to compare componment by component to verify compatibility
876 for (int i=0;i<fields1->size();i++) {
877 BPatch_field * field1 = (*fields1)[i];
878 BPatch_field * field2 = (*fields2)[i];
880 BPatch_type * ftype1 = (BPatch_type *)field1->getType();
881 BPatch_type * ftype2 = (BPatch_type *)field2->getType();
883 if(!(ftype1->isCompatible(ftype2))) {
884 BPatch_reportError(BPatchWarning, 112,
885 "struct/union field type mismatch ");
894 cerr<<"UNKNOWN TYPE, UNABLE TO COMPARE!!"<<endl;
898 if (name && otype->name) {
899 sprintf(message, "%s is not compatible with %s ", name, otype->name);
901 sprintf(message, "unknown type mismatch ");
903 BPatch_reportError(BPatchWarning, 112, message);
909 * void BPatch_type::addField
910 * Creates field object and adds it to the list of fields for this
911 * BPatch_type object.
914 void BPatch_type::addField(const char * _fieldname, BPatch_dataClass _typeDes,
917 BPatch_field * newField;
919 newField = new BPatch_field(_fieldname, _typeDes, value);
921 // Add field to list of enum fields
922 fieldList.push_back(newField);
926 * void BPatch_type::addField
927 * Creates field object and adds it to the list of fields for this
928 * BPatch_type object.
929 * ENUMS C++ - have visibility
931 void BPatch_type::addField(const char * _fieldname, BPatch_dataClass _typeDes,
932 int value, BPatch_visibility _vis)
934 BPatch_field * newField;
936 newField = new BPatch_field(_fieldname, _typeDes, value, _vis);
938 // Add field to list of enum fields
939 fieldList.push_back(newField);
943 * void BPatch_type::addField
944 * Creates field object and adds it to the list of fields for this
945 * BPatch_type object.
948 void BPatch_type::addField(const char * _fieldname, BPatch_dataClass _typeDes,
949 BPatch_type *_type, int _offset, int _nsize)
951 BPatch_field * newField;
953 // API defined structs/union's size are defined on the fly.
954 if (this->type_ == BPatch_dataStructure)
955 this->size += _nsize;
956 else if ( this->type_ == BPatch_dataUnion) {
957 if( _nsize > size) size = _nsize;
958 } else if (type_ == BPatch_dataCommon) {
959 if (size < _offset + _nsize) size = _offset + _nsize;
960 } assert ( this->size > 0 );
962 // Create Field for struct or union
963 newField = new BPatch_field(_fieldname, _typeDes, _type, _offset, _nsize);
965 // Add field to list of struct/union fields
966 fieldList.push_back(newField);
971 * void BPatch_type::addField
972 * Creates field object and adds it to the list of fields for this
973 * BPatch_type object.
974 * STRUCTS OR UNIONS C++ have visibility
976 void BPatch_type::addField(const char * _fieldname, BPatch_dataClass _typeDes,
977 BPatch_type *_type, int _offset, int _size,
978 BPatch_visibility _vis)
980 BPatch_field * newField;
982 // Create Field for struct or union
983 newField = new BPatch_field(_fieldname, _typeDes, _type, _offset, _size,
986 // Add field to list of struct/union fields
987 fieldList.push_back(newField);
992 * BPatch_field::BPatch_field
994 * Constructor for BPatch_field. Creates a field object for
995 * an enumerated type.
996 * type = offset = size = 0;
998 BPatch_field::BPatch_field(const char * fName, BPatch_dataClass _typeDes,
1003 fieldname = strdup(fName);
1007 vis = BPatch_visUnknown;
1008 // printf("adding field %s\n", fName);
1013 * BPatch_field::BPatch_field
1015 * Constructor for BPatch_field. Creates a field object for
1016 * an enumerated type with a C++ visibility value
1017 * type = offset = size = 0;
1019 BPatch_field::BPatch_field(const char * fName, BPatch_dataClass _typeDes,
1020 int evalue, BPatch_visibility _vis)
1024 fieldname = strdup(fName);
1029 // printf("adding field %s\n", fName);
1034 * BPatch_field::BPatch_field
1036 * Constructor for BPatch_field. Creates a field object for
1037 * an struct and union types.
1040 BPatch_field::BPatch_field(const char * fName, BPatch_dataClass _typeDes,
1041 BPatch_type *suType, int suOffset, int suSize)
1047 fieldname = strdup(fName);
1051 vis = BPatch_visUnknown;
1055 * BPatch_field::BPatch_field
1057 * Constructor for BPatch_field. Creates a field object for
1058 * a struct and union types for C++ fields that have visibility.
1061 BPatch_field::BPatch_field(const char * fName, BPatch_dataClass _typeDes,
1062 BPatch_type *suType, int suOffset, int suSize,
1063 BPatch_visibility _vis)
1069 fieldname = strdup(fName);
1077 /**************************************************************************
1079 *************************************************************************/
1081 * BPatch_localVar Constructor
1084 BPatch_localVar::BPatch_localVar(char * _name, BPatch_type * _type,
1085 int _lineNum,int _frameOffset, int _sc, bool fr)
1088 name = strdup(_name);
1093 frameOffset = _frameOffset;
1095 storageClass = _sc; //Only for COFF format. Default value is scAbs
1100 * BPatch_localVar destructor
1103 BPatch_localVar::~BPatch_localVar()
1106 //XXX jdd 5/25/99 More to do later