Changeset cb9a2ed in rtems-testing


Ignore:
Timestamp:
May 7, 2010, 6:53:58 PM (9 years ago)
Author:
Glenn Humphrey <glenn.humphrey@…>
Branches:
4.11, 8895273c193787f84c4585a10f6d6aceb3b25dc4
Children:
856dc6c
Parents:
0d567a5
Message:

2010-05-07 Glenn Humphrey

Location:
rtems-coverage
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • rtems-coverage/ChangeLog

    r0d567a5 rcb9a2ed  
     12010-05-07      Glenn Humphrey
     2
     3        * CoverageReaderQEMU.cc, CoverageReaderRTEMS.cc,
     4        CoverageReaderSkyeye.cc, CoverageReaderTSIM.cc, DesiredSymbols.cc,
     5        DesiredSymbols.h, ExecutableInfo.cc, ExecutableInfo.h,
     6        ObjdumpProcessor.cc, ObjdumpProcessor.h, SymbolTable.cc,
     7        SymbolTable.h, covoar.cc: Removed the use of nm to generate the
     8        symbol for each executable. Modified the ObjdumpProcessor to populate
     9        the symbol table and create the coverage maps.
     10
    1112010-05-07      Joel Sherrill <joel.sherrill@oarcorp.com>
    212
  • rtems-coverage/CoverageReaderQEMU.cc

    r0d567a5 rcb9a2ed  
    1515
    1616#include "CoverageReaderQEMU.h"
     17#include "CoverageMap.h"
    1718#include "ExecutableInfo.h"
    18 #include "CoverageMap.h"
    1919
    2020/* XXX really not always right */
  • rtems-coverage/CoverageReaderRTEMS.cc

    r0d567a5 rcb9a2ed  
    1515
    1616#include "CoverageReaderRTEMS.h"
     17#include "CoverageMap.h"
    1718#include "ExecutableInfo.h"
    1819#include "rtemscov_header.h"
     
    3334  )
    3435  {
    35     FILE                        *coverageFile;
     36    CoverageMapBase*             aCoverageMap = NULL;
    3637    uintptr_t                    baseAddress;
     38    uint8_t                      cover;
     39    FILE*                        coverageFile;
     40    rtems_coverage_map_header_t  header;
     41    uintptr_t                    i;
    3742    uintptr_t                    length;
     43    struct stat                  statbuf;
    3844    int                          status;
    39     uintptr_t                    i;
    40     uint8_t                      cover;
    41     rtems_coverage_map_header_t  header;
    42     struct stat                  statbuf;
    4345
    4446    //
     
    4648    //
    4749    status = stat( file, &statbuf );
    48     if ( status == -1 ) {
     50    if (status == -1) {
    4951      fprintf( stderr, "Unable to stat %s\n", file );
    5052      return false;
    5153    }
    5254
    53     if ( statbuf.st_size == 0 ) {
     55    if (statbuf.st_size == 0) {
    5456      fprintf( stderr, "%s is 0 bytes long\n", file );
    5557      return false;
     
    6062    //
    6163    coverageFile = fopen( file, "r" );
    62     if ( !coverageFile ) {
     64    if (!coverageFile) {
    6365      fprintf( stderr, "Unable to open %s\n", file );
    6466      return false;
     
    6668
    6769    status = fread( &header, sizeof(header), 1, coverageFile );
    68     if ( status != 1 ) {
     70    if (status != 1) {
    6971      fprintf( stderr, "Unable to read header from %s\n", file );
    7072      return false;
     
    8991    // Read and process each line of the coverage file.
    9092    //
    91     for ( i=0 ; i<length ; i++ ) {
     93    for (i=0; i<length; i++) {
    9294      status = fread( &cover, sizeof(uint8_t), 1, coverageFile );
    93       if ( status != 1 ) {
     95      if (status != 1) {
    9496        fprintf(
    9597          stderr,
     
    101103      }
    102104
    103       if ( cover ) {
    104         executableInformation->markWasExecuted( baseAddress + i );
     105      //
     106      // Obtain the coverage map containing the address and
     107      // mark the address as executed.
     108      //
     109      if (cover) {
     110        aCoverageMap = executableInformation->getCoverageMap( baseAddress + i );
     111        if (aCoverageMap)
     112          aCoverageMap->setWasExecuted( baseAddress + i );
    105113      }
    106114    }
  • rtems-coverage/CoverageReaderSkyeye.cc

    r0d567a5 rcb9a2ed  
    1515
    1616#include "CoverageReaderSkyeye.h"
     17#include "CoverageMap.h"
    1718#include "ExecutableInfo.h"
    1819#include "skyeye_header.h"
     
    3334  )
    3435  {
    35     uintptr_t     baseAddress;
    36     uint8_t       cover;
    37     FILE*         coverageFile;
    38     prof_header_t header;
    39     uintptr_t     i;
    40     uintptr_t     length;
    41     struct stat   statbuf;
    42     int           status;
     36    CoverageMapBase* aCoverageMap = NULL;
     37    uintptr_t        baseAddress;
     38    uint8_t          cover;
     39    FILE*            coverageFile;
     40    prof_header_t    header;
     41    uintptr_t        i;
     42    uintptr_t        length;
     43    struct stat      statbuf;
     44    int              status;
    4345
    4446    //
     
    101103      }
    102104
     105      //
     106      // Obtain the coverage map containing the address and
     107      // mark the address as executed.
     108      //
     109      // NOTE: This method ONLY works for Skyeye in 32-bit mode.
     110      //
    103111      if (cover & 0x01) {
    104         executableInformation->markWasExecuted( baseAddress + i );
    105         executableInformation->markWasExecuted( baseAddress + i + 1 );
    106         executableInformation->markWasExecuted( baseAddress + i + 2 );
    107         executableInformation->markWasExecuted( baseAddress + i + 3 );
     112        aCoverageMap = executableInformation->getCoverageMap( baseAddress + i );
     113        if (aCoverageMap) {
     114          aCoverageMap->setWasExecuted( baseAddress + i );
     115          aCoverageMap->setWasExecuted( baseAddress + i + 1 );
     116          aCoverageMap->setWasExecuted( baseAddress + i + 2 );
     117          aCoverageMap->setWasExecuted( baseAddress + i + 3 );
     118        }
    108119      }
     120
    109121      if (cover & 0x10) {
    110         executableInformation->markWasExecuted( baseAddress + i + 4 );
    111         executableInformation->markWasExecuted( baseAddress + i + 5 );
    112         executableInformation->markWasExecuted( baseAddress + i + 6 );
    113         executableInformation->markWasExecuted( baseAddress + i + 7 );
     122        aCoverageMap = executableInformation->getCoverageMap(
     123          baseAddress + i + 4
     124        );
     125        if (aCoverageMap) {
     126          aCoverageMap->setWasExecuted( baseAddress + i + 4 );
     127          aCoverageMap->setWasExecuted( baseAddress + i + 5 );
     128          aCoverageMap->setWasExecuted( baseAddress + i + 6 );
     129          aCoverageMap->setWasExecuted( baseAddress + i + 7 );
     130        }
    114131      }
    115132    }
  • rtems-coverage/CoverageReaderTSIM.cc

    r0d567a5 rcb9a2ed  
    1515
    1616#include "CoverageReaderTSIM.h"
     17#include "CoverageMap.h"
    1718#include "ExecutableInfo.h"
    1819
     
    3233  )
    3334  {
    34     int         baseAddress;
    35     int         cover;
    36     FILE*       coverageFile;
    37     int         i;
    38     struct stat statbuf;
    39     int         status;
     35    CoverageMapBase* aCoverageMap = NULL;
     36    int              baseAddress;
     37    int              cover;
     38    FILE*            coverageFile;
     39    int              i;
     40    struct stat      statbuf;
     41    int              status;
    4042
    4143    //
     
    4345    //
    4446    status = stat( file, &statbuf );
    45     if ( status == -1 ) {
     47    if (status == -1) {
    4648      fprintf( stderr, "Unable to stat %s\n", file );
    4749      return false;
    4850    }
    4951
    50     if ( statbuf.st_size == 0 ) {
     52    if (statbuf.st_size == 0) {
    5153      fprintf( stderr, "%s is 0 bytes long\n", file );
    5254      return false;
     
    5759    //
    5860    coverageFile = fopen( file, "r" );
    59     if ( !coverageFile ) {
     61    if (!coverageFile) {
    6062      fprintf( stderr, "Unable to open %s\n", file );
    6163      return false;
     
    6769    while ( 1 ) {
    6870      status = fscanf( coverageFile, "%x : ", &baseAddress );
    69       if ( status == EOF || status == 0 ) {
     71      if (status == EOF || status == 0) {
    7072        break;
    7173      }
    72       // fprintf( stderr, "%08x : ", baseAddress );
    73       for ( i=0 ; i < 0x80 ; i+=4 ) {
     74
     75      for (i=0; i < 0x80; i+=4) {
    7476        status = fscanf( coverageFile, "%d", &cover );
    75         if ( status == EOF || status == 0 ) {
     77        if (status == EOF || status == 0) {
    7678          fprintf(
    7779            stderr,
     
    8284          break;
    8385        }
    84         // fprintf( stderr, "%d ", cover );
    85         if ( cover & 1 ) {
    86           executableInformation->markWasExecuted( baseAddress + i );
    87           executableInformation->markWasExecuted( baseAddress + i + 1 );
    88           executableInformation->markWasExecuted( baseAddress + i + 2 );
    89           executableInformation->markWasExecuted( baseAddress + i + 3 );
     86
     87        //
     88        // Obtain the coverage map containing the address and
     89        // mark the address as executed.
     90        //
     91        if (cover & 1) {
     92          aCoverageMap = executableInformation->getCoverageMap(
     93            baseAddress + i
     94          );
     95          if (aCoverageMap) {
     96            aCoverageMap->setWasExecuted( baseAddress + i );
     97            aCoverageMap->setWasExecuted( baseAddress + i + 1 );
     98            aCoverageMap->setWasExecuted( baseAddress + i + 2 );
     99            aCoverageMap->setWasExecuted( baseAddress + i + 3 );
     100          }
    90101        }
    91102      }
    92       // fprintf( stderr, "\n" );
    93  
    94103    }
    95104
  • rtems-coverage/DesiredSymbols.cc

    r0d567a5 rcb9a2ed  
    107107  }
    108108
    109   void DesiredSymbols::Preprocess( void )
    110   {
    111     CoverageMapBase*                                             theCoverageMap;
    112     std::list<ObjdumpProcessor::objdumpLine_t>::reverse_iterator itr;
    113     std::list<ObjdumpProcessor::objdumpLine_t>::iterator         fitr;
    114     DesiredSymbols::symbolSet_t::iterator                        sitr;
     109  void DesiredSymbols::preprocess( void )
     110  {
     111    ObjdumpProcessor::objdumpLines_t::iterator         fitr;
     112    ObjdumpProcessor::objdumpLines_t::reverse_iterator itr;
     113    DesiredSymbols::symbolSet_t::iterator              sitr;
     114    CoverageMapBase*                                   theCoverageMap;
    115115
    116116    // Look at each symbol.
     
    146146      }
    147147
    148       for (fitr = sitr->second.instructions.begin(), fitr++;
     148      // Mark any branch instructions.
     149      for (fitr = sitr->second.instructions.begin();
    149150           fitr != sitr->second.instructions.end();
    150151           fitr++) {
    151152        if (fitr->isBranch) {
    152            theCoverageMap->setIsBranch( fitr->address -  sitr->second.baseAddress );
     153           theCoverageMap->setIsBranch(
     154             fitr->address - sitr->second.baseAddress
     155           );
    153156        }
    154157      }
    155 
    156158    }
    157159  }
     
    159161  void DesiredSymbols::computeUncovered( void )
    160162  {
    161     uint32_t                                             a, la, ha;
    162     uint32_t                                             endAddress;
    163     std::list<ObjdumpProcessor::objdumpLine_t>::reverse_iterator itr;
    164     DesiredSymbols::symbolSet_t::iterator                sitr;
    165     CoverageRanges*                                      theBranches;
    166     CoverageMapBase*                                     theCoverageMap;
    167     CoverageRanges*                                      theRanges;
     163    uint32_t                                           a, la, ha;
     164    uint32_t                                           endAddress;
     165    ObjdumpProcessor::objdumpLines_t::reverse_iterator itr;
     166    DesiredSymbols::symbolSet_t::iterator              sitr;
     167    CoverageRanges*                                    theBranches;
     168    CoverageMapBase*                                   theCoverageMap;
     169    CoverageRanges*                                    theRanges;
    168170
    169171    // Look at each symbol.
  • rtems-coverage/DesiredSymbols.h

    r0d567a5 rcb9a2ed  
    211211
    212212    /*!
    213      *  This method preprocess each symbols coverage map to marking nop
     213     *  This method preprocesses each symbol's coverage map to mark nop
    214214     *  and branch information.
    215215     */
    216     void Preprocess( void );
     216    void preprocess( void );
    217217
    218218  private:
  • rtems-coverage/ExecutableInfo.cc

    r0d567a5 rcb9a2ed  
    6969  void ExecutableInfo::initialize( void )
    7070  {
    71     CoverageMapBase                       *aCoverageMap;
    72     uint32_t                               highAddress;
    73     SymbolTable::symbolInfo*               info;
    74     DesiredSymbols::symbolSet_t::iterator  itr;
    75     uint32_t                               lowAddress;
    76     std::string                            symbol;
    77 
    78     // Create and initialize symbol table.
    79     if ( Verbose )
    80       fprintf( stderr, "Reading symbol table of %s\n", fileName.c_str() );
     71    // Create the symbol table.
    8172    theSymbolTable = new SymbolTable();
    82     theSymbolTable->load( fileName );
    83 
    84     // Create a coverage map for each symbol to analyze.
    85     for (itr = SymbolsToAnalyze->set.begin();
    86          itr != SymbolsToAnalyze->set.end();
    87          itr++) {
    88 
    89       symbol = (*itr).first;
    90       info = NULL;
    91       info = theSymbolTable->getInfo( symbol );
    92       if (!info) {
    93         /* A little too verbose :-D */
    94         #if 0
    95         if (Verbose)
    96           fprintf(
    97             stderr,
    98             "Unable to find symbol information for %s\n",
    99             symbol.c_str()
    100           );
    101         #endif
    102         continue;
    103       }
    104 
    105       lowAddress = info->startingAddress;
    106       highAddress = lowAddress + info->length - 1;
    107 
    108       aCoverageMap = NULL;
    109       aCoverageMap = new CoverageMap( lowAddress, highAddress );
    110       if (!aCoverageMap) {
    111         fprintf(
    112           stderr, "Unable to create coverage map for %s\n", symbol.c_str()
    113         );
    114         continue;
    115       }
    116 
    117       coverageMaps[ symbol ] = aCoverageMap;
    118     }
    11973  }
    12074
    121   void ExecutableInfo::markBranchNotTaken(
    122     uint32_t address
     75  CoverageMapBase* ExecutableInfo::createCoverageMap (
     76    const std::string& symbolName,
     77    uint32_t           lowAddress,
     78    uint32_t           highAddress
    12379  )
    12480  {
    125     CoverageMapBase* aCoverageMap = NULL;
    126     uint32_t         beginning;
     81    CoverageMapBase* theMap = NULL;
    12782
    128     // Obtain the coverage map containing the specified address.
    129     aCoverageMap = getCoverageMap( address );
     83    theMap = new CoverageMap( lowAddress, highAddress );
    13084
    131     // Ensure that coverage map exists.
    132     if (aCoverageMap) {
     85    if (!theMap)
     86      fprintf(
     87        stderr, "Unable to create coverage map for %s\n",
     88        symbolName.c_str()
     89      );
    13390
    134       // Determine the beginning address of the instruction that
    135       // contains the specified address.  We only want to mark the
    136       // beginning address of the instruction.
    137       if (aCoverageMap->getBeginningOfInstruction( address, &beginning )) {
    138         aCoverageMap->setIsBranch( beginning );
    139         aCoverageMap->setWasNotTaken( beginning );
    140         if (Verbose)
    141           fprintf(
    142             stderr, "Marking branch not taken at 0x%x\n", beginning
    143           );
    144       }
    145     }
    146   }
     91    else
     92      coverageMaps[ symbolName ] = theMap;
    14793
    148   void ExecutableInfo::markBranchTaken(
    149     uint32_t address
    150   )
    151   {
    152     CoverageMapBase* aCoverageMap = NULL;
    153     uint32_t         beginning;
    154 
    155     // Obtain the coverage map containing the specified address.
    156     aCoverageMap = getCoverageMap( address );
    157 
    158     // Ensure that coverage map exists.
    159     if (aCoverageMap) {
    160 
    161       // Determine the beginning address of the instruction that
    162       // contains the specified address.  We only want to mark the
    163       // beginning address of the instruction.
    164       if (aCoverageMap->getBeginningOfInstruction( address, &beginning )) {
    165         aCoverageMap->setIsBranch( beginning );
    166         aCoverageMap->setWasTaken( beginning );
    167         if (Verbose)
    168           fprintf(
    169             stderr, "Marking branch taken at 0x%x\n", beginning
    170           );
    171       }
    172     }
    173   }
    174 
    175   void ExecutableInfo::markStartOfInstruction(
    176     uint32_t address
    177   )
    178   {
    179     CoverageMapBase* aCoverageMap = NULL;
    180 
    181     // Obtain the coverage map containing the specified address.
    182     aCoverageMap = getCoverageMap( address );
    183 
    184     // Ensure that coverage map exists.
    185     if (aCoverageMap)
    186       aCoverageMap->setIsStartOfInstruction( address );
    187   }
    188 
    189   void ExecutableInfo::markWasExecuted(
    190     uint32_t address
    191   )
    192   {
    193     CoverageMapBase* aCoverageMap = NULL;
    194 
    195     // Obtain the coverage map containing the specified address.
    196     aCoverageMap = getCoverageMap( address );
    197 
    198     // Ensure that coverage map exists.
    199     if (aCoverageMap)
    200       aCoverageMap->setWasExecuted( address );
     94    return theMap;
    20195  }
    20296
  • rtems-coverage/ExecutableInfo.h

    r0d567a5 rcb9a2ed  
    7878
    7979    /*!
    80      *  This method marks the specified address of the executable
    81      *  as a branch instruction and indicates that it was NOT taken.
     80     *  This method creates a coverage map for the specified symbol.
    8281     *
    83      *  @param[in] address indicates the address of the branch instruction
    84      *             that was NOT taken
     82     *  @param[in] symbolName specifies the name of the symbol
     83     *  @param[in] lowAddress specifies the low address of the coverage map
     84     *  @param[in] highAddress specifies the high address of the coverage map
     85     *
     86     *  @return Returns a pointer to the coverage map
    8587     */
    86     void markBranchNotTaken(
    87       uint32_t address
    88     );
    89 
    90     /*!
    91      *  This method marks the specified address of the executable
    92      *  as a branch instruction and indicates that it was taken.
    93      *
    94      *  @param[in] address indicates the address of the branch instruction
    95      *             that was taken
    96      */
    97     void markBranchTaken(
    98       uint32_t address
    99     );
    100 
    101     /*!
    102      *  This method marks the specified address of the executable
    103      *  as the starting address for an instruction.
    104      *
    105      *  @param[in] address indicates the address of the start of an instruction
    106      */
    107     void markStartOfInstruction(
    108       uint32_t address
    109     );
    110 
    111     /*!
    112      *  This method marks the specified address of the executable
    113      *  as an address that was executed.
    114      *
    115      *  @param[in] address indicates the address that was executed
    116      */
    117     void markWasExecuted(
    118       uint32_t address
     88    CoverageMapBase* createCoverageMap (
     89      const std::string& symbolName,
     90      uint32_t           lowAddress,
     91      uint32_t           highAddress
    11992    );
    12093
  • rtems-coverage/ObjdumpProcessor.cc

    r0d567a5 rcb9a2ed  
    2020#include "ObjdumpProcessor.h"
    2121#include "app_common.h"
     22#include "CoverageMap.h"
    2223#include "ExecutableInfo.h"
     24#include "SymbolTable.h"
    2325#include "TargetFactory.h"
    2426
    2527namespace Coverage {
     28
     29  void finalizeSymbol(
     30    ExecutableInfo* const            executableInfo,
     31    std::string&                     symbolName,
     32    uint32_t                         lowAddress,
     33    uint32_t                         highAddress,
     34    ObjdumpProcessor::objdumpLines_t instructions,
     35    SymbolInformation*               symbolInfo
     36  ) {
     37
     38    CoverageMapBase*                           aCoverageMap = NULL;
     39    ObjdumpProcessor::objdumpLines_t::iterator itr;
     40    SymbolTable*                               theSymbolTable;
     41
     42    // If there are NOT already saved instructions, save them.
     43    if (symbolInfo->instructions.empty()) {
     44      symbolInfo->sourceFile = executableInfo->getFileName();
     45      symbolInfo->baseAddress = lowAddress;
     46      symbolInfo->instructions = instructions;
     47    }
     48
     49    // Add the symbol to this executable's symbol table.
     50    theSymbolTable = executableInfo->getSymbolTable();
     51    theSymbolTable->addSymbol(
     52      symbolName, lowAddress, highAddress - lowAddress + 1
     53    );
     54
     55    // Create a coverage map for the symbol.
     56    aCoverageMap = executableInfo->createCoverageMap(
     57      symbolName, lowAddress, highAddress
     58    );
     59
     60    if (aCoverageMap) {
     61
     62      // Mark the start of each instruction in the coverage map.
     63      for (itr = instructions.begin();
     64           itr != instructions.end();
     65           itr++ ) {
     66
     67        aCoverageMap->setIsStartOfInstruction( itr->address );
     68      }
     69
     70      // Create a unified coverage map for the symbol.
     71      SymbolsToAnalyze->createCoverageMap(
     72        symbolName, highAddress - lowAddress + 1
     73      );
     74    }
     75  }
    2676
    2777  ObjdumpProcessor::ObjdumpProcessor()
     
    91141      sprintf(
    92142        buffer,
    93         "%s -da --source %s | sed -e \'s/ *$//\' >%s",
     143        "%s -da --section=.text --source %s | sed -e \'s/ *$//\' >%s",
    94144        Tools->getObjdump(),
    95145         exeFileName.c_str(),
     
    101151        fprintf(
    102152          stderr,
    103           "ERROR: ObjdumpProcessor::load - command (%s) failed with %d\n",
     153          "ERROR: ObjdumpProcessor::getFile - command (%s) failed with %d\n",
    104154          buffer,
    105155          status
     
    114164      fprintf(
    115165        stderr,
    116         "ERROR: ObjdumpProcessor::load - unable to open %s\n",
     166        "ERROR: ObjdumpProcessor::getFile - unable to open %s\n",
    117167        dumpFile
    118168      );
     
    176226  }
    177227
    178 
    179228  void ObjdumpProcessor::load(
    180229    ExecutableInfo* const executableInformation
    181230  )
    182231  {
    183     uint32_t           baseAddress;
     232    uint32_t           address;
     233    uint32_t           baseAddress = 0;
    184234    char               buffer[ 512 ];
    185235    char*              cStatus;
    186     uint32_t           endAddress = 0xffffffff;
     236    std::string        currentSymbol = "";
    187237    uint32_t           instructionAddress;
    188238    int                items;
     
    190240    FILE*              objdumpFile;
    191241    bool               processSymbol = false;
    192     bool               saveInstructionDump = false;
    193242    char               symbol[ 100 ];
    194     SymbolInformation* symbolInfo = NULL;
     243    SymbolInformation* symbolInformation = NULL;
    195244    char               terminator;
    196 
    197 
     245    objdumpLines_t     theInstructions;
     246
     247    // Obtain the objdump file.
    198248    objdumpFile = getFile( executableInformation->getFileName() );
    199249
     
    204254      cStatus = fgets( buffer, 512, objdumpFile );
    205255      if (cStatus == NULL) {
     256
     257        // If we are currently processing a symbol, finalize it.
     258        if ((processSymbol) && (symbolInformation)) {
     259          finalizeSymbol(
     260            executableInformation,
     261            currentSymbol,
     262            baseAddress,
     263            address,  // XXX fix to determine corrent end address
     264            theInstructions,
     265            symbolInformation
     266          );
     267          fprintf(
     268            stderr,
     269            "WARNING: ObjdumpProcessor::load - analysis of symbol %s \n"
     270            "         may be incorrect.  It was the last symbol in %s\n"
     271            "         and the length of its last instruction is assumed to be one.\n",
     272            currentSymbol.c_str(),
     273            executableInformation->getFileName().c_str()
     274          );
     275        }
    206276        break;
    207277      }
     278
    208279      buffer[ strlen(buffer) - 1] = '\0';
    209280
     
    216287
    217288      // Look for the start of a symbol's objdump and extract
    218       // address and symbol.
     289      // address and symbol (i.e. address <symbolname>:).
    219290      items = sscanf(
    220291        buffer,
    221292        "%x <%[^>]>%c",
    222         &baseAddress, symbol, &terminator
    223       );
    224 
    225       // If all items found ...
     293        &address, symbol, &terminator
     294      );
     295
     296      // If all items found, we are at the beginning of a symbol's objdump.
    226297      if ((items == 3) && (terminator == ':')) {
    227298
    228         // we are at the beginning of a symbol's objdump and
    229         // must end any processing of the previous symbol.
     299        // If we are currently processing a symbol, finalize it.
     300        if ((processSymbol) && (symbolInformation)) {
     301          finalizeSymbol(
     302            executableInformation,
     303            currentSymbol,
     304            baseAddress,
     305            address - 1,
     306            theInstructions,
     307            symbolInformation
     308          );
     309        }
     310
     311        // Start processing of a new symbol.
     312        baseAddress = 0;
     313        currentSymbol = "";
    230314        processSymbol = false;
    231         saveInstructionDump = false;
    232 
    233         // See if the symbol is one that we care about.
    234         symbolInfo = SymbolsToAnalyze->find( symbol );
    235 
    236         // If it is, ...
    237         if (symbolInfo) {
    238 
    239           // indicate that we are processing a symbols objdump and
    240           // compute the ending address for termination.
     315        theInstructions.clear();
     316
     317        // See if the new symbol is one that we care about.
     318        symbolInformation = SymbolsToAnalyze->find( symbol );
     319
     320        if (symbolInformation) {
     321          baseAddress = address;
     322          currentSymbol = symbol;
    241323          processSymbol = true;
    242           endAddress = baseAddress +
    243            executableInformation->getSymbolTable()->getLength( symbol ) - 1;
    244 
    245           // If there are NOT already instructions available, indicate that they
    246           // are to be saved.
    247           if (symbolInfo->instructions.empty()) {
    248             saveInstructionDump = true;
    249             symbolInfo->sourceFile = executableInformation->getFileName();
    250             symbolInfo->baseAddress = baseAddress;
    251           }
     324          theInstructions.push_back( lineInfo );
    252325        }
    253326      }
     
    265338        if ((items == 2) && (terminator == ':')) {
    266339
    267           // and we are NOT beyond the end of the symbol's objdump,
    268           if (instructionAddress <= endAddress) {
    269 
    270             // update the line's information and ...
    271             lineInfo.address       = instructionAddress;
    272             lineInfo.isInstruction = true;
    273             lineInfo.isNop         = isNop( buffer, lineInfo.nopSize );
    274             lineInfo.isBranch      = isBranchLine( buffer );
    275 
    276             // mark the address as the beginning of an instruction.
    277             executableInformation->markStartOfInstruction( instructionAddress );
    278           }
    279 
    280           // If we are beyond the end of the symbol's objdump,
    281           // it's time to end processing of this symbol.
    282           else {
    283             processSymbol = false;
    284             saveInstructionDump = false;
    285           }
     340          // update the line's information, save it and ...
     341          lineInfo.address       = instructionAddress;
     342          lineInfo.isInstruction = true;
     343          lineInfo.isNop         = isNop( buffer, lineInfo.nopSize );
     344          lineInfo.isBranch      = isBranchLine( buffer );
    286345        }
    287       }
    288 
    289       // If we are processing a symbol, ...
    290       if (processSymbol && saveInstructionDump) {
    291 
    292         // add line to the current symbol's information and ...
    293         symbolInfo->instructions.push_back( lineInfo );
    294 
    295       }
    296     }
    297   }
    298 
     346
     347        // Always save the line.
     348        theInstructions.push_back( lineInfo );
     349      }
     350    }
     351  }
    299352}
  • rtems-coverage/ObjdumpProcessor.h

    r0d567a5 rcb9a2ed  
    7373    } objdumpLine_t;
    7474
     75    typedef std::list<objdumpLine_t> objdumpLines_t;
     76
    7577    typedef std::list<uint32_t> objdumpFile_t;
    7678
     
    133135
    134136    objdumpFile_t       objdumpList;
    135     Target::TargetBase  *target_m;
    136 
     137    Target::TargetBase* target_m;
    137138
    138139    /*!
  • rtems-coverage/SymbolTable.cc

    r0d567a5 rcb9a2ed  
    2626  SymbolTable::~SymbolTable()
    2727  {
     28  }
     29
     30  void SymbolTable::addSymbol(
     31    const std::string& symbol,
     32    const uint32_t     start,
     33    const uint32_t     length
     34  )
     35  {
     36    uint32_t       end = 0;
     37    symbol_entry_t entry;
     38    symbolInfo     symbolData;
     39
     40    // Add an entry to the address map.
     41    end = start + length - 1;
     42    entry.low = start;
     43    entry.high = end;
     44    entry.symbol = symbol;
     45    contents[ end ] = entry;
     46
     47    // Add an entry to the symbol information map.
     48    symbolData.startingAddress = start;
     49    symbolData.length = length;
     50    info[ symbol ] = symbolData;
    2851  }
    2952
     
    5679  )
    5780  {
    58     contents_t::iterator it = contents.end();
     81    contents_t::iterator it;
    5982
     83    // Ensure that the symbol table is not empty.
    6084    if ( contents.size() == 0 )
    6185      return "";
    6286
    63     it--;
    64     if (address > ((*it).first)) {
    65       return "";
    66     }
     87    // Find the first entry whose end address is greater
     88    // than the specified address.
     89    it = contents.lower_bound( address );
    6790
    68     it = contents.lower_bound( address );
    69     if (((*it).second).min <= address ) {
    70       return ((*it).second).symbol;
    71     } else {
    72       return "";
    73     }
    74   }
     91    // If an entry was found and its low address is less than or
     92    // equal to the specified address, then return the symbol.
     93    if ((it != contents.end()) && ((it->second).low <= address ))
     94      return (it->second).symbol;
    7595
    76   bool SymbolTable::load(
    77     const std::string& executableName
    78   )
    79   {
    80     char        buffer[512];
    81     char       *cStatus;
    82     uint32_t    end = 0;
    83     int         items;
    84     uint32_t    length = 0;
    85     FILE       *nmFile = NULL;
    86     uint32_t    start = 0;
    87     char        symbol[ 100 ];
    88     symbolInfo  symbolData;
    89     char        nmName[128];
    90 
    91 
    92     sprintf(
    93       nmName,
    94       "%s.nm",
    95       executableName.c_str()
    96     );
    97 
    98     // Generate the nm output
    99     if (FileIsNewer(executableName.c_str(), nmName )){
    100 
    101       sprintf( buffer, "%s -n -f sysv %s | sed -e \'s/ *$//\' >%s",
    102         Tools->getNm(), executableName.c_str(), nmName );
    103 
    104       if ( system( buffer ) ) {
    105         fprintf(
    106           stderr,
    107           "ERROR: SymbolTable::load - command (%s) failed\n",
    108           buffer
    109         );
    110         exit( -1 );
    111       }
    112     }
    113 
    114     // Read the file and process each desired symbol
    115     nmFile = fopen( nmName, "r" );
    116     if ( !nmFile ) {
    117       fprintf(
    118         stderr,
    119         "ERROR: SymbolTable::load - unable to open %s\n",
    120         nmName
    121       );
    122       exit(-1);
    123     }
    124 
    125     // Process all lines from the nm file.
    126     while ( 1 ) {
    127 
    128       // Get the line.
    129       cStatus = fgets( buffer, 512, nmFile );
    130       if ( cStatus == NULL ) {
    131         break;
    132       }
    133       buffer[ strlen(buffer) - 1] = '\0';
    134 
    135       // Extract the symbol, start address and length.
    136       items = sscanf(
    137         buffer,
    138         "%[^| ] |%x|%*[^|]| FUNC|%x",
    139         symbol, &start, &length
    140       );
    141 
    142       // If all items found ...
    143       if (items == 3) {
    144 
    145         // and it is a desired symbol, ...
    146         if (SymbolsToAnalyze->isDesired( symbol )) {
    147 
    148           // add the symbol information to the symbol table.
    149           end = start + length - 1;
    150           symbol_entry_t entry = { start, end, symbol };
    151           contents[end] = entry;
    152 
    153           symbolData.startingAddress = start;
    154           symbolData.length = length;
    155           info[ symbol ] = symbolData;
    156 
    157           // Also create a coverage map for the results of the analysis.
    158           SymbolsToAnalyze->createCoverageMap( symbol, length );
    159         }
    160       }
    161     }
    162 
    163     fclose( nmFile );
    164 
    165     // Remove temporary file
    166     // (void) system( "rm -f nm.tmp" );
    167     return true;
     96    return "";
    16897  }
    16998
  • rtems-coverage/SymbolTable.h

    r0d567a5 rcb9a2ed  
    4747
    4848    /*!
     49     *  This method adds the specified symbol information to the
     50     *  symbol table.
     51     *
     52     *  @param[in] symbol specifies the symbol to add
     53     *  @param[in] start specifies the symbol's start address
     54     *  @param[in] length specifies the symbol's length
     55     *
     56     */
     57    void addSymbol(
     58      const std::string& symbol,
     59      const uint32_t     start,
     60      const uint32_t     length
     61    );
     62
     63    /*!
    4964     *  This method returns the symbol information for the specified symbol.
    5065     *
     
    7994    );
    8095
    81     /*!
    82      *  This method loads the symbol table from the specified executable.
    83      *
    84      *  @param[in] executableName specifies the file name of the executable
    85      *
    86      *  @return Returns TRUE if the symbol table was loaded and
    87      *          FALSE otherwise.
    88      */
    89     bool load(
    90       const std::string& executableName
    91     );
    92 
    9396  private:
    9497
    9598    /*!
    96      *  This map associates each address from an executable
    97      *  with the symbol that contains the address.
     99     *  This map associates the end address of a symbol's address
     100     *  range with the symbol's address range definition.
    98101     */
    99102    typedef struct {
    100        uint32_t min;
    101        uint32_t max;
     103       uint32_t    low;
     104       uint32_t    high;
    102105       std::string symbol;
    103106    } symbol_entry_t;
    104107    typedef std::map< uint32_t, symbol_entry_t > contents_t;
    105108    contents_t contents;
    106 
    107109
    108110    /*!
  • rtems-coverage/covoar.cc

    r0d567a5 rcb9a2ed  
    343343  }
    344344
    345   // Do necessary preprocessing uncovered ranges and branches
     345  // Do necessary preprocessing of uncovered ranges and branches
    346346  if (Verbose)
    347      fprintf( stderr, "Preprocess uncovered ranges and branches\n" );
    348   SymbolsToAnalyze->Preprocess();
     347    fprintf( stderr, "Preprocess uncovered ranges and branches\n" );
     348  SymbolsToAnalyze->preprocess();
    349349
    350350  // Determine the uncovered ranges and branches.
Note: See TracChangeset for help on using the changeset viewer.