From 4aaae86166692baf69cbe2212ae28cb068094edb Mon Sep 17 00:00:00 2001 From: bdemsky Date: Tue, 9 Nov 2004 18:58:18 +0000 Subject: [PATCH] Added support for dynamically allocated arrays. --- .../structextract/dumpstructures.c | 116 +++++++++++++++++- .../structextract/dumpstructures.h | 1 + 2 files changed, 111 insertions(+), 6 deletions(-) diff --git a/Repair/RepairCompiler/structextract/dumpstructures.c b/Repair/RepairCompiler/structextract/dumpstructures.c index 72951e9..a7bfdf6 100755 --- a/Repair/RepairCompiler/structextract/dumpstructures.c +++ b/Repair/RepairCompiler/structextract/dumpstructures.c @@ -28,19 +28,27 @@ #define GETJUSTTYPE 3 int FOLLOW_PTRS=0; - +struct genhashtable * arrayt=NULL; +struct genhashtable * arraytype=NULL; int process_elf_binary_data(char* filename); char *rootfile=NULL; +char *arrayfile=NULL; int main(int argc, char **argv) { + int i; if (argc<2) return 0; if (argc>=3) rootfile=argv[2]; - if (argc==4&&(strcmp("-r",argv[3])==0)) - FOLLOW_PTRS=1; - + for(i=3;i0&&(a==13||a==10||!readmore)) { + state=0; + sizebuf[offset]=0; + { + char *str=copystr(buf); + char *sizestr=copystr(sizebuf); + genputtable(arrayt,str,sizestr); + } + offset=0; + } + } + } + for (i = 0; i < dwarf_entry_array_size; i++) { cur_entry = &dwarf_entry_array[i]; @@ -265,7 +311,18 @@ void initializeTypeArray() } offset+=getsize(type); newname=escapestr(name); - printf(" %s %s%s;\n",typestr,newname,poststr); + { + char buf[512]; + char *dtype; + sprintf(buf, "%s.%s\0", collection_ptr->name,newname); + if (arrayt!=NULL&&gencontains(arrayt, &buf)) { + genputtable(arraytype, copystr(buf), typestr); + dtype=deref(typestr); + printf(" %s_array * %s%s;\n",dtype,newname,poststr); + free(dtype); + } else + printf(" %s %s%s;\n",typestr,newname,poststr); + } free(newname); } } @@ -274,6 +331,26 @@ void initializeTypeArray() printf("}\n\n"); } } + if (arrayt!=NULL) { + struct geniterator * gi=gengetiterator(arrayt); + while(1) { + char * str=(char *)gennext(gi); + char *size=NULL; + char *typestr=NULL; + if (str==NULL) + break; + + size=(char *)gengettable(arrayt,str); + typestr=deref((char *)gengettable(arraytype,str)); + + printf("structure %s_array {\n",typestr); + printf(" %s elem[%s];\n",typestr,size); + printf("}\n"); + free(typestr); + } + genfreeiterator(gi); + } + } int printtype(collection_type *collection_ptr,struct genhashtable *ght) @@ -316,7 +393,18 @@ int printtype(collection_type *collection_ptr,struct genhashtable *ght) offset+=getsize(type); newname=escapestr(name); - printf(" %s %s%s;\n",typestr,newname,poststr); + { + char buf[512]; + char *dtype; + sprintf(buf, "%s.%s\0", collection_ptr->name,newname); + if (arrayt!=NULL&&gencontains(arrayt, &buf)) { + genputtable(arraytype, buf, typestr); + dtype=deref(typestr); + printf(" %s_array * %s%s;\n",dtype,newname,poststr); + free(dtype); + } else + printf(" %s %s%s;\n",typestr,newname,poststr); + } free(newname); } } @@ -371,6 +459,22 @@ int getsize(dwarf_entry *type) { } } +char * deref(char *name) { + char *str=copystr(name); + char *initstr=str; + for(;(*str)!=0;str++) + ; + for(;(str!=initstr)&&((*str)!='*');str--) + ; + if ((*str)=='*') { + (*str)=0; + str--; + for(;(str!=initstr)&&((*str)==' ');str--) + (*str)=0; + } + return initstr; +} + char * printname(dwarf_entry * type,int op) { if (type==NULL) { if (op==GETTYPE||op==GETJUSTTYPE) diff --git a/Repair/RepairCompiler/structextract/dumpstructures.h b/Repair/RepairCompiler/structextract/dumpstructures.h index 3419fc1..65c094a 100755 --- a/Repair/RepairCompiler/structextract/dumpstructures.h +++ b/Repair/RepairCompiler/structextract/dumpstructures.h @@ -48,6 +48,7 @@ struct Structure { struct Structure * TypeArray; unsigned long TypeArraySize; +char * deref(char *name); void daikon_preprocess_entry_array(); void initializeTypeArray(); int entry_is_type(dwarf_entry *entry); -- 2.34.1