Fixed arrays some more...
authorbdemsky <bdemsky>
Tue, 13 Jul 2004 06:46:03 +0000 (06:46 +0000)
committerbdemsky <bdemsky>
Tue, 13 Jul 2004 06:46:03 +0000 (06:46 +0000)
Repair/RepairCompiler/structextract/dumpstructures.c
Repair/RepairCompiler/structextract/dumpstructures.h
Repair/RepairCompiler/structextract/typedata.c
Repair/RepairCompiler/structextract/typedata.h

index 2b51bdc59c81e5f606abb3eb6944556ddf511d75..e4b015f6b9a609514d9d2c8f6da0a19ada3e7cb1 100755 (executable)
@@ -18,8 +18,7 @@
 #include "dumpstructures.h"
 #include "typedata.h"
 #include "elf/dwarf2.h"
-#include "common.h"
-#include "GenericHashtable.h"
+
 
 #define GETTYPE 1
 #define POSTNAME 2
@@ -92,24 +91,32 @@ void initializeTypeArray()
          int value=0;
          for(j=0;j<collection_ptr->num_members;j++) {
            dwarf_entry *entry=collection_ptr->members[j];
-           member * member_ptr=(member *)entry->entry_ptr;
-           char *name=member_ptr->name;
-           dwarf_entry *type=member_ptr->type_ptr;
-           char *typestr=printname(type,GETTYPE);
-           char *poststr=printname(type,POSTNAME);
-
-           if (typestr!=NULL)
+           if (entry->tag_name==DW_TAG_inheritance) {
              value++;
+             continue;
+           }
+           {
+             member * member_ptr=(member *)entry->entry_ptr;
+             char *name=member_ptr->name;
+             dwarf_entry *type=member_ptr->type_ptr;
+             char *typestr=printname(type,GETTYPE);
+             char *poststr=printname(type,POSTNAME);
+             
+             if (typestr!=NULL)
+               value++;
+           }
          }
          if (collection_ptr->name!=NULL) {
            struct valuepair *vp=NULL;
            if (gencontains(ght,collection_ptr->name))
              vp=(struct valuepair *)gengettable(ght,collection_ptr->name);
            if (vp==NULL||vp->value<value) {
-             vp=(struct valuepair*)calloc(1,sizeof(struct valuepair));
+             if (vp==NULL) {
+               vp=(struct valuepair*)calloc(1,sizeof(struct valuepair));
+               genputtable(ght,collection_ptr->name,vp);
+             }
              vp->value=value;
              vp->index=i;
-             genputtable(ght,collection_ptr->name,vp);
            }
          }
         }
@@ -131,28 +138,102 @@ void initializeTypeArray()
            if (vp->index!=i)
              continue;
          }
-         printf("structure %s {\n",collection_ptr->name);
+         j=0;
+         printf("structure %s ",collection_ptr->name);
+
+         while(j<collection_ptr->num_members&&
+               collection_ptr->members[j]->tag_name==DW_TAG_inheritance) {
+           inherit *in_ptr=(inherit*)collection_ptr->members[j]->entry_ptr;
+           dwarf_entry *typeptr=in_ptr->target_ptr;
+           collection_type* sub_ptr = (collection_type*)(typeptr->entry_ptr);
+           if (j==0)
+             printf("subclasses ");
+           else
+             printf(", ");
+           printf("%s ",sub_ptr->name);
+           j++;
+         }
+         printf("{ \n");
          
          for(j=0;j<collection_ptr->num_members;j++) {
            dwarf_entry *entry=collection_ptr->members[j];
-           member * member_ptr=(member *)entry->entry_ptr;
-           char *name=member_ptr->name;
-           dwarf_entry *type=member_ptr->type_ptr;
-           char *typestr=printname(type,GETTYPE);
-           char *poststr=printname(type,POSTNAME);
-           if (member_ptr->data_member_location>offset) {
-             printf("   reserved byte[%ld];\n",member_ptr->data_member_location-offset);
-             offset=member_ptr->data_member_location;
+           if (entry->tag_name==DW_TAG_inheritance) {
+             inherit * inherit_ptr=(inherit *)entry->entry_ptr;
+             if (inherit_ptr->data_member_location>offset) {
+               printf("   reserved byte[%ld];\n",inherit_ptr->data_member_location-offset);
+               offset=inherit_ptr->data_member_location;
+             }
+             {
+               dwarf_entry *type=inherit_ptr->target_ptr;
+               collection_type *c_ptr=(collection_type*)type->entry_ptr;
+               offset+=printtype(c_ptr,ght);
+             }
+           } else {
+             member * member_ptr=(member *)entry->entry_ptr;
+             char *name=member_ptr->name;
+             dwarf_entry *type=member_ptr->type_ptr;
+             char *typestr=printname(type,GETTYPE);
+             char *poststr=printname(type,POSTNAME);
+             if (member_ptr->data_member_location>offset) {
+               printf("   reserved byte[%ld];\n",member_ptr->data_member_location-offset);
+               offset=member_ptr->data_member_location;
+             }
+             offset+=getsize(type);
+             
+             printf("   %s %s%s;\n",typestr,name,poststr);
            }
-           offset+=getsize(type);
-
-           printf("   %s %s%s;\n",typestr,name,poststr);
          }
          printf("}\n\n");
         }
     }
 }
 
