covoar: Add information to improve diagnostics.

This commit is contained in:
Hermann Felbinger
2017-08-26 09:15:53 +01:00
committed by Chris Johns
parent b857151112
commit cb018bcdff
9 changed files with 67 additions and 38 deletions

View File

@@ -10,9 +10,10 @@
namespace Coverage { namespace Coverage {
CoverageMap::CoverageMap( CoverageMap::CoverageMap(
uint32_t low, const std::string& exefileName,
uint32_t high uint32_t low,
) : CoverageMapBase(low, high) uint32_t high
) : CoverageMapBase(exefileName, low, high)
{ {
} }

View File

@@ -27,8 +27,9 @@ namespace Coverage {
* @param[in] high specifies the highest address of the coverage map. * @param[in] high specifies the highest address of the coverage map.
*/ */
CoverageMap( CoverageMap(
uint32_t low, const std::string& exefileName,
uint32_t high uint32_t low,
uint32_t high
); );
/* Inherit documentation from base class. */ /* Inherit documentation from base class. */

View File

@@ -16,13 +16,15 @@
namespace Coverage { namespace Coverage {
CoverageMapBase::CoverageMapBase( CoverageMapBase::CoverageMapBase(
uint32_t low, const std::string& exefileName,
uint32_t high uint32_t low,
uint32_t high
) )
{ {
uint32_t a; uint32_t a;
AddressRange_t range; AddressRange_t range;
range.fileName = exefileName;
range.lowAddress = low; range.lowAddress = low;
range.highAddress = high; range.highAddress = high;
RangeList.push_back( range ); RangeList.push_back( range );

View File

@@ -27,6 +27,11 @@ namespace Coverage {
* range per symbol. * range per symbol.
*/ */
typedef struct { typedef struct {
/*!
* This is the file from which this originated.
*/
std::string fileName;
/*! /*!
* This is the low address of the address map range. * This is the low address of the address map range.
*/ */
@@ -48,12 +53,14 @@ namespace Coverage {
/*! /*!
* This method constructs a CoverageMapBase instance. * This method constructs a CoverageMapBase instance.
* *
* @param[in] exefileName specifies the executable this originated in
* @param[in] low specifies the lowest address of the coverage map * @param[in] low specifies the lowest address of the coverage map
* @param[in] high specifies the highest address of the coverage map * @param[in] high specifies the highest address of the coverage map
*/ */
CoverageMapBase( CoverageMapBase(
uint32_t low, const std::string& exefileName,
uint32_t high uint32_t low,
uint32_t high
); );
/*! /*!

View File

@@ -335,6 +335,7 @@ namespace Coverage {
void DesiredSymbols::createCoverageMap( void DesiredSymbols::createCoverageMap(
const std::string& exefileName,
const std::string& symbolName, const std::string& symbolName,
uint32_t size uint32_t size
) )
@@ -363,19 +364,27 @@ namespace Coverage {
// ensure that the specified size matches the existing size. // ensure that the specified size matches the existing size.
if (itr->second.stats.sizeInBytes != size) { if (itr->second.stats.sizeInBytes != size) {
// Changed ERROR to INFO because size mismatch is not treated as
// error anymore.
// Set smallest size as size and continue.
// Update value for longer byte size.
// 2015-07-22
fprintf( fprintf(
stderr, stderr,
"ERROR: DesiredSymbols::createCoverageMap - Attempt to create " "INFO: DesiredSymbols::createCoverageMap - Attempt to create "
"unified coverage maps for %s with different sizes (%d != %d)\n", "unified coverage maps for %s with different sizes (%s/%d != %s/%d)\n",
symbolName.c_str(), symbolName.c_str(),
exefileName.c_str(),
itr->second.stats.sizeInBytes, itr->second.stats.sizeInBytes,
itr->second.sourceFile->getFileName().c_str(),
size size
); );
if ( itr->second.stats.sizeInBytes < size ) if ( itr->second.stats.sizeInBytes < size )
itr->second.stats.sizeInBytes = size; itr->second.stats.sizeInBytes = size;
else else
size = itr->second.stats.sizeInBytes; size = itr->second.stats.sizeInBytes;
// exit( -1 );
} }
} }
@@ -384,13 +393,14 @@ namespace Coverage {
highAddress = size - 1; highAddress = size - 1;
aCoverageMap = new CoverageMap( 0, highAddress ); aCoverageMap = new CoverageMap( exefileName, 0, highAddress );
if (!aCoverageMap) { if (!aCoverageMap) {
fprintf( fprintf(
stderr, stderr,
"ERROR: DesiredSymbols::createCoverageMap - Unable to allocate " "ERROR: DesiredSymbols::createCoverageMap - Unable to allocate "
"coverage map for %s\n", "coverage map for %s:%s\n",
exefileName.c_str(),
symbolName.c_str() symbolName.c_str()
); );
exit( -1 ); exit( -1 );
@@ -653,6 +663,8 @@ namespace Coverage {
// Ensure that the source and destination coverage maps // Ensure that the source and destination coverage maps
// are the same size. // are the same size.
// Changed from ERROR msg to INFO, because size mismatch is not
// treated as error anymore. 2015-07-20
dMapSize = itr->second.stats.sizeInBytes; dMapSize = itr->second.stats.sizeInBytes;
sBaseAddress = sourceCoverageMap->getFirstLowAddress(); sBaseAddress = sourceCoverageMap->getFirstLowAddress();
sMapSize = sourceCoverageMap->getSize(); sMapSize = sourceCoverageMap->getSize();
@@ -660,12 +672,11 @@ namespace Coverage {
fprintf( fprintf(
stderr, stderr,
"ERROR: DesiredSymbols::mergeCoverageMap - Unable to merge " "INFO: DesiredSymbols::mergeCoverageMap - Unable to merge "
"coverage map for %s because the sizes are different\n", "coverage map for %s because the sizes are different\n",
symbolName.c_str() symbolName.c_str()
); );
return; return;
// exit( -1 );
} }
// Merge the data for each address. // Merge the data for each address.

View File

@@ -20,8 +20,8 @@
namespace Coverage { namespace Coverage {
/*! /*!
* *
* This class defines the statistics that are tracked. * This class defines the statistics that are tracked.
*/ */
class Statistics { class Statistics {
@@ -34,7 +34,7 @@ namespace Coverage {
int branchesAlwaysTaken; int branchesAlwaysTaken;
/*! /*!
* This member variable contains the total number of branches where * This member variable contains the total number of branches where
* one or more paths were executed. * one or more paths were executed.
*/ */
int branchesExecuted; int branchesExecuted;
@@ -55,7 +55,7 @@ namespace Coverage {
* This member contains the size in Bytes. * This member contains the size in Bytes.
*/ */
uint32_t sizeInBytes; uint32_t sizeInBytes;
/*! /*!
* This member contains the size in Bytes. * This member contains the size in Bytes.
*/ */
@@ -93,7 +93,7 @@ namespace Coverage {
/*! /*!
* This method constructs a Statistics instance. * This method constructs a Statistics instance.
*/ */
Statistics(): Statistics():
branchesAlwaysTaken(0), branchesAlwaysTaken(0),
branchesExecuted(0), branchesExecuted(0),
@@ -137,7 +137,7 @@ namespace Coverage {
/*! /*!
* This member contains the statistics kept on each symbol. * This member contains the statistics kept on each symbol.
*/ */
Statistics stats; Statistics stats;
/*! /*!
@@ -186,24 +186,24 @@ namespace Coverage {
typedef std::map<std::string, SymbolInformation> symbolSet_t; typedef std::map<std::string, SymbolInformation> symbolSet_t;
/*! /*!
* This variable contains a map of symbol sets for each * This variable contains a map of symbol sets for each
* symbol in the system keyed on the symbol name. * symbol in the system keyed on the symbol name.
*/ */
symbolSet_t set; symbolSet_t set;
/*! /*!
* This method constructs a DesiredSymbols instance. * This method constructs a DesiredSymbols instance.
*/ */
DesiredSymbols(); DesiredSymbols();
/*! /*!
* This method destructs a DesiredSymbols instance. * This method destructs a DesiredSymbols instance.
*/ */
~DesiredSymbols(); ~DesiredSymbols();
/*! /*!
* This method loops through the coverage map and * This method loops through the coverage map and
* calculates the statistics that have not already * calculates the statistics that have not already
* been filled in. * been filled in.
*/ */
void calculateStatistics( void ); void calculateStatistics( void );
@@ -218,11 +218,14 @@ namespace Coverage {
* This method creates a coverage map for the specified symbol * This method creates a coverage map for the specified symbol
* using the specified size. * using the specified size.
* *
* @param[in] exefileName specifies the executable from which the
* coverage map is being created
* @param[in] symbolName specifies the symbol for which to create * @param[in] symbolName specifies the symbol for which to create
* a coverage map * a coverage map
* @param[in] size specifies the size of the coverage map to create * @param[in] size specifies the size of the coverage map to create
*/ */
void createCoverageMap( void createCoverageMap(
const std::string& exefileName,
const std::string& symbolName, const std::string& symbolName,
uint32_t size uint32_t size
); );
@@ -316,7 +319,7 @@ namespace Coverage {
/*! /*!
* This member contains the statistics kept on each symbol. * This member contains the statistics kept on each symbol.
*/ */
Statistics stats; Statistics stats;
private: private:

View File

@@ -89,6 +89,7 @@ namespace Coverage {
} }
CoverageMapBase* ExecutableInfo::createCoverageMap ( CoverageMapBase* ExecutableInfo::createCoverageMap (
const std::string& fileName,
const std::string& symbolName, const std::string& symbolName,
uint32_t lowAddress, uint32_t lowAddress,
uint32_t highAddress uint32_t highAddress
@@ -99,7 +100,7 @@ namespace Coverage {
itr = coverageMaps.find( symbolName ); itr = coverageMaps.find( symbolName );
if ( itr == coverageMaps.end() ) { if ( itr == coverageMaps.end() ) {
theMap = new CoverageMap( lowAddress, highAddress ); theMap = new CoverageMap( fileName, lowAddress, highAddress );
coverageMaps[ symbolName ] = theMap; coverageMaps[ symbolName ] = theMap;
} else { } else {
theMap = itr->second; theMap = itr->second;

View File

@@ -93,6 +93,7 @@ namespace Coverage {
/*! /*!
* This method creates a coverage map for the specified symbol. * This method creates a coverage map for the specified symbol.
* *
* @param[in] exefileName specifies the source of the information
* @param[in] symbolName specifies the name of the symbol * @param[in] symbolName specifies the name of the symbol
* @param[in] lowAddress specifies the low address of the coverage map * @param[in] lowAddress specifies the low address of the coverage map
* @param[in] highAddress specifies the high address of the coverage map * @param[in] highAddress specifies the high address of the coverage map
@@ -100,6 +101,7 @@ namespace Coverage {
* @return Returns a pointer to the coverage map * @return Returns a pointer to the coverage map
*/ */
CoverageMapBase* createCoverageMap ( CoverageMapBase* createCoverageMap (
const std::string& exefileName,
const std::string& symbolName, const std::string& symbolName,
uint32_t lowAddress, uint32_t lowAddress,
uint32_t highAddress uint32_t highAddress

View File

@@ -3,7 +3,7 @@
* *
* This file contains the implementation of the functions supporting * This file contains the implementation of the functions supporting
* the reading of an objdump output file and adding nops to a * the reading of an objdump output file and adding nops to a
* coverage map. * coverage map.
*/ */
#include <assert.h> #include <assert.h>
@@ -97,7 +97,7 @@ namespace Coverage {
// Create a coverage map for the symbol. // Create a coverage map for the symbol.
aCoverageMap = executableInfo->createCoverageMap( aCoverageMap = executableInfo->createCoverageMap(
symbolName, lowAddress, endAddress executableInfo->getFileName().c_str(), symbolName, lowAddress, endAddress
); );
if (aCoverageMap) { if (aCoverageMap) {
@@ -112,7 +112,8 @@ namespace Coverage {
// Create a unified coverage map for the symbol. // Create a unified coverage map for the symbol.
SymbolsToAnalyze->createCoverageMap( SymbolsToAnalyze->createCoverageMap(
symbolName, endAddress - lowAddress + 1 executableInfo->getFileName().c_str(), symbolName,
endAddress - lowAddress + 1
); );
} }
} }
@@ -170,7 +171,7 @@ namespace Coverage {
std::string tmp = inLibName; std::string tmp = inLibName;
if ( tmp.find( Library ) != tmp.npos ) { if ( tmp.find( Library ) != tmp.npos ) {
// fprintf( stderr, "%s - 0x%08x\n", inLibName, offset ); // fprintf( stderr, "%s - 0x%08x\n", inLibName, offset );
address = offset; address = offset;
break; break;
} }
} }
@@ -182,9 +183,9 @@ namespace Coverage {
} }
bool ObjdumpProcessor::IsBranch( bool ObjdumpProcessor::IsBranch(
const char *instruction const char *instruction
) )
{ {
if ( !TargetInfo ) { if ( !TargetInfo ) {
fprintf( fprintf(
stderr, stderr,
@@ -230,7 +231,7 @@ namespace Coverage {
return TargetInfo->isNopLine( line, size ); return TargetInfo->isNopLine( line, size );
} }
FILE* ObjdumpProcessor::getFile( std::string fileName ) FILE* ObjdumpProcessor::getFile( std::string fileName )
{ {
char dumpFile[128]; char dumpFile[128];
FILE* objdumpFile; FILE* objdumpFile;
@@ -238,7 +239,7 @@ namespace Coverage {
int status; int status;
sprintf( dumpFile, "%s.dmp", fileName.c_str() ); sprintf( dumpFile, "%s.dmp", fileName.c_str() );
// Generate the objdump. // Generate the objdump.
if (FileIsNewer( fileName.c_str(), dumpFile )) { if (FileIsNewer( fileName.c_str(), dumpFile )) {
sprintf( sprintf(
@@ -259,7 +260,7 @@ namespace Coverage {
); );
exit( -1 ); exit( -1 );
} }
} }
// Open the objdump file. // Open the objdump file.
objdumpFile = fopen( dumpFile, "r" ); objdumpFile = fopen( dumpFile, "r" );
@@ -283,7 +284,7 @@ namespace Coverage {
if (itr == objdumpList.end()) { if (itr == objdumpList.end()) {
return 0; return 0;
} }
itr++; itr++;
if (itr == objdumpList.end()) { if (itr == objdumpList.end()) {
return 0; return 0;