Changeset e7bb58a in rtems-testing for covoar/ObjdumpProcessor.cc


Ignore:
Timestamp:
May 25, 2010, 7:14:48 PM (9 years ago)
Author:
Jennifer Averett <Jennifer.Averett@…>
Branches:
4.11, 8895273c193787f84c4585a10f6d6aceb3b25dc4
Children:
e662966
Parents:
2b85270
Message:

2010-05-25 Jennifer Averett <Jennifer.Averett@…>

  • DesiredSymbols?.cc, Explanations.cc, ObjdumpProcessor?.cc, TraceReaderLogQEMU.cc, app_common.cc, app_common.h: Added a inputBuffer to app_common and modified all fgets calls to use this buffer. This will allow for a size increase if necessary.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • covoar/ObjdumpProcessor.cc

    r2b85270 re7bb58a  
    133133    #define METHOD "ERROR: ObjdumpProcessor::determineLoadAddress - "
    134134    FILE*        loadAddressFile = NULL;
    135     char         buffer[ 512 ];
    136135    char*        cStatus;
    137136    uint32_t     offset;
     
    141140      return 0;
    142141
    143 #if 0
    144     static FILE* gdbCommands = NULL;
    145     int          items;
    146     uint32_t     loadAddress;
    147     FILE*        objdumpFile = NULL;
    148     int          status;
    149     char         terminator;
    150 
    151 
    152     //
    153     // Invoke gdb to determine the physical load address
    154     // of the .text section.
    155     //
    156 
    157     // Create a gdb input commands file.
    158     if (!gdbCommands) {
    159 
    160       gdbCommands = fopen( "gdbCommands", "w" );
    161       if (!gdbCommands) {
    162         fprintf(
    163           stderr,
    164           "ERROR: ObjdumpProcessor::determineLoadAddress - "
    165           "unable to create gdbCommands\n"
    166         );
    167         exit( -1 );
    168       }
    169 
    170       fprintf(
    171         gdbCommands,
    172         "set pagination off\n"
    173         "b main\n"
    174         "r\n"
    175         "info sharedlibrary\n"
    176         "quit\n"
    177       );
    178 
    179       fclose( gdbCommands );
    180     }
    181 
    182     // Invoke gdb.
    183     sprintf(
    184       buffer,
    185       "gdb -x gdbCommands %s | grep %s | cut -d ' ' -f1 > %s",
    186       (theExecutable->getFileName()).c_str(),
    187       (theExecutable->getLibraryName()).c_str(),
    188       "library_addr.tmp"
    189     );
    190 
    191     status = system( buffer );
    192     if (status) {
    193       fprintf(
    194         stderr,
    195         "ERROR: ObjdumpProcessor::determineLoadAddress - "
    196         "command (%s) failed with %d\n",
    197         buffer,
    198         status
    199       );
    200       exit( -1 );
    201     }
    202 
    203     // Read load address.
    204     loadAddressFile = fopen( "library_addr.tmp", "r" );
    205     if (!loadAddressFile) {
    206       fprintf(
    207         stderr,
    208         "ERROR: ObjdumpProcessor::determineLoadAddress - "
    209         "unable to open library_addr.tmp\n"
    210       );
    211       exit( -1 );
    212     }
    213 
    214     cStatus = fgets( buffer, 512, loadAddressFile );
    215     items = sscanf(
    216       buffer, "%x", &loadAddress
    217     );
    218 
    219     fclose( loadAddressFile );
    220     unlink( "library_addr.tmp" );
    221 
    222     //
    223     // Partially process an objdump of the library to determine the first
    224     // symbol's offset from the physical load address of the library.
    225     //
    226 
    227     // Obtain the objdump file.
    228     objdumpFile = getFile( theExecutable->getLibraryName() );
    229 
    230     // Process the objdump file.
    231     while ( 1 ) {
    232 
    233       // Get a line.
    234       cStatus = fgets( buffer, 512, objdumpFile );
    235       if (cStatus == NULL) {
    236         fprintf(
    237           stderr,
    238           "ERROR: ObjdumpProcessor::determineLoadAddress - "
    239           "no symbol found in objdump file\n"
    240         );
    241         exit( -1 );
    242       }
    243 
    244       // Look for the start of a symbol's objdump and extract
    245       // address and symbol (i.e. address <symbolname>:).
    246       items = sscanf(
    247         buffer,
    248         "%x <%*[^>]>%c",
    249         &offset, &terminator
    250       );
    251 
    252       // If all items found, we have found the first symbol's objdump.
    253       if ((items == 2) && (terminator == ':')) {
    254         break;
    255       }
    256     }
    257 
    258     return (loadAddress - offset);
    259 # endif
    260 #if 1
    261142    std::string dlinfoName = theExecutable->getFileName();
    262143    uint32_t address;
     
    276157
    277158      // Get a line.
    278       cStatus = fgets( buffer, 512, loadAddressFile );
     159      cStatus = fgets( inputBuffer, MAX_LINE_LENGTH, loadAddressFile );
    279160      if (cStatus == NULL) {
    280161        fprintf(
     
    287168        exit( -1 );
    288169      }
    289       sscanf( buffer, "%s %x", inLibName, &offset );
     170      sscanf( inputBuffer, "%s %x", inLibName, &offset );
    290171      std::string tmp = inLibName;
    291172      if ( tmp.find( Library ) != tmp.npos ) {
     
    298179    fclose( loadAddressFile );
    299180    return address;
    300 #endif
     181
    301182    #undef METHOD
    302183  }
     
    418299  )
    419300  {
    420     char               buffer[ 512 ];
    421301    char*              cStatus;
    422302    int                items;
     
    435315
    436316      // Get the line.
    437       cStatus = fgets( buffer, 512, objdumpFile );
     317      cStatus = fgets( inputBuffer, MAX_LINE_LENGTH, objdumpFile );
    438318      if (cStatus == NULL) {
    439319        break;
    440320      }
    441       buffer[ strlen(buffer) - 1] = '\0';
     321      inputBuffer[ strlen(inputBuffer) - 1] = '\0';
    442322
    443323      // See if it is the dump of an instruction.
    444324      items = sscanf(
    445         buffer,
     325        inputBuffer,
    446326        "%x%c",
    447327        &offset, &terminator
     
    461341  )
    462342  {
    463     char               buffer[ 512 ];
    464343    char*              cStatus;
    465344    std::string        currentSymbol = "";
     
    487366
    488367      // Get the line.
    489       cStatus = fgets( buffer, 512, objdumpFile );
     368      cStatus = fgets( inputBuffer, MAX_LINE_LENGTH, objdumpFile );
    490369      if (cStatus == NULL) {
    491370
     
    512391      }
    513392
    514       buffer[ strlen(buffer) - 1] = '\0';
    515 
    516       lineInfo.line          = buffer;
     393      inputBuffer[ strlen(inputBuffer) - 1] = '\0';
     394
     395      lineInfo.line          = inputBuffer;
    517396      lineInfo.address       = 0xffffffff;
    518397      lineInfo.isInstruction = false;
     
    524403      // offset and symbol (i.e. offset <symbolname>:).
    525404      items = sscanf(
    526         buffer,
     405        inputBuffer,
    527406        "%x <%[^>]>%c",
    528407        &offset, symbol, &terminator1
     
    564443        // See if it is the dump of an instruction.
    565444        items = sscanf(
    566           buffer,
     445          inputBuffer,
    567446          "%x%c\t%*[^\t]%c",
    568447          &instructionOffset, &terminator1, &terminator2
     
    576455           executableInformation->getLoadAddress() + instructionOffset;
    577456          lineInfo.isInstruction = true;
    578           lineInfo.isNop         = isNop( buffer, lineInfo.nopSize );
    579           lineInfo.isBranch      = isBranchLine( buffer );
     457          lineInfo.isNop         = isNop( inputBuffer, lineInfo.nopSize );
     458          lineInfo.isBranch      = isBranchLine( inputBuffer );
    580459        }
    581460
Note: See TracChangeset for help on using the changeset viewer.