+int printtype(collection_type *collection_ptr,struct genhashtable *ght)
+{
+  int j=0;
+  int offset=0;
+  int value=0;
+  
+  struct valuepair *vp=NULL;
+  if (gencontains(ght,collection_ptr->name))
+    vp=(struct valuepair *)gengettable(ght,collection_ptr->name);
+  if (vp!=NULL)
+    collection_ptr=(collection_type*) dwarf_entry_array[vp->index].entry_ptr;
+
+  for(j=0;j<collection_ptr->num_members;j++) {
+    dwarf_entry *entry=collection_ptr->members[j];
+    if (entry->tag_name==DW_TAG_inheritance) {
+      inherit * inherit_ptr=(inherit *)entry->entry_ptr;
+      if (inherit_ptr->data_member_location>offset) {
+       printf("   reserved byte[%ld];\n",inherit_ptr->data_member_location-offset);
+       offset=inherit_ptr->data_member_location;
+      }
+
+      {
+       dwarf_entry *type=inherit_ptr->target_ptr;
+       collection_type *c_ptr=(collection_type*)type->entry_ptr;
+       offset+=printtype(c_ptr,ght);
+      }
+    } else {
+      member * member_ptr=(member *)entry->entry_ptr;
+      char *name=member_ptr->name;
+      dwarf_entry *type=member_ptr->type_ptr;
+      char *typestr=printname(type,GETTYPE);
+      char *poststr=printname(type,POSTNAME);
+      if (member_ptr->data_member_location>offset) {
+       printf("   reserved byte[%ld];\n",member_ptr->data_member_location-offset);
+       offset=member_ptr->data_member_location;
+      }
+      offset+=getsize(type);
+      
+      printf("   %s %s%s;\n",typestr,name,poststr);
+    }
+  }
+  return offset;
+}
+
+
+
 int getsize(dwarf_entry *type) {
   if (type==NULL)
     return 0;
@@ -161,7 +242,11 @@ int getsize(dwarf_entry *type) {
     return 4;
   case DW_TAG_array_type: {
     modifier_type * modifier_ptr=(modifier_type*)type->entry_ptr;
-    int size=((array_bound*)modifier_ptr->array_ptr[0]->entry_ptr)->upperbound+1;
+    int size=1;
+    int i;
+    for(i=0;i<modifier_ptr->num_array;i++) {
+      size*=((array_bound*)modifier_ptr->array_ptr[i]->entry_ptr)->upperbound+1;
+    }
     return size*getsize(modifier_ptr->target_ptr);
   }
   case DW_TAG_base_type: {
@@ -197,9 +282,13 @@ char * printname(dwarf_entry * type,int op) {
        char *typename=printname(modifier_ptr->target_ptr,op);
        return typename;
     } else if (op==POSTNAME) {
-      int size=((array_bound*)modifier_ptr->array_ptr[0]->entry_ptr)->upperbound+1;
+      int i;
+      int size=1;
       char *typename=printname(modifier_ptr->target_ptr,op);
       char *newptr=(char *)malloc(200);
+      for(i=0;i<modifier_ptr->num_array;i++) {
+       size*=((array_bound*)modifier_ptr->array_ptr[i]->entry_ptr)->upperbound+1;
+      }
       sprintf(newptr,"%s[%ld]",typename,size);
       return newptr;
     }
index 52b32be16612fdc050757a6ab528dc090e57d111..3419fc1ee1681917453c59e6fa0b1e26cfd78c9c 100755 (executable)
@@ -19,7 +19,8 @@
 #define DUMP_H
 
 #include "typedata.h"
-
+#include "common.h"
+#include "GenericHashtable.h"
 
 struct StructureElement {
   char *fieldname;
@@ -52,4 +53,5 @@ void initializeTypeArray();
 int entry_is_type(dwarf_entry *entry);
 char * printname(dwarf_entry * entry,int op);
 int getsize(dwarf_entry *type);
+int printtype(collection_type *collection_ptr,struct genhashtable *);
 #endif
index 9491146247771f642033f2ad82c46ea160620dad..cdeae71b673d16a3fe7ab372fef50cf212e01d28 100755 (executable)
@@ -72,6 +72,7 @@ char tag_is_relevant_entry(unsigned long tag)
     case DW_TAG_base_type:
     case DW_TAG_typedef:
     case DW_TAG_const_type:
+    case DW_TAG_inheritance:
     case DW_TAG_enumerator:
     case DW_TAG_subprogram:
     case DW_TAG_volatile_type:
@@ -218,7 +219,7 @@ char entry_is_listening_for_attribute(dwarf_entry* e, unsigned long attr)
     case DW_AT_const_value:
       return tag_is_enumerator(tag);
     case DW_AT_data_member_location:
-      return tag_is_member(tag);
+      return tag_is_member(tag)||tag==DW_TAG_inheritance;
     case DW_AT_type:
       return (tag_is_modifier_type(tag) ||
               tag_is_member(tag) ||
@@ -226,7 +227,8 @@ char entry_is_listening_for_attribute(dwarf_entry* e, unsigned long attr)
               tag_is_formal_parameter(tag) ||
               tag_is_function_type(tag)||
              tag==DW_TAG_typedef||
-             tag==DW_TAG_const_type);
+             tag==DW_TAG_const_type||
+             tag==DW_TAG_inheritance);
     case DW_AT_upper_bound:
       return (tag==DW_TAG_subrange_type);
     case DW_AT_encoding:
@@ -263,6 +265,9 @@ char harvest_type_value(dwarf_entry* e, unsigned long value)
   } else if (tag==DW_TAG_typedef) {
     ((tdef*)e->entry_ptr)->target_ID = value;
     return 1;
+  } else if (tag==DW_TAG_inheritance) {
+    ((inherit*)e->entry_ptr)->target_ID = value;
+    return 1;
   } else if (tag==DW_TAG_const_type) {
     ((consttype*)e->entry_ptr)->target_ID = value;
     return 1;
@@ -510,6 +515,10 @@ char harvest_data_member_location(dwarf_entry* e, long value)
       ((member*)e->entry_ptr)->data_member_location = value;
       return 1;
     }
+  else if (tag==DW_TAG_inheritance) {
+    ((inherit*)e->entry_ptr)->data_member_location = value;
+    return 1;
+  }
   else
     return 0;
 }
@@ -768,6 +777,20 @@ void link_entries_to_type_entries()
               bound_ptr->target_ptr=&dwarf_entry_array[target_index];
             }
       }
