Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

/users/u3/mtikir/PMaCInstrumentor_v1601/src/SymbolTable.C

Go to the documentation of this file.
00001 #include <Instruction.h>
00002 #include <DemangleWrapper.h>
00003 #include <SymbolTable.h>
00004 #include <StringTable.h>
00005 #include <SectHeader.h>
00006 #include <RawSection.h>
00007 #include <Auxilary.h>
00008 #include <XCoffFile.h>
00009 #include <BinaryFile.h>
00010 
00011 int compareSymbolValue(const void* arg1,const void* arg2){
00012     Symbol* sym1 = *((Symbol**)arg1);
00013     Symbol* sym2 = *((Symbol**)arg2);
00014     uint64_t vl1 = sym1->GET(n_value);
00015     uint64_t vl2 = sym2->GET(n_value);
00016 
00017     if(vl1 < vl2)
00018         return -1;
00019     if(vl1 > vl2)
00020         return 1;
00021 
00022     ASSERT((sym1->GET(n_scnum) == sym2->GET(n_scnum)) && 
00023            "FATAL: Two symbols with the same address but different sections");
00024 
00025     return 0;
00026 }
00027 
00028 int searchSymbolValue(const void* arg1,const void* arg2){
00029     uint64_t key = *((uint64_t*)arg1);
00030     Symbol* sym = *((Symbol**)arg2);
00031     uint64_t val = sym->GET(n_value);
00032 
00033     if(key < val)
00034         return -1;
00035     if(key > val)
00036         return 1;
00037     return 0;
00038 }
00039 
00040 bool Symbol::unknownSymbol(){
00041     if(isAuxilary())
00042         return false;
00043     if(IS_SYMB_TYPE(ALIAS) || IS_SYMB_TYPE(ARG) || IS_SYMB_TYPE(AUTO) || 
00044        IS_SYMB_TYPE(EFCN) || IS_SYMB_TYPE(ENTAG) || IS_SYMB_TYPE(EOS) || 
00045        IS_SYMB_TYPE(EXTDEF) || IS_SYMB_TYPE(FIELD) || IS_SYMB_TYPE(HIDDEN) || 
00046        IS_SYMB_TYPE(LABEL) || IS_SYMB_TYPE(LINE) || IS_SYMB_TYPE(MOE) || 
00047        IS_SYMB_TYPE(MOS) || IS_SYMB_TYPE(MOU) || IS_SYMB_TYPE(REG) || 
00048        IS_SYMB_TYPE(REGPARM) || IS_SYMB_TYPE(STRTAG) || IS_SYMB_TYPE(TPDEF) || 
00049        IS_SYMB_TYPE(ULABEL) || IS_SYMB_TYPE(UNTAG) || IS_SYMB_TYPE(USTATIC))
00050        return true;
00051     return false;
00052 }
00053 
00054 bool Symbol::stringInDebugSection(){
00055     if(isAuxilary())
00056         return false;
00057 
00058     if(IS_SYMB_TYPE(BCOMM) || IS_SYMB_TYPE(DECL) || IS_SYMB_TYPE(ECOML) || 
00059        IS_SYMB_TYPE(ECOMM) || IS_SYMB_TYPE(ENTRY) || IS_SYMB_TYPE(FUN) || 
00060        IS_SYMB_TYPE(GSYM) || IS_SYMB_TYPE(LSYM) || IS_SYMB_TYPE(PSYM) || 
00061        IS_SYMB_TYPE(RPSYM) || IS_SYMB_TYPE(RSYM) || IS_SYMB_TYPE(STSYM) ||
00062        IS_SYMB_TYPE(TCSYM))
00063         return true;
00064     return false;
00065 }
00066 
00067 
00068 char* Symbol::getName(StringTable* stringTable,DebugSection* debugRawSect){
00069     char* ptr = NULL;
00070     if(!stringInDebugSection()){
00071         ASSERT(stringTable && "FATAL : String is needed from string table");
00072         ptr = getNameStringTable(stringTable);
00073     } else {
00074         ASSERT(debugRawSect && "FATAL : String is needed from debug");
00075         ptr = getNameDebugSection(debugRawSect);
00076     }
00077     ASSERT(ptr && "FATAL : the symbol name does not exist");
00078     return ptr;
00079 }
00080 
00081 void Symbol::print(StringTable* stringTable,DebugSection* debugRawSect,bool followAux){
00082 
00083     char* ptr = getName(stringTable,debugRawSect);
00084 
00085     DemangleWrapper wrapper;
00086     char* demangled = wrapper.demangle_combined(ptr);
00087 
00088     PRINT_INFOR("SYM\t%10s [%7d](sec %2d)(fl 0x00)(ty %3x)(scl %3d) (nx %d) 0x%016llx %s --- %s",
00089             getTypeName(),getIndex(),GET(n_scnum),GET(n_type),GET(n_sclass),
00090             GET(n_numaux),GET(n_value),ptr,demangled);
00091     free(ptr);
00092 
00093     if(followAux && getNext()){
00094         for(SymbolBase* s = getNext(); s; s = s->getNext()){
00095             s->print(stringTable,debugRawSect,followAux);
00096         }
00097     }
00098 }
00099 
00100 #define NO_NAME_OFFSET (uint32_t)(-1)
00101 uint32_t Symbol32::getNameOffset(){
00102     uint32_t offset = NO_NAME_OFFSET;
00103     uint32_t zeroes = GET(n_zeroes);
00104     if(!zeroes){
00105         offset = GET(n_offset);
00106     } 
00107     return offset;
00108 }
00109 
00110 uint32_t Symbol64::getNameOffset(){
00111     uint32_t offset = GET(n_offset);
00112     return offset;
00113 }
00114 
00115 char* Symbol32::getNameDebugSection(DebugSection* rawDebugSect){
00116     char* ret = NULL;
00117     char tmpBuffer[9];
00118     if(!rawDebugSect)
00119         return ret;
00120 
00121     uint32_t offset = getNameOffset();
00122     if(offset == NO_NAME_OFFSET){
00123         strncpy(tmpBuffer,GET(n_name),8);
00124         tmpBuffer[8] = '\0';
00125         ret = tmpBuffer;
00126     } else {
00127         ret = rawDebugSect->getString(offset);
00128     }
00129     return strdup(ret);
00130 }
00131 
00132 char* Symbol64::getNameDebugSection(DebugSection* rawDebugSect){
00133     char* ret = NULL;
00134     if(!rawDebugSect)
00135         return ret;
00136 
00137     uint32_t offset = getNameOffset();
00138     ret = rawDebugSect->getString(offset);
00139     return strdup(ret);
00140 }
00141 
00142 char* Symbol32::getNameStringTable(StringTable* stringTable){
00143 
00144     char* ret = NULL;
00145     char tmpBuffer[9];
00146 
00147     if(!stringTable)
00148         return ret;
00149 
00150     uint32_t offset = getNameOffset();
00151     if(offset == NO_NAME_OFFSET){
00152         strncpy(tmpBuffer,GET(n_name),8);
00153         tmpBuffer[8] = '\0';
00154         ret = tmpBuffer;
00155     } else {
00156         ret = stringTable->getString(offset);
00157     }
00158     return strdup(ret);
00159 }
00160 char* Symbol64::getNameStringTable(StringTable* stringTable){
00161     char* ret = NULL;
00162     if(!stringTable)
00163         return ret;
00164 
00165     uint32_t offset = getNameOffset();
00166     ret = stringTable->getString(offset);
00167     return strdup(ret);
00168 }
00169 
00170 void Symbol32::changeValueCopy(uint64_t value,char* buff){
00171     SYMENT newEntry;
00172     newEntry = entry;
00173     newEntry.n_value = value;
00174     memcpy(buff,&newEntry,Size__NN_bit_SymbolTable_Entry);
00175 }
00176 
00177 void Symbol64::changeValueCopy(uint64_t value,char* buff){
00178     SYMENT_64 newEntry;
00179     newEntry = entry;
00180     newEntry.n_value = value;
00181     memcpy(buff,&newEntry,Size__NN_bit_SymbolTable_Entry);
00182 }
00183 
00184 
00185 Symbol* binarySearch(Symbol** symbols,uint32_t symbolCount,uint64_t value){
00186 
00187     if(!symbolCount)
00188         return NULL;
00189 
00190     Symbol* ret = NULL;
00191 
00192     uint32_t beginIndex = 0;
00193     uint32_t endIndex = symbolCount;
00194     
00195     uint32_t midIndex = 0;
00196     Symbol* midSymbol = NULL;
00197     uint64_t midVal = 0;
00198 
00199     while(beginIndex < endIndex){
00200         midIndex = (beginIndex+endIndex) / 2;
00201         midSymbol = symbols[midIndex];
00202         midVal = midSymbol->GET(n_value);
00203 
00204         if(midVal > value){
00205             endIndex = midIndex;
00206         } else if(midVal < value){
00207             beginIndex = midIndex+1;
00208         } else {
00209             ret = midSymbol;
00210             break;
00211         }
00212     }
00213 
00214     if(!ret){
00215         if(value < midVal){
00216             if(midIndex) {
00217                 midIndex--;
00218                 ret = symbols[midIndex];
00219             }
00220         } else {
00221             if(midIndex < (symbolCount-1)){
00222                 ret = midSymbol;
00223             }
00224         }
00225     }
00226 
00227     return ret;
00228 }
00229 
00230 Symbol* Symbol::findSymbol(Symbol** symbols,uint32_t symbolCount,uint64_t value){
00231     return binarySearch(symbols,symbolCount,value);
00232 }
00233 
00234 
00235 
00236 #define CASE_SYMBOL_TYPE(__str)  case C_ ## __str: return #__str
00237 const char* Symbol::getTypeName(){
00238     switch(GET(n_sclass)){
00239         CASE_SYMBOL_TYPE(ALIAS);
00240         CASE_SYMBOL_TYPE(ARG);
00241         CASE_SYMBOL_TYPE(AUTO);
00242         CASE_SYMBOL_TYPE(BCOMM);
00243         CASE_SYMBOL_TYPE(BINCL);
00244         CASE_SYMBOL_TYPE(BLOCK);
00245         CASE_SYMBOL_TYPE(BSTAT);
00246         CASE_SYMBOL_TYPE(DECL);
00247         CASE_SYMBOL_TYPE(ECOML);
00248         CASE_SYMBOL_TYPE(ECOMM);
00249         CASE_SYMBOL_TYPE(EFCN);
00250         CASE_SYMBOL_TYPE(EINCL);
00251         CASE_SYMBOL_TYPE(ENTAG);
00252         CASE_SYMBOL_TYPE(ENTRY);
00253         CASE_SYMBOL_TYPE(EOS);
00254         CASE_SYMBOL_TYPE(ESTAT);
00255         CASE_SYMBOL_TYPE(EXT);
00256         CASE_SYMBOL_TYPE(EXTDEF);
00257         CASE_SYMBOL_TYPE(FCN);
00258         CASE_SYMBOL_TYPE(FIELD);
00259         CASE_SYMBOL_TYPE(FILE);
00260         CASE_SYMBOL_TYPE(FUN);
00261         CASE_SYMBOL_TYPE(GSYM);
00262         CASE_SYMBOL_TYPE(HIDDEN);
00263         CASE_SYMBOL_TYPE(HIDEXT);
00264         CASE_SYMBOL_TYPE(INFO);
00265         CASE_SYMBOL_TYPE(LABEL);
00266         CASE_SYMBOL_TYPE(LINE);
00267         CASE_SYMBOL_TYPE(LSYM);
00268         CASE_SYMBOL_TYPE(MOE);
00269         CASE_SYMBOL_TYPE(MOS);
00270         CASE_SYMBOL_TYPE(MOU);
00271         CASE_SYMBOL_TYPE(NULL);
00272         CASE_SYMBOL_TYPE(PSYM);
00273         CASE_SYMBOL_TYPE(REG);
00274         CASE_SYMBOL_TYPE(REGPARM);
00275         CASE_SYMBOL_TYPE(RPSYM);
00276         CASE_SYMBOL_TYPE(RSYM);
00277         CASE_SYMBOL_TYPE(STAT);
00278         CASE_SYMBOL_TYPE(STRTAG);
00279         CASE_SYMBOL_TYPE(STSYM);
00280         CASE_SYMBOL_TYPE(TCSYM);
00281         CASE_SYMBOL_TYPE(TPDEF);
00282         CASE_SYMBOL_TYPE(ULABEL);
00283         CASE_SYMBOL_TYPE(UNTAG);
00284         CASE_SYMBOL_TYPE(USTATIC);
00285         CASE_SYMBOL_TYPE(WEAKEXT);
00286         default: {
00287             PRINT_INFOR("Some symbol that is not known - %d",GET(n_sclass));
00288             return "SYM_UNK_NAME";
00289         }
00290     }
00291 }
00292 
00293 SymbolTable::SymbolTable(char* ptr,uint32_t nsyms,XCoffFile* xcoff) 
00294     : Base(XCoffClassTypes_symbol_table),symbolTablePtr(ptr),
00295       numberOfSymbols(nsyms),stringTable(NULL),debugRawSect(NULL),
00296       xCoffFile(xcoff)
00297 {
00298     symbols = new SymbolBase*[numberOfSymbols];
00299 }
00300 
00301 SymbolTable::~SymbolTable(){
00302     for(uint32_t i=0;i<numberOfSymbols;i++)
00303         delete symbols[i];
00304     delete[] symbols;
00305 }
00306 
00307 void SymbolTable::print() { 
00308 
00309     PRINT_INFOR("SYMBOLTABLE");
00310     if(symbolTablePtr && sizeInBytes && numberOfSymbols){
00311         PRINT_INFOR("\tSize  : %d",sizeInBytes);
00312         PRINT_INFOR("\tCoun  : %d",numberOfSymbols);
00313     } else {
00314         PRINT_INFOR("\tSize  : 0 EMPTY");
00315     }
00316 
00317     PRINT_INFOR("\tSyms  :");
00318     for(uint32_t i=0;i<numberOfSymbols;i++){
00319         if(!symbols[i]->isAuxilary()){
00320             symbols[i]->print(stringTable,debugRawSect,true);
00321         }
00322     }
00323 }
00324 
00325 void SymbolTable::printSymbol(uint32_t index) {
00326     ASSERT((index < numberOfSymbols) && "FATAL : SymbolBase does not exists");
00327     printSymbol(symbols[index]);
00328 }
00329 
00330 void SymbolTable::printSymbol(SymbolBase* sym) {
00331     sym->print(stringTable,debugRawSect,true);
00332 }
00333 
00334 
00335 SymbolBase* SymbolTable::newSymbol(SymbolBase* lastSymbol,
00336                                    uint8_t remaningAux,
00337                                    BinaryInputFile* binaryInputFile,uint32_t index,
00338                                    XCoffFile* xcoff)
00339 {
00340 
00341     SymbolBase* ret = NULL;
00342     if(lastSymbol){
00343         ASSERT(!lastSymbol->isAuxilary() && "FATAL : last symbol should be non-axilary");
00344     }
00345 
00346     Symbol* symbol = (Symbol*)lastSymbol;
00347     bool delayed = false;
00348 
00349     if(!remaningAux){
00350         if(xcoff->is64Bit()){
00351             ret = new Symbol64(index);
00352         } else {
00353             ret = new Symbol32(index);
00354         }
00355     } else {
00356         if(symbol->IS_SYMB_TYPE(FILE)){
00357             if(xcoff->is64Bit()){
00358                 ret = new AuxilaryFile64(index);
00359             } else {
00360                 ret = new AuxilaryFile32(index);
00361             }
00362         } else if(symbol->IS_SYMB_TYPE(STAT)){ 
00363             ret = new AuxilarySection(index);
00364         } else if(symbol->IS_SYMB_TYPE(BLOCK) ||
00365                   symbol->IS_SYMB_TYPE(FCN)){
00366             if(xcoff->is64Bit()){
00367                 ret = new AuxilaryBlock64(index);
00368             } else {
00369                 ret = new AuxilaryBlock32(index);
00370             }
00371         } else if(symbol->IS_SYMB_TYPE(EXT) ||
00372                   symbol->IS_SYMB_TYPE(HIDEXT) ||
00373                   symbol->IS_SYMB_TYPE(WEAKEXT)){
00374             if(xcoff->is64Bit()){
00375                 if(remaningAux == 1){
00376                     ret = new AuxilaryCSect64(index);
00377                 } else {
00378                     delayed = true;
00379                     ret = new AuxilaryFunction64(index);
00380                 }
00381             } else {
00382                 if(remaningAux == 1){
00383                     ret = new AuxilaryCSect32(index);
00384                 } else {
00385                     ret = new AuxilaryFunction32(index);
00386                 }
00387             }
00388         } else {
00389             ASSERT(0 && "FATAL : there is an auxliary for an unknown type");
00390         }
00391     }
00392 
00393     binaryInputFile->copyBytesIterate(ret->charStream(),Size__NN_bit_SymbolTable_Entry);
00394 
00395     if(remaningAux){
00396         if((symbol->IS_SYMB_TYPE(EXT) ||
00397             symbol->IS_SYMB_TYPE(HIDEXT) ||
00398             symbol->IS_SYMB_TYPE(WEAKEXT)) &&
00399             (remaningAux == 1)){
00400                 ASSERT((((Auxilary*)ret)->getAuxilaryType() == Type__Auxilary_Symbol_CSect) &&
00401                        "FATAL : The last aux entry should be of type CSECT");
00402         }
00403         if(delayed){
00404             if(((Auxilary*)ret)->getAuxilaryType() == Type__Auxilary_Symbol_Exception){
00405                 SymbolBase* newRet = new AuxilaryException(ret->getIndex());
00406                 memcpy(newRet->charStream(),ret->charStream(),Size__NN_bit_SymbolTable_Entry);
00407                 delete ret;
00408                 ret = newRet;
00409             }
00410         }
00411     }
00412     return ret;
00413 }
00414 
00415 uint32_t SymbolTable::read(BinaryInputFile* binaryInputFile){
00416 
00417     sizeInBytes = Size__NN_bit_SymbolTable_Entry * numberOfSymbols;
00418 
00419     uint32_t ret = 0;
00420 
00421     binaryInputFile->setInPointer(symbolTablePtr);
00422     setFileOffset(binaryInputFile->currentOffset());
00423 
00424     uint8_t isAux = 0;
00425     SymbolBase* currentSym = NULL;
00426     SymbolBase* prevEntry = NULL;
00427     for(uint32_t i = 0;i<numberOfSymbols;i++){
00428         symbols[i] = newSymbol(currentSym,isAux,binaryInputFile,i,xCoffFile);
00429         ret += Size__NN_bit_SymbolTable_Entry;
00430 
00431         if(isAux){
00432             ASSERT(currentSym && "A sym should exists before AUX");
00433             ASSERT(prevEntry && "Prev should exists before AUX");
00434             symbols[i]->setPrev(currentSym);
00435             prevEntry->setNext(symbols[i]);
00436             isAux--;
00437         } else {
00438             isAux = ((Symbol*)symbols[i])->GET(n_numaux);
00439             currentSym = symbols[i];
00440             if(((Symbol*)currentSym)->unknownSymbol()){
00441                 PRINT_DEBUG("Information about %s is not known very well",
00442                             currentSym->getTypeName());
00443             }
00444         }
00445         prevEntry = symbols[i];
00446     }
00447 
00448     ASSERT((sizeInBytes == ret) && "FATAL : Somehow the number of read does not match");
00449 
00450     PRINT_INFOR("SymbolBase table contains %d symbols (%d bytes) at %#x",
00451                 numberOfSymbols,sizeInBytes,(uint32_t)(symbolTablePtr-binaryInputFile->inPtrBase()));
00452     
00453     return ret;
00454 }
00455 
00456 #define INVALID_SYMBOL_LENGTH (uint64_t)-1
00457 
00458 uint8_t SymbolTable::getStorageMapping(SymbolBase* symBase){
00459     if(symBase->isAuxilary())
00460         return (uint8_t)-1;
00461 
00462     Symbol* sym = (Symbol*)symBase;
00463     if(!sym->IS_SYMB_TYPE(EXT) &&
00464        !sym->IS_SYMB_TYPE(HIDEXT) &&
00465        !sym->IS_SYMB_TYPE(WEAKEXT))
00466         return (uint8_t)-1;
00467 
00468     Auxilary* aux = (Auxilary*)(sym->getNext());
00469     for(;aux;aux=(Auxilary*)aux->getNext()){
00470         if(aux->getAuxilaryType() == Type__Auxilary_Symbol_CSect){
00471             AuxilaryCSect* auxCsect = (AuxilaryCSect*)aux;
00472             return auxCsect->GET_A(x_smclas,x_csect);
00473         }
00474     }
00475 
00476     return (uint8_t)-1;
00477 }
00478 
00479 uint64_t SymbolTable::getSymbolLength(SymbolBase* symBase){
00480 
00481     if(symBase->isAuxilary())
00482         return 0;
00483 
00484     Symbol* sym = (Symbol*)symBase;
00485     if(!sym->IS_SYMB_TYPE(EXT) &&
00486        !sym->IS_SYMB_TYPE(HIDEXT) &&
00487        !sym->IS_SYMB_TYPE(WEAKEXT))
00488        return 0;
00489 
00490     uint8_t numaux = sym->GET(n_numaux);
00491     Auxilary* aux = (Auxilary*)(sym->getNext());
00492 
00493     if(!numaux || !aux)
00494         return 0;
00495 
00496     uint64_t ret = 0;
00497     AuxilaryCSect* auxCsect = NULL;
00498 
00499     ret = INVALID_SYMBOL_LENGTH;
00500     for(;aux;aux=(Auxilary*)aux->getNext()){
00501 
00502         uint64_t fsize = 0;
00503         switch(aux->getAuxilaryType()){
00504             case Type__Auxilary_Symbol_Function:
00505                 fsize = ((AuxilaryFunction*)aux)->GET_A(x_fsize,x_fcn);
00506                 break;
00507             case Type__Auxilary_Symbol_Exception: 
00508                 fsize = ((AuxilaryException*)aux)->GET_A(x_fsize,x_except);
00509                 break;
00510             case Type__Auxilary_Symbol_CSect: 
00511                 auxCsect = (AuxilaryCSect*)aux;
00512                 break;
00513             default: 
00514                 break;
00515         }
00516         if(fsize && (ret == INVALID_SYMBOL_LENGTH)){
00517             ret = fsize; /* the first non-positive entry **/
00518         }
00519     }
00520 
00521     if(ret == INVALID_SYMBOL_LENGTH){
00522         ASSERT(auxCsect && "FATAL : the last entry in ...EXT should be a csect");
00523 
00524         ret = auxCsect->getLength();
00525         uint8_t smtype = auxCsect->GET_A(x_smtyp,x_csect);
00526         uint8_t lengthMod = smtype & 0x7;
00527 
00528         switch(lengthMod){
00529             case XTY_LD:
00530                 ret = getSymbolLength(getSymbol(ret));
00531                 break;
00532             case XTY_ER:
00533                 ret = 0;
00534                 break;
00535             case XTY_SD:
00536             case XTY_CM:
00537             default:
00538                 break;
00539         }
00540     }
00541 
00542     return ret;
00543 }
00544 
00545 uint32_t SymbolTable::filterSortAddressSymbols(Symbol** symbolArray,uint32_t arrayLength){
00546     uint32_t currIndex = 0;
00547     for(uint32_t i=0;i<numberOfSymbols;i++){
00548         SymbolBase* base = symbols[i];
00549         if(base->isAuxilary())
00550             continue;
00551 
00552         Symbol* sym= (Symbol*)base;
00553         if(!sym->IS_SYMB_TYPE(EXT) &&
00554            !sym->IS_SYMB_TYPE(HIDEXT) &&
00555            !sym->IS_SYMB_TYPE(WEAKEXT) &&
00556            !sym->IS_SYMB_TYPE(BLOCK) &&
00557            !sym->IS_SYMB_TYPE(STAT))
00558             continue;
00559 
00560         if(!sym->GET(n_value) || (sym->GET(n_scnum) <= 0))
00561             continue;
00562 
00563         char* ptr = getSymbolName(i);
00564         while(*ptr == '.')
00565             ptr++;
00566 
00567         if(!strlen(ptr) ||
00568            !strcmp(ptr,"text") ||
00569            !strcmp(ptr,"data") ||
00570            !strcmp(ptr,"bss"))
00571                 continue;
00572 
00573         if(currIndex < arrayLength)
00574             symbolArray[currIndex++] = sym;
00575         else {
00576             free(ptr);
00577             break;
00578         }
00579     }
00580     if(currIndex){
00581         qsort(symbolArray,currIndex,sizeof(Symbol*),compareSymbolValue);
00582     }
00583     return currIndex;
00584 }
00585 bool Symbol::builtinSaveRestore(char* ptr){
00586 
00587     while(*ptr == '.')
00588         ptr++;
00589 
00590     if(!strlen(ptr) ||
00591 #if 1
00592        !strcmp(ptr,"fres") ||
00593        !strcmp(ptr,"fsav") ||
00594 #endif
00595        !strncmp(ptr,"_savef",6) ||
00596        !strncmp(ptr,"_restf",6) ||
00597        !strncmp(ptr,"_savegpr",8) ||
00598        !strncmp(ptr,"_restgpr",8) ||
00599        !strncmp(ptr,"$SAVEF",6) ||
00600        !strncmp(ptr,"$RESTF",6) ||
00601        !strncmp(ptr,"Ssavef",6) ||
00602        !strncmp(ptr,"Srestf",6) ||
00603        !strcmp(ptr,"text") ||
00604        !strcmp(ptr,"data") ||
00605        !strcmp(ptr,"bss"))
00606         return true;
00607 
00608     return false;
00609 }
00610 
00611 uint32_t SymbolTable::filterSortBSSSymbols(Symbol** symbolArray,uint32_t arrayLength){
00612         SectHeader* header = getXCoffFile()->getBSSSection()->getSectHeader();
00613     uint16_t sectionIndex = header->getIndex();
00614 
00615     uint32_t currIndex = 0;
00616     for(uint32_t i=0;i<numberOfSymbols;i++){
00617         SymbolBase* base = symbols[i];
00618 
00619         if(base->isAuxilary())
00620             continue;
00621 
00622         Symbol* sym= (Symbol*)base;
00623         if(sym->GET(n_scnum) != sectionIndex)
00624             continue;
00625 
00626         if(currIndex < arrayLength)
00627             symbolArray[currIndex++] = sym;
00628         else{
00629             break;
00630         }
00631     }
00632     if(currIndex){
00633         qsort(symbolArray,currIndex,sizeof(Symbol*),compareSymbolValue);
00634     }
00635     return currIndex;
00636 }
00637 
00638 uint32_t SymbolTable::filterSortFuncSymbols(Symbol** symbolArray,uint32_t arrayLength,SectHeader* header){
00639 
00640     uint16_t sectionIndex = header->getIndex();
00641 
00642     uint32_t currIndex = 0;
00643     for(uint32_t i=0;i<numberOfSymbols;i++){
00644         SymbolBase* base = symbols[i];
00645 
00646         if(base->isAuxilary())
00647             continue;
00648 
00649         Symbol* sym= (Symbol*)base;
00650         if(sym->GET(n_scnum) != sectionIndex)
00651             continue;
00652 
00653         if(!sym->IS_SYMB_TYPE(EXT) &&
00654            !sym->IS_SYMB_TYPE(HIDEXT) &&
00655            !sym->IS_SYMB_TYPE(WEAKEXT))
00656             continue;
00657 
00658         if(!header->inRange(sym->GET(n_value)))
00659             continue;
00660 
00661         char* ptr = getSymbolName(i);
00662         if(!Symbol::builtinSaveRestore(ptr)){
00663             if(currIndex < arrayLength)
00664                 symbolArray[currIndex++] = sym;
00665             else{
00666                 free(ptr);
00667                 break;
00668             }
00669         }
00670 
00671         free(ptr);
00672     }
00673     if(currIndex){
00674         qsort(symbolArray,currIndex,sizeof(Symbol*),compareSymbolValue);
00675     }
00676     return currIndex;
00677 }
00678 

Generated on Mon Jan 28 11:08:33 2008 for PMaCInstrumentor by doxygen 1.3.5