Changeset 881824f in rtems-tools


Ignore:
Timestamp:
May 11, 2018, 2:24:11 AM (11 months ago)
Author:
Chris Johns <chrisj@…>
Branches:
master
Children:
1c85380
Parents:
1e21ea7
git-author:
Chris Johns <chrisj@…> (05/11/18 02:24:11)
git-committer:
Chris Johns <chrisj@…> (06/18/18 02:26:16)
Message:

tester/covoar: Remove all exit() calls and throw an rld::error exception.

Add a suitable catch to covoar's main.

Location:
tester/covoar
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • tester/covoar/CoverageFactory.cc

    r1e21ea7 r881824f  
    1010#include <stdlib.h>
    1111#include <string.h>
     12
     13#include <rld.h>
    1214
    1315#include "CoverageFactory.h"
     
    3638    return COVERAGE_FORMAT_TSIM;
    3739
    38   fprintf(
    39     stderr,
    40     "ERROR: %s is an unknown coverage format "
    41     "(supported formats - QEMU, RTEMS, Skyeye and TSIM)\n",
    42     format
    43   );
    44   exit( 1 );
     40  std::ostringstream what;
     41  what << format << " is an unknown coverage format "
     42       << "(supported formats - QEMU, RTEMS, Skyeye and TSIM)";
     43  throw rld::error( what, "Coverage" );
    4544}
    4645
  • tester/covoar/CoverageReaderQEMU.cc

    r1e21ea7 r881824f  
    1010#include <stdio.h>
    1111#include <stdlib.h>
     12#include <stdio.h>
    1213#include <sys/stat.h>
     14
     15#include <rld.h>
    1316
    1417#include "app_common.h"
     
    4952    uint8_t             branchInfo;
    5053
    51     taken    = TargetInfo->qemuTakenBit();
    52     notTaken = TargetInfo->qemuNotTakenBit();
     54    taken      = TargetInfo->qemuTakenBit();
     55    notTaken   = TargetInfo->qemuNotTakenBit();
    5356    branchInfo = taken | notTaken;
    5457
     
    5659    // Open the coverage file and read the header.
    5760    //
    58     traceFile = OPEN( file, "r" );
     61    traceFile = ::OPEN( file, "r" );
    5962    if (!traceFile) {
    60       fprintf(
    61         stderr,
    62         "ERROR: CoverageReaderQEMU::processFile - Unable to open %s\n",
    63         file
    64       );
    65       exit( -1 );
     63      std::ostringstream what;
     64      what << "Unable to open " << file;
     65      throw rld::error( what, "CoverageReaderQEMU::processFile" );
    6666    }
    6767
    68     status = fread( &header, sizeof(trace_header), 1, traceFile );
     68    status = ::fread( &header, sizeof(trace_header), 1, traceFile );
    6969    if (status != 1) {
    70       fprintf(
    71         stderr,
    72         "ERROR: CoverageReaderQEMU::processFile - "
    73         "Unable to read header from %s\n",
    74         file
    75       );
    76       exit( -1 );
     70      ::fclose( traceFile );
     71      std::ostringstream what;
     72      what << "Unable to read header from " << file;
     73      throw rld::error( what, "CoverageReaderQEMU::processFile" );
    7774    }
    78 
    79     #if 0
    80       fprintf(
    81         stderr,
    82         "magic = %s\n"
    83         "version = %d\n"
    84         "kind = %d\n"
    85         "sizeof_target_pc = %d\n"
    86         "big_endian = %d\n"
    87         "machine = %02x:%02x\n",
    88         header.magic,
    89         header.version,
    90         header.kind,
    91         header.sizeof_target_pc,
    92         header.big_endian,
    93         header.machine[0], header.machine[1]
    94        );
    95     #endif
    9675
    9776    //
     
    9978    //
    10079#define ENTRIES 1024
    101     while (1) {
     80    while (true) {
    10281      CoverageMapBase     *aCoverageMap = NULL;
    10382      struct trace_entry  entries[ENTRIES];
     
    10786
    10887      // Read and process each line of the coverage file.
    109       num_entries = fread(
     88      num_entries = ::fread(
    11089        entries,
    11190        sizeof(struct trace_entry),
     
    150129      }
    151130    }
    152     fclose( traceFile );
     131    ::fclose( traceFile );
    153132  }
    154133}
  • tester/covoar/CoverageReaderRTEMS.cc

    r1e21ea7 r881824f  
    99#include <stdlib.h>
    1010#include <sys/stat.h>
     11
     12#include <iostream>
     13#include <iomanip>
     14
     15#include <rld.h>
    1116
    1217#include "CoverageReaderRTEMS.h"
     
    4247    // Open the coverage file and read the header.
    4348    //
    44     coverageFile = fopen( file, "r" );
     49    coverageFile = ::fopen( file, "r" );
    4550    if (!coverageFile) {
    46       fprintf(
    47         stderr,
    48         "ERROR: CoverageReaderRTEMS::processFile - Unable to open %s\n",
    49         file
    50       );
    51       exit( -1 );
     51      std::ostringstream what;
     52      what << "Unable to open " << file;
     53      throw rld::error( what, "CoverageReaderRTEMS::processFile" );
    5254    }
    5355
    54     status = fread( &header, sizeof(header), 1, coverageFile );
     56    status = ::fread( &header, sizeof(header), 1, coverageFile );
    5557    if (status != 1) {
    56       fprintf(
    57         stderr,
    58         "ERROR: CoverageReaderRTEMS::processFile - "
    59         "Unable to read header from %s\n",
    60         file
    61       );
    62       exit( -1 );
     58      ::fclose( coverageFile );
     59      std::ostringstream what;
     60      what << "Unable to read header from " << file;
     61      throw rld::error( what, "CoverageReaderRTEMS::processFile" );
    6362    }
    6463
    6564    baseAddress = header.start;
    6665    length      = header.end - header.start;
    67    
    68     #if 0
    69     fprintf(
    70       stderr,
    71       "%s: 0x%08x 0x%08x 0x%08lx/%ld\n",
    72       file,
    73       header.start,
    74       header.end,
    75       (unsigned long) length,
    76       (unsigned long) length
    77     );
    78     #endif
    7966
    8067    //
    8168    // Read and process each line of the coverage file.
    8269    //
    83     for (i=0; i<length; i++) {
    84       status = fread( &cover, sizeof(uint8_t), 1, coverageFile );
     70    for (i = 0; i < length; i++) {
     71      status = ::fread( &cover, sizeof(uint8_t), 1, coverageFile );
    8572      if (status != 1) {
    86         fprintf(
    87           stderr,
    88           "CoverageReaderRTEMS::ProcessFile - breaking after 0x%08x in %s\n",
    89           (unsigned int) i,
    90           file
    91         );
     73        std::cerr << "breaking after 0x"
     74                  << std::hex << std::setfill('0')
     75                  << std::setw(8) << i
     76                  << std::setfill(' ') << std::dec
     77                  << " in " << file
     78                  << std::endl;
    9279        break;
    9380      }
     
    10491    }
    10592
    106     fclose( coverageFile );
     93    ::fclose( coverageFile );
    10794  }
    10895}
  • tester/covoar/CoverageReaderSkyeye.cc

    r1e21ea7 r881824f  
    99#include <stdlib.h>
    1010#include <sys/stat.h>
     11
     12#include <iostream>
     13#include <iomanip>
    1114
    1215#include "CoverageReaderSkyeye.h"
     
    4245    // Open the coverage file and read the header.
    4346    //
    44     coverageFile = fopen( file, "r" );
     47    coverageFile = ::fopen( file, "r" );
    4548    if (!coverageFile) {
    46       fprintf(
    47         stderr,
    48         "ERROR: CoverageReaderSkyeye::processFile - Unable to open %s\n",
    49         file
    50       );
    51       exit( -1 );
     49      std::ostringstream what;
     50      what << "Unable to open " << file;
     51      throw rld::error( what, "CoverageReaderSkyeye::processFile" );
    5252    }
    5353
    54     status = fread( &header, sizeof(header), 1, coverageFile );
     54    status = ::fread( &header, sizeof(header), 1, coverageFile );
    5555    if (status != 1) {
    56       fprintf(
    57         stderr,
    58         "ERROR: CoverageReaderSkyeye::processFile - "
    59         "Unable to read header from %s\n",
    60         file
    61       );
    62       exit( -1 );
     56      ::fclose( coverageFile );
     57      std::ostringstream what;
     58      what << "Unable to read header from " << file;
     59      throw rld::error( what, "CoverageReaderSkyeye::processFile" );
    6360    }
    6461
    6562    baseAddress = header.prof_start;
    6663    length      = header.prof_end - header.prof_start;
    67    
    68     #if 0
    69     fprintf(
    70       stderr,
    71       "%s: 0x%08x 0x%08x 0x%08lx/%ld\n",
    72       file,
    73       header.prof_start,
    74       header.prof_end,
    75       (unsigned long) length,
    76       (unsigned long) length
    77     );
    78     #endif
    7964
    8065    //
    8166    // Read and process each line of the coverage file.
    8267    //
    83     for (i=0; i<length; i+=8) {
    84       status = fread( &cover, sizeof(uint8_t), 1, coverageFile );
     68    for (i = 0; i < length; i += 8) {
     69      status = ::fread( &cover, sizeof(uint8_t), 1, coverageFile );
    8570      if (status != 1) {
    86         fprintf(
    87           stderr,
    88           "CoverageReaderSkyeye::ProcessFile - breaking after 0x%08x in %s\n",
    89           (unsigned int) i,
    90           file
    91         );
     71        std::cerr << "CoverageReaderSkyeye::ProcessFile - breaking after 0x"
     72                  << std::hex << std::setfill('0')
     73                  << std::setw(8) << i
     74                  << std::setfill(' ') << std::dec
     75                  << " in " << file
     76                  << std::endl;
    9277        break;
    9378      }
     
    122107    }
    123108
    124     fclose( coverageFile );
     109    ::fclose( coverageFile );
    125110  }
    126111}
  • tester/covoar/CoverageReaderTSIM.cc

    r1e21ea7 r881824f  
    99#include <stdlib.h>
    1010#include <sys/stat.h>
     11
     12#include <iostream>
     13#include <iomanip>
     14
     15#include <rld.h>
    1116
    1217#include "app_common.h"
     
    4146    // Open the coverage file.
    4247    //
    43     coverageFile = fopen( file, "r" );
     48    coverageFile = ::fopen( file, "r" );
    4449    if (!coverageFile) {
    45       fprintf(
    46         stderr,
    47         "ERROR: CoverageReaderTSIM::processFile - Unable to open %s\n",
    48         file
    49       );
    50       exit( -1 );
     50      std::ostringstream what;
     51      what << "Unable to open " << file;
     52      throw rld::error( what, "CoverageReaderTSIM::processFile" );
    5153    }
    5254
     
    5456    // Read and process each line of the coverage file.
    5557    //
    56     while ( 1 ) {
    57       status = fscanf( coverageFile, "%x : ", &baseAddress );
     58    while ( true ) {
     59      status = ::fscanf( coverageFile, "%x : ", &baseAddress );
    5860      if (status == EOF || status == 0) {
    5961        break;
    6062      }
    6163
    62       for (i=0; i < 0x80; i+=4) {
     64      for (i = 0; i < 0x80; i += 4) {
    6365        unsigned int a;
    64         status = fscanf( coverageFile, "%x", &cover );
     66        status = ::fscanf( coverageFile, "%x", &cover );
    6567        if (status == EOF || status == 0) {
    66           fprintf(
    67             stderr,
    68             "CoverageReaderTSIM: WARNING! Short line in %s at address 0x%08x\n",
    69             file,
    70             baseAddress
    71           );
     68          std::cerr << "CoverageReaderTSIM: WARNING! Short line in "
     69                    << file
     70                    << " at address 0x"
     71                    << std::hex << std::setfill('0')
     72                    << baseAddress
     73                    << std::setfill(' ') << std::dec
     74                    << std::endl;
    7275          break;
    7376        }
     
    98101    }
    99102
    100     fclose( coverageFile );
     103    ::fclose( coverageFile );
    101104  }
    102105}
  • tester/covoar/CoverageWriterRTEMS.cc

    r1e21ea7 r881824f  
    1010#include <string.h>
    1111
     12#include <iostream>
     13#include <iomanip>
     14
     15#include <rld.h>
     16
    1217#include "CoverageWriterRTEMS.h"
    1318#include "rtemscov_header.h"
    1419
    1520namespace Coverage {
    16  
     21
    1722  CoverageWriterRTEMS::CoverageWriterRTEMS()
    1823  {
     
    3944     *  read the file and update the coverage map passed in
    4045     */
    41     coverageFile = fopen( file, "w" );
     46    coverageFile = ::fopen( file, "w" );
    4247    if ( !coverageFile ) {
    43       fprintf(
    44         stderr,
    45         "ERROR: CoverageWriterRTEMS::writeFile - unable to open %s\n",
    46         file
    47       );
    48       exit(-1);
     48      std::ostringstream what;
     49      what << "Unable to open " << file;
     50      throw rld::error( what, "CoverageWriterRTEMS::writeFile" );
    4951    }
    5052
     
    5759    strcpy( header.desc, "RTEMS Coverage Data" );
    5860
    59     status = fwrite(&header, 1, sizeof(header), coverageFile);
     61    status = ::fwrite(&header, 1, sizeof(header), coverageFile);
    6062    if (status != sizeof(header)) {
    61       fprintf(
    62         stderr,
    63         "ERROR: CoverageWriterRTEMS::writeFile - unable to write header "
    64         "to %s\n",
    65         file
    66       );
    67       exit(-1);
     63      ::fclose( coverageFile );
     64      std::ostringstream what;
     65      what << "Unable to write header to " << file;
     66      throw rld::error( what, "CoverageWriterRTEMS::writeFile" );
    6867    }
    6968
     
    7271      status = fwrite(&cover, 1, sizeof(cover), coverageFile);
    7372      if (status != sizeof(cover)) {
    74         fprintf(
    75           stderr,
    76           "ERROR: CoverageWriterRTEMS::writeFile - write to %s "
    77           "at address 0x%08x failed\n",
    78           file,
    79           a
    80         );
    81         exit( -1 );
     73        std::cerr << "CoverageWriterRTEMS::writeFile - write to "
     74                  << file
     75                  << " at address 0x%"
     76                  << std::hex << std::setfill('0')
     77                  << std::setw(8) << a
     78                  << std::setfill(' ') << std::dec
     79                  << " failed"
     80                  << std::endl;
    8281      }
    83       // fprintf( stderr, "0x%x %d\n", a, cover );
    8482    }
    8583
    86     fclose( coverageFile );
     84    ::fclose( coverageFile );
    8785  }
    8886}
  • tester/covoar/CoverageWriterSkyeye.cc

    r1e21ea7 r881824f  
    99#include <stdio.h>
    1010#include <stdlib.h>
     11#include <stdio.h>
    1112#include <string.h>
     13
     14#include <iostream>
     15#include <iomanip>
     16
     17#include <rld.h>
    1218
    1319#include "CoverageWriterSkyeye.h"
     
    1521
    1622namespace Coverage {
    17  
     23
    1824  CoverageWriterSkyeye::CoverageWriterSkyeye()
    1925  {
     
    4046     *  read the file and update the coverage map passed in
    4147     */
    42     coverageFile = fopen( file, "w" );
     48    coverageFile = ::fopen( file, "w" );
    4349    if ( !coverageFile ) {
    44       fprintf(
    45         stderr,
    46         "ERROR: CoverageWriterSkyeye::writeFile - unable to open %s\n",
    47         file
    48       );
    49       exit(-1);
     50      std::ostringstream what;
     51      what << "Unable to open " << file;
     52      throw rld::error( what, "CoverageWriterSkyeye::writeFile" );
    5053    }
    5154
     
    5861    strcpy( header.desc, "Skyeye Coverage Data" );
    5962
    60     status = fwrite(&header, 1, sizeof(header), coverageFile);
     63    status = ::fwrite(&header, 1, sizeof(header), coverageFile);
    6164    if (status != sizeof(header)) {
    62       fprintf(
    63         stderr,
    64         "ERROR: CoverageWriterSkyeye::writeFile - unable to write header "
    65         "to %s\n",
    66         file
    67       );
    68       exit(-1);
     65      ::fclose( coverageFile );
     66      std::ostringstream what;
     67      what << "Unable to write header to " << file;
     68      throw rld::error( what, "CoverageWriterSkyeye::writeFile" );
    6969    }
    7070
    71     for ( a=lowAddress ; a < highAddress ; a+= 8 ) {
     71    for ( a = lowAddress; a < highAddress; a += 8 ) {
    7272      cover  = ((coverage->wasExecuted( a ))     ? 0x01 : 0);
    7373      cover |= ((coverage->wasExecuted( a + 4 )) ? 0x10 : 0);
    7474      status = fwrite(&cover, 1, sizeof(cover), coverageFile);
    7575      if (status != sizeof(cover)) {
    76         fprintf(
    77           stderr,
    78           "ERROR: CoverageWriterSkyeye::writeFile - write to %s "
    79           "at address 0x%08x failed\n",
    80           file,
    81           a
    82         );
    83         exit( -1 );
     76        ::fclose( coverageFile );
     77        std::ostringstream what;
     78        what << "write to " << file
     79             << " at address 0x"
     80             << std::hex << std::setfill('0')
     81             << std::setw(8) << a
     82             << std::setfill(' ') << std::dec
     83             << "failed";
     84        throw rld::error( what, "CoverageWriterSkyeye::writeFile" );
    8485      }
    85       // fprintf( stderr, "0x%x %d\n", a, cover );
    8686    }
    8787
    88     fclose( coverageFile );
     88    ::fclose( coverageFile );
    8989  }
    9090}
  • tester/covoar/CoverageWriterTSIM.cc

    r1e21ea7 r881824f  
    99#include <stdlib.h>
    1010
     11#include <iostream>
     12#include <iomanip>
     13
     14#include <rld.h>
     15
    1116#include "CoverageWriterTSIM.h"
    1217
    1318namespace Coverage {
    14  
     19
    1520  CoverageWriterTSIM::CoverageWriterTSIM()
    1621  {
     
    2126  }
    2227
    23  
     28
    2429  void CoverageWriterTSIM::writeFile(
    2530    const char* const file,
     
    3843     *  read the file and update the coverage map passed in
    3944     */
    40     coverageFile = fopen( file, "w" );
     45    coverageFile = ::fopen( file, "w" );
    4146    if ( !coverageFile ) {
    42       fprintf(
    43         stderr,
    44         "ERROR: CoverageWriterTSIM::writeFile - unable to open %s\n",
    45         file
    46       );
    47       exit(-1);
     47      std::ostringstream what;
     48      what << "Unable to open " << file;
     49      throw rld::error( what, "CoverageWriterTSIM::writeFile" );
    4850    }
    4951
    50     for ( a=lowAddress ; a < highAddress ; a+= 0x80 ) {
     52    for ( a = lowAddress; a < highAddress; a += 0x80 ) {
    5153      status = fprintf( coverageFile, "%x : ", a );
    5254      if ( status == EOF || status == 0 ) {
    5355        break;
    5456      }
    55       // fprintf( stderr, "%08x : ", baseAddress );
    56       for ( i=0 ; i < 0x80 ; i+=4 ) {
     57      for ( i = 0; i < 0x80; i += 4 ) {
    5758        cover = ((coverage->wasExecuted( a + i )) ? 1 : 0);
    58         status = fprintf( coverageFile, "%d ", cover );
     59        status = ::fprintf( coverageFile, "%d ", cover );
    5960        if ( status == EOF || status == 0 ) {
    60           fprintf(
    61             stderr,
    62             "ERROR: CoverageWriterTSIM:writeFile - write to %s "
    63             "at address 0x%08x failed\n",
    64             file,
    65             a
    66           );
    67           exit( -1 );
     61          ::fclose( coverageFile );
     62          std::ostringstream what;
     63          what << "write to " << file
     64               << " at address 0x"
     65               << std::hex << std::setfill('0')
     66               << std::setw(8) << a
     67               << std::setfill(' ') << std::dec
     68               << "failed";
     69          throw rld::error( what, "CoverageWriterTSIM::writeFile" );
    6870        }
    69         // fprintf( stderr, "%d ", cover );
    7071      }
    71       fprintf( coverageFile, "\n" );
    72       // fprintf( stderr, "\n" );
    73  
     72      ::fprintf( coverageFile, "\n" );
    7473    }
    7574
    76     fclose( coverageFile );
     75    ::fclose( coverageFile );
    7776  }
    7877}
  • tester/covoar/DesiredSymbols.cc

    r1e21ea7 r881824f  
    3838  }
    3939
    40   bool DesiredSymbols::load(
     40  void DesiredSymbols::load(
    4141    const std::string& symbolsSet,
    4242    const std::string& buildTarget,
     
    4646  {
    4747    rld::files::cache cache;
    48     bool              r = true;
    4948
    5049    //
     
    104103        set[sym.name()] = *(new SymbolInformation);
    105104      }
    106 
    107     } catch (rld::error re) {
    108       std::cerr << "error: "
    109                 << re.where << ": " << re.what
    110                 << std::endl;
    111       r = false;
    112105    } catch (...) {
    113106      cache.close();
     
    116109
    117110    cache.close();
    118 
    119     return r;
    120111  }
    121112
     
    333324
    334325    if (itr == set.end()) {
    335       std::cerr << "ERROR: DesiredSymbols::createCoverageMap - Unable to create "
    336                 << "unified coverage map for "
    337                 << symbolName
    338                 << " because it is NOT a desired symbol"
    339                 << std::endl;
    340       exit( -1 );
     326      std::ostringstream what;
     327      what << "Unable to create unified coverage map for "
     328           << symbolName
     329           << " because it is NOT a desired symbol";
     330      throw rld::error( what, "DesiredSymbols::createCoverageMap" );
    341331    }
    342332
     
    374364
    375365      aCoverageMap = new CoverageMap( exefileName, 0, highAddress );
    376       if (!aCoverageMap) {
    377 
    378         fprintf(
    379           stderr,
    380           "ERROR: DesiredSymbols::createCoverageMap - Unable to allocate "
    381           "coverage map for %s:%s\n",
    382           exefileName.c_str(),
    383           symbolName.c_str()
    384         );
    385         exit( -1 );
    386       }
    387366
    388367      if ( Verbose )
     
    491470
    492471    if (itr == set.end()) {
    493       std::cerr << "ERROR: DesiredSymbols::mergeCoverageMap - Unable to merge "
    494                 << "coverage map for %s because it is NOT a desired symbol"
    495                 << symbolName
    496                 << std::endl;
    497       exit( -1 );
     472      std::ostringstream what;
     473      what << "Unable to merge coverage map for "
     474           << symbolName
     475           << " because it is NOT a desired symbol";
     476      throw rld::error( what, "DesiredSymbols::mergeCoverageMap" );
    498477    }
    499478
  • tester/covoar/DesiredSymbols.h

    r1e21ea7 r881824f  
    298298     *  @param[in] buildTarget The build target
    299299     *  @param[in] buildBSP The BSP
    300      *  @return Returns false if the load fails.
    301      */
    302     bool load(
     300     */
     301    void load(
    303302      const std::string& symbolsSet,
    304303      const std::string& buildTarget,
  • tester/covoar/ExecutableInfo.cc

    r1e21ea7 r881824f  
    2626    if (theLibraryName)
    2727      libraryName = theLibraryName;
    28     try {
    29       executable.open();
    30       executable.begin();
    31       executable.load_symbols(symbols);
    32       debug.begin(executable.elf());
    33       debug.load_debug();
    34     } catch (rld::error re) {
    35       std::cerr << "error: "
    36                 << re.where << ": " << re.what
    37                 << std::endl;
    38       exit(2);
    39     } catch (...) {
    40       exit(2);
    41     }
     28
     29    executable.open();
     30    executable.begin();
     31    executable.load_symbols(symbols);
     32    debug.begin(executable.elf());
     33    debug.load_debug();
    4234  }
    4335
  • tester/covoar/Explanations.cc

    r1e21ea7 r881824f  
    22 *  @brief Explanations Implementation
    33 *
    4  *  This file contains the implementation of the functions 
     4 *  This file contains the implementation of the functions
    55 *  which provide a base level of functionality of a Explanations.
    66 */
     
    1010#include <string.h>
    1111#include <unistd.h>
     12
     13#include <rld.h>
    1214
    1315#include "Explanations.h"
     
    3739      return;
    3840
    39     explain = fopen( explanations, "r" );
     41    explain = ::fopen( explanations, "r" );
    4042    if (!explain) {
    41       fprintf(
    42         stderr,
    43         "ERROR: Explanations::load - unable to open explanations file %s\n",
    44         explanations
    45       );
    46       exit(-1);
     43      std::ostringstream what;
     44      what << "Unable to open " << explanations;
     45      throw rld::error( what, "Explanations::load" );
    4746    }
    4847
     
    6362      // Have we already seen this one?
    6463      if (set.find( inputBuffer ) != set.end()) {
    65         fprintf(
    66           stderr,
    67           "ERROR: Explanations::load - line %d "
    68           "contains a duplicate explanation (%s)\n",
    69           line,
    70           inputBuffer
    71         );
    72         exit( -1 );
     64        std::ostringstream what;
     65        what << "line " << line
     66             << "contains a duplicate explanation ("
     67             << inputBuffer << ")";
     68        throw rld::error( what, "Explanations::load" );
    7369      }
    7470
     
    7773      e->found = false;
    7874
    79       // Get the classification 
     75      // Get the classification
    8076      cStatus = fgets( inputBuffer, MAX_LINE_LENGTH, explain );
    8177      if (cStatus == NULL) {
    82         fprintf(
    83           stderr,
    84           "ERROR: Explanations::load - line %d "
    85           "out of sync at the classification\n",
    86           line
    87         );
    88         exit( -1 );
     78        std::ostringstream what;
     79        what << "line " << line
     80             << "out of sync at the classification";
     81        throw rld::error( what, "Explanations::load" );
    8982      }
    9083      inputBuffer[ strlen(inputBuffer) - 1] = '\0';
     
    9285      line++;
    9386
    94       // Get the explanation 
     87      // Get the explanation
    9588      while (1) {
    9689        cStatus = fgets( inputBuffer, MAX_LINE_LENGTH, explain );
    9790        // fprintf( stderr, "%d - %s\n", line, inputBuffer );
    9891        if (cStatus == NULL) {
    99           fprintf(
    100             stderr,
    101             "ERROR: Explanations::load - line %d "
    102             "out of sync at the explanation\n",
    103             line
    104           );
    105           exit( -1 );
     92          std::ostringstream what;
     93          what << "line " << line
     94               << "out of sync at the explanation";
     95          throw rld::error( what, "Explanations::load" );
    10696        }
    10797        inputBuffer[ strlen(inputBuffer) - 1] = '\0';
     
    131121    if (set.find( start ) == set.end()) {
    132122      #if 0
    133         fprintf( stderr,
    134           "Warning: Unable to find explanation for %s\n",
    135           start.c_str()
    136         );
     123        std::cerr << "Warning: Unable to find explanation for "
     124                  << start << std::endl;
    137125      #endif
    138126      return NULL;
     
    151139    if (!fileName)
    152140      return;
    153    
     141
    154142    notFoundFile = fopen( fileName, "w" );
    155143    if (!fileName) {
    156       fprintf(
    157         stderr,
    158         "ERROR: Explanations::writeNotFound - unable to open file %s\n",
    159         fileName
    160       );
    161       exit( -1 );
     144      std::ostringstream what;
     145      what << "Unable to open " << fileName
     146           << "out of sync at the explanation";
     147      throw rld::error( what, "Explanations::writeNotFound" );
    162148    }
    163    
     149
    164150    for (std::map<std::string, Explanation>::iterator itr = set.begin();
    165151         itr != set.end();
     
    167153      Explanation e = (*itr).second;
    168154      std::string key = (*itr).first;
    169  
     155
    170156      if (!e.found) {
    171157        notFoundOccurred = true;
     
    175161          e.startingPoint.c_str()
    176162        );
    177       } 
     163      }
    178164    }
    179165    fclose( notFoundFile );
     
    181167    if (!notFoundOccurred) {
    182168      if (!unlink( fileName )) {
    183         fprintf( stderr,
    184           "Warning: Unable to unlink %s\n\n",
    185           fileName
    186         );
     169        std::cerr << "Warning: Unable to unlink " << fileName
     170                  << std::endl
     171                  << std::endl;
    187172      }
    188     } 
     173    }
    189174  }
    190175
  • tester/covoar/ObjdumpProcessor.cc

    r1e21ea7 r881824f  
    150150    dlinfoName += ".dlinfo";
    151151    // Read load address.
    152     loadAddressFile = fopen( dlinfoName.c_str(), "r" );
     152    loadAddressFile = ::fopen( dlinfoName.c_str(), "r" );
    153153    if (!loadAddressFile) {
    154       fprintf( stderr, METHOD "unable to open %s\n", dlinfoName.c_str() );
    155       exit( -1 );
     154      std::ostringstream what;
     155      what << "Unable to open " << dlinfoName;
     156      throw rld::error( what, METHOD );
    156157    }
    157158
     
    160161
    161162      // Get a line.
    162       cStatus = fgets( inputBuffer, MAX_LINE_LENGTH, loadAddressFile );
     163      cStatus = ::fgets( inputBuffer, MAX_LINE_LENGTH, loadAddressFile );
    163164      if (cStatus == NULL) {
    164         fprintf(
    165           stderr,
    166           METHOD "library %s not found in %s\n",
    167           Library.c_str(),
    168           dlinfoName.c_str()
    169         );
    170         fclose( loadAddressFile );
    171         exit( -1 );
     165        ::fclose( loadAddressFile );
     166        std::ostringstream what;
     167        what << "library " << Library << " not found in " << dlinfoName;
     168        throw rld::error( what, METHOD );
    172169      }
    173170      sscanf( inputBuffer, "%s %x", inLibName, &offset );
     
    180177    }
    181178
    182     fclose( loadAddressFile );
     179    ::fclose( loadAddressFile );
    183180    return address;
    184181
  • tester/covoar/ReportsHtml.cc

    r1e21ea7 r881824f  
    22#include <stdlib.h>
    33#include <string.h>
     4
     5#include <rld.h>
    46
    57#include "ReportsHtml.h"
     
    2527#else
    2628#define TABLE_HEADER_CLASS
    27 #define TABLE_FOOTER 
     29#define TABLE_FOOTER
    2830#endif
    2931
     
    5759
    5860    FILE*  aFile;
    59    
     61
    6062    // Open the file
    6163    aFile = OpenFile( fileName );
     
    7880      "Coverage Analysis Reports</div>\n"
    7981      "<div class =\"datetime\">%s</div>\n",
    80       asctime( localtime(&timestamp_m) ) 
     82      asctime( localtime(&timestamp_m) )
    8183    );
    8284
     
    110112  {
    111113    FILE*  aFile;
    112    
     114
    113115    // Open the file
    114116    aFile = ReportsBase::OpenFile( fileName );
     
    155157      "<body>\n"
    156158      "<pre class=\"code\">\n",
    157       asctime( localtime(&timestamp_m) ) 
     159      asctime( localtime(&timestamp_m) )
    158160    );
    159161
     
    207209        "</thead>\n"
    208210        "<tbody>\n",
    209         asctime( localtime(&timestamp_m) ) 
     211        asctime( localtime(&timestamp_m) )
    210212      );
    211213    }
    212    
     214
    213215    return aFile;
    214216  }
     
    256258      "</thead>\n"
    257259      "<tbody>\n",
    258         asctime( localtime(&timestamp_m) ) 
     260        asctime( localtime(&timestamp_m) )
    259261
    260262     );
     
    299301      "</thead>\n"
    300302      "<tbody>\n",
    301         asctime( localtime(&timestamp_m) ) 
     303        asctime( localtime(&timestamp_m) )
    302304
    303305     );
     
    347349      "</thead>\n"
    348350      "<tbody>\n",
    349         asctime( localtime(&timestamp_m) ) 
     351        asctime( localtime(&timestamp_m) )
    350352
    351353    );
     
    399401      "</thead>\n"
    400402      "<tbody>\n",
    401         asctime( localtime(&timestamp_m) ) 
     403        asctime( localtime(&timestamp_m) )
    402404
    403405    );
     
    409411  )
    410412  {
    411     fprintf( 
    412       aFile,
    413       "<hr>\n" 
    414     );
    415   }
    416  
     413    fprintf(
     414      aFile,
     415      "<hr>\n"
     416    );
     417  }
     418
    417419  void ReportsHtml::AnnotatedEnd(
    418420    FILE*                aFile
     
    421423  }
    422424
    423   void ReportsHtml::PutAnnotatedLine( 
    424     FILE*                aFile, 
    425     AnnotatedLineState_t state, 
    426     std::string          line, 
    427     uint32_t             id 
     425  void ReportsHtml::PutAnnotatedLine(
     426    FILE*                aFile,
     427    AnnotatedLineState_t state,
     428    std::string          line,
     429    uint32_t             id
    428430  )
    429431  {
     
    431433    char        number[10];
    432434
    433    
     435
    434436    sprintf(number,"%d", id);
    435437
     
    461463        break;
    462464      default:
    463         fprintf(stderr, "ERROR:  ReportsHtml::PutAnnotatedLine Unknown state\n");
    464         exit( -1 );
     465        throw rld::error( "Unknown state", "ReportsHtml::PutAnnotatedLine");
    465466        break;
    466467    }
     
    518519
    519520    // symbol
    520     fprintf( 
    521       report, 
    522       "<td class=\"covoar-td\" align=\"center\">%s</td>\n",     
     521    fprintf(
     522      report,
     523      "<td class=\"covoar-td\" align=\"center\">%s</td>\n",
    523524      symbolPtr->first.c_str()
    524525    );
    525526
    526527    // line
    527     fprintf( 
    528       report, 
    529       "<td class=\"covoar-td\" align=\"center\"><a href =\"annotated.html#range%d\">%s</td>\n",     
     528    fprintf(
     529      report,
     530      "<td class=\"covoar-td\" align=\"center\"><a href =\"annotated.html#range%d\">%s</td>\n",
    530531      rangePtr->id,
    531532      rangePtr->lowSourceLine.c_str()
     
    535536    i = rangePtr->lowSourceLine.find(":");
    536537    temp =  rangePtr->lowSourceLine.substr (0, i);
    537     fprintf( 
    538       report, 
    539       "<td class=\"covoar-td\" align=\"center\">%s</td>\n",     
     538    fprintf(
     539      report,
     540      "<td class=\"covoar-td\" align=\"center\">%s</td>\n",
    540541      temp.c_str()
    541542    );
    542  
     543
    543544    // Size in bytes
    544     fprintf( 
    545       report, 
     545    fprintf(
     546      report,
    546547      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
    547548      rangePtr->highAddress - rangePtr->lowAddress + 1
     
    551552    if (rangePtr->reason ==
    552553      Coverage::CoverageRanges::UNCOVERED_REASON_BRANCH_ALWAYS_TAKEN)
    553       fprintf( 
     554      fprintf(
    554555        report,
    555556        "<td class=\"covoar-td\" align=\"center\">Always Taken</td>\n"
     
    557558    else if (rangePtr->reason ==
    558559      Coverage::CoverageRanges::UNCOVERED_REASON_BRANCH_NEVER_TAKEN)
    559       fprintf( 
    560         report, 
     560      fprintf(
     561        report,
    561562        "<td class=\"covoar-td\" align=\"center\">Never Taken</td>\n"
    562563      );
     
    582583    if ( !explanation ) {
    583584      // Write Classificationditr->second.baseAddress
    584       fprintf( 
    585         report, 
     585      fprintf(
     586        report,
    586587        "<td class=\"covoar-td\" align=\"center\">NONE</td>\n"
    587588        "<td class=\"covoar-td\" align=\"center\">No Explanation</td>\n"
     
    590591      char explanationFile[48];
    591592      sprintf( explanationFile, "explanation%d.html", rangePtr->id );
    592       fprintf( 
    593         report, 
     593      fprintf(
     594        report,
    594595        "<td class=\"covoar-td\" align=\"center\">%s</td>\n"
    595596        "<td class=\"covoar-td\" align=\"center\">"
     
    654655
    655656    // symbol
    656     fprintf( 
    657       report, 
    658       "<td class=\"covoar-td\" align=\"center\">%s</td>\n",     
     657    fprintf(
     658      report,
     659      "<td class=\"covoar-td\" align=\"center\">%s</td>\n",
    659660      symbol.c_str()
    660661    );
    661     fprintf( 
    662       noRangeFile, 
    663       "<td class=\"covoar-td\" align=\"center\">%s</td>\n",     
     662    fprintf(
     663      noRangeFile,
     664      "<td class=\"covoar-td\" align=\"center\">%s</td>\n",
    664665      symbol.c_str()
    665666    );
    666667
    667668    // starting line
    668     fprintf( 
    669       report, 
     669    fprintf(
     670      report,
    670671      "<td class=\"covoar-td\" align=\"center\">unknown</td>\n"
    671672     );
    672      
     673
    673674    // file
    674     fprintf( 
    675       report, 
     675    fprintf(
     676      report,
    676677      "<td class=\"covoar-td\" align=\"center\">unknown</td>\n"
    677678     );
    678      
     679
    679680     // Size in bytes
    680     fprintf( 
    681       report, 
     681    fprintf(
     682      report,
    682683      "<td class=\"covoar-td\" align=\"center\">unknown</td>\n"
    683684    );
    684685
    685686    // Size in instructions
    686     fprintf( 
    687       report, 
     687    fprintf(
     688      report,
    688689      "<td class=\"covoar-td\" align=\"center\">unknown</td>\n"
    689     ); 
     690    );
    690691
    691692    // See if an explanation is available
    692     fprintf( 
    693       report, 
     693    fprintf(
     694      report,
    694695      "<td class=\"covoar-td\" align=\"center\">Unknown</td>\n"
    695696      "<td class=\"covoar-td\" align=\"center\">"
     
    720721
    721722    // symbol
    722     fprintf( 
    723       report, 
    724       "<td class=\"covoar-td\" align=\"center\">%s</td>\n",     
     723    fprintf(
     724      report,
     725      "<td class=\"covoar-td\" align=\"center\">%s</td>\n",
    725726      symbolPtr->first.c_str()
    726727    );
    727728
    728729    // Range
    729     fprintf( 
    730       report, 
     730    fprintf(
     731      report,
    731732      "<td class=\"covoar-td\" align=\"center\"><a href =\"annotated.html#range%d\">%s <br>%s</td>\n",
    732       rangePtr->id,   
     733      rangePtr->id,
    733734      rangePtr->lowSourceLine.c_str(),
    734735      rangePtr->highSourceLine.c_str()
     
    738739    i = rangePtr->lowSourceLine.find(":");
    739740    temp =  rangePtr->lowSourceLine.substr (0, i);
    740     fprintf( 
    741       report, 
    742       "<td class=\"covoar-td\" align=\"center\">%s</td>\n",     
     741    fprintf(
     742      report,
     743      "<td class=\"covoar-td\" align=\"center\">%s</td>\n",
    743744      temp.c_str()
    744745    );
    745        
     746
    746747    // Size in bytes
    747     fprintf( 
    748       report, 
     748    fprintf(
     749      report,
    749750      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
    750751      rangePtr->highAddress - rangePtr->lowAddress + 1
     
    752753
    753754    // Size in instructions
    754     fprintf( 
    755       report, 
     755    fprintf(
     756      report,
    756757      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
    757758      rangePtr->instructionCount
    758     ); 
     759    );
    759760
    760761    // See if an explanation is available
    761762    explanation = AllExplanations->lookupExplanation( rangePtr->lowSourceLine );
    762763    if ( !explanation ) {
    763       fprintf( 
    764         report, 
     764      fprintf(
     765        report,
    765766        "<td class=\"covoar-td\" align=\"center\">NONE</td>\n"
    766767      );
    767       fprintf( 
    768         report, 
     768      fprintf(
     769        report,
    769770        "<td class=\"covoar-td\" align=\"center\">No Explanation</td>\n"
    770771      );
     
    773774
    774775      sprintf( explanationFile, "explanation%d.html", rangePtr->id );
    775       fprintf( 
    776         report, 
     776      fprintf(
     777        report,
    777778        "<td class=\"covoar-td\" align=\"center\">%s</td>\n"
    778779        "<td class=\"covoar-td\" align=\"center\">"
     
    806807
    807808    // size
    808     fprintf( 
    809       report, 
     809    fprintf(
     810      report,
    810811      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
    811812      range->highAddress - range->lowAddress + 1
     
    813814
    814815    // symbol
    815     fprintf( 
    816       report, 
    817       "<td class=\"covoar-td\" align=\"center\">%s</td>\n",     
     816    fprintf(
     817      report,
     818      "<td class=\"covoar-td\" align=\"center\">%s</td>\n",
    818819      symbol->first.c_str()
    819820    );
    820821
    821822    // line
    822     fprintf( 
    823       report, 
    824       "<td class=\"covoar-td\" align=\"center\"><a href =\"annotated.html#range%d\">%s</td>\n",     
     823    fprintf(
     824      report,
     825      "<td class=\"covoar-td\" align=\"center\"><a href =\"annotated.html#range%d\">%s</td>\n",
    825826      range->id,
    826827      range->lowSourceLine.c_str()
     
    830831    i = range->lowSourceLine.find(":");
    831832    temp =  range->lowSourceLine.substr (0, i);
    832     fprintf( 
    833       report, 
    834       "<td class=\"covoar-td\" align=\"center\">%s</td>\n",     
     833    fprintf(
     834      report,
     835      "<td class=\"covoar-td\" align=\"center\">%s</td>\n",
    835836      temp.c_str()
    836837    );
    837    
     838
    838839    fprintf( report, "</tr>\n");
    839840
     
    847848  )
    848849  {
    849  
     850
    850851    // Mark the background color different for odd and even lines.
    851852    if ( ( count%2 ) != 0 )
     
    855856
    856857    // symbol
    857     fprintf( 
    858       report, 
    859       "<td class=\"covoar-td\" align=\"center\">%s</td>\n",     
     858    fprintf(
     859      report,
     860      "<td class=\"covoar-td\" align=\"center\">%s</td>\n",
    860861      symbol->first.c_str()
    861862    );
    862863
    863864    // Total Size in Bytes
    864     fprintf( 
    865       report, 
     865    fprintf(
     866      report,
    866867      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
    867868      symbol->second.stats.sizeInBytes
    868869    );
    869870
    870     // Total Size in Instructions 
    871     fprintf( 
    872       report, 
     871    // Total Size in Instructions
     872    fprintf(
     873      report,
    873874      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
    874875      symbol->second.stats.sizeInInstructions
     
    876877
    877878    // Total Uncovered Ranges
    878     fprintf( 
    879       report, 
    880       "<td class=\"covoar-td\" align=\"center\">%d</td>\n",     
     879    fprintf(
     880      report,
     881      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
    881882      symbol->second.stats.uncoveredRanges
    882883    );
    883884
    884885    // Uncovered Size in Bytes
    885     fprintf( 
    886       report, 
     886    fprintf(
     887      report,
    887888      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
    888889      symbol->second.stats.uncoveredBytes
    889890    );
    890891
    891     // Uncovered Size in Instructions 
    892     fprintf( 
    893       report, 
     892    // Uncovered Size in Instructions
     893    fprintf(
     894      report,
    894895      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
    895896       symbol->second.stats.uncoveredInstructions
     
    897898
    898899    // Total number of branches
    899     fprintf( 
    900       report, 
    901       "<td class=\"covoar-td\" align=\"center\">%d</td>\n",     
     900    fprintf(
     901      report,
     902      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
    902903      symbol->second.stats.branchesNotExecuted +  symbol->second.stats.branchesExecuted
    903904    );
    904905
    905906    // Total Always Taken
    906     fprintf( 
    907       report, 
     907    fprintf(
     908      report,
    908909      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
    909910      symbol->second.stats.branchesAlwaysTaken
     
    911912
    912913    // Total Never Taken
    913     fprintf( 
    914       report, 
     914    fprintf(
     915      report,
    915916      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
    916917      symbol->second.stats.branchesNeverTaken
     
    919920    // % Uncovered Instructions
    920921    if ( symbol->second.stats.sizeInInstructions == 0 )
    921       fprintf( 
    922         report, 
     922      fprintf(
     923        report,
    923924        "<td class=\"covoar-td\" align=\"center\">100.00</td>\n"
    924925      );
    925     else     
    926       fprintf( 
    927         report, 
     926    else
     927      fprintf(
     928        report,
    928929        "<td class=\"covoar-td\" align=\"center\">%.2f</td>\n",
    929930        (symbol->second.stats.uncoveredInstructions*100.0)/
     
    933934    // % Uncovered Bytes
    934935    if ( symbol->second.stats.sizeInBytes == 0 )
    935       fprintf( 
    936         report, 
     936      fprintf(
     937        report,
    937938        "<td class=\"covoar-td\" align=\"center\">100.00</td>\n"
    938939      );
    939     else     
    940       fprintf( 
    941         report, 
     940    else
     941      fprintf(
     942        report,
    942943        "<td class=\"covoar-td\" align=\"center\">%.2f</td>\n",
    943944        (symbol->second.stats.uncoveredBytes*100.0)/
     
    973974        TABLE_FOOTER
    974975        "</tbody>\n"
    975         "</table>\n" 
     976        "</table>\n"
    976977      );
    977978    }
    978979    fprintf(
    979980      aFile,
    980       "</pre>\n" 
     981      "</pre>\n"
    981982      "</body>\n"
    982983      "</html>"
     
    994995      TABLE_FOOTER
    995996      "</tbody>\n"
    996       "</table>\n" 
    997       "</pre>\n" 
     997      "</table>\n"
     998      "</pre>\n"
    998999      "</body>\n"
    9991000      "</html>"
     
    10111012      TABLE_FOOTER
    10121013      "</tbody>\n"
    1013       "</table>\n" 
    1014       "</pre>\n" 
     1014      "</table>\n"
     1015      "</pre>\n"
    10151016      "</body>\n"
    10161017      "</html>"
     
    10291030      TABLE_FOOTER
    10301031      "</tbody>\n"
    1031       "</table>\n" 
    1032       "</pre>\n" 
     1032      "</table>\n"
     1033      "</pre>\n"
    10331034      "</body>\n"
    10341035      "</html>"
     
    10461047      TABLE_FOOTER
    10471048       "</tbody>\n"
    1048       "</table>\n" 
    1049       "</pre>\n" 
     1049      "</table>\n"
     1050      "</pre>\n"
    10501051      "</body>\n"
    10511052      "</html>"
  • tester/covoar/SymbolTable.cc

    r1e21ea7 r881824f  
    1010#include <stdlib.h>
    1111#include <string.h>
     12
     13#include <rld.h>
    1214
    1315#include "SymbolTable.h"
     
    4446    symbolData.startingAddress = start;
    4547    symbolData.length = length;
    46      
     48
    4749    if ( info[ symbol ].empty() == false ) {
    4850      if ( info[ symbol ].front().length != length ) {
    49         fprintf(stderr,
    50           "ERROR==> Different lengths for the symbol %s (%d and %d)\n",
    51           symbol.c_str(),
    52           info[ symbol ].front().length,
    53           length
    54         );
    55         exit( 0 );
     51        std::ostringstream what;
     52        what << "Different lengths for the symbol "
     53             << symbol
     54             << " (" << info[ symbol ].front().length
     55             << " and " << length
     56             << ")";
     57        throw rld::error( what, "SymbolTable::addSymbol" );
    5658      }
    5759    }
  • tester/covoar/TargetBase.cc

    r1e21ea7 r881824f  
    22 *  @brief TargetBase Implementation
    33 *
    4  *  This file contains the implementation of the base class for 
     4 *  This file contains the implementation of the base class for
    55 *  functions supporting target unique functionallity.
    66 */
    7 
    8 #include "TargetBase.h"
    9 #include "qemu-traces.h"
    107
    118#include <algorithm>
     
    1310#include <stdlib.h>
    1411
     12#include <rld.h>
     13
     14#include "TargetBase.h"
     15#include "qemu-traces.h"
     16
    1517namespace Target {
    1618
    17   TargetBase::TargetBase( 
     19  TargetBase::TargetBase(
    1820    std::string targetName
    1921  ):
     
    6668
    6769    if (branchInstructions.empty()) {
    68       fprintf(
    69         stderr,
    70         "DETERMINE BRANCH INSTRUCTIONS FOR THIS ARCHITECTURE! -- fix me\n"
    71        );
    72        exit( -1 );   
     70      throw rld::error(
     71        "DETERMINE BRANCH INSTRUCTIONS FOR THIS ARCHITECTURE! -- fix me",
     72        "TargetBase::isBranch"
     73      );
    7374    }
    74    
     75
    7576    i = find(branchInstructions.begin(), branchInstructions.end(), instruction);
    7677    if ( i  == branchInstructions.end() )
     
    9192    int  result;
    9293
    93    
     94
    9495    ch = &(line[0]);
    9596
    9697    // Increment to the first tab in the line
    97     while ((*ch != '\t') && (*ch != '\0')) { 
     98    while ((*ch != '\t') && (*ch != '\0')) {
    9899      ch++;
    99100    }
     
    105106
    106107    // Increment to the second tab in the line
    107     while ((*ch != '\t') && (*ch != '\0')) 
     108    while ((*ch != '\t') && (*ch != '\0'))
    108109      ch++;
    109110    if (*ch != '\t') {
  • tester/covoar/TargetFactory.cc

    r1e21ea7 r881824f  
    99//!
    1010
     11#include <stdio.h>
     12#include <stdlib.h>
     13#include <string.h>
     14#include <unistd.h>
     15
     16#include <rld.h>
     17
    1118#include "TargetFactory.h"
    1219
     
    1724#include "Target_lm32.h"
    1825#include "Target_sparc.h"
    19 #include <stdio.h>
    20 #include <stdlib.h>
    21 #include <string.h>
    22 #include <unistd.h>
    2326
    2427namespace Target {
     
    3538     const char    *theTarget;
    3639     //! This is the static wrapper for the constructor.
    37      TargetBase *(*theCtor)( 
     40     TargetBase *(*theCtor)(
    3841       std::string
    3942     );
     
    7780    }
    7881
    79     fprintf(
    80       stderr,
    81       "ERROR!!! %s is not a known architecture!!!\n",
    82       cpu.c_str()
    83     );
    84     fprintf( stderr, "-- fix me\n" );
    85     exit( 1 );
     82    std::ostringstream what;
     83    what << cpu << "is not a known architecture!!! - fix me" << std::endl;
     84    throw rld::error( what, "TargetFactory" );
    8685
    8786    return NULL;
  • tester/covoar/Target_arm.cc

    r1e21ea7 r881824f  
    22 *  @brief Target_arm Implementation
    33 *
    4  *  This file contains the implementation of the base class for 
     4 *  This file contains the implementation of the base class for
    55 *  functions supporting target unique functionallity.
    66 */
    7 #include "Target_arm.h"
     7
    88#include <stdio.h>
    99#include <stdlib.h>
    1010#include <string.h>
    1111#include <unistd.h>
     12
     13#include <rld.h>
     14
     15#include "Target_arm.h"
    1216
    1317namespace Target {
     
    3236    branchInstructions.push_back("bvc");
    3337    branchInstructions.push_back("bvs");
    34  
     38
    3539    branchInstructions.sort();
    3640
     
    4751  {
    4852    if (!strcmp( &line[strlen(line)-3], "nop")) {
    49       size = 4; 
     53      size = 4;
    5054      return true;
    5155    }
     
    6771
    6872    return false;
    69  
     73
    7074  }
    7175
    7276  bool Target_arm::isBranch(
    7377      const char* instruction
    74   ) 
     78  )
    7579  {
    76     fprintf( stderr, "DETERMINE BRANCH INSTRUCTIONS FOR THIS ARCHITECTURE! -- fix me\n" );
    77     exit( -1 );   
     80    throw rld::error(
     81      "DETERMINE BRANCH INSTRUCTIONS FOR THIS ARCHITECTURE! -- fix me",
     82      "Target_arm::isBranch"
     83    );
    7884  }
    7985
  • tester/covoar/Target_m68k.cc

    r1e21ea7 r881824f  
    22 *  @brief Target_m68k Implementation
    33 *
    4  *  This file contains the implementation of the base class for 
     4 *  This file contains the implementation of the base class for
    55 *  functions supporting target unique functionallity.
    66 */
    7 #include "Target_m68k.h"
    8 #include "qemu-traces.h"
    97#include <stdio.h>
    108#include <stdlib.h>
    119#include <string.h>
    1210#include <unistd.h>
     11
     12#include <rld.h>
     13
     14#include "Target_m68k.h"
     15#include "qemu-traces.h"
    1316
    1417namespace Target {
     
    6568    branchInstructions.push_back("bvss");
    6669    branchInstructions.push_back("bvsl");
    67  
     70
    6871    branchInstructions.sort();
    6972
     
    8083  {
    8184    if (!strcmp( &line[strlen(line)-3], "nop")) {
    82       size = 2; 
     85      size = 2;
    8386      return true;
    8487    }
     
    8891      // Until binutils 2.20, binutils would fill with rts not nop
    8992      if (!strcmp( &line[strlen(line)-3], "rts")) {
    90         size = 4; 
     93        size = 4;
    9194        return true;
    92       } 
     95      }
    9396    #endif
    9497
     
    100103  )
    101104  {
    102     fprintf(
    103       stderr,
    104       "DETERMINE BRANCH INSTRUCTIONS FOR THIS ARCHITECTURE! -- fix me\n"
     105    throw rld::error(
     106      "DETERMINE BRANCH INSTRUCTIONS FOR THIS ARCHITECTURE! -- fix me",
     107      "Target_m68k::isBranch"
    105108    );
    106     exit( -1 );   
    107109  }
    108110
  • tester/covoar/Target_powerpc.cc

    r1e21ea7 r881824f  
    22 *  @brief Target_powerpc Implementation
    33 *
    4  *  This file contains the implementation of the base class for 
     4 *  This file contains the implementation of the base class for
    55 *  functions supporting target unique functionallity.
    66 */
    7 #include "Target_powerpc.h"
    87#include <stdio.h>
    98#include <stdlib.h>
    109#include <string.h>
    1110#include <unistd.h>
     11
     12#include <rld.h>
     13
     14#include "Target_powerpc.h"
    1215
    1316namespace Target {
     
    4750    branchInstructions.push_back("bclrl");
    4851
    49  
    50     branchInstructions.sort();   
     52
     53    branchInstructions.sort();
    5154  }
    5255
     
    6164  {
    6265    if (!strcmp( &line[strlen(line)-3], "nop")) {
    63       size = 4; 
     66      size = 4;
    6467      return true;
    6568    }
     
    7275  )
    7376  {
    74     fprintf( stderr, "DETERMINE BRANCH INSTRUCTIONS FOR THIS ARCHITECTURE! -- fix me\n" );
    75     exit( -1 );   
     77    throw rld::error(
     78      "DETERMINE BRANCH INSTRUCTIONS FOR THIS ARCHITECTURE! -- fix me",
     79      "Target_powerpc::isBranch"
     80    );
    7681  }
    7782
  • tester/covoar/TraceConverter.cc

    r1e21ea7 r881824f  
    1414#include <unistd.h>
    1515
     16#include <rld.h>
     17#include <rld-process.h>
     18
    1619#include "qemu-log.h"
    1720#include "TraceReaderLogQEMU.h"
     
    2124#include "app_common.h"
    2225#include "TargetFactory.h"
    23 
    24 #include "rld.h"
    25 #include "rld-process.h"
    2626
    2727#ifdef _WIN32
  • tester/covoar/TraceWriterQEMU.cc

    r1e21ea7 r881824f  
    3939#include <sys/stat.h>
    4040
     41#include <iostream>
     42#include <iomanip>
     43
     44#include <rld-process.h>
     45
    4146#include "app_common.h"
    4247#include "TraceWriterQEMU.h"
     
    4449#include "CoverageMap.h"
    4550#include "qemu-traces.h"
    46 
    47 #include "rld-process.h"
    4851
    4952#if HAVE_STAT64
     
    9598    // Open the trace file.
    9699    //
    97     traceFile = OPEN( file, "w" );
     100    traceFile = ::OPEN( file, "w" );
    98101    if (!traceFile) {
    99       fprintf( stderr, "Unable to open %s\n", file );
     102      std::ostringstream what;
     103      std::cerr << "Unable to open " << file << std::endl;
    100104      return false;
    101105    }
     
    111115    header.machine[0] = 0; // XXX ??
    112116    header.machine[1] = 0; // XXX ??
    113     status = fwrite( &header, sizeof(trace_header), 1, traceFile );
     117    status = ::fwrite( &header, sizeof(trace_header), 1, traceFile );
    114118    if (status != 1) {
    115       fprintf( stderr, "Unable to write header to %s\n", file );
     119      std::cerr << "Unable to write header to " << file << std::endl;
    116120      return false;
    117121    }
    118122
    119123    if (Verbose)
    120       fprintf(
    121         stderr,
    122         "magic = %s\n"
    123         "version = %d\n"
    124         "kind = %d\n"
    125         "sizeof_target_pc = %d\n"
    126         "big_endian = %d\n"
    127         "machine = %02x:%02x\n",
    128         header.magic,
    129         header.version,
    130         header.kind,
    131         header.sizeof_target_pc,
    132         header.big_endian,
    133         header.machine[0], header.machine[1]
    134        );
     124      std::cerr << "magic = " << header.magic << std::endl
     125                << "version = " << header.version << std::endl
     126                << "kind = " << header.kind << std::endl
     127                << "sizeof_target_pc = " << header.sizeof_target_pc << std::endl
     128                << "big_endian = " << header.big_endian << std::endl
     129                << std::hex << std::setfill('0')
     130                << "machine = " << std::setw(2) << header.machine[0]
     131                << ':' << header.machine[1]
     132                << std::dec << std::setfill(' ')
     133                << std::endl;
    135134
    136135    //
     
    154153          break;
    155154        default:
    156           fprintf(stderr, "Unknown exit Reason\n");
    157           exit(1);
     155          throw rld::error( "Unknown exit Reason", "TraceWriterQEMU::writeFile" );
    158156          break;
    159157       }
    160158
    161159      if ( Verbose )
    162         fprintf(stderr, "%x %x %x\n", entry.pc, entry.size, entry.op);
     160        std::cerr << std::hex << std::setfill('0')
     161                  << entry.pc << ' ' << entry.size << ' ' << entry.op
     162                  << std::dec << std::setfill(' ')
     163                  << std::endl;
    163164
    164       status = fwrite( &entry, sizeof(entry), 1, traceFile );
     165      status = ::fwrite( &entry, sizeof(entry), 1, traceFile );
    165166      if (status != 1) {
    166         fprintf( stderr, "Unable to write entry to %s\n", file );
     167        std::cerr << "Unable to write entry to " << file << std::endl;
    167168        return false;
    168169      }
    169170    }
    170171
    171     fclose( traceFile );
     172    ::fclose( traceFile );
    172173    return true;
    173174  }
  • tester/covoar/covoar.cc

    r1e21ea7 r881824f  
     1#include <iostream>
     2#include <iomanip>
     3
     4#include <cxxabi.h>
    15#include <ctype.h>
    26#include <errno.h>
     
    1317#include <list>
    1418
     19#include <rld.h>
     20#include <rld-process.h>
     21
    1522#include "app_common.h"
    1623#include "CoverageFactory.h"
     
    2431#include "GcovData.h"
    2532
    26 #include "rld-process.h"
    27 
    2833#ifdef _WIN32
    2934  #define kill(p,s) raise(s)
     
    3237typedef std::list<std::string> CoverageNames;
    3338typedef std::list<Coverage::ExecutableInfo*> Executables;
     39typedef std::string option_error;
    3440
    3541/*
     
    106112    }
    107113    if (!fail.empty()) {
    108       std::cerr << "ERROR: " << fail << std::endl;
    109       exit(EXIT_FAILURE);
     114      throw rld::error( fail, "createBuildPath" );
    110115    }
    111116  }
     
    139144}
    140145
    141 #define PrintableString(_s) \
    142 ((!(_s)) ? "NOT SET" : (_s))
    143 
    144 static void
    145 fatal_signal( int signum )
    146 {
    147   signal( signum, SIG_DFL );
    148 
    149   rld::process::temporaries_clean_up();
    150 
    151   /*
    152    * Get the same signal again, this time not handled, so its normal effect
    153    * occurs.
    154    */
    155   kill( getpid(), signum );
    156 }
    157 
    158 static void
    159 setup_signals( void )
    160 {
    161   if ( signal( SIGINT, SIG_IGN ) != SIG_IGN )
    162     signal( SIGINT, fatal_signal );
    163 #ifdef SIGHUP
    164   if ( signal( SIGHUP, SIG_IGN ) != SIG_IGN )
    165     signal( SIGHUP, fatal_signal );
    166 #endif
    167   if ( signal( SIGTERM, SIG_IGN ) != SIG_IGN )
    168     signal( SIGTERM, fatal_signal );
    169 #ifdef SIGPIPE
    170   if ( signal( SIGPIPE, SIG_IGN ) != SIG_IGN )
    171     signal( SIGPIPE, fatal_signal );
    172 #endif
    173 #ifdef SIGCHLD
    174   signal( SIGCHLD, SIG_DFL );
    175 #endif
    176 }
    177 
    178 int main(
     146int covoar(
    179147  int    argc,
    180148  char** argv
     
    205173  bool                          debug = false;
    206174  std::string                   symbolSet;
    207   std::string                   progname;
    208175  std::string                   option;
    209176  int                           opt;
    210177
    211   setup_signals();
    212 
    213178  //
    214179  // Process command line options.
    215180  //
    216   progname = rld::path::basename(argv[0]);
    217181
    218182  while ((opt = getopt(argc, argv, "1:L:e:c:g:E:f:s:S:T:O:p:vd")) != -1) {
     
    233197      case 'd': debug               = true;   break;
    234198      default: /* '?' */
    235         usage(progname);
    236         exit(EXIT_FAILURE);
    237     }
    238   }
    239   try
    240   {
    241     /*
    242      * Validate inputs.
    243      */
    244 
    245     /*
    246      * Validate that we have a symbols of interest file.
    247      */
    248     if ( symbolSet.empty() ) {
    249       option = "symbol set file -S";
    250       throw option;
    251     }
    252 
    253     /*
    254      * Has path to explanations.txt been specified.
    255      */
    256     if ( !explanations ) {
    257       option = "explanations -E";
    258       throw option;
    259     }
    260 
    261     /*
    262      * Check for project name.
    263      */
    264     if ( !projectName ) {
    265       option = "project name -p";
    266       throw option;
    267     }
    268   }
    269   catch( std::string option )
    270   {
    271     std::cerr << "error missing option: " + option << std::endl;
    272     usage(progname);
    273     exit(EXIT_FAILURE);
    274   }
     199        throw option_error( "unknown option" );
     200    }
     201  }
     202
     203  /*
     204   * Validate inputs.
     205   */
     206
     207  /*
     208   * Validate that we have a symbols of interest file.
     209   */
     210  if ( symbolSet.empty() )
     211    throw option_error( "symbol set file -S" );
     212
     213  /*
     214   * Has path to explanations.txt been specified.
     215   */
     216  if ( !explanations )
     217    throw option_error( "explanations -E" );
     218
     219  /*
     220   * Check for project name.
     221   */
     222  if ( !projectName )
     223    throw option_error( "project name -p" );
    275224
    276225  // If a single executable was specified, process the remaining
     
    333282
    334283  // Ensure that there is at least one executable to process.
    335   if (executablesToAnalyze.empty()) {
    336     std::cerr << "error: No information to analyze" << std::endl;
    337     exit(EXIT_FAILURE);
    338   }
     284  if (executablesToAnalyze.empty())
     285    throw rld::error( "No information to analyze", "covoar" );
    339286
    340287  // The executablesToAnalyze and coverageFileNames containers need
    341288  // to be the name size of some of the code below breaks. Lets
    342289  // check and make sure.
    343   if (executablesToAnalyze.size() != coverageFileNames.size()) {
    344     std::cerr << "ERROR: executables and coverage name size mismatch" << std::endl;
    345     exit(EXIT_FAILURE);
    346   }
     290  if (executablesToAnalyze.size() != coverageFileNames.size())
     291    throw rld::error( "executables and coverage name size mismatch", "covoar" );
    347292
    348293  //
     
    399344  // Read symbol configuration file and load needed symbols.
    400345  //
    401   if (!SymbolsToAnalyze->load( symbolSet, buildTarget, buildBSP, Verbose )) {
    402       exit(EXIT_FAILURE);
    403   }
     346  SymbolsToAnalyze->load( symbolSet, buildTarget, buildBSP, Verbose );
    404347
    405348  if ( Verbose )
     
    414357  // Create coverage map reader.
    415358  coverageReader = Coverage::CreateCoverageReader(coverageFormat);
    416   if (!coverageReader) {
    417     std::cerr << "error: Unable to create coverage file reader" << std::endl;
    418     exit(EXIT_FAILURE);
    419   }
     359  if (!coverageReader)
     360    throw rld::error( "Unable to create coverage file reader", "covoar" );
    420361
    421362  // Create the objdump processor.
     
    556497  return 0;
    557498}
     499
     500#define PrintableString(_s) \
     501((!(_s)) ? "NOT SET" : (_s))
     502
     503static void
     504fatal_signal( int signum )
     505{
     506  signal( signum, SIG_DFL );
     507
     508  rld::process::temporaries_clean_up();
     509
     510  /*
     511   * Get the same signal again, this time not handled, so its normal effect
     512   * occurs.
     513   */
     514  kill( getpid(), signum );
     515}
     516
     517static void
     518setup_signals( void )
     519{
     520  if ( signal( SIGINT, SIG_IGN ) != SIG_IGN )
     521    signal( SIGINT, fatal_signal );
     522#ifdef SIGHUP
     523  if ( signal( SIGHUP, SIG_IGN ) != SIG_IGN )
     524    signal( SIGHUP, fatal_signal );
     525#endif
     526  if ( signal( SIGTERM, SIG_IGN ) != SIG_IGN )
     527    signal( SIGTERM, fatal_signal );
     528#ifdef SIGPIPE
     529  if ( signal( SIGPIPE, SIG_IGN ) != SIG_IGN )
     530    signal( SIGPIPE, fatal_signal );
     531#endif
     532#ifdef SIGCHLD
     533  signal( SIGCHLD, SIG_DFL );
     534#endif
     535}
     536
     537void
     538unhandled_exception (void)
     539{
     540  std::cerr << "error: exception handling error, please report" << std::endl;
     541  exit (1);
     542}
     543
     544int main(
     545  int    argc,
     546  char** argv
     547)
     548{
     549  std::string progname( argv[0] );
     550  int         ec = 0;
     551
     552  setup_signals();
     553
     554  std::set_terminate(unhandled_exception);
     555
     556  try
     557  {
     558    progname = rld::path::basename(argv[0]);
     559    covoar( argc, argv );
     560  }
     561  catch ( option_error oe )
     562  {
     563    std::cerr << "error: missing option: " + oe << std::endl;
     564    usage(progname);
     565    ec = EXIT_FAILURE;
     566  }
     567  catch (rld::error re)
     568  {
     569    std::cerr << "error: "
     570              << re.where << ": " << re.what
     571              << std::endl;
     572    ec = 10;
     573  }
     574  catch (std::exception e)
     575  {
     576    int   status;
     577    char* realname;
     578    realname = abi::__cxa_demangle (e.what(), 0, 0, &status);
     579    std::cerr << "error: exception: " << realname << " [";
     580    ::free (realname);
     581    const std::type_info &ti = typeid (e);
     582    realname = abi::__cxa_demangle (ti.name(), 0, 0, &status);
     583    std::cerr << realname << "] " << e.what () << std::endl << std::flush;
     584    ::free (realname);
     585    ec = 11;
     586  }
     587  catch (...)
     588  {
     589    /*
     590     * Helps to know if this happens.
     591     */
     592    std::cerr << "error: unhandled exception" << std::endl;
     593    ec = 12;
     594  }
     595
     596  return ec;
     597}
Note: See TracChangeset for help on using the changeset viewer.