+      else if (tag==DW_TAG_inheritance) {
+          char success = 0;
+          unsigned long target_index = 0;
+          inherit* bound_ptr = (inherit*)(cur_entry->entry_ptr);
+          unsigned long target_ID = bound_ptr->target_ID;
+
+          // Use a binary search to try to find the index of the entry in the
+          // array with the corresponding target_ID
+          success = binary_search_dwarf_entry_array(target_ID, &target_index);
+          if (success)
+            {
+              bound_ptr->target_ptr=&dwarf_entry_array[target_index];
+            }
+      }
       else if (tag_is_function(tag))
         {
           char success = 0;
@@ -883,7 +906,9 @@ void link_collection_to_members(dwarf_entry* e, unsigned long dist_to_end)
       while ((member_count < dist_to_end) // put this first! short-circuit eval.
              && cur_entry->level>currentlevel)
         {
-         if (cur_entry->tag_name==DW_TAG_member&&cur_entry->level==(currentlevel+1))
+         if ((cur_entry->tag_name==DW_TAG_member||
+              cur_entry->tag_name==DW_TAG_inheritance)&&
+             cur_entry->level==(currentlevel+1))
            member_count++;
           cur_entry++;
         }
@@ -917,7 +942,9 @@ void link_collection_to_members(dwarf_entry* e, unsigned long dist_to_end)
       while ((member_count < dist_to_end) // put this first! short-circuit eval.
              && cur_entry->level>currentlevel)
         {
-         if (cur_entry->tag_name==DW_TAG_member&&cur_entry->level==(currentlevel+1))
+         if ((cur_entry->tag_name==DW_TAG_member||
+              cur_entry->tag_name==DW_TAG_inheritance)
+             &&cur_entry->level==(currentlevel+1))
            collection_ptr->members[member_count++]=cur_entry;
           cur_entry++;
         }
@@ -1215,6 +1242,9 @@ void initialize_dwarf_entry_ptr(dwarf_entry* e)
       else if (e->tag_name==DW_TAG_typedef) {
        e->entry_ptr=calloc(1,sizeof(tdef));
       }
+      else if (e->tag_name==DW_TAG_inheritance) {
+       e->entry_ptr=calloc(1,sizeof(inherit));
+      }
       else if (e->tag_name==DW_TAG_const_type) {
        e->entry_ptr=calloc(1,sizeof(consttype));
       }
index 76326c573dffcfb6ee1ab06b64c49b2df1e1b180..c08cfffb127811ec031dc2870fc24ceadd61f8fa 100755 (executable)
@@ -79,6 +79,13 @@ typedef struct
   dwarf_entry* target_ptr; // Type that this entry modifies (DW_AT_type)
 } consttype;
 
+typedef struct
+{ 
+  unsigned long target_ID; // ID of the entry that contains the type that this modifies
+  dwarf_entry* target_ptr; // Type that this entry modifies (DW_AT_type)
+  long data_member_location; // Addr offset relative to struct head
+} inherit;
+
 // collection_type = {structure_type, union_type, enumeration_type}
 typedef struct
 {