[PATCH v1] GcovData: Convert to c++ and fix formatting

Ryan Long ryan.long at oarcorp.com
Mon Jun 14 19:08:13 UTC 2021


Converted printf statements to c++'s method of printing, adjusted to use
c++ file handling, changed char arrays to strings, fixed inconsistent
formatting.
---
 tester/covoar/GcovData.cc         | 388 +++++++++++++++++---------------
 tester/covoar/GcovData.h          |  32 +--
 tester/covoar/GcovFunctionData.cc | 457 ++++++++++++++++++++------------------
 tester/covoar/GcovFunctionData.h  |  76 ++++---
 4 files changed, 509 insertions(+), 444 deletions(-)

diff --git a/tester/covoar/GcovData.cc b/tester/covoar/GcovData.cc
index e8b8573..7847ce6 100644
--- a/tester/covoar/GcovData.cc
+++ b/tester/covoar/GcovData.cc
@@ -1,5 +1,4 @@
 /*
- *  TODO: use strings instead of cstrings for reliability and saving memory
  *  TODO: use global buffers
  *
  */
@@ -34,71 +33,73 @@ namespace Gcov {
   {
   }
 
-  bool GcovData::readGcnoFile( const char* const  fileName )
+  bool GcovData::readGcnoFile( const std::string& fileName )
   {
-    int        status;
-    FILE*      gcovFile;
-    char*      tempString;
-    char*      tempString2;
-    char*      tempString3;
-
-    if ( strlen(fileName) >= FILE_NAME_LENGTH ){
-      fprintf(
-        stderr,
-        "ERROR: File name is too long to be correctly stored: %u\n",
-        (unsigned int) strlen(fileName)
-      );
+    int                 status;
+    std::ifstream       gcovFile;
+    std::string         tempString;
+    std::string         tempString2;
+    std::string         tempString3;
+    size_t              index;
+
+    if ( fileName.length() >= FILE_NAME_LENGTH ) {
+      std::cerr << "ERROR: File name is too long to be correctly stored: "
+                << fileName.length() << std::endl;
       return false;
     }
-    strcpy( gcnoFileName, fileName );
-    strcpy( gcdaFileName, fileName );
-    strcpy( textFileName, fileName );
-    strcpy( cFileName, fileName );
-    tempString = strstr( gcdaFileName,".gcno" );
-    tempString2 = strstr( textFileName,".gcno" );
-    tempString3 = strstr( cFileName,".gcno" );
-
-    if ( (tempString == NULL) && (tempString2 == NULL) ){
-      fprintf(stderr, "ERROR: incorrect name of *.gcno file\n");
-    }
-    else
-    {
-      strcpy( tempString, ".gcda");             // construct gcda file name
-      strcpy( tempString2, ".txt");             // construct report file name
-      strcpy( tempString3, ".c");               // construct source file name
+
+    gcnoFileName = fileName;
+    gcdaFileName = fileName;
+    textFileName = fileName;
+    cFileName    = fileName;
+    tempString   = gcdaFileName;
+    tempString2  = textFileName;
+    tempString3  = cFileName;
+
+    index = tempString.find( ".gcno" );
+    if ( index == std::string::npos ) {
+      std::cerr << "ERROR: incorrect name of *.gcno file" << std::endl;
+      return false;
+    } else {
+      // construct gcda file name
+      tempString = tempString.replace( index, strlen( ".gcno" ), ".gcda" );
+
+      // construct report file name
+      tempString2 = tempString2.replace( index, strlen( ".gcno" ), ".txt" );
+
+      // construct source file name
+      tempString3 = tempString3.replace( index, strlen( ".gcno" ), ".c" );
     }
 
     // Debug message
-    // fprintf( stderr, "Readning file: %s\n",  gcnoFileName);
+    // std::cerr << "Reading file: " << gcnoFileName << std::endl;
 
     // Open the notes file.
-    gcovFile = fopen( gcnoFileName, "r" );
+    gcovFile.open( gcnoFileName );
     if ( !gcovFile ) {
-      fprintf( stderr, "Unable to open %s\n", gcnoFileName );
+      std::cerr << "Unable to open " << gcnoFileName << std::endl;
       return false;
     }
 
     // Read and validate the gcnoPreamble (magic, version, timestamp) from the file
-    status = readFilePreamble( &gcnoPreamble, gcovFile, GCNO_MAGIC );
-    if ( status <= 0 ){
-      fprintf( stderr, "Unable to read %s\n", gcnoFileName );
-      fclose( gcovFile );
+    status = readFilePreamble( &gcnoPreamble, &gcovFile, GCNO_MAGIC );
+    if ( status <= 0 ) {
+      std::cerr << "Unable to read " << gcnoFileName << std::endl;
       return false;
     }
 
     //Read all remaining frames from file
-    while( readFrame(gcovFile) ){}
+    while( readFrame( &gcovFile ) ) {}
 
-    fclose( gcovFile );
     return true;
   }
 
 
-  bool GcovData::writeGcdaFile ()
+  bool GcovData::writeGcdaFile()
   {
     gcov_preamble         preamble;
     gcov_frame_header     header;
-    FILE*                 gcdaFile;
+    std::ofstream         gcdaFile;
     functions_iterator_t  currentFunction;
     arcs_iterator_t       currentArc;
     uint32_t              buffer;
@@ -109,32 +110,35 @@ namespace Gcov {
     uint64_t              llBuffer[4096];    // TODO: Use common buffer
     gcov_statistics       objectStats;
     gcov_statistics       programStats;
-    size_t                status;
+    size_t                bytes_before;
+    size_t                bytes_after;
 
     // Debug message
-    // fprintf( stderr, "Writing file: %s\n",  gcdaFileName);
+    //std::cerr << "Writing file: " <<  gcdaFileName << std::endl;
 
     // Lets clear counters sumators
-    countersSum     = 0;
-    countersMax     = 0;
+    countersSum        = 0;
+    countersMax        = 0;
     countersFoundSum   = 0;
 
     // Open the data file.
-    gcdaFile = fopen( gcdaFileName, "w" );
+    gcdaFile.open( gcdaFileName );
     if ( !gcdaFile ) {
-      fprintf( stderr, "Unable to create %s\n", gcdaFileName );
+      std::cerr << "Unable to create " << gcdaFileName << std::endl;
       return false;
     }
 
     //Form preamble
-    preamble.magic  = GCDA_MAGIC;
-    preamble.version  = gcnoPreamble.version;
-    preamble.timestamp  = gcnoPreamble.timestamp;
+    preamble.magic = GCDA_MAGIC;
+    preamble.version = gcnoPreamble.version;
+    preamble.timestamp = gcnoPreamble.timestamp;
 
     //Write preamble
-    status = fwrite (&preamble , sizeof( preamble ), 1 , gcdaFile );
-    if ( status != 1 )
-      fprintf( stderr, "Error while writing gcda preamble to a file %s\n", gcdaFileName );
+    gcdaFile.write( (char *) &preamble , 4 * sizeof( preamble ) );
+    if ( gcdaFile.fail() ) {
+      std::cerr << "Error while writing gcda preamble to a file "
+                << gcdaFileName << std::endl;
+    }
 
     //Write function info and counter counts
     for (
@@ -146,38 +150,56 @@ namespace Gcov {
       //Write function announcement frame header (length always equals 2)
       header.tag = GCOV_TAG_FUNCTION;
       header.length = 2;
-      status = fwrite (&header, sizeof(header), 1, gcdaFile );
-      if ( status != 1 )
-        fprintf( stderr, "Error while writing function announcement to a file %s\n", gcdaFileName );
+      gcdaFile.write( (char *) &header, sizeof( header ) );
+      if ( gcdaFile.fail() ) {
+        std::cerr << "Error while writing function announcement to a file "
+                  << gcdaFileName << std::endl;
+      }
 
       //Write function id
       buffer = (*currentFunction).getId();
-      status = fwrite (&buffer, sizeof( buffer ), 1, gcdaFile );
-      if ( status != 1 )
-        fprintf( stderr, "Error while writing function id to a file %s\n", gcdaFileName );
+      gcdaFile.write( (char *) &buffer, sizeof( buffer ) );
+      if ( gcdaFile.fail() ) {
+        std::cerr << "Error while writing function id to a file "
+                  << gcdaFileName << std::endl;
+      }
 
       //Write function checksum
       buffer = (*currentFunction).getChecksum();
-      status = fwrite (&buffer, sizeof( buffer ), 1, gcdaFile );
-      if ( status != 1 )
-        fprintf( stderr, "Error while writing function checksum to a file %s\n", gcdaFileName );
+      gcdaFile.write( (char *) &buffer, sizeof( buffer ) );
+      if ( gcdaFile.fail() ) {
+        std::cerr << "Error while writing function checksum to a file "
+                  << gcdaFileName << std::endl;
+      }
 
       // Determine how many counters there are
       // and store their counts in buffer
       countersFound = 0;
-      (*currentFunction).getCounters( llBuffer, countersFound, countersSum, countersMax );
+      (*currentFunction).getCounters(
+        llBuffer,
+        countersFound,
+        countersSum,
+        countersMax
+      );
       countersFoundSum += countersFound;
 
       //Write info about counters
       header.tag = GCOV_TAG_COUNTER;
       header.length = countersFound * 2;
-      status = fwrite (&header, sizeof( header ), 1, gcdaFile );
-      if ( status != 1 )
-        fprintf( stderr, "Error while writing counter header to a file %s\n", gcdaFileName );
+      gcdaFile.write( (char *) &header, sizeof( header ) );
+      if ( gcdaFile.fail() ) {
+        std::cerr << "Error while writing counter header to a file "
+                  << gcdaFileName << std::endl;
+      }
 
-      status = fwrite (llBuffer, sizeof( uint64_t ), countersFound , gcdaFile );
-      if ( status != countersFound )
-        fprintf( stderr, "Error while writing counter data to a file %s\n", gcdaFileName );
+      bytes_before = gcdaFile.tellp();
+
+      gcdaFile.write( (char *) llBuffer, sizeof( uint64_t ) * countersFound );
+      bytes_after = gcdaFile.tellp();
+      if ( bytes_after - bytes_before != countersFound ) {
+        std::cerr << "Error while writing counter data to a file "
+                  << gcdaFileName << std::endl;
+      }
     }
 
     // Prepare frame with object file statistics
@@ -191,12 +213,17 @@ namespace Gcov {
     objectStats.sumMax = countersMax;    // we have no clue
 
     // Write data
-    status = fwrite (&header, sizeof( header ), 1, gcdaFile );
-    if ( status != 1 )
-      fprintf( stderr, "Error while writing stats header to a file %s\n", gcdaFileName );
-    status = fwrite (&objectStats, sizeof( objectStats ), 1, gcdaFile );
-    if ( status != 1 )
-      fprintf( stderr, "Error while writing object stats to a file %s\n", gcdaFileName );
+    gcdaFile.write( (char *) &header, sizeof( header ) );
+    if ( gcdaFile.fail() ) {
+      std::cerr << "Error while writing stats header to a file "
+                << gcdaFileName << std::endl;
+    }
+
+    gcdaFile.write( (char *) &objectStats, sizeof( objectStats ) );
+    if ( gcdaFile.fail() ) {
+      std::cerr << "Error while writing object stats to a file "
+                << gcdaFileName << std::endl;
+    }
 
 
     // Prepare frame with program statistics
@@ -210,38 +237,40 @@ namespace Gcov {
     programStats.sumMax = countersMax;    // we have no clue
 
     // Write data
-    status = fwrite (&header, sizeof( header ), 1, gcdaFile );
-    if ( status != 1 )
-      fprintf( stderr, "Error while writing stats header to a file %s\n", gcdaFileName );
-    status = fwrite (&programStats, sizeof( programStats ), 1, gcdaFile );
-    if ( status != 1 )
-      fprintf( stderr, "Error while writing program stats to a file %s\n", gcdaFileName );
+    gcdaFile.write( (char *) &header, sizeof( header ) );
+    if ( gcdaFile.fail() ) {
+      std::cerr << "Error while writing stats header to a file "
+                << gcdaFileName << std::endl;
+    }
 
-    fclose( gcdaFile );
+    gcdaFile.write( (char *) &programStats, sizeof( programStats ) );
+    if ( gcdaFile.fail() ) {
+      std::cerr << "Error while writing program stats to a file "
+                << gcdaFileName << std::endl;
+    }
 
     return true;
   }
 
   bool GcovData::readFrame(
-         FILE*         gcovFile
+    std::ifstream*         gcovFile
   )
   {
     gcov_frame_header   header;
     char                buffer[512];
-    uint32_t            intBuffer[4096];
+    char                intBuffer[16384];
     uint32_t            tempBlockId;
     blocks_iterator_t   tempBlockIterator;
     int                 status;
 
-    status = readFrameHeader( &header, gcovFile);
-
+    status = readFrameHeader( &header, gcovFile );
     if ( status <= 0 ) {
       // Not printing error message because this
       // happenns at the end of each file
       return false;
     }
 
-    switch (header.tag){
+    switch (header.tag) {
 
       case GCOV_TAG_FUNCTION:
 
@@ -249,80 +278,79 @@ namespace Gcov {
           numberOfFunctions++;
           GcovFunctionData newFunction;
 
-          if ( !readFunctionFrame(header, gcovFile, &newFunction) ){
-            fprintf( stderr, "Error while reading FUNCTION from gcov file...\n" );
+          if ( !readFunctionFrame( header, gcovFile, &newFunction ) ) {
+            std::cerr << "Error while reading FUNCTION from gcov file...\n";
             return false;
           }
 
-          functions.push_back(newFunction);
+          functions.push_back( newFunction );
         }
 
         break;
 
       case GCOV_TAG_BLOCKS:
 
-        status = fread( &intBuffer, 4, header.length, gcovFile );
-        if ( status != (int) header.length){
-          fprintf(
-            stderr, "Error while reading BLOCKS from gcov file...\n"
-            "Header lenght is %u instead of %u\n",
-            header.length,
-            status
-          );
+        gcovFile->read( intBuffer, header.length );
+        if ( gcovFile->gcount() != (int) header.length ) {
+          std::cerr << "Error while reading BLOCKS from gcov file...\n"
+                    << "Header length is " << header.length
+                    << " instead of " << gcovFile->gcount()
+                    << std::endl;
           return false;
         }
 
-        for( uint32_t i = 0; i < header.length; i++ )
-          functions.back().addBlock(i, intBuffer[i], "");
+        for( uint32_t i = 0; i < header.length; i++ ) {
+          functions.back().addBlock( i, intBuffer[i], "" );
+        }
 
         break;
 
       case GCOV_TAG_ARCS:
 
-        status = fread( &intBuffer, 4, header.length, gcovFile );
-        if (status != (int) header.length){
+        gcovFile->read( intBuffer, header.length );
+        if ( gcovFile->gcount() != (int) header.length ) {
           return false;
         }
 
-        for ( int i = 1; i < (int) header.length; i += 2 )
-          functions.back().addArc(intBuffer[0], intBuffer[i], intBuffer[i+1]);
+        for ( int i = 1; i < (int) header.length; i += 2 ) {
+          functions.back().addArc( intBuffer[0], intBuffer[i], intBuffer[i+1] );
+        }
 
         break;
 
       case GCOV_TAG_LINES:
 
-        status = fread( &intBuffer, 4, 2, gcovFile );
-        if (status != 2 || intBuffer[1] != 0){
-          fprintf(
-            stderr,
-            "Error while reading block id for LINES from gcov file..."
-          );
+        gcovFile->read( intBuffer, 2 );
+        if ( gcovFile->gcount() != 2 || intBuffer[1] != 0 ) {
+          std::cerr << "Error while reading block id for LINES from gcov "
+                    << "file...";
           return false;
         }
         tempBlockId = intBuffer[0];
         header.length -= 2;
 
         // Find the right block
-        tempBlockIterator =functions.back().findBlockById(tempBlockId);
+        tempBlockIterator =functions.back().findBlockById( tempBlockId );
 
-        header.length -= readString(buffer, gcovFile);
+        header.length -= readString( buffer, gcovFile );
         functions.back().setBlockFileName( tempBlockIterator, buffer );
 
-        status = fread( &intBuffer, 4, header.length, gcovFile );
-        if (status != (int) header.length){
-          fprintf( stderr, "Error while reading LINES from gcov file..." );
+        gcovFile->read( intBuffer, header.length );
+        if ( gcovFile->gcount() != (int) header.length ) {
+          std::cerr << "Error while reading LINES from gcov file...";
           return false;
-        }
-
-        else
-          for (int i = 0; i < (int) (header.length - 2); i++)
+        } else {
+          for (int i = 0; i < (int) (header.length - 2); i++) {
             functions.back().addBlockLine( tempBlockIterator, intBuffer[i] );
+          }
+        }
 
         break;
 
       default:
 
-        fprintf( stderr, "\n\nERROR - encountered unknown *.gcno tag : 0x%x\n", header.tag );
+        std::cerr << "\n\nERROR - encountered unknown *.gcno tag : 0x"
+                  << std::hex << header.tag << std::dec << std::endl;
         break;
       }
 
@@ -330,22 +358,22 @@ namespace Gcov {
   }
 
   int GcovData::readString(
-    char*     buffer,   //TODO: use global buffer here
-    FILE*     gcovFile
+    char*              buffer,   //TODO: use global buffer here
+    std::ifstream*     gcovFile
   )
   {
-    int          status;
     int          length;
 
-    status = fread( &length, sizeof(int), 1, gcovFile );
-    if (status != 1){
-      fprintf( stderr, "ERROR: Unable to read string length from gcov file\n" );
+    gcovFile->read( (char *) &length, sizeof( int ) );
+    if ( gcovFile->gcount() != sizeof( int ) ) {
+      std::cerr << "ERROR: Unable to read string length from gcov file"
+                << std::endl;
       return -1;
     }
 
-    status = fread( buffer, length * 4 , 1, gcovFile );
-    if (status != 1){
-      fprintf( stderr, "ERROR: Unable to read string from gcov file\n" );
+    gcovFile->read( buffer, length * 4 );
+    if ( gcovFile->gcount() != length * 4 ) {
+      std::cerr << "ERROR: Unable to read string from gcov file" << std::endl;
       return -1;
     }
 
@@ -356,16 +384,15 @@ namespace Gcov {
 
   int GcovData::readFrameHeader(
     gcov_frame_header*   header,
-    FILE*             gcovFile
+    std::ifstream*       gcovFile
   )
   {
-    int          status;
     int          length;
 
-    length = sizeof(gcov_frame_header);
-    status = fread( header, length, 1, gcovFile );
-    if (status != 1){
-      //fprintf( stderr, "ERROR: Unable to read frame header from gcov file\n" );
+    length = sizeof( gcov_frame_header );
+    gcovFile->read( (char *) header, length );
+    if ( gcovFile->gcount() != length ) {
+      std::cerr << "ERROR: Unable to read frame header from gcov file\n";
       return -1;
     }
 
@@ -373,23 +400,24 @@ namespace Gcov {
   }
 
   int GcovData::readFilePreamble(
-     gcov_preamble*       preamble,
-     FILE*             gcovFile,
+     gcov_preamble*  preamble,
+     std::ifstream*  gcovFile,
      uint32_t        desiredMagic
   )
   {
-    int          status;
     int          length;
 
     length = sizeof( gcov_preamble );
-    status = fread( preamble, sizeof( gcov_preamble), 1, gcovFile );
-    if (status <= 0) {
-      fprintf( stderr, "Error while reading file preamble\n" );
+    gcovFile->read( (char *) &preamble, 4 * sizeof( gcov_preamble ) );
+    if ( gcovFile->gcount() != 4 * sizeof( gcov_preamble ) ) {
+      std::cerr << "Error while reading file preamble " << std::endl;
       return -1;
     }
 
     if ( preamble->magic != GCNO_MAGIC ) {
-      fprintf( stderr, "File is not a valid *.gcno output (magic: 0x%4x)\n", preamble->magic );
+      std::cerr << "File is not a valid *.gcno output (magic: 0x"
+                << std::hex << std::setw( 4 ) << preamble->magic
+                << ")" << std::endl;
       return -1;
     }
 
@@ -398,17 +426,17 @@ namespace Gcov {
 
   bool GcovData::readFunctionFrame(
     gcov_frame_header   header,
-    FILE*           gcovFile,
-    GcovFunctionData*  function
+    std::ifstream*      gcovFile,
+    GcovFunctionData*   function
   )
   {
     char         buffer[512];    //TODO: use common buffers
-    uint32_t     intBuffer[4096];
-    int          status;
+    char         intBuffer[16384];
 
-    status = fread( &intBuffer, 8, 1, gcovFile );
-    if (status != 1){
-      fprintf( stderr, "ERROR: Unable to read Function ID & checksum\n" );
+    gcovFile->read( (char *) &intBuffer, 8 );
+    if ( gcovFile->gcount() != 8 ) {
+      std::cerr << "ERROR: Unable to read Function ID & checksum "
+                << std::endl;
       return false;
     }
     header.length -= 2;
@@ -419,9 +447,10 @@ namespace Gcov {
     function->setFunctionName( buffer );
     header.length -= readString( buffer, gcovFile );
     function->setFileName( buffer );
-    status = fread( &intBuffer, 4, header.length, gcovFile );
-    if (status <= 0){
-    fprintf( stderr, "ERROR: Unable to read Function starting line number\n" );
+    gcovFile->read( (char*) &intBuffer, 4 * header.length );
+    if (gcovFile->gcount() != 4 * header.length ) {
+      std::cerr << "ERROR: Unable to read Function starting line number"
+                << std::endl;
       return false;
     }
     function->setFirstLineNumber( intBuffer[0] );
@@ -433,64 +462,56 @@ namespace Gcov {
   {
     functions_iterator_t   currentFunction;
     uint32_t               i = 1;          //iterator
-    FILE*                  textFile;
+    std::ofstream          textFile;
 
     // Debug message
-    // fprintf( stderr, "Writing file: %s\n",  textFileName);
+    // std::cerr << "Writing file: " << textFileName << std::endl;
 
     // Open the data file.
-    textFile = fopen( textFileName, "w" );
+    textFile.open( textFileName );
     if ( !textFile ) {
-      fprintf( stderr, "Unable to create %s\n", textFileName );
+      std::cerr << "Unable to create " << textFileName << std::endl;
       return false;
     }
 
-    printGcnoFileInfo( textFile );
+    printGcnoFileInfo( &textFile );
 
     for (
       currentFunction = functions.begin();
       currentFunction != functions.end();
       currentFunction++
-    )
-    {
-      (*currentFunction).printFunctionInfo( textFile, i );
-      (*currentFunction).printCoverageInfo( textFile, i );
+    ) {
+      (*currentFunction).printFunctionInfo( &textFile, i );
+      (*currentFunction).printCoverageInfo( &textFile, i );
       i++;
     }
 
-    fclose ( textFile );
     return true;
   }
 
-  void GcovData::printGcnoFileInfo( FILE * textFile )
+  void GcovData::printGcnoFileInfo( std::ofstream* textFile )
   {
-    fprintf(
-      textFile,
-      "\nFILE:\t\t\t%s\n"
-      "magic:\t\t\t%x\n"
-      "version:\t\t%x\n"
-      "timestamp:\t\t%x\n"
-      "functions found: \t%u\n\n",
-      gcnoFileName,
-      gcnoPreamble.magic,
-      gcnoPreamble.version,
-      gcnoPreamble.timestamp,
-      numberOfFunctions
-    );
+    (*textFile) << "\nFILE:\t\t\t" << gcnoFileName << std::endl << std::hex
+                << "magic:\t\t\t" << gcnoPreamble.magic << std::endl
+                << "version:\t\t" << gcnoPreamble.version << std::endl
+                << "timestamp:\t\t" << gcnoPreamble.timestamp << std::endl
+                << std::dec
+                << "functions found: \t\n\n" << gcnoPreamble.timestamp
+                << std::endl << std::endl;
   }
 
-  void GcovData::writeGcovFile( )
+  void GcovData::writeGcovFile()
   {
     //std::cerr << "Attempting to run gcov for: " << cFileName << std::endl;
     std::ostringstream command;
-    command << "( cd " << rld::path::dirname (cFileName)
-            << " && gcov " << rld::path::basename (cFileName)
+    command << "( cd " << rld::path::dirname(cFileName)
+            << " && gcov " << rld::path::basename(cFileName)
             << " &>> gcov.log)";
     //std::cerr << "> " << command << std::endl;
-    system( command.str ().c_str () );
+    system( command.str().c_str() );
   }
 
-  bool GcovData::processCounters(  )
+  bool GcovData::processCounters()
   {
     functions_iterator_t  currentFunction;
     bool                  status = true;
@@ -499,9 +520,8 @@ namespace Gcov {
       currentFunction = functions.begin();
       currentFunction != functions.end();
       currentFunction++
-    )
-    {
-      if ( !(*currentFunction).processFunctionCounters(  ) )
+    ) {
+      if ( !(*currentFunction).processFunctionCounters() )
         status = false;
     }
 
diff --git a/tester/covoar/GcovData.h b/tester/covoar/GcovData.h
index 0e74b02..540bd92 100644
--- a/tester/covoar/GcovData.h
+++ b/tester/covoar/GcovData.h
@@ -10,6 +10,8 @@
 #include <stdint.h>
 #include <list>
 #include <iostream>
+#include <iomanip>
+#include <fstream>
 #include "GcovFunctionData.h"
 
 namespace Gcov {
@@ -81,7 +83,7 @@ struct gcov_statistics
      *
      *  @return Returns TRUE if the method succeeded and FALSE if it failed.
      */
-    bool readGcnoFile( const char* const  fileName );
+    bool readGcnoFile( const std::string&  fileName );
 
     /*!
      *  This method writes the *.gcda file. It also produces and stores
@@ -89,7 +91,7 @@ struct gcov_statistics
      *
      *  @return Returns TRUE if the method succeeded and FALSE if it failed.
      */
-    bool writeGcdaFile ();
+    bool writeGcdaFile();
 
     /*!
      *  This method writes all contained information to stdout file
@@ -102,21 +104,21 @@ struct gcov_statistics
      *  This method runs gcov to generate report. This method should
      *  be used only when gcno and gcda files are already generated.
      */
-    void writeGcovFile( );
+    void writeGcovFile();
 
     /*!
      *  This method calculates values of counters for all functions
      */
-    bool processCounters( void );
+    bool processCounters();
 
   private:
 
     uint32_t                            numberOfFunctions;
     gcov_preamble                       gcnoPreamble;
-    char                                gcnoFileName[FILE_NAME_LENGTH];
-    char                                gcdaFileName[FILE_NAME_LENGTH];
-    char                                textFileName[FILE_NAME_LENGTH];
-    char                                cFileName[FILE_NAME_LENGTH];
+    std::string                         gcnoFileName;
+    std::string                         gcdaFileName;
+    std::string                         textFileName;
+    std::string                         cFileName;
     functions_t                         functions;
 
 
@@ -128,7 +130,7 @@ struct gcov_statistics
      *  @return true if read was succesfull, false otherwise
      */
     bool readFrame(
-      FILE*       gcovFile
+      std::ifstream*       gcovFile
     );
 
     /*!
@@ -140,8 +142,8 @@ struct gcov_statistics
      *  @return Returns length of words read (word = 32bit) or -1 if error ocurred
      */
     int readString(
-      char*       buffer,
-      FILE*       gcovFile
+      char*                buffer,
+      std::ifstream*       gcovFile
     );
 
     /*!
@@ -155,7 +157,7 @@ struct gcov_statistics
      */
     int readFrameHeader(
       gcov_frame_header*  header,
-      FILE*               gcovFile
+      std::ifstream*      gcovFile
     );
 
     /*!
@@ -170,7 +172,7 @@ struct gcov_statistics
      */
     int readFilePreamble(
       gcov_preamble*      preamble,
-      FILE*               gcovFile,
+      std::ifstream*      gcovFile,
       const uint32_t      desiredMagic
     );
 
@@ -185,7 +187,7 @@ struct gcov_statistics
      */
     bool readFunctionFrame(
       gcov_frame_header   header,
-      FILE*               gcovFile,
+      std::ifstream*      gcovFile,
       GcovFunctionData*   function
     );
 
@@ -193,7 +195,7 @@ struct gcov_statistics
      *  This method prints info about previously read *.gcno file
      *  to a specified report file
      */
-    void printGcnoFileInfo( FILE * textFile );
+    void printGcnoFileInfo( std::ofstream* textFile );
   };
 }
 #endif
diff --git a/tester/covoar/GcovFunctionData.cc b/tester/covoar/GcovFunctionData.cc
index 90b1be0..850f68e 100644
--- a/tester/covoar/GcovFunctionData.cc
+++ b/tester/covoar/GcovFunctionData.cc
@@ -44,57 +44,47 @@ namespace Gcov {
     firstLineNumber = lineNo;
   }
 
-  bool GcovFunctionData::setFunctionName( const char* fcnName )
+  bool GcovFunctionData::setFunctionName( const std::string& fcnName )
   {
-    std::string   symbolName;
+    std::string  symbolName;
 
     symbolName = fcnName;
 
-    if ( strlen(fcnName) >= FUNCTION_NAME_LENGTH ) {
-      fprintf(
-        stderr,
-        "ERROR: Function name is too long to be correctly stored: %u\n",
-        (unsigned int) strlen(fcnName)
-      );
+    if ( fcnName.length() >= FUNCTION_NAME_LENGTH ) {
+      std::cerr << "ERROR: Function name is too long to be correctly stored: "
+                << fcnName.length() << std::endl;
       return false;
     }
 
-    strcpy (functionName, fcnName);
+    functionName = fcnName;
 
     // Tie function to its coverage map
     symbolInfo = SymbolsToAnalyze->find( symbolName );
-    if ( symbolInfo != NULL )
+    if ( symbolInfo != NULL ) {
       coverageMap = symbolInfo->unifiedCoverageMap;
+    }
 
 #if 0
-    if ( coverageMap == NULL) {
-      fprintf(
-        stderr,
-        "ERROR: Could not find coverage map for: %s\n",
-        symbolName.c_str()
-      );
+    if ( coverageMap == NULL ) {
+      std::cerr << "ERROR: Could not find coverage map for: " << symbolName
+                << std::endl;
     } else {
-      fprintf(
-        stderr,
-        "SUCCESS: Hound coverage map for: %s\n",
-        symbolName.c_str()
-      );
-   }
+      std::cerr << "SUCCESS: Found coverage map for: " << symbolName
+                << std::endl;
+    }
 #endif
 
     return true;
   }
 
-  bool GcovFunctionData::setFileName( const char* fileName ) {
-    if ( strlen(fileName) >= FILE_NAME_LENGTH ){
-      fprintf(
-        stderr,
-        "ERROR: File name is too long to be correctly stored: %u\n",
-        (unsigned int) strlen(fileName)
-      );
+  bool GcovFunctionData::setFileName( const std::string fileName ) {
+    if ( fileName.length() >= FILE_NAME_LENGTH ) {
+      std::cerr << "ERROR: File name is too long to be correctly stored: "
+                << fileName.length() << std::endl;
       return false;
     }
-    strcpy (sourceFileName, fileName);
+
+    sourceFileName = fileName;
     return true;
   }
 
@@ -114,10 +104,10 @@ namespace Gcov {
   }
 
   void GcovFunctionData::getCounters(
-    uint64_t* counterValues,
-    uint32_t &countersFound,
-    uint64_t &countersSum,
-    uint64_t &countersMax
+    uint64_t*  counterValues,
+    uint32_t&  countersFound,
+    uint64_t&  countersSum,
+    uint64_t&  countersMax
   )
   {
     arcs_iterator_t  currentArc;
@@ -129,19 +119,25 @@ namespace Gcov {
 
     // Locate relevant counters and copy their values
     i = 0;
-    for(
+    for (
       currentArc = arcs.begin();
       currentArc != arcs.end();
       currentArc++
     )
     {
-      if ( currentArc->flags == 0 || currentArc->flags == 2 ||
-           currentArc->flags == 4 ) {
+      if (
+        currentArc->flags == 0 ||
+        currentArc->flags == 2 ||
+        currentArc->flags == 4
+      ) {
         countersFound++;
         countersSum += currentArc->counter;
         counterValues[i] = currentArc->counter;
-        if ( countersMax <= currentArc->counter)
+
+        if ( countersMax <= currentArc->counter) {
           countersMax = currentArc->counter;
+        }
+
         i++;
       }
     }
@@ -171,120 +167,122 @@ namespace Gcov {
   void GcovFunctionData::addBlock(
     const uint32_t  id,
     const uint32_t  flags,
-    const char *    sourceFileName
+    const char*     sourceFileName
   )
   {
     gcov_block_info block;
 
     numberOfBlocks++;
-    block.id    = id;
+    block.id = id;
     block.flags = flags;
     block.numberOfLines = 0;
     block.counter = 0;
-    strcpy (block.sourceFileName, sourceFileName);
-    blocks.push_back(block);
+    strcpy( block.sourceFileName, sourceFileName );
+    blocks.push_back( block );
   }
 
   void GcovFunctionData::printFunctionInfo(
-    FILE * textFile,
-    uint32_t function_number
+    std::ofstream*  textFile,
+    uint32_t        function_number
   )
   {
     blocks_iterator_t  currentBlock;
     arcs_iterator_t    currentArc;
 
-    fprintf(
-      textFile,
-      "\n\n=========================="
-      "FUNCTION %3d "
-      "==========================\n\n",
-      function_number
-    );
-    fprintf(
-      textFile,
-      "Name:      %s\n"
-      "File:      %s\n"
-      "Line:      %u\n"
-      "Id:        %u\n"
-      "Checksum:  0x%x\n\n",
-      functionName,
-      sourceFileName,
-      firstLineNumber,
-      id,
-      checksum
-    );
+    (*textFile) << "\n\n=========================="
+                << "FUNCTION  " << std::setw( 3 ) << function_number
+                << "=========================="
+                << std::endl << std::endl
+                << "Name:      " << functionName << std::endl
+                << "File:      " << sourceFileName << std::endl
+                << "Line:      " << firstLineNumber << std::endl
+                << "Id:        " << id << std::endl
+                << "Checksum:  0x" << std::hex << checksum
+                << std::endl << std::endl << std::dec;
 
     // Print arcs info
-    for ( currentArc = arcs.begin(); currentArc != arcs.end(); currentArc++ ) {
+    for (
+      currentArc = arcs.begin();
+      currentArc != arcs.end();
+      currentArc++
+    ) {
       printArcInfo( textFile, currentArc );
     }
-    fprintf( textFile, "\n");
+    (*textFile) << std::endl;
 
     // Print blocks info
-    for ( currentBlock = blocks.begin();
-          currentBlock != blocks.end();
-          currentBlock++
+    for (
+      currentBlock = blocks.begin();
+      currentBlock != blocks.end();
+      currentBlock++
     ) {
       printBlockInfo( textFile, currentBlock );
     }
   }
 
   void GcovFunctionData::printCoverageInfo(
-    FILE     *textFile,
-    uint32_t  function_number
+    std::ofstream*  textFile,
+    uint32_t        function_number
   )
   {
     uint32_t        baseAddress = 0;
     uint32_t        baseSize;
     uint32_t        currentAddress;
-    std::list<Coverage::ObjdumpProcessor::objdumpLine_t>::iterator   instruction;
+    std::list<Coverage::ObjdumpProcessor::objdumpLine_t>::iterator instruction;
 
     if ( coverageMap != NULL ) {
 
-      for (instruction = symbolInfo->instructions.begin();
-           instruction != symbolInfo->instructions.end();
-           instruction++) {
+      for (
+        instruction = symbolInfo->instructions.begin();
+        instruction != symbolInfo->instructions.end();
+        instruction++
+      ) {
         if( instruction->isInstruction ) {
           baseAddress = instruction->address;
           break;
         }
       }
-      baseSize   = coverageMap->getSize();
-
-      fprintf(
-        textFile,
-        "\nInstructions (Base address: 0x%08x, Size: %4u): \n\n",
-        baseAddress,
-        baseSize
-      );
-      for ( instruction = symbolInfo->instructions.begin();
-            instruction != symbolInfo->instructions.end();
-            instruction++
-      )
-      {
+      baseSize = coverageMap->getSize();
+
+      (*textFile) << "\nInstructions (Base address: 0x"
+                  << std::setfill('0') << std::setw( 8 )
+                  << std::hex << baseAddress << std::dec << std::setfill(' ')
+                  << ", Size: " << std::setw( 4 ) << baseSize
+                  << "):" << std::endl << std::endl;
+
+      for (
+        instruction = symbolInfo->instructions.begin();
+        instruction != symbolInfo->instructions.end();
+        instruction++
+      ) {
         if ( instruction->isInstruction ) {
           currentAddress = instruction->address - baseAddress;
-          fprintf( textFile, "0x%-70s ", instruction->line.c_str() );
-          fprintf( textFile, "| 0x%08x ",   currentAddress );
-          fprintf( textFile, "*");
-          fprintf( textFile,
-                    "| exec: %4u ",
-                    coverageMap->getWasExecuted( currentAddress )
-          );
-          fprintf( textFile, "| taken/not: %4u/%4u ",
-                    coverageMap->getWasTaken( currentAddress ),
-                    coverageMap->getWasNotTaken( currentAddress )
-          );
-
-          if ( instruction->isBranch )
-            fprintf( textFile, "| Branch " );
-          else
-            fprintf( textFile, "         " );
 
-          if ( instruction->isNop )
-            fprintf( textFile, "| NOP(%3u) \n", instruction->nopSize );
-          else
-            fprintf( textFile, "           \n" );
+          (*textFile) << std::left << "0x" << std::setw( 70 )
+                      << instruction->line.c_str() << " " << std::right
+                      << "| 0x" << std::hex << std::setfill('0')
+                      << std::setw( 8 ) << currentAddress << " "
+                      << std::dec << std::setfill(' ')
+                      << "*| exec: " << std::setw( 4 )
+                      << coverageMap->getWasExecuted( currentAddress )
+                      << " | taken/not: " << std::setw( 4 )
+                      << coverageMap->getWasTaken( currentAddress )
+                      << "/" << std::setw( 4 )
+                      << coverageMap->getWasNotTaken( currentAddress )
+                      << " ";
+
+          if ( instruction->isBranch ) {
+            (*textFile) << "| Branch ";
+          } else {
+            (*textFile) << "         ";
+          }
+
+          if ( instruction->isNop ) {
+            (*textFile) << "| NOP(" << std::setw( 3 ) << instruction->nopSize
+                        << ") " << std::endl;
+          } else {
+            (*textFile) << "           " << std::endl;
+          }
         }
       }
     }
@@ -292,10 +290,10 @@ namespace Gcov {
 
   void GcovFunctionData::setBlockFileName(
     const blocks_iterator_t  block,
-    const char               *fileName
+    const char*              fileName
   )
   {
-    strcpy(block->sourceFileName, fileName);
+    strcpy( block->sourceFileName, fileName );
   }
 
   void GcovFunctionData::addBlockLine(
@@ -303,99 +301,98 @@ namespace Gcov {
     const uint32_t           line
   )
   {
-    block->lines.push_back(line);
+    block->lines.push_back( line );
     (block->numberOfLines)++;
   }
 
   blocks_iterator_t GcovFunctionData::findBlockById(
-    const uint32_t    id
+    const uint32_t  id
   )
   {
     blocks_iterator_t blockIterator;
 
     if ( !blocks.empty() ) {
       blockIterator = blocks.begin();
-      while ( blockIterator != blocks.end() ){
-        if ( blockIterator->id ==  id)
+      while ( blockIterator != blocks.end() ) {
+        if ( blockIterator->id == id) {
           break;
+        }
+
         blockIterator++;
       }
     } else {
-      fprintf(
-        stderr,
-        "ERROR: GcovFunctionData::findBlockById() failed, no blocks present\n"
-      );
+      std::cerr << "ERROR: GcovFunctionData::findBlockById() failed"
+                << ", no blocks present" << std::endl;
     }
+
     return blockIterator;
   }
 
   void GcovFunctionData::printArcInfo(
-                FILE * textFile, arcs_iterator_t arc
+    std::ofstream*   textFile,
+    arcs_iterator_t  arc
   )
   {
-    fprintf(
-      textFile,
-      " > ARC %3u -> %3u ",
-      arc->sourceBlock,
-      arc->destinationBlock
-    );
-
-    fprintf( textFile, "\tFLAGS: ");
-    switch ( arc->flags ){
+    (*textFile) << " > ARC " << std::setw( 3 ) << arc->sourceBlock
+                << " -> " << std::setw( 3 ) << arc->destinationBlock << " ";
+
+    (*textFile) << "\tFLAGS: ";
+    switch ( arc->flags ) {
       case 0:
-        fprintf( textFile, "( ___________ ____ _______ )");
+        (*textFile) << "( ___________ ____ _______ )";
         break;
       case 1:
-        fprintf( textFile, "( ___________ ____ ON_TREE )");
+        (*textFile) << "( ___________ ____ ON_TREE )";
         break;
       case 2:
-        fprintf( textFile, "( ___________ FAKE _______ )");
+        (*textFile) << "( ___________ FAKE _______ )";
         break;
       case 3:
-        fprintf( textFile, "( ___________ FAKE ON_TREE )");
+        (*textFile) << "( ___________ FAKE ON_TREE )";
         break;
       case 4:
-        fprintf( textFile, "( FALLTHROUGH ____ _______ )");
+        (*textFile) << "( FALLTHROUGH ____ _______ )";
         break;
       case 5:
-        fprintf( textFile, "( FALLTHROUGH ____ ON_TREE )");
+        (*textFile) << "( FALLTHROUGH ____ ON_TREE )";
         break;
       default:
-        fprintf( textFile, "( =======FLAGS_ERROR====== )");
-        fprintf( stderr,
-                " ERROR: Unknown arc flag: 0x%x\n",
-                arcs.back().flags
-        );
+        (*textFile) << "( =======FLAGS_ERROR====== )";
+        std::cerr << " ERROR: Unknown arc flag: 0x"
+                  << std::hex << arcs.back().flags << std::endl
+                  << std::dec;
         break;
     }
-    fprintf( textFile, "\tTaken: %5" PRIu64 "\n", (uint64_t) arc->counter );
+
+    (*textFile) << "\tTaken: " << std::setw( 5 ) << arc->counter << std::endl;
   }
 
   void GcovFunctionData::printBlockInfo(
-    FILE * textFile,
-    blocks_iterator_t block
+    std::ofstream*     textFile,
+    blocks_iterator_t  block
   )
   {
     std::list<uint32_t>::iterator  line;
 
-    fprintf(
-      textFile,
-      " > BLOCK %3u from %s\n"
-      "    -counter: %5" PRIu64 "\n"
-      "    -flags: 0x%" PRIx32 "\n"
-      "    -lines: ",
-      block->id,
-      block->sourceFileName,
-      (uint64_t) block->counter,
-      block->flags
-    );
-    if ( !block->lines.empty( ) )
-      for ( line = block->lines.begin() ; line != block->lines.end(); line++ )
-        fprintf ( textFile, "%u, ", *line);
-    fprintf ( textFile, "\n");
+    (*textFile) << " > BLOCK " << std::setw( 3 ) << block->id
+                << " from " << block->sourceFileName << std::endl
+                << "    -counter: " << std::setw( 5 ) << block->counter << "\n"
+                << "    -flags: 0x" << std::hex << block->flags << std::endl
+                << "    -lines: ";
+
+    if ( !block->lines.empty() )
+      for (
+        line = block->lines.begin() ;
+        line != block->lines.end();
+        line++
+      ) {
+        (*textFile) << *line << ", ";
+      }
+
+    (*textFile) << std::endl;
   }
 
-  bool GcovFunctionData::processFunctionCounters( void ) {
+  bool GcovFunctionData::processFunctionCounters() {
 
     uint32_t               baseAddress = 0;
     uint32_t               currentAddress = 0;
@@ -407,14 +404,17 @@ namespace Gcov {
     std::list<uint64_t>    taken;       // List of taken counts for branches
     std::list<uint64_t>    notTaken;    // List of not taken counts for branches
 
-    //fprintf( stderr, "DEBUG: Processing counters for file: %s\n", sourceFileName  );
-    if ( blocks.empty() || arcs.empty() || coverageMap == NULL || symbolInfo->instructions.empty())
-    {
-      //fprintf( stderr,
-      //          "DEBUG: sanity check returned false for function: %s from file: %s\n",
-      //          functionName,
-      //          sourceFileName
-      //);
+    //std::cerr << "DEBUG: Processing counters for file: " << sourceFileName
+    //          << std::endl;
+    if (
+      blocks.empty()      ||
+      arcs.empty()        ||
+      coverageMap == NULL ||
+      symbolInfo->instructions.empty()
+    ) {
+      //std::cerr << "DEBUG: sanity check returned false for function: "
+      //          << functionName << " from file: " << sourceFileName
+      //          << std::endl;
       return false;
     }
 
@@ -430,29 +430,30 @@ namespace Gcov {
     // Find taken/not taken values for branches
     if ( !processBranches( &taken , &notTaken ) )
     {
-      //fprintf( stderr,
-      //          "ERROR: Failed to process branches for function: %s from file: %s\n",
-      //          functionName,
-      //          sourceFileName
-      //);
+      //std::cerr << "ERROR: Failed to process branches for function: "
+      //          << functionName << " from file: " << sourceFileName
+      //          << std::endl;
       return false;
     };
 
     // Process the branching arcs
     while ( blockIterator != blocks.end() ) {
-      //fprintf( stderr, "DEBUG: Processing branches\n" );
+      //std::cerr << "DEBUG: Processing branches" << std::endl;
       while ( arcIterator->sourceBlock != blockIterator->id ) {
         if ( arcIterator == arcs.end() ) {
-          //fprintf( stderr, "ERROR: Unexpectedly runned out of arcs to analyze\n" );
+          //std::cerr << "ERROR: Unexpectedly runned out of arcs to analyze"
+          //          << std::endl;
           return false;
         }
+
         arcIterator++;
         arcIterator2++;
       }
 
       // If no more branches break;
-      if ( arcIterator2 == arcs.end() )
+      if ( arcIterator2 == arcs.end() ) {
         break;
+      }
 
       // If this is a branch without FAKE arcs process it
       if (
@@ -461,15 +462,16 @@ namespace Gcov {
         !( arcIterator2->flags & FAKE_ARC_FLAG )
       ) {
         if ( taken.empty() || notTaken.empty() ) {
-          fprintf(
-            stderr,
-            "ERROR: Branchess missing for function: %s from file: %s\n",
-            functionName,
-            sourceFileName
-          );
+          std::cerr << "ERROR: Branches missing for function: "
+                    << functionName << " from file: " << sourceFileName
+                    << std::endl;
           return false;
         }
-        //fprintf( stderr, "DEBUG: Found true branching arc %3u -> %3u\n", arcIterator->sourceBlock, arcIterator->destinationBlock );
+
+        //std::cerr << "DEBUG: Found true branching arc "
+        //          << std::setw( 3 ) << arcIterator->sourceBlock << " -> "
+        //          << std::setw( 3 ) << arcIteratior->destinationBlock
+        //          << std::endl;
         if ( arcIterator->flags & FALLTHROUGH_ARC_FLAG ) {
           arcIterator->counter = notTaken.front();
           notTaken.pop_front();
@@ -484,16 +486,21 @@ namespace Gcov {
 
         blockIterator2 = blocks.begin();
         //TODO: ADD FAILSAFE
-        while ( arcIterator->destinationBlock != blockIterator2->id)
+        while ( arcIterator->destinationBlock != blockIterator2->id) {
           blockIterator2++;
+        }
+
         blockIterator2->counter += arcIterator->counter;
 
         blockIterator2 = blocks.begin();
         //TODO: ADD FAILSAFE
-        while ( arcIterator2->destinationBlock != blockIterator2->id)
+        while ( arcIterator2->destinationBlock != blockIterator2->id) {
             blockIterator2++;
-          blockIterator2->counter += arcIterator2->counter;
+        }
+
+         blockIterator2->counter += arcIterator2->counter;
       }
+
       blockIterator++;
     }
 
@@ -510,7 +517,8 @@ namespace Gcov {
     while ( blockIterator != blocks.end() ) {
       while ( arcIterator->sourceBlock != blockIterator->id ) {
         if ( arcIterator == arcs.end() ) {
-          fprintf( stderr, "ERROR: Unexpectedly runned out of arcs to analyze\n" );
+          std::cerr << "ERROR: Unexpectedly runned out of arcs to analyze"
+                    << std::endl;
           return false;
         }
         arcIterator++;
@@ -519,37 +527,48 @@ namespace Gcov {
 
       // If this is the last arc, propagate counter and exit
       if ( arcIterator2 == arcs.end() ) {
-        //fprintf( stderr,
-        //        "DEBUG: Found last arc %3u -> %3u\n",
-        //        arcIterator->sourceBlock,
-        //        arcIterator->destinationBlock
+        //std::cerr << "DEBUG: Found last arc " << std::setw( 3 )
+        //          << arcIterator->sourceBlock << " -> " << std::setw( 3 )
+        //          << arcIterator->destinationBlock << std::endl;
         //);
         arcIterator->counter = blockIterator->counter;
         blockIterator2 =  blocks.begin();
-        while ( arcIterator->destinationBlock != blockIterator2->id)  //TODO: ADD FAILSAFE
+        while ( arcIterator->destinationBlock != blockIterator2->id) {  //TODO: ADD FAILSAFE
           blockIterator2++;
+        }
         blockIterator2->counter += arcIterator->counter;
+
         return true;
       }
 
       // If this is not a branch, propagate counter and continue
       if ( arcIterator->sourceBlock != arcIterator2->sourceBlock ) {
-        //fprintf( stderr, "DEBUG: Found simple arc %3u -> %3u\n", arcIterator->sourceBlock, arcIterator->destinationBlock );
+        //std::cerr << "DEBUG: Found simple arc " << std::setw( 3 )
+        //          << arcIterator->sourceBlock << " -> " << std::setw( 3 )
+        //          << arcIterator->destinationBlock << std::endl;
         arcIterator->counter = blockIterator->counter;
         blockIterator2 =  blocks.begin();;
-        while ( arcIterator->destinationBlock != blockIterator2->id) //TODO: ADD FAILSAFE
+        while ( arcIterator->destinationBlock != blockIterator2->id) { //TODO: ADD FAILSAFE
           blockIterator2++;
+        }
+
         blockIterator2->counter += arcIterator->counter;
       }
 
       // If this is  a branch with FAKE arc
-      else if ( (arcIterator->sourceBlock == arcIterator2->sourceBlock ) && ( arcIterator2->flags & FAKE_ARC_FLAG ))
-      {
-        //fprintf( stderr, "DEBUG: Found fake branching arc %3u -> %3u\n", arcIterator->sourceBlock, arcIterator->destinationBlock );
+      else if (
+        (arcIterator->sourceBlock == arcIterator2->sourceBlock ) &&
+        (arcIterator2->flags & FAKE_ARC_FLAG )
+      ) {
+        //std::cerr << "DEBUG: Found fake branching arc " << std::setw( 3 )
+        //          << arcIterator->sourceBlock << " -> " << std::setw( 3 )
+        //          << arcIterator->destinationBlock << std::endl;
         arcIterator->counter = blockIterator->counter;
         blockIterator2 =  blocks.begin();
-        while ( arcIterator->destinationBlock != blockIterator2->id) //TODO: ADD FAILSAFE
+        while ( arcIterator->destinationBlock != blockIterator2->id) { //TODO: ADD FAILSAFE
           blockIterator2++;
+        }
+
         blockIterator2->counter += arcIterator->counter;
       }
 
@@ -561,37 +580,53 @@ namespace Gcov {
   }
 
   bool GcovFunctionData::processBranches(
-            std::list<uint64_t> * taken ,
-            std::list<uint64_t> * notTaken
+    std::list<uint64_t>*  taken ,
+    std::list<uint64_t>*  notTaken
   )
   {
     uint32_t        baseAddress = 0;
     uint32_t        currentAddress;
     std::list<Coverage::ObjdumpProcessor::objdumpLine_t>::iterator   instruction;
 
-    if ( coverageMap == NULL )
+    if ( coverageMap == NULL ) {
       return false;
+    }
 
     //baseAddress = coverageMap->getFirstLowAddress();      //symbolInfo->baseAddress;
-    for (instruction = symbolInfo->instructions.begin(); instruction != symbolInfo->instructions.end(); instruction++)
+    for (
+      instruction = symbolInfo->instructions.begin();
+      instruction != symbolInfo->instructions.end();
+      instruction++
+    ) {
       if( instruction->isInstruction ) {
         baseAddress = instruction->address;
         break;
       }
+    }
 
-    //fprintf( stderr, "DEBUG: Processing instructions in search of branches\n" );
-    for (instruction = symbolInfo->instructions.begin(); instruction != symbolInfo->instructions.end(); instruction++)
-    {
-      if ( instruction->isInstruction) {
+    // std::cerr << "DEBUG: Processing instructions in search of branches"
+    //           << std::endl
+    for (
+      instruction = symbolInfo->instructions.begin();
+      instruction != symbolInfo->instructions.end();
+      instruction++
+    ) {
+      if ( instruction->isInstruction ) {
         currentAddress = instruction-> address - baseAddress;
         if ( instruction->isBranch ) {
-          taken->push_back ( (uint64_t) coverageMap->getWasTaken( currentAddress  ) );
-          notTaken->push_back ( (uint64_t) coverageMap->getWasNotTaken( currentAddress ) );
-          //fprintf( stderr,
-          //          "Added branch to list taken/not: %4u/%4u\n",
-          //          coverageMap->getWasTaken( currentAddress ),
-          //          coverageMap->getWasNotTaken( currentAddress )
-          //);
+          taken->push_back(
+            (uint64_t) coverageMap->getWasTaken( currentAddress )
+          );
+
+          notTaken->push_back(
+            (uint64_t) coverageMap->getWasNotTaken( currentAddress )
+          );
+
+          //std::cerr << "Added branch to list taken/not: " << std::setw( 4 )
+          //          << coverageMap->getWasTaken( currentAddress )
+          //          << "/" << std::setw( 4 )
+          //          << coverageMap->getWasNotTaken( currentAddress )
+          //          << std::endl;
         }
       }
     }
diff --git a/tester/covoar/GcovFunctionData.h b/tester/covoar/GcovFunctionData.h
index 812b45c..4065e17 100644
--- a/tester/covoar/GcovFunctionData.h
+++ b/tester/covoar/GcovFunctionData.h
@@ -9,6 +9,8 @@
 
 #include <stdint.h>
 #include <list>
+#include <fstream>
+#include <iomanip>
 #include "CoverageMapBase.h"
 #include "DesiredSymbols.h"
 
@@ -23,20 +25,20 @@ namespace Gcov {
 
 struct gcov_arc_info
 {
-  uint32_t    sourceBlock;
-  uint32_t    destinationBlock;
-  uint32_t    flags;
-  uint64_t    counter;
+  uint32_t                        sourceBlock;
+  uint32_t                        destinationBlock;
+  uint32_t                        flags;
+  uint64_t                        counter;
 };
 
 struct gcov_block_info
 {
-  uint32_t                    id;
-  uint32_t                    flags;
-  uint32_t                    numberOfLines;
-  uint64_t                    counter;
-  char                        sourceFileName[FILE_NAME_LENGTH];
-  std::list<uint32_t>         lines;
+  uint32_t                        id;
+  uint32_t                        flags;
+  uint32_t                        numberOfLines;
+  uint64_t                        counter;
+  char                            sourceFileName[FILE_NAME_LENGTH];
+  std::list<uint32_t>             lines;
 };
 
 typedef std::list<gcov_arc_info>                arcs_t;
@@ -98,7 +100,7 @@ typedef std::list<gcov_block_info>::iterator    blocks_iterator_t;
      *  @return Returns TRUE if the method succeeded and FALSE if it failed.
      */
     bool setFunctionName(
-      const char*                 fcnName
+      const std::string&          fcnName
     );
 
     /*!
@@ -109,7 +111,7 @@ typedef std::list<gcov_block_info>::iterator    blocks_iterator_t;
      *  @return Returns TRUE if the method succeeded and FALSE if it failed.
      */
     bool setFileName(
-      const char*                 fileName
+      const std::string           fileName
     );
 
     /*!
@@ -121,8 +123,8 @@ typedef std::list<gcov_block_info>::iterator    blocks_iterator_t;
      *  @return Returns TRUE if the method succeeded and FALSE if it failed.
      */
     void setBlockFileName(
-      const blocks_iterator_t             block,
-      const char*                         fileName
+      const blocks_iterator_t     block,
+      const char*                 fileName
     );
 
     /*!
@@ -154,10 +156,10 @@ typedef std::list<gcov_block_info>::iterator    blocks_iterator_t;
      *  @param[out] countersMax used to return max counter value
      */
     void getCounters(
-      uint64_t* counterValues,
-      uint32_t &countersFound,
-      uint64_t &countersSum,
-      uint64_t &countersMax
+      uint64_t*                   counterValues,
+      uint32_t&                   countersFound,
+      uint64_t&                   countersSum,
+      uint64_t&                   countersMax
     );
 
     /*!
@@ -167,9 +169,9 @@ typedef std::list<gcov_block_info>::iterator    blocks_iterator_t;
      *  @param[in] destination passes destination block number
      */
     void addArc(
-      uint32_t    source,
-      uint32_t    destination,
-      uint32_t    flags
+      uint32_t                    source,
+      uint32_t                    destination,
+      uint32_t                    flags
     );
 
     /*!
@@ -210,12 +212,18 @@ typedef std::list<gcov_block_info>::iterator    blocks_iterator_t;
     /*!
      *  This method prints info about function
      */
-    void printFunctionInfo( FILE * textFile, uint32_t function_number );
+    void printFunctionInfo(
+      std::ofstream*              textFile,
+      uint32_t                    function_number
+    );
 
     /*!
      *  This method prints info about coverage of this function
      */
-    void printCoverageInfo( FILE * textFile, uint32_t function_number );
+    void printCoverageInfo(
+      std::ofstream*              textFile,
+      uint32_t                    function_number
+    );
 
     /*!
      *  This method prints info about chosen arc in arcs list
@@ -224,8 +232,8 @@ typedef std::list<gcov_block_info>::iterator    blocks_iterator_t;
      *  @param[in] arc passes iterator identifying arc
      */
     void printArcInfo(
-      FILE * textFile,
-      arcs_iterator_t arc
+      std::ofstream*              textFile,
+      arcs_iterator_t             arc
     );
 
     /*!
@@ -234,14 +242,14 @@ typedef std::list<gcov_block_info>::iterator    blocks_iterator_t;
      *  @param[in] block passes iterator identifying block
      */
     void printBlockInfo(
-      FILE * textFile,
-      blocks_iterator_t block
+      std::ofstream*              textFile,
+      blocks_iterator_t           block
     );
 
     /*!
      *  This method calculates values of arc counters
      */
-    bool processFunctionCounters( void );
+    bool processFunctionCounters();
 
   private:
 
@@ -252,15 +260,15 @@ typedef std::list<gcov_block_info>::iterator    blocks_iterator_t;
     uint32_t            numberOfArcs;
     arcs_t              arcs;
     blocks_t            blocks;
-    char                functionName[FUNCTION_NAME_LENGTH];
-    char                sourceFileName[FILE_NAME_LENGTH];
+    std::string         functionName;
+    std::string         sourceFileName;
 
     /*!
      *  This member contains the unified or merged coverage map
      *  and symbol info for the symbol.
      */
-    Coverage::CoverageMapBase*          coverageMap;
-    Coverage::SymbolInformation*        symbolInfo;
+    Coverage::CoverageMapBase*    coverageMap;
+    Coverage::SymbolInformation*  symbolInfo;
 
     /*!
      *  This method creates list of taken/not taken values
@@ -270,8 +278,8 @@ typedef std::list<gcov_block_info>::iterator    blocks_iterator_t;
      *  @param[in] notTaken   used to return not taken counts list
      */
     bool processBranches(
-      std::list<uint64_t> * taken,
-      std::list<uint64_t> * notTaken
+      std::list<uint64_t>*        taken,
+      std::list<uint64_t>*        notTaken
     );
   };
 
-- 
1.8.3.1



More information about the devel mailing list