summaryrefslogtreecommitdiffstats
path: root/tester/covoar
diff options
context:
space:
mode:
Diffstat (limited to 'tester/covoar')
-rw-r--r--tester/covoar/ConfigFile.cc138
-rw-r--r--tester/covoar/ConfigFile.h8
-rw-r--r--tester/covoar/ExecutableInfo.cc103
-rw-r--r--tester/covoar/ExecutableInfo.h16
-rw-r--r--tester/covoar/Explanations.cc51
-rw-r--r--tester/covoar/Explanations.h14
-rw-r--r--tester/covoar/ObjdumpProcessor.cc284
-rw-r--r--tester/covoar/ObjdumpProcessor.h26
-rw-r--r--tester/covoar/ReportsBase.cc79
-rw-r--r--tester/covoar/SymbolTable.cc70
-rw-r--r--tester/covoar/TargetBase.cc35
-rw-r--r--tester/covoar/TargetBase.h18
-rw-r--r--tester/covoar/TargetFactory.cc24
-rw-r--r--tester/covoar/Target_aarch64.cc18
-rw-r--r--tester/covoar/Target_aarch64.h6
-rw-r--r--tester/covoar/Target_arm.cc16
-rw-r--r--tester/covoar/Target_arm.h6
-rw-r--r--tester/covoar/Target_i386.cc22
-rw-r--r--tester/covoar/Target_i386.h4
-rw-r--r--tester/covoar/Target_lm32.cc6
-rw-r--r--tester/covoar/Target_lm32.h4
-rw-r--r--tester/covoar/Target_m68k.cc12
-rw-r--r--tester/covoar/Target_m68k.h6
-rw-r--r--tester/covoar/Target_powerpc.cc8
-rw-r--r--tester/covoar/Target_powerpc.h4
-rw-r--r--tester/covoar/Target_riscv.cc6
-rw-r--r--tester/covoar/Target_riscv.h6
-rw-r--r--tester/covoar/Target_sparc.cc12
-rw-r--r--tester/covoar/Target_sparc.h6
-rw-r--r--tester/covoar/TraceConverter.cc174
-rw-r--r--tester/covoar/TraceList.cc14
31 files changed, 645 insertions, 551 deletions
diff --git a/tester/covoar/ConfigFile.cc b/tester/covoar/ConfigFile.cc
index c16b64a..1fbefd1 100644
--- a/tester/covoar/ConfigFile.cc
+++ b/tester/covoar/ConfigFile.cc
@@ -7,14 +7,21 @@
#include "ConfigFile.h"
#include <string.h>
-#include <stdio.h>
#include <ctype.h>
+#include <iostream>
+#include <fstream>
+#include <sstream>
+
+static void print_invalid_line_number( const std::string& file, int line_no )
+{
+ std::cerr << file << ": line" << line_no << " is invalid: " << line
+ << std::endl;
+}
+
namespace Configuration {
- FileReader::FileReader(
- Options_t *options
- )
+ FileReader::FileReader( Options_t *options )
{
options_m = options;
}
@@ -23,44 +30,40 @@ namespace Configuration {
{
}
- bool FileReader::processFile(
- const char* const file
- )
+ bool FileReader::processFile( const std::string& file )
{
#define METHOD "FileReader::processFile - "
- FILE * in;
- char line[256];
- char option[256];
- char value[256];
- int line_no;
- int i;
- int j;
-
- if ( file == NULL ) {
- fprintf( stderr, METHOD "NULL filename\n" );
+ #define MAX_LENGTH 256
+
+ std::ifstream in;
+ std::string line;
+ char option[MAX_LENGTH];
+ char value[MAX_LENGTH];
+ int line_no;
+ int i;
+ int j;
+
+ if ( file.empty() ) {
+ std::cerr << METHOD << "Empty filename" << std::endl;
return false;
}
- in = fopen( file, "r" );
- if ( !in ) {
- fprintf( stderr, METHOD "unable to open %s\n", file );
+ in.open( file );
+ if ( !in.is_open() ) {
+ std::cerr << METHOD << "unable to open " << file << std::endl;
return false;
}
line_no = 0;
- while (fgets(line, sizeof(line), in) != NULL) {
+ while ( std::getline( line, MAX_LENGTH ) ) {
int length;
line_no++;
- length = (int) strlen( line );
- if ( line[length - 1] != '\n' ) {
- fprintf(
- stderr,
- "%s: line %d is too long",
- file,
- line_no
- );
+ length = (int) line.length();
+ if ( length > MAX_LENGTH ) {
+ std::cerr << file << ": line " << line_no << " is too long"
+ << std::endl;
continue;
}
@@ -72,7 +75,7 @@ namespace Configuration {
*
* LHS = RHS # comment
*/
- for (i=0 ; i<length ; i++ ) {
+ for ( i = 0; i < length; i++ ) {
if ( line[i] == '#' ) {
line[i] = '\0';
length = i;
@@ -83,70 +86,51 @@ namespace Configuration {
/*
* Strip off trailing white space
*/
- for (i=length-1 ; i>=0 && isspace(line[i]) ; i-- )
+ for ( i = length - 1; i >= 0 && isspace( line[i] ); i-- )
;
line[i+1] = '\0';
- length = i+1;
+ length = i + 1;
/* Ignore empty lines. We have stripped
* all comments and blanks therefore, only
* an empty string needs to be checked.
*/
- if (line[0] == '\0')
+ if ( line[0] == '\0' ) {
continue;
+ }
- if (sscanf(line, "%s", option) != 1) {
- fprintf(
- stderr,
- "%s: line %d is invalid: %s\n",
- file,
- line_no,
- line
- );
+ if ( std::sscanf( line.c_str(), "%s", option ) != 1 ) {
+ print_invalid_line_number( file, line_no );
continue;
}
- for (i=0; ((line[i] != '=') && (i<length)); i++)
+ for ( i=0; ( ( line[i] != '=' ) && ( i < length ) ); i++ )
;
- if (i == length) {
- fprintf(
- stderr,
- "%s: line %d is invalid: %s\n",
- file,
- line_no,
- line
- );
+ if ( i == length ) {
+ print_invalid_line_number( file, line_no );
continue;
}
i++;
value[0] = '\0';
- while ( isspace(line[i]) )
+ while ( isspace( line[i] ) ) {
i++;
- for (j=0; line[i] != '\0'; i++, j++ )
+ }
+
+ for ( j = 0; line[i] != '\0'; i++, j++ ) {
value[j] = line[i];
+ }
+
value[j] = '\0';
- if (value[0] == '\0') {
- fprintf(
- stderr,
- "%s: line %d is invalid: %s\n",
- file,
- line_no,
- line
- );
+ if ( value[0] == '\0' ) {
+ print_invalid_line_number( file, line_no );
continue;
}
- if ( !setOption(option, value) ) {
- fprintf(
- stderr,
- "%s: line %d: option %s is unknown\n",
- file,
- line_no,
- option
- );
+ if ( !setOption( option, value ) ) {
+ print_invalid_line_number( file, line_no );
continue;
}
@@ -160,37 +144,37 @@ namespace Configuration {
const char* const value
)
{
- Options_t *o;
+ Options_t* o;
- for ( o=options_m ; o->option ; o++ ) {
+ for ( o = options_m; o->option; o++ ) {
if ( !strcmp( o->option, option ) ) {
o->value = strdup( value );
return true;
}
}
+
return false;
}
- const char *FileReader::getOption(
- const char* const option
- )
+ const char *FileReader::getOption( const char* const option )
{
Options_t *o;
- for ( o=options_m ; o->option ; o++ ) {
+ for ( o = options_m; o->option; o++ ) {
if ( !strcmp( o->option, option ) ) {
return o->value;
}
}
+
return NULL;
}
- void FileReader::printOptions(void)
+ void FileReader::printOptions()
{
Options_t *o;
- for ( o=options_m ; o->option ; o++ ) {
- fprintf( stderr, "(%s)=(%s)\n", o->option, o->value );
+ for ( o = options_m; o->option; o++ ) {
+ std::cerr << '(' << o->option << ")=(" << o->value << ')' << std::endl;
}
}
}
diff --git a/tester/covoar/ConfigFile.h b/tester/covoar/ConfigFile.h
index 0bae7ac..0339c12 100644
--- a/tester/covoar/ConfigFile.h
+++ b/tester/covoar/ConfigFile.h
@@ -53,9 +53,7 @@ namespace Configuration {
*
* @return Returns TRUE if the method succeeded and FALSE if it failed.
*/
- virtual bool processFile(
- const char* const file
- );
+ virtual bool processFile( const std::string& file );
bool setOption(
const char* const option,
@@ -66,7 +64,7 @@ namespace Configuration {
const char* const option
);
- void printOptions(void);
+ void printOptions();
private:
/*!
@@ -78,7 +76,7 @@ namespace Configuration {
*
* @return Returns TRUE if the method succeeded and FALSE if it failed.
*/
- Options_t *options_m;
+ Options_t* options_m;
};
diff --git a/tester/covoar/ExecutableInfo.cc b/tester/covoar/ExecutableInfo.cc
index 418a7f4..5f8584e 100644
--- a/tester/covoar/ExecutableInfo.cc
+++ b/tester/covoar/ExecutableInfo.cc
@@ -21,74 +21,81 @@ namespace Coverage {
const std::string& theLibraryName,
bool verbose,
DesiredSymbols& symbolsToAnalyze
- ) : fileName(theExecutableName),
- loadAddress(0),
- symbolsToAnalyze_m(symbolsToAnalyze)
+ ) : fileName( theExecutableName ),
+ loadAddress( 0 ),
+ symbolsToAnalyze_m( symbolsToAnalyze )
{
- if ( !theLibraryName.empty() )
+ if ( !theLibraryName.empty() ) {
libraryName = theLibraryName;
+ }
- if (verbose) {
+ if ( verbose ) {
std::cerr << "Loading executable " << theExecutableName;
- if ( !theLibraryName.empty() )
+ if ( !theLibraryName.empty() ) {
std::cerr << " (" << theLibraryName << ')';
+ }
+
std::cerr << std::endl;
}
- rld::files::object executable(theExecutableName);
+ rld::files::object executable( theExecutableName );
executable.open();
executable.begin();
- executable.load_symbols(symbols);
+ executable.load_symbols( symbols );
rld::dwarf::file debug;
- debug.begin(executable.elf());
+ debug.begin( executable.elf() );
debug.load_debug();
debug.load_functions();
- for (auto& cu : debug.get_cus()) {
- AddressLineRange& range = mapper.makeRange(cu.pc_low(), cu.pc_high());
+ for ( auto& cu : debug.get_cus() ) {
+ AddressLineRange& range = mapper.makeRange( cu.pc_low(), cu.pc_high() );
// Does not filter on desired symbols under the assumption that the test
// code and any support code is small relative to what is being tested.
- for (const auto &address : cu.get_addresses()) {
- range.addSourceLine(address);
+ for ( const auto &address : cu.get_addresses() ) {
+ range.addSourceLine( address );
}
- for (auto& func : cu.get_functions()) {
- if (!func.has_machine_code()) {
+ for ( auto& func : cu.get_functions() ) {
+ if ( !func.has_machine_code() ) {
continue;
}
- if (!symbolsToAnalyze_m.isDesired(func.name())) {
+ if ( !symbolsToAnalyze_m.isDesired( func.name() ) ) {
continue;
}
- if (func.is_inlined()) {
- if (func.is_external()) {
+ if ( func.is_inlined() ) {
+ if ( func.is_external() ) {
// Flag it
std::cerr << "Function is both external and inlined: "
<< func.name() << std::endl;
}
- if (func.has_entry_pc()) {
+ if ( func.has_entry_pc() ) {
continue;
}
// If the low PC address is zero, the symbol does not appear in
// this executable.
- if (func.pc_low() == 0) {
+ if ( func.pc_low() == 0 ) {
continue;
}
}
// We can't process a zero size function.
- if (func.pc_high() == 0) {
+ if ( func.pc_high() == 0 ) {
continue;
}
- createCoverageMap (cu.name(), func.name(),
- func.pc_low(), func.pc_high() - 1);
+ createCoverageMap(
+ cu.name(),
+ func.name(),
+ func.pc_low(),
+ func.pc_high() - 1
+ );
}
}
}
@@ -97,16 +104,18 @@ namespace Coverage {
{
}
- void ExecutableInfo::dumpCoverageMaps( void ) {
- ExecutableInfo::CoverageMaps::iterator itr;
+ void ExecutableInfo::dumpCoverageMaps()
+ {
+ ExecutableInfo::CoverageMaps::iterator itr;
- for (auto& cm : coverageMaps) {
+ for ( auto& cm : coverageMaps ) {
std::cerr << "Coverage Map for " << cm.first << std::endl;
cm.second->dump();
}
}
- void ExecutableInfo::dumpExecutableInfo( void ){
+ void ExecutableInfo::dumpExecutableInfo()
+ {
std::cout << std::endl
<< "== Executable info ==" << std::endl
<< "executable = " << getFileName () << std::endl
@@ -115,7 +124,7 @@ namespace Coverage {
theSymbolTable.dumpSymbolTable();
}
- CoverageMapBase* ExecutableInfo::getCoverageMap ( uint32_t address )
+ CoverageMapBase* ExecutableInfo::getCoverageMap( uint32_t address )
{
CoverageMapBase* aCoverageMap = NULL;
CoverageMaps::iterator it;
@@ -123,29 +132,29 @@ namespace Coverage {
// Obtain the coverage map containing the specified address.
itsSymbol = theSymbolTable.getSymbol( address );
- if (itsSymbol != "") {
- aCoverageMap = &findCoverageMap(itsSymbol);
+ if ( itsSymbol != "" ) {
+ aCoverageMap = &findCoverageMap( itsSymbol );
}
return aCoverageMap;
}
- const std::string& ExecutableInfo::getFileName ( void ) const
+ const std::string& ExecutableInfo::getFileName() const
{
return fileName;
}
- const std::string ExecutableInfo::getLibraryName( void ) const
+ const std::string ExecutableInfo::getLibraryName() const
{
return libraryName;
}
- uint32_t ExecutableInfo::getLoadAddress( void ) const
+ uint32_t ExecutableInfo::getLoadAddress() const
{
return loadAddress;
}
- SymbolTable* ExecutableInfo::getSymbolTable ( void )
+ SymbolTable* ExecutableInfo::getSymbolTable()
{
return &theSymbolTable;
}
@@ -155,8 +164,10 @@ namespace Coverage {
)
{
CoverageMaps::iterator cmi = coverageMaps.find( symbolName );
- if ( cmi == coverageMaps.end() )
- throw CoverageMapNotFoundError(symbolName);
+ if ( cmi == coverageMaps.end() ) {
+ throw CoverageMapNotFoundError( symbolName );
+ }
+
return *(cmi->second);
}
@@ -167,8 +178,8 @@ namespace Coverage {
uint32_t highAddress
)
{
- CoverageMapBase *theMap;
- CoverageMaps::iterator itr;
+ CoverageMapBase* theMap;
+ CoverageMaps::iterator itr;
if ( lowAddress > highAddress ) {
std::ostringstream what;
@@ -195,22 +206,24 @@ namespace Coverage {
std::string& line
)
{
- std::string file;
- int lno;
- mapper.getSource (address, file, lno);
+ std::string file;
+ int lno;
std::ostringstream ss;
+
+ mapper.getSource( address, file, lno );
ss << file << ':' << lno;
line = ss.str ();
}
- bool ExecutableInfo::hasDynamicLibrary( void )
+ bool ExecutableInfo::hasDynamicLibrary()
{
return !libraryName.empty();
}
- void ExecutableInfo::mergeCoverage( void ) {
- for (auto& cm : coverageMaps) {
- if (symbolsToAnalyze_m.isDesired( cm.first ))
+ void ExecutableInfo::mergeCoverage()
+ {
+ for ( auto& cm : coverageMaps ) {
+ if ( symbolsToAnalyze_m.isDesired( cm.first ) )
symbolsToAnalyze_m.mergeCoverageMap( cm.first, cm.second );
}
}
diff --git a/tester/covoar/ExecutableInfo.h b/tester/covoar/ExecutableInfo.h
index 0adebcb..34f023d 100644
--- a/tester/covoar/ExecutableInfo.h
+++ b/tester/covoar/ExecutableInfo.h
@@ -62,12 +62,12 @@ class DesiredSymbols;
* This method prints the contents of all coverage maps for
* this executable.
*/
- void dumpCoverageMaps( void );
+ void dumpCoverageMaps();
/*!
* This method prints the contents of Executable info containers
*/
- void dumpExecutableInfo( void );
+ void dumpExecutableInfo();
/*!
* This method returns a pointer to the executable's coverage map
@@ -84,28 +84,28 @@ class DesiredSymbols;
*
* @return Returns the executable's file name
*/
- const std::string& getFileName( void ) const;
+ const std::string& getFileName() const;
/*!
* This method returns the library name associated with the executable.
*
* @return Returns the executable's library name
*/
- const std::string getLibraryName( void ) const;
+ const std::string getLibraryName() const;
/*!
* This method returns the load address of the dynamic library
*
* @return Returns the load address of the dynamic library
*/
- uint32_t getLoadAddress( void ) const;
+ uint32_t getLoadAddress() const;
/*!
* This method returns a pointer to the executable's symbol table.
*
* @return Returns a pointer to the symbol table.
*/
- SymbolTable* getSymbolTable( void );
+ SymbolTable* getSymbolTable();
/*!
* This method finds a coverage map for the specified symbol.
@@ -131,13 +131,13 @@ class DesiredSymbols;
*
* @return Returns TRUE if
*/
- bool hasDynamicLibrary( void );
+ bool hasDynamicLibrary();
/*!
* This method merges the coverage maps for this executable into
* the unified coverage map.
*/
- void mergeCoverage( void );
+ void mergeCoverage();
/*!
* This method sets the load address of the dynamic library
diff --git a/tester/covoar/Explanations.cc b/tester/covoar/Explanations.cc
index 4142418..d9d7a4f 100644
--- a/tester/covoar/Explanations.cc
+++ b/tester/covoar/Explanations.cc
@@ -26,19 +26,18 @@ namespace Coverage {
{
}
- void Explanations::load(
- const char* const explanations
- )
+ void Explanations::load( const std::string& explanations )
{
- std::ifstream explain;
- Explanation e;
- int line = 1;
+ std::ifstream explain;
+ Explanation e;
+ int line = 1;
- if (!explanations)
+ if ( explanations.empty() ) {
return;
+ }
explain.open( explanations );
- if (!explain) {
+ if ( !explain ) {
std::ostringstream what;
what << "Unable to open " << explanations;
throw rld::error( what, "Explanations::load" );
@@ -50,14 +49,15 @@ namespace Coverage {
// skip blank lines between
do {
std::getline( explain, input_line );
- if (explain.fail()) {
+ if ( explain.fail() ) {
return;
}
+
line++;
} while ( input_line.empty() );
// Have we already seen this one?
- if (set.find( input_line ) != set.end()) {
+ if ( set.find( input_line ) != set.end() ) {
std::ostringstream what;
what << "line " << line
<< "contains a duplicate explanation ("
@@ -71,7 +71,7 @@ namespace Coverage {
// Get the classification
std::getline( explain, input_line );
- if (explain.fail()) {
+ if ( explain.fail() ) {
std::ostringstream what;
what << "line " << line
<< "out of sync at the classification";
@@ -85,14 +85,14 @@ namespace Coverage {
line++;
const std::string delimiter = "+++";
- if (input_line.compare( delimiter ) == 0) {
+ if ( input_line.compare( delimiter ) == 0 ) {
break;
}
// XXX only taking last line. Needs to be a vector
e.explanation.push_back( input_line );
}
- if (explain.fail()) {
+ if ( explain.fail() ) {
std::ostringstream what;
what << "line " << line
<< "out of sync at the explanation";
@@ -109,7 +109,7 @@ namespace Coverage {
const std::string& start
)
{
- if (set.find( start ) == set.end()) {
+ if ( set.find( start ) == set.end() ) {
#if 0
std::cerr << "Warning: Unable to find explanation for "
<< start << std::endl;
@@ -120,38 +120,39 @@ namespace Coverage {
return &set[ start ];
}
- void Explanations::writeNotFound(
- const char* const fileName
- )
+ void Explanations::writeNotFound( const std::string& fileName )
{
std::ofstream notFoundFile;
bool notFoundOccurred = false;
- if (!fileName)
+ if ( fileName.empty() ) {
return;
+ }
notFoundFile.open( fileName );
- if (!notFoundFile) {
+ if ( !notFoundFile ) {
std::ostringstream what;
what << "Unable to open " << fileName
<< " out of sync at the explanation";
throw rld::error( what, "Explanations::writeNotFound" );
}
- for (std::map<std::string, Explanation>::iterator itr = set.begin();
- itr != set.end();
- itr++) {
+ for (
+ std::map<std::string, Explanation>::iterator itr = set.begin();
+ itr != set.end();
+ itr++
+ ) {
Explanation e = (*itr).second;
std::string key = (*itr).first;
- if (!e.found) {
+ if ( !e.found ) {
notFoundOccurred = true;
notFoundFile << e.startingPoint << std::endl;
}
}
- if (!notFoundOccurred) {
- if (!unlink( fileName )) {
+ if ( !notFoundOccurred ) {
+ if ( !unlink( fileName.c_str() ) ) {
std::cerr << "Warning: Unable to unlink " << fileName
<< std::endl
<< std::endl;
diff --git a/tester/covoar/Explanations.h b/tester/covoar/Explanations.h
index de0c051..c147c11 100644
--- a/tester/covoar/Explanations.h
+++ b/tester/covoar/Explanations.h
@@ -49,7 +49,7 @@ namespace Coverage {
/*!
* This method constructs an Explanation instance.
*/
- Explanation() {found = false;}
+ Explanation() { found = false; }
/*!
* This method destructs an Explanation instance.
@@ -87,9 +87,7 @@ namespace Coverage {
* @param[in] explanations specifies the file name containing
* the explanation information
*/
- void load(
- const char* const explanations
- );
+ void load( const std::string& explanations );
/*!
* This method returns the explanation associated with the
@@ -98,9 +96,7 @@ namespace Coverage {
* @param[in] start specifies the starting line number for
* which to search
*/
- const Explanation *lookupExplanation(
- const std::string& start
- );
+ const Explanation *lookupExplanation( const std::string& start );
/*!
* This method writes a file that contains a list of any
@@ -108,9 +104,7 @@ namespace Coverage {
*
* @param[in] fileName specifies the name of the file to write
*/
- void writeNotFound(
- const char* const fileName
- );
+ void writeNotFound( const std::string& fileName );
};
diff --git a/tester/covoar/ObjdumpProcessor.cc b/tester/covoar/ObjdumpProcessor.cc
index c910046..0aef978 100644
--- a/tester/covoar/ObjdumpProcessor.cc
+++ b/tester/covoar/ObjdumpProcessor.cc
@@ -13,6 +13,8 @@
#include <string.h>
#include <algorithm>
#include <string>
+#include <fstream>
+#include <iomanip>
#include "ObjdumpProcessor.h"
#include "CoverageMap.h"
@@ -36,73 +38,81 @@ namespace Coverage {
) {
// Find the symbol's coverage map.
try {
- CoverageMapBase& coverageMap = executableInfo->findCoverageMap(symbolName);
+ CoverageMapBase& coverageMap =
+ executableInfo->findCoverageMap( symbolName );
uint32_t firstInstructionAddress = UINT32_MAX;
// Find the address of the first instruction.
- for (auto& line : instructions) {
- if (line.isInstruction) {
+ for ( auto& line : instructions ) {
+ if ( line.isInstruction ) {
firstInstructionAddress = line.address;
break;
}
}
- if (firstInstructionAddress == UINT32_MAX) {
+ if ( firstInstructionAddress == UINT32_MAX ) {
std::ostringstream what;
what << "Could not find first instruction address for symbol "
- << symbolName << " in " << executableInfo->getFileName();
+ << symbolName << " in " << executableInfo->getFileName();
throw rld::error( what, "Coverage::finalizeSymbol" );
}
- int rangeIndex = -1;
+ int rangeIndex = -1;
uint32_t lowAddress = UINT32_MAX;
do {
rangeIndex++;
- lowAddress = coverageMap.getLowAddressOfRange(rangeIndex);
- } while (firstInstructionAddress != lowAddress);
+ lowAddress = coverageMap.getLowAddressOfRange( rangeIndex );
+ } while ( firstInstructionAddress != lowAddress );
- uint32_t sizeWithoutNops = coverageMap.getSizeOfRange(rangeIndex);
- uint32_t size = sizeWithoutNops;
- uint32_t highAddress = lowAddress + size - 1;
+ uint32_t sizeWithoutNops = coverageMap.getSizeOfRange( rangeIndex );
+ uint32_t size = sizeWithoutNops;
+ uint32_t highAddress = lowAddress + size - 1;
uint32_t computedHighAddress = highAddress;
// Find the high address as reported by the address of the last NOP
// instruction. This ensures that NOPs get marked as executed later.
- for (auto instruction = instructions.rbegin();
- instruction != instructions.rend();
- instruction++) {
- if (instruction->isInstruction) {
- if (instruction->isNop) {
+ for (
+ auto instruction = instructions.rbegin();
+ instruction != instructions.rend();
+ instruction++
+ ) {
+ if ( instruction->isInstruction ) {
+ if ( instruction->isNop ) {
computedHighAddress = instruction->address + instruction->nopSize;
}
+
break;
}
}
- if (highAddress != computedHighAddress) {
- std::cerr << "Function's high address differs between DWARF and objdump: "
- << symbolName << " (0x" << std::hex << highAddress << " and 0x"
- << computedHighAddress - 1 << ")" << std::dec << std::endl;
+ if ( highAddress != computedHighAddress ) {
+ std::cerr << "Function's high address differs between DWARF and "
+ << "objdump: " << symbolName << " (0x" << std::hex
+ << highAddress << " and 0x"
+ << computedHighAddress - 1 << ")" << std::dec << std::endl;
+
size = computedHighAddress - lowAddress;
}
// If there are NOT already saved instructions, save them.
SymbolInformation* symbolInfo = symbolsToAnalyze.find( symbolName );
- if (symbolInfo->instructions.empty()) {
- symbolInfo->sourceFile = executableInfo;
- symbolInfo->baseAddress = lowAddress;
+ if ( symbolInfo->instructions.empty() ) {
+ symbolInfo->sourceFile = executableInfo;
+ symbolInfo->baseAddress = lowAddress;
symbolInfo->instructions = instructions;
}
// Add the symbol to this executable's symbol table.
SymbolTable* theSymbolTable = executableInfo->getSymbolTable();
theSymbolTable->addSymbol(
- symbolName, lowAddress, highAddress - lowAddress + 1
+ symbolName,
+ lowAddress,
+ highAddress - lowAddress + 1
);
// Mark the start of each instruction in the coverage map.
- for (auto& instruction : instructions) {
+ for ( auto& instruction : instructions ) {
coverageMap.setIsStartOfInstruction( instruction.address );
}
@@ -114,16 +124,16 @@ namespace Coverage {
sizeWithoutNops,
verbose
);
- } catch (const ExecutableInfo::CoverageMapNotFoundError& e) {
+ } catch ( const ExecutableInfo::CoverageMapNotFoundError& e ) {
// Allow execution to continue even if a coverage map could not be
// found.
std::cerr << "Coverage map not found for symbol " << e.what()
- << std::endl;
+ << std::endl;
}
}
ObjdumpProcessor::ObjdumpProcessor(
- DesiredSymbols& symbolsToAnalyze,
+ DesiredSymbols& symbolsToAnalyze,
std::shared_ptr<Target::TargetBase>& targetInfo
): symbolsToAnalyze_m( symbolsToAnalyze ),
targetInfo_m( targetInfo )
@@ -139,14 +149,14 @@ namespace Coverage {
)
{
#define METHOD "ERROR: ObjdumpProcessor::determineLoadAddress - "
- FILE* loadAddressFile = NULL;
- char* cStatus;
- uint32_t offset;
- char inputBuffer[MAX_LINE_LENGTH];
+ std::ifstream loadAddressFile;
+ uint32_t offset;
+ char inputBuffer[ MAX_LINE_LENGTH ];
// This method should only be call for a dynamic library.
- if (!theExecutable->hasDynamicLibrary())
+ if ( !theExecutable->hasDynamicLibrary() ) {
return 0;
+ }
std::string dlinfoName = theExecutable->getFileName();
uint32_t address;
@@ -155,8 +165,8 @@ namespace Coverage {
dlinfoName += ".dlinfo";
// Read load address.
- loadAddressFile = ::fopen( dlinfoName.c_str(), "r" );
- if (!loadAddressFile) {
+ loadAddressFile.open( dlinfoName );
+ if ( !loadAddressFile.is_open() ) {
std::ostringstream what;
what << "Unable to open " << dlinfoName;
throw rld::error( what, METHOD );
@@ -166,23 +176,26 @@ namespace Coverage {
while ( 1 ) {
// Get a line.
- cStatus = ::fgets( inputBuffer, MAX_LINE_LENGTH, loadAddressFile );
- if (cStatus == NULL) {
- ::fclose( loadAddressFile );
+ loadAddressFile.getline( inputBuffer, MAX_LINE_LENGTH );
+ if ( loadAddressFile.fail() && loadAddressFile.is_open() ) {
+ loadAddressFile.close();
std::ostringstream what;
what << "library " << Library << " not found in " << dlinfoName;
throw rld::error( what, METHOD );
}
+
sscanf( inputBuffer, "%s %x", inLibName, &offset );
std::string tmp = inLibName;
if ( tmp.find( Library ) != tmp.npos ) {
- // fprintf( stderr, "%s - 0x%08x\n", inLibName, offset );
+ // std::cerr << inLibName << " - 0x"
+ // << std::setfill( '0' ) << std::setw( 8 ) << std::hex
+ // << offset << std::endl
+ // << std::dec << std::setfill( ' ' );
address = offset;
break;
}
}
- ::fclose( loadAddressFile );
return address;
#undef METHOD
@@ -195,23 +208,21 @@ namespace Coverage {
stderr,
"ERROR: ObjdumpProcessor::IsBranch - unknown architecture\n"
);
- assert(0);
+ assert( 0 );
return false;
}
return targetInfo_m->isBranch( instruction );
}
- bool ObjdumpProcessor::isBranchLine(
- const char* const line
- )
+ bool ObjdumpProcessor::isBranchLine( const std::string& line )
{
if ( !targetInfo_m ) {
fprintf(
stderr,
"ERROR: ObjdumpProcessor::isBranchLine - unknown architecture\n"
);
- assert(0);
+ assert( 0 );
return false;
}
@@ -219,11 +230,11 @@ namespace Coverage {
}
bool ObjdumpProcessor::isNop(
- const char* const line,
- int& size
+ const std::string& line,
+ int& size
)
{
- if ( !targetInfo_m ){
+ if ( !targetInfo_m ) {
fprintf(
stderr,
"ERROR: ObjdumpProcessor::isNop - unknown architecture\n"
@@ -236,21 +247,32 @@ namespace Coverage {
}
void ObjdumpProcessor::getFile(
- std::string fileName,
+ std::string fileName,
rld::process::tempfile& objdumpFile,
rld::process::tempfile& err
- )
+ )
{
rld::process::status status;
- rld::process::arg_container args = { targetInfo_m->getObjdump(),
- "-Cda", "--section=.text", "--source",
- fileName };
+ rld::process::arg_container args = {
+ targetInfo_m->getObjdump(),
+ "-Cda",
+ "--section=.text",
+ "--source",
+ fileName
+ };
+
try
{
- status = rld::process::execute( targetInfo_m->getObjdump(),
- args, objdumpFile.name(), err.name() );
- if ( (status.type != rld::process::status::normal)
- || (status.code != 0) ) {
+ status = rld::process::execute(
+ targetInfo_m->getObjdump(),
+ args,
+ objdumpFile.name(),
+ err.name()
+ );
+ if (
+ ( status.type != rld::process::status::normal ) ||
+ ( status.code != 0 )
+ ) {
throw rld::error( "Objdump error", "generating objdump" );
}
} catch( rld::error& err )
@@ -269,12 +291,12 @@ namespace Coverage {
objdumpFile_t::iterator itr;
itr = find ( objdumpList.begin(), objdumpList.end(), address );
- if (itr == objdumpList.end()) {
+ if ( itr == objdumpList.end() ) {
return 0;
}
itr++;
- if (itr == objdumpList.end()) {
+ if ( itr == objdumpList.end() ) {
return 0;
}
@@ -283,21 +305,22 @@ namespace Coverage {
}
void ObjdumpProcessor::loadAddressTable (
- ExecutableInfo* const executableInformation,
- rld::process::tempfile& objdumpFile,
- rld::process::tempfile& err
+ ExecutableInfo* const executableInformation,
+ rld::process::tempfile& objdumpFile,
+ rld::process::tempfile& err
)
{
- int items;
- uint32_t offset;
- char terminator;
- std::string line;
+ int items;
+ uint32_t offset;
+ char terminator;
+ std::string line;
// Obtain the objdump file.
- if ( !executableInformation->hasDynamicLibrary() )
+ if ( !executableInformation->hasDynamicLibrary() ) {
getFile( executableInformation->getFileName(), objdumpFile, err );
- else
+ } else {
getFile( executableInformation->getLibraryName(), objdumpFile, err );
+ }
// Process all lines from the objdump file.
while ( true ) {
@@ -309,14 +332,10 @@ namespace Coverage {
}
// See if it is the dump of an instruction.
- items = sscanf(
- line.c_str(),
- "%x%c",
- &offset, &terminator
- );
+ items = sscanf( line.c_str(), "%x%c", &offset, &terminator );
// If it looks like an instruction ...
- if ((items == 2) && (terminator == ':')) {
+ if ( ( items == 2 ) && ( terminator == ':' ) ) {
objdumpList.push_back(
executableInformation->getLoadAddress() + offset
);
@@ -325,42 +344,43 @@ namespace Coverage {
}
void ObjdumpProcessor::load(
- ExecutableInfo* const executableInformation,
- rld::process::tempfile& objdumpFile,
- rld::process::tempfile& err,
- bool verbose
+ ExecutableInfo* const executableInformation,
+ rld::process::tempfile& objdumpFile,
+ rld::process::tempfile& err,
+ bool verbose
)
{
- std::string currentSymbol = "";
- uint32_t instructionOffset;
- int items;
- int found;
- objdumpLine_t lineInfo;
- uint32_t offset;
- bool processSymbol = false;
- char symbol[ MAX_LINE_LENGTH ];
- char terminator1;
- char terminatorOne;
- char terminator2;
- objdumpLines_t theInstructions;
- char instruction[ MAX_LINE_LENGTH ];
- char ID[ MAX_LINE_LENGTH ];
- std::string call = "";
- std::string jumpTableID = "";
- std::string line = "";
+ std::string currentSymbol = "";
+ uint32_t instructionOffset;
+ int items;
+ int found;
+ objdumpLine_t lineInfo;
+ uint32_t offset;
+ bool processSymbol = false;
+ char symbol[ MAX_LINE_LENGTH ];
+ char terminator1;
+ char terminatorOne;
+ char terminator2;
+ objdumpLines_t theInstructions;
+ char instruction[ MAX_LINE_LENGTH ];
+ char ID[ MAX_LINE_LENGTH ];
+ std::string call = "";
+ std::string jumpTableID = "";
+ std::string line = "";
// Obtain the objdump file.
- if ( !executableInformation->hasDynamicLibrary() )
+ if ( !executableInformation->hasDynamicLibrary() ) {
getFile( executableInformation->getFileName(), objdumpFile, err );
- else
+ } else {
getFile( executableInformation->getLibraryName(), objdumpFile, err );
+ }
while ( true ) {
// Get the line.
objdumpFile.read_line( line );
if ( line.empty() ) {
// If we are currently processing a symbol, finalize it.
- if (processSymbol) {
+ if ( processSymbol ) {
finalizeSymbol(
executableInformation,
currentSymbol,
@@ -368,23 +388,23 @@ namespace Coverage {
verbose,
symbolsToAnalyze_m
);
- fprintf(
- stderr,
- "WARNING: ObjdumpProcessor::load - analysis of symbol %s \n"
- " may be incorrect. It was the last symbol in %s\n"
- " and the length of its last instruction is assumed "
- " to be one.\n",
- currentSymbol.c_str(),
- executableInformation->getFileName().c_str()
- );
+
+ std::cerr << "WARNING: ObjdumpProcessor::load - analysis of symbol "
+ << currentSymbol << std::endl
+ << " may be incorrect. It was the last symbol in "
+ << executableInformation->getFileName() << std::endl
+ << " and the length of its last instruction"
+ << " is assumed to be one."
+ << std::endl;
}
+
objdumpFile.close();
break;
}
// Remove any extra line break
- if (line.back() == '\n') {
- line.erase(line.end() - 1);
+ if ( line.back() == '\n' ) {
+ line.erase( line.end() - 1 );
}
lineInfo.line = line;
@@ -402,22 +422,28 @@ namespace Coverage {
items = sscanf(
line.c_str(),
"%x <%[^>]>%c",
- &offset, symbol, &terminator1
+ &offset,
+ symbol,
+ &terminator1
);
// See if it is a jump table.
found = sscanf(
line.c_str(),
"%x%c\t%*[^\t]%c%s %*x %*[^+]%s",
- &instructionOffset, &terminatorOne, &terminator2, instruction, ID
+ &instructionOffset,
+ &terminatorOne,
+ &terminator2,
+ instruction,
+ ID
);
call = instruction;
jumpTableID = ID;
// If all items found, we are at the beginning of a symbol's objdump.
- if ((items == 3) && (terminator1 == ':')) {
+ if ( ( items == 3 ) && ( terminator1 == ':' ) ) {
// If we are currently processing a symbol, finalize it.
- if (processSymbol) {
+ if ( processSymbol ) {
finalizeSymbol(
executableInformation,
currentSymbol,
@@ -442,24 +468,27 @@ namespace Coverage {
// When this happens, the compiler will generate a function with a
// ".part.n" suffix. For our purposes, this generated function part is
// equivalent to the original function and should be treated as such.
- char *periodIndex = strstr(symbol, ".");
- if (periodIndex != NULL) {
+ char *periodIndex = strstr( symbol, "." );
+ if ( periodIndex != NULL ) {
*periodIndex = 0;
}
// See if the new symbol is one that we care about.
- if (symbolsToAnalyze_m.isDesired( symbol )) {
+ if ( symbolsToAnalyze_m.isDesired( symbol ) ) {
currentSymbol = symbol;
processSymbol = true;
theInstructions.push_back( lineInfo );
}
}
// If it looks like a jump table, finalize the symbol.
- else if ( (found == 5) && (terminatorOne == ':') && (terminator2 == '\t')
- && (call.find( "call" ) != std::string::npos)
- && (jumpTableID.find( "+0x" ) != std::string::npos)
- && processSymbol )
- {
+ else if (
+ ( found == 5 ) &&
+ ( terminatorOne == ':' ) &&
+ ( terminator2 == '\t' ) &&
+ ( call.find( "call" ) != std::string::npos ) &&
+ ( jumpTableID.find( "+0x" ) != std::string::npos ) &&
+ processSymbol
+ ) {
// If we are currently processing a symbol, finalize it.
if ( processSymbol ) {
finalizeSymbol(
@@ -470,19 +499,26 @@ namespace Coverage {
symbolsToAnalyze_m
);
}
+
processSymbol = false;
}
- else if (processSymbol) {
+ else if ( processSymbol ) {
// See if it is the dump of an instruction.
items = sscanf(
line.c_str(),
"%x%c\t%*[^\t]%c",
- &instructionOffset, &terminator1, &terminator2
+ &instructionOffset,
+ &terminator1,
+ &terminator2
);
// If it looks like an instruction ...
- if ((items == 3) && (terminator1 == ':') && (terminator2 == '\t')) {
+ if (
+ ( items == 3 ) &&
+ ( terminator1 == ':' ) &&
+ ( terminator2 == '\t' )
+ ) {
// update the line's information, save it and ...
lineInfo.address =
executableInformation->getLoadAddress() + instructionOffset;
diff --git a/tester/covoar/ObjdumpProcessor.h b/tester/covoar/ObjdumpProcessor.h
index 05a667f..b3c7262 100644
--- a/tester/covoar/ObjdumpProcessor.h
+++ b/tester/covoar/ObjdumpProcessor.h
@@ -91,7 +91,7 @@ namespace Coverage {
* This method constructs an ObjdumpProcessor instance.
*/
ObjdumpProcessor(
- DesiredSymbols& symbolsToAnalyze,
+ DesiredSymbols& symbolsToAnalyze,
std::shared_ptr<Target::TargetBase>& targetInfo
);
@@ -100,24 +100,24 @@ namespace Coverage {
*/
virtual ~ObjdumpProcessor();
- uint32_t determineLoadAddress(
- ExecutableInfo* theExecutable
- );
+ uint32_t determineLoadAddress( ExecutableInfo* theExecutable );
/*!
* This method fills a tempfile with the .text section of objdump
* for the given file name.
*/
- void getFile( std::string fileName,
- rld::process::tempfile& dmp,
- rld::process::tempfile& err );
+ void getFile(
+ std::string fileName,
+ rld::process::tempfile& dmp,
+ rld::process::tempfile& err
+ );
/*!
* This method fills the objdumpList list with all the
* instruction addresses in the object dump file.
*/
void loadAddressTable (
- ExecutableInfo* const executableInformation,
+ ExecutableInfo* const executableInformation,
rld::process::tempfile& dmp,
rld::process::tempfile& err
);
@@ -150,9 +150,7 @@ namespace Coverage {
* the given line in the objdmp file is a branch instruction,
* otherwise it returns false.
*/
- bool isBranchLine(
- const char* const line
- );
+ bool isBranchLine( const std::string& line );
/*!
* This method sets the targetInfo_m variable.
@@ -167,7 +165,7 @@ namespace Coverage {
* This variable consists of a list of all instruction addresses
* extracted from the obj dump file.
*/
- objdumpFile_t objdumpList;
+ objdumpFile_t objdumpList;
/*!
* This method determines whether the specified line is a
@@ -179,8 +177,8 @@ namespace Coverage {
* @return Returns TRUE if the instruction is a nop, FALSE otherwise.
*/
bool isNop(
- const char* const line,
- int& size
+ const std::string& line,
+ int& size
);
/*!
diff --git a/tester/covoar/ReportsBase.cc b/tester/covoar/ReportsBase.cc
index 219e5af..eb56c4f 100644
--- a/tester/covoar/ReportsBase.cc
+++ b/tester/covoar/ReportsBase.cc
@@ -65,7 +65,7 @@ void ReportsBase::OpenFile(
// Create the output directory if it does not already exist
#ifdef _WIN32
- sc = _mkdir( symbolSetOutputDirectory );
+ sc = _mkdir( symbolSetOutputDirectory.c_str() );
#else
sc = mkdir( symbolSetOutputDirectory.c_str(), 0755 );
#endif
@@ -591,80 +591,75 @@ void GenerateReports(
bool branchInfoAvailable
)
{
- typedef std::list<ReportsBase *> reportList_t;
+ using reportList_ptr = std::unique_ptr<ReportsBase>;
+ using reportList = std::vector<reportList_ptr>;
- reportList_t reportList;
- reportList_t::iterator ritr;
+ reportList reports;
std::string reportName;
- ReportsBase* reports;
time_t timestamp;
timestamp = time( NULL ); /* get current cal time */
- reports = new ReportsText(
- timestamp,
- symbolSetName,
- allExplanations,
- projectName,
- outputDirectory,
- symbolsToAnalyze,
- branchInfoAvailable
+ reports.emplace_back(
+ new ReportsText(
+ timestamp,
+ symbolSetName,
+ allExplanations,
+ projectName,
+ outputDirectory,
+ symbolsToAnalyze,
+ branchInfoAvailable
+ )
);
- reportList.push_back( reports );
- reports = new ReportsHtml(
- timestamp,
- symbolSetName,
- allExplanations,
- projectName,
- outputDirectory,
- symbolsToAnalyze,
- branchInfoAvailable
+ reports.emplace_back(
+ new ReportsHtml(
+ timestamp,
+ symbolSetName,
+ allExplanations,
+ projectName,
+ outputDirectory,
+ symbolsToAnalyze,
+ branchInfoAvailable
+ )
);
- reportList.push_back( reports );
- for ( ritr = reportList.begin(); ritr != reportList.end(); ritr++ ) {
- reports = *ritr;
+ for ( auto& report: reports ) {
- reportName = "index" + reports->ReportExtension();
+ reportName = "index" + report->ReportExtension();
if ( verbose ) {
std::cerr << "Generate " << reportName << std::endl;
}
- reports->WriteIndex( reportName );
+ report->WriteIndex( reportName );
- reportName = "annotated" + reports->ReportExtension();
+ reportName = "annotated" + report->ReportExtension();
if ( verbose ) {
std::cerr << "Generate " << reportName << std::endl;
}
- reports->WriteAnnotatedReport( reportName );
+ report->WriteAnnotatedReport( reportName );
- reportName = "branch" + reports->ReportExtension();
+ reportName = "branch" + report->ReportExtension();
if ( verbose ) {
std::cerr << "Generate " << reportName << std::endl;
}
- reports->WriteBranchReport( reportName );
+ report->WriteBranchReport( reportName );
- reportName = "uncovered" + reports->ReportExtension();
+ reportName = "uncovered" + report->ReportExtension();
if ( verbose ) {
std::cerr << "Generate " << reportName << std::endl;
}
- reports->WriteCoverageReport( reportName );
+ report->WriteCoverageReport( reportName );
- reportName = "sizes" + reports->ReportExtension();
+ reportName = "sizes" + report->ReportExtension();
if ( verbose ) {
std::cerr << "Generate " << reportName << std::endl;
}
- reports->WriteSizeReport( reportName );
+ report->WriteSizeReport( reportName );
- reportName = "symbolSummary" + reports->ReportExtension();
+ reportName = "symbolSummary" + report->ReportExtension();
if ( verbose ) {
std::cerr << "Generate " << reportName << std::endl;
}
- reports->WriteSymbolSummaryReport( reportName, symbolsToAnalyze );
- }
-
- for ( ritr = reportList.begin(); ritr != reportList.end(); ritr++ ) {
- reports = *ritr;
- delete reports;
+ report->WriteSymbolSummaryReport( reportName, symbolsToAnalyze );
}
ReportsBase::WriteSummaryReport(
diff --git a/tester/covoar/SymbolTable.cc b/tester/covoar/SymbolTable.cc
index cfbd7a3..a33a348 100644
--- a/tester/covoar/SymbolTable.cc
+++ b/tester/covoar/SymbolTable.cc
@@ -30,9 +30,9 @@ namespace Coverage {
const uint32_t length
)
{
- uint32_t end = 0;
- symbol_entry_t entry;
- symbolInfo_t symbolData;
+ uint32_t end = 0;
+ symbol_entry_t entry;
+ symbolInfo_t symbolData;
// Add an entry to the address map.
end = start + length - 1;
@@ -45,14 +45,14 @@ namespace Coverage {
symbolData.startingAddress = start;
symbolData.length = length;
- for (auto& symData : info[ symbol ]) {
+ for ( auto& symData : info[ symbol ] ) {
// The starting address could differ since we strip any suffixes beginning
// with a '.'
- if (symData.startingAddress != start) {
+ if ( symData.startingAddress != start ) {
continue;
}
- if (symData.length != length) {
+ if ( symData.length != length ) {
std::ostringstream what;
what << "Different lengths for the symbol "
<< symbol
@@ -66,39 +66,36 @@ namespace Coverage {
info[ symbol ].push_back( symbolData );
}
- SymbolTable::symbolInfo* SymbolTable::getInfo(
- const std::string& symbol
- )
+ SymbolTable::symbolInfo* SymbolTable::getInfo( const std::string& symbol )
{
info_t::iterator it = info.find( symbol );
- if (it == info.end())
+ if ( it == info.end() ) {
return NULL;
- else
- return (&(it->second));
+ } else {
+ return ( &(it->second) );
+ }
}
- uint32_t SymbolTable::getLength(
- const std::string& symbol
- )
+ uint32_t SymbolTable::getLength( const std::string& symbol )
{
info_t::iterator it = info.find( symbol );
- if (it == info.end())
+ if ( it == info.end() ) {
return 0;
- else
- return ((*it).second.front().length);
+ } else {
+ return ( (*it).second.front().length );
+ }
}
- std::string SymbolTable::getSymbol(
- uint32_t address
- )
+ std::string SymbolTable::getSymbol( uint32_t address )
{
contents_t::iterator it;
// Ensure that the symbol table is not empty.
- if ( contents.size() == 0 )
+ if ( contents.size() == 0 ) {
return "";
+ }
// Find the first entry whose end address is greater
// than the specified address.
@@ -106,23 +103,32 @@ namespace Coverage {
// If an entry was found and its low address is less than or
// equal to the specified address, then return the symbol.
- if ((it != contents.end()) && ((it->second).low <= address ))
+ if ( ( it != contents.end() ) && ( ( it->second ).low <= address ) ) {
return (it->second).symbol;
+ }
return "";
}
void SymbolTable::dumpSymbolTable( void )
{
- symbolInfo symbolTable;
- symbolInfoIterator_t symbolIterator;
- infoIterator_t infoIterator;
-
- for (infoIterator = info.begin() ; infoIterator != info.end(); infoIterator++)
- {
- for (symbolIterator = infoIterator->second.begin() ; symbolIterator != infoIterator->second.end(); symbolIterator++)
- {
- fprintf( stdout, "%s:\tStarting address = %#x\tLength = %u\n", infoIterator->first.c_str(), symbolIterator->startingAddress, symbolIterator->length );
+ symbolInfo symbolTable;
+ symbolInfoIterator_t symbolIterator;
+ infoIterator_t infoIterator;
+
+ for (
+ infoIterator = info.begin();
+ infoIterator != info.end();
+ infoIterator++
+ ) {
+ for (
+ symbolIterator = infoIterator->second.begin();
+ symbolIterator != infoIterator->second.end();
+ symbolIterator++
+ ) {
+ std::cerr << infoIterator->first << ":\tStarting address = 0x"
+ << std::hex << symbolIterator->startingAddress << std::dec
+ << "\tLength = " << symbolIterator->length << std::endl;
}
}
}
diff --git a/tester/covoar/TargetBase.cc b/tester/covoar/TargetBase.cc
index 7ee45b5..a62e90f 100644
--- a/tester/covoar/TargetBase.cc
+++ b/tester/covoar/TargetBase.cc
@@ -40,24 +40,24 @@ namespace Target {
{
}
- const char* TargetBase::getAddr2line() const
+ const std::string& TargetBase::getAddr2line() const
{
- return addr2line_m.c_str();
+ return addr2line_m;
}
- const char* TargetBase::getCPU( void ) const
+ const std::string& TargetBase::getCPU() const
{
- return cpu_m.c_str();
+ return cpu_m;
}
- const char* TargetBase::getObjdump() const
+ const std::string& TargetBase::getObjdump() const
{
- return objdump_m.c_str();
+ return objdump_m;
}
- const char* TargetBase::getTarget( void ) const
+ const std::string& TargetBase::getTarget() const
{
- return targetName_m.c_str();
+ return targetName_m;
}
bool TargetBase::isBranch( const std::string& instruction )
@@ -83,12 +83,13 @@ namespace Target {
}
bool TargetBase::isBranchLine(
- const char* const line
+ const std::string& line
)
{
- #define WARNING \
- "WARNING: TargetBase::isBranchLine - (%d) " \
- "Unable to find instruction in: %s\n"
+ #define WARNING_PT1 \
+ "WARNING: TargetBase::isBranchLine - ("
+ #define WARNING_PT2 \
+ ") Unable to find instruction in: "
const char *ch;
char instruction[120];
int result;
@@ -101,7 +102,7 @@ namespace Target {
ch++;
}
if (*ch != '\t') {
- fprintf( stderr, WARNING, 1, line );
+ std::cerr << WARNING_PT1 << 1 << WARNING_PT2 << line << std::endl;
return false;
}
ch++;
@@ -110,7 +111,7 @@ namespace Target {
while ((*ch != '\t') && (*ch != '\0'))
ch++;
if (*ch != '\t') {
- fprintf( stderr, WARNING, 2, line) ;
+ std::cerr << WARNING_PT1 << 2 << WARNING_PT2 << line << std::endl;
return false;
}
ch++;
@@ -119,19 +120,19 @@ namespace Target {
// after the second tab.
result = sscanf( ch, "%s", instruction );
if (result != 1) {
- fprintf( stderr, WARNING, 3, line );
+ std::cerr << WARNING_PT1 << 3 << WARNING_PT2 << line << std::endl;
return false;
}
return isBranch( instruction );
}
- uint8_t TargetBase::qemuTakenBit(void)
+ uint8_t TargetBase::qemuTakenBit()
{
return TRACE_OP_BR0;
}
- uint8_t TargetBase::qemuNotTakenBit(void)
+ uint8_t TargetBase::qemuNotTakenBit()
{
return TRACE_OP_BR1;
}
diff --git a/tester/covoar/TargetBase.h b/tester/covoar/TargetBase.h
index e5c143e..0a75c85 100644
--- a/tester/covoar/TargetBase.h
+++ b/tester/covoar/TargetBase.h
@@ -42,28 +42,28 @@ namespace Target {
*
* @return Returns the target specific addr2line program name
*/
- const char* getAddr2line( void ) const;
+ const std::string& getAddr2line() const;
/*!
* This method returns the CPU name.
*
* @return Returns the target cpu name
*/
- const char* getCPU( void ) const;
+ const std::string& getCPU() const;
/*!
* This method returns the program name for objdump.
*
* @return Returns the target specific objdump program name
*/
- const char* getObjdump( void ) const;
+ const std::string& getObjdump() const;
/*!
* This method returns the target name.
*
* @return Returns the target name
*/
- const char* getTarget( void ) const;
+ const std::string& getTarget() const;
/*!
* This method determines whether the specified line from a
@@ -75,8 +75,8 @@ namespace Target {
* @return Returns TRUE if the instruction is a nop, FALSE otherwise.
*/
virtual bool isNopLine(
- const char* const line,
- int& size
+ const std::string& line,
+ int& size
) = 0;
@@ -90,7 +90,7 @@ namespace Target {
* @return Returns TRUE if the instruction is a branch, FALSE otherwise.
*/
bool isBranchLine(
- const char* const line
+ const std::string& line
);
@@ -104,13 +104,13 @@ namespace Target {
* This method returns the bit set by Qemu in the trace record
* when a branch is taken.
*/
- virtual uint8_t qemuTakenBit(void);
+ virtual uint8_t qemuTakenBit();
/*!
* This method returns the bit set by Qemu in the trace record
* when a branch is taken.
*/
- virtual uint8_t qemuNotTakenBit(void);
+ virtual uint8_t qemuNotTakenBit();
protected:
diff --git a/tester/covoar/TargetFactory.cc b/tester/covoar/TargetFactory.cc
index 57ba686..0b6be52 100644
--- a/tester/covoar/TargetFactory.cc
+++ b/tester/covoar/TargetFactory.cc
@@ -37,11 +37,9 @@ namespace Target {
//!
typedef struct {
//! This is the string found in configuration to match.
- const char *theTarget;
+ std::string theTarget;
//! This is the static wrapper for the constructor.
- TargetBase *(*theCtor)(
- std::string
- );
+ TargetBase *(*theCtor)( std::string );
} FactoryEntry_t;
//!
@@ -60,27 +58,27 @@ namespace Target {
{ "powerpc", Target_powerpc_Constructor },
{ "sparc", Target_sparc_Constructor },
{ "riscv", Target_riscv_Constructor },
- { "TBD", NULL },
+ { "TBD", NULL }
};
- TargetBase* TargetFactory(
- std::string targetName
- )
+ TargetBase* TargetFactory( std::string targetName )
{
size_t i;
std::string cpu;
i = targetName.find( '-' );
- if ( i == targetName.npos )
+ if ( i == targetName.npos ) {
cpu = targetName;
- else
+ } else {
cpu = targetName.substr( 0, i );
+ }
- // fprintf( stderr, "%s --> %s\n", targetName.c_str(), cpu.c_str());
+ // std::cerr << targetName << " --> " << cpu << std::endl;
// Iterate over the table trying to find an entry with a matching name
- for ( i=0 ; i < sizeof(FactoryTable) / sizeof(FactoryEntry_t); i++ ) {
- if ( !strcmp(FactoryTable[i].theTarget, cpu.c_str() ) )
+ for ( i = 0 ; i < sizeof( FactoryTable ) / sizeof( FactoryEntry_t ); i++) {
+ if ( FactoryTable[i].theTarget == cpu ) {
return FactoryTable[i].theCtor( targetName );
+ }
}
std::ostringstream what;
diff --git a/tester/covoar/Target_aarch64.cc b/tester/covoar/Target_aarch64.cc
index 4d16456..139f5fe 100644
--- a/tester/covoar/Target_aarch64.cc
+++ b/tester/covoar/Target_aarch64.cc
@@ -49,31 +49,33 @@ namespace Target {
}
bool Target_aarch64::isNopLine(
- const char* const line,
- int& size
+ const std::string& line,
+ int& size
)
{
- if (!strcmp( &line[strlen(line)-3], "nop")) {
+ size_t stringLen = line.length();
+
+ if ( line.substr( stringLen - 3 ) == "nop" ) {
size = 4;
return true;
}
- if (!strncmp( &line[strlen(line)-6], "udf", 3)) {
+ if ( line.substr( stringLen - 6, 3 ) == "udf" ) {
size = 4;
return true;
}
// On ARM, there are literal tables at the end of methods.
// We need to avoid them.
- if (!strncmp( &line[strlen(line)-10], ".byte", 5)) {
+ if ( line.substr( stringLen - 10, 5 ) == ".byte" ) {
size = 1;
return true;
}
- if (!strncmp( &line[strlen(line)-13], ".short", 6)) {
+ if ( line.substr( stringLen - 13, 6 ) == ".short" ) {
size = 2;
return true;
}
- if (!strncmp( &line[strlen(line)-16], ".word", 5)) {
+ if ( line.substr( stringLen - 16, 5 ) == ".word" ) {
size = 4;
return true;
}
@@ -82,7 +84,7 @@ namespace Target {
}
bool Target_aarch64::isBranch(
- const char* instruction
+ const std::string& instruction
)
{
throw rld::error(
diff --git a/tester/covoar/Target_aarch64.h b/tester/covoar/Target_aarch64.h
index fb011e8..42353e5 100644
--- a/tester/covoar/Target_aarch64.h
+++ b/tester/covoar/Target_aarch64.h
@@ -42,8 +42,8 @@ namespace Target {
* @return Returns TRUE if the instruction is a nop, FALSE otherwise.
*/
virtual bool isNopLine(
- const char* const line,
- int& size
+ const std::string& line,
+ int& size
) override;
/*!
@@ -51,7 +51,7 @@ namespace Target {
* objdump file is a branch instruction.
*/
bool isBranch(
- const char* const instruction
+ const std::string& instruction
);
/* Documentation inherited from base class */
diff --git a/tester/covoar/Target_arm.cc b/tester/covoar/Target_arm.cc
index 94d50bb..50c9ce3 100644
--- a/tester/covoar/Target_arm.cc
+++ b/tester/covoar/Target_arm.cc
@@ -82,26 +82,28 @@ namespace Target {
}
bool Target_arm::isNopLine(
- const char* const line,
- int& size
+ const std::string& line,
+ int& size
)
{
- if (!strcmp( &line[strlen(line)-3], "nop")) {
+ size_t stringLen = line.length();
+
+ if ( line.substr( stringLen - 3 ) == "nop" ) {
size = 4;
return true;
}
// On ARM, there are literal tables at the end of methods.
// We need to avoid them.
- if (!strncmp( &line[strlen(line)-10], ".byte", 5)) {
+ if ( line.substr( stringLen - 10, 5 ) == ".byte" ) {
size = 1;
return true;
}
- if (!strncmp( &line[strlen(line)-13], ".short", 6)) {
+ if ( line.substr( stringLen - 13, 6 ) == ".short" ) {
size = 2;
return true;
}
- if (!strncmp( &line[strlen(line)-16], ".word", 5)) {
+ if ( line.substr( stringLen - 16, 5 ) == ".word" ) {
size = 4;
return true;
}
@@ -111,7 +113,7 @@ namespace Target {
}
bool Target_arm::isBranch(
- const char* instruction
+ const std::string& instruction
)
{
throw rld::error(
diff --git a/tester/covoar/Target_arm.h b/tester/covoar/Target_arm.h
index 80b68af..3ff9b6f 100644
--- a/tester/covoar/Target_arm.h
+++ b/tester/covoar/Target_arm.h
@@ -42,8 +42,8 @@ namespace Target {
* @return Returns TRUE if the instruction is a nop, FALSE otherwise.
*/
bool isNopLine(
- const char* const line,
- int& size
+ const std::string& line,
+ int& size
);
/*!
@@ -51,7 +51,7 @@ namespace Target {
* objdump file is a branch instruction.
*/
bool isBranch(
- const char* const instruction
+ const std::string& instruction
);
private:
diff --git a/tester/covoar/Target_i386.cc b/tester/covoar/Target_i386.cc
index 2990273..cb8e64d 100644
--- a/tester/covoar/Target_i386.cc
+++ b/tester/covoar/Target_i386.cc
@@ -57,39 +57,41 @@ namespace Target {
}
bool Target_i386::isNopLine(
- const char* const line,
- int& size
+ const std::string& line,
+ int& size
)
{
- if (!strcmp( &line[strlen(line)-3], "nop")) {
+ size_t stringLen = line.length();
+
+ if ( line.substr( stringLen - 3 ) == "nop" ) {
size = 1;
return true;
}
// i386 has some two and three byte nops
- if (!strncmp( &line[strlen(line)-14], "xchg %ax,%ax", 14)) {
+ if ( line.substr( stringLen - 14 ) == "xchg %ax,%ax" ) {
size = 2;
return true;
}
- if (!strncmp( &line[strlen(line)-16], "xor %eax,%eax", 16)) {
+ if ( line.substr( stringLen - 16 ) == "xor %eax,%eax" ) {
size = 2;
return true;
}
- if (!strncmp( &line[strlen(line)-16], "xor %ebx,%ebx", 16)) {
+ if ( line.substr( stringLen - 16 ) == "xor %ebx,%ebx" ) {
size = 2;
return true;
}
- if (!strncmp( &line[strlen(line)-16], "xor %esi,%esi", 16)) {
+ if ( line.substr( stringLen - 16 ) == "xor %esi,%esi" ) {
size = 2;
return true;
}
- if (!strncmp( &line[strlen(line)-21], "lea 0x0(%esi),%esi", 21)) {
+ if ( line.substr( stringLen - 21 ) == "lea 0x0(%esi),%esi" ) {
size = 3;
return true;
}
- if (!strncmp( &line[strlen(line)-28], "lea 0x0(%esi,%eiz,1),%esi", 28)) {
+ if ( line.substr( stringLen - 28 ) == "lea 0x0(%esi,%eiz,1),%esi" ) {
// Could be 4 or 7 bytes of padding.
- if (!strncmp( &line[strlen(line)-32], "00", 2)) {
+ if ( line.substr( stringLen - 32, 2 ) == "00" ) {
size = 7;
} else {
size = 4;
diff --git a/tester/covoar/Target_i386.h b/tester/covoar/Target_i386.h
index 3641de7..c9a79cd 100644
--- a/tester/covoar/Target_i386.h
+++ b/tester/covoar/Target_i386.h
@@ -43,8 +43,8 @@ namespace Target {
* @return Returns TRUE if the instruction is a nop, FALSE otherwise.
*/
bool isNopLine(
- const char* const line,
- int& size
+ const std::string& line,
+ int& size
);
/* Documentation inherited from base class */
diff --git a/tester/covoar/Target_lm32.cc b/tester/covoar/Target_lm32.cc
index 18e7191..7babbd2 100644
--- a/tester/covoar/Target_lm32.cc
+++ b/tester/covoar/Target_lm32.cc
@@ -30,11 +30,11 @@ namespace Target {
}
bool Target_lm32::isNopLine(
- const char* const line,
- int& size
+ const std::string& line,
+ int& size
)
{
- if (!strcmp( &line[strlen(line)-3], "nop")) {
+ if ( line.substr( line.length() - 3 ) == "nop" ) {
size = 4;
return true;
}
diff --git a/tester/covoar/Target_lm32.h b/tester/covoar/Target_lm32.h
index 5d23db5..d21776e 100644
--- a/tester/covoar/Target_lm32.h
+++ b/tester/covoar/Target_lm32.h
@@ -43,8 +43,8 @@ namespace Target {
* @return Returns TRUE if the instruction is a nop, FALSE otherwise.
*/
bool isNopLine(
- const char* const line,
- int& size
+ const std::string& line,
+ int& size
);
private:
diff --git a/tester/covoar/Target_m68k.cc b/tester/covoar/Target_m68k.cc
index 536ae80..7c761be 100644
--- a/tester/covoar/Target_m68k.cc
+++ b/tester/covoar/Target_m68k.cc
@@ -77,11 +77,13 @@ namespace Target {
}
bool Target_m68k::isNopLine(
- const char* const line,
- int& size
+ const std::string& line,
+ int& size
)
{
- if (!strcmp( &line[strlen(line)-3], "nop")) {
+ size_t stringLen = line.length();
+
+ if ( line.substr( stringLen - 3 ) == "nop" ) {
size = 2;
return true;
}
@@ -89,7 +91,7 @@ namespace Target {
#define GNU_LD_FILLS_ALIGNMENT_WITH_RTS
#if defined(GNU_LD_FILLS_ALIGNMENT_WITH_RTS)
// Until binutils 2.20, binutils would fill with rts not nop
- if (!strcmp( &line[strlen(line)-3], "rts")) {
+ if ( line.substr( stringLen - 3 ) == "rts" ) {
size = 4;
return true;
}
@@ -99,7 +101,7 @@ namespace Target {
}
bool Target_m68k::isBranch(
- const char* const instruction
+ const std::string& instruction
)
{
throw rld::error(
diff --git a/tester/covoar/Target_m68k.h b/tester/covoar/Target_m68k.h
index 5ed7933..13a6030 100644
--- a/tester/covoar/Target_m68k.h
+++ b/tester/covoar/Target_m68k.h
@@ -43,8 +43,8 @@ namespace Target {
* @return Returns TRUE if the instruction is a nop, FALSE otherwise.
*/
bool isNopLine(
- const char* const line,
- int& size
+ const std::string& line,
+ int& size
);
/*!
@@ -52,7 +52,7 @@ namespace Target {
* objdump file is a branch instruction.
*/
bool isBranch(
- const char* const instruction
+ const std::string& instruction
);
/* Documentation inherited from base class */
diff --git a/tester/covoar/Target_powerpc.cc b/tester/covoar/Target_powerpc.cc
index c62feb0..6cc541d 100644
--- a/tester/covoar/Target_powerpc.cc
+++ b/tester/covoar/Target_powerpc.cc
@@ -58,11 +58,11 @@ namespace Target {
}
bool Target_powerpc::isNopLine(
- const char* const line,
- int& size
+ const std::string& line,
+ int& size
)
{
- if (!strcmp( &line[strlen(line)-3], "nop")) {
+ if ( line.substr( line.length() - 3 ) == "nop" ) {
size = 4;
return true;
}
@@ -71,7 +71,7 @@ namespace Target {
}
bool Target_powerpc::isBranch(
- const char* const instruction
+ const std::string& instruction
)
{
throw rld::error(
diff --git a/tester/covoar/Target_powerpc.h b/tester/covoar/Target_powerpc.h
index 3008d4c..b446918 100644
--- a/tester/covoar/Target_powerpc.h
+++ b/tester/covoar/Target_powerpc.h
@@ -43,7 +43,7 @@ namespace Target {
* @return Returns TRUE if the instruction is a nop, FALSE otherwise.
*/
bool isNopLine(
- const char* const line,
+ const std::string& line,
int& size
);
@@ -52,7 +52,7 @@ namespace Target {
* objdump file is a branch instruction.
*/
bool isBranch(
- const char* const instruction
+ const std::string& instruction
);
private:
diff --git a/tester/covoar/Target_riscv.cc b/tester/covoar/Target_riscv.cc
index 13c81c5..d0b5a8e 100644
--- a/tester/covoar/Target_riscv.cc
+++ b/tester/covoar/Target_riscv.cc
@@ -62,11 +62,11 @@ namespace Target {
}
bool Target_riscv::isNopLine(
- const char* const line,
- int& size
+ const std::string& line,
+ int& size
)
{
- if (!strcmp( &line[strlen(line)-3], "nop")){
+ if ( line.substr( line.length() - 3 ) == "nop" ) {
size = 4;
return true;
}
diff --git a/tester/covoar/Target_riscv.h b/tester/covoar/Target_riscv.h
index 64a63d4..1442f69 100644
--- a/tester/covoar/Target_riscv.h
+++ b/tester/covoar/Target_riscv.h
@@ -67,8 +67,8 @@ namespace Target {
* @return Returns True if the instruction is nop, False otherwise.
*/
bool isNopLine(
- const char* const line,
- int& size
+ const std::string& line,
+ int& size
);
/*!
@@ -80,7 +80,7 @@ namespace Target {
*/
bool isBranch(
- const char* const instruction
+ const std::string& instruction
);
private:
diff --git a/tester/covoar/Target_sparc.cc b/tester/covoar/Target_sparc.cc
index fbdcd1e..a9435cb 100644
--- a/tester/covoar/Target_sparc.cc
+++ b/tester/covoar/Target_sparc.cc
@@ -56,23 +56,25 @@ namespace Target {
}
bool Target_sparc::isNopLine(
- const char* const line,
- int& size
+ const std::string& line,
+ int& size
)
{
- if (!strcmp( &line[strlen(line)-3], "nop")) {
+ size_t stringLen = line.length();
+
+ if ( line.substr( stringLen - 3 ) == "nop" ) {
size = 4;
return true;
}
- if (!strcmp( &line[strlen(line)-7], "unknown")) {
+ if ( line.substr( stringLen - 7 ) == "unknown" ) {
size = 4;
return true;
}
#define GNU_LD_FILLS_ALIGNMENT_WITH_RTS
#if defined(GNU_LD_FILLS_ALIGNMENT_WITH_RTS)
// Until binutils 2.20, binutils would fill with rts not nop
- if (!strcmp( &line[strlen(line)-3], "rts")) {
+ if ( line.substr( stringLen - 3 ) == "rts" ) {
size = 4;
return true;
}
diff --git a/tester/covoar/Target_sparc.h b/tester/covoar/Target_sparc.h
index 0e38859..cbe2faf 100644
--- a/tester/covoar/Target_sparc.h
+++ b/tester/covoar/Target_sparc.h
@@ -43,8 +43,8 @@ namespace Target {
* @return Returns TRUE if the instruction is a nop, FALSE otherwise.
*/
bool isNopLine(
- const char* const line,
- int& size
+ const std::string& line,
+ int& size
);
/*!
@@ -52,7 +52,7 @@ namespace Target {
* objdump file is a branch instruction.
*/
bool isBranch(
- const char* const instruction
+ const std::string& instruction
);
private:
diff --git a/tester/covoar/TraceConverter.cc b/tester/covoar/TraceConverter.cc
index 16c69d4..e393268 100644
--- a/tester/covoar/TraceConverter.cc
+++ b/tester/covoar/TraceConverter.cc
@@ -27,20 +27,18 @@
#define kill(p,s) raise(s)
#endif
-char* progname;
+std::string progname;
void usage()
{
- fprintf(
- stderr,
- "Usage: %s [-v] -c CPU -e executable -t tracefile [-E logfile]\n",
- progname
- );
- exit(1);
+ std::cerr << "Usage: "
+ << progname
+ << " [-v] -c CPU -e executable -t tracefile [-E logfile]"
+ << std::endl;
+ exit( 1 );
}
-static void
-fatal_signal( int signum )
+static void fatal_signal( int signum )
{
signal( signum, SIG_DFL );
@@ -53,20 +51,23 @@ fatal_signal( int signum )
kill( getpid(), signum );
}
-static void
-setup_signals( void )
+static void setup_signals()
{
- if ( signal (SIGINT, SIG_IGN) != SIG_IGN )
+ if ( signal (SIGINT, SIG_IGN) != SIG_IGN ) {
signal( SIGINT, fatal_signal );
+ }
#ifdef SIGHUP
- if ( signal( SIGHUP, SIG_IGN ) != SIG_IGN )
+ if ( signal( SIGHUP, SIG_IGN ) != SIG_IGN ) {
signal( SIGHUP, fatal_signal );
+ }
#endif
- if ( signal( SIGTERM, SIG_IGN ) != SIG_IGN )
+ if ( signal( SIGTERM, SIG_IGN ) != SIG_IGN ) {
signal( SIGTERM, fatal_signal );
+ }
#ifdef SIGPIPE
- if ( signal( SIGPIPE, SIG_IGN ) != SIG_IGN )
+ if ( signal( SIGPIPE, SIG_IGN ) != SIG_IGN ) {
signal( SIGPIPE, fatal_signal );
+ }
#endif
#ifdef SIGCHLD
signal( SIGCHLD, SIG_DFL );
@@ -78,20 +79,45 @@ int main(
char** argv
)
{
- int opt;
- Trace::TraceReaderLogQEMU log;
- Trace::TraceWriterQEMU trace;
- const char *cpuname = "";
- const char *executable = "";
- const char *tracefile = "";
- const char *logname = "/tmp/qemu.log";
- Coverage::ExecutableInfo* executableInfo;
- rld::process::tempfile objdumpFile( ".dmp" );
- rld::process::tempfile err( ".err" );
- Coverage::DesiredSymbols symbolsToAnalyze;
- bool verbose = false;
- std::string dynamicLibrary;
- int ec = 0;
+ int opt;
+ Trace::TraceReaderLogQEMU log;
+ Trace::TraceWriterQEMU trace;
+ std::string cpuname;
+ std::string executable;
+ std::string tracefile;
+ std::string logname = "/tmp/qemu.log";
+ Coverage::ExecutableInfo* executableInfo;
+ Coverage::DesiredSymbols symbolsToAnalyze;
+ bool verbose = false;
+ std::string dynamicLibrary;
+ int ec = 0;
+ std::shared_ptr<Target::TargetBase> targetInfo;
+ rld::process::tempfile *objdumpFile;
+ rld::process::tempfile *err;
+
+ try
+ {
+ objdumpFile = new rld::process::tempfile( ".dmp" );
+ }
+ catch ( rld::error re )
+ {
+ std::cerr << "Failed to make .dmp tempfile " << std::endl;
+ ec = 10;
+
+ return ec;
+ }
+
+ try
+ {
+ err = new rld::process::tempfile( ".err" );
+ }
+ catch ( rld::error re )
+ {
+ std::cerr << "Failed to make .err tempfile " << std::endl;
+ ec = 10;
+
+ return ec;
+ }
setup_signals();
@@ -100,52 +126,64 @@ int main(
//
progname = argv[0];
- while ((opt = getopt(argc, argv, "c:e:l:L:t:v")) != -1) {
- switch (opt) {
- case 'c': cpuname = optarg; break;
- case 'e': executable = optarg; break;
- case 'l': logname = optarg; break;
+ while ( (opt = getopt( argc, argv, "c:e:l:L:t:v" ) ) != -1 ) {
+ switch ( opt ) {
+ case 'c': cpuname = optarg; break;
+ case 'e': executable = optarg; break;
+ case 'l': logname = optarg; break;
case 'L': dynamicLibrary = optarg; break;
- case 't': tracefile = optarg; break;
- case 'v': verbose = true; break;
- default: usage();
+ case 't': tracefile = optarg; break;
+ case 'v': verbose = true; break;
+ default: usage();
}
}
// Make sure we have all the required parameters
- if ( !cpuname ) {
- fprintf( stderr, "cpuname not specified\n" );
+ if ( cpuname.empty() ) {
+ std::cerr << "cpuname not specified" << std::endl;
usage();
}
- if ( !executable ) {
- fprintf( stderr, "executable not specified\n" );
+ if ( executable.empty() ) {
+ std::cerr << "executable not specified" << std::endl;
usage();
}
- if ( !tracefile ) {
- fprintf( stderr, "output trace file not specified\n" );
+ if ( tracefile.empty() ) {
+ std::cerr << "output trace file not specified" << std::endl;
usage();
}
+
// Create toolnames.
- std::shared_ptr<Target::TargetBase>
- targetInfo( Target::TargetFactory( cpuname ) );
+ try
+ {
+ targetInfo.reset( Target::TargetFactory( cpuname ) );
+ }
+ catch ( rld::error re )
+ {
+ std::cerr << "error: "
+ << re.where << ": " << re.what
+ << std::endl;
+ ec = 10;
+
+ return ec;
+ }
Coverage::ObjdumpProcessor objdumpProcessor( symbolsToAnalyze, targetInfo );
- if ( !dynamicLibrary.empty() )
+ if ( !dynamicLibrary.empty() ) {
executableInfo = new Coverage::ExecutableInfo(
- executable,
+ executable.c_str(),
dynamicLibrary,
false,
symbolsToAnalyze
);
- else {
+ } else {
try
{
executableInfo = new Coverage::ExecutableInfo(
- executable,
+ executable.c_str(),
"",
false,
symbolsToAnalyze
@@ -161,13 +199,37 @@ int main(
}
// If a dynamic library was specified, determine the load address.
- if ( !dynamicLibrary.empty() )
- executableInfo->setLoadAddress(
- objdumpProcessor.determineLoadAddress( executableInfo )
- );
- objdumpProcessor.loadAddressTable( executableInfo, objdumpFile, err );
- log.processFile( logname, objdumpProcessor );
- trace.writeFile( tracefile, &log, verbose );
+ if ( !dynamicLibrary.empty() ) {
+ try
+ {
+ executableInfo->setLoadAddress(
+ objdumpProcessor.determineLoadAddress( executableInfo )
+ );
+ }
+ catch ( rld::error re )
+ {
+ std::cerr << "error: "
+ << re.where << ": " << re.what
+ << std::endl;
+ ec = 10;
+
+ return ec;
+ }
+ }
+
+ try
+ {
+ objdumpProcessor.loadAddressTable( executableInfo, *objdumpFile, *err );
+ log.processFile( logname.c_str(), objdumpProcessor );
+ trace.writeFile( tracefile.c_str(), &log, verbose );
+ }
+ catch ( rld::error re )
+ {
+ std::cerr << "error: "
+ << re.where << ": " << re.what
+ << std::endl;
+ ec = 10;
+ }
return ec;
}
diff --git a/tester/covoar/TraceList.cc b/tester/covoar/TraceList.cc
index a4e29e6..51ecfd8 100644
--- a/tester/covoar/TraceList.cc
+++ b/tester/covoar/TraceList.cc
@@ -1,5 +1,6 @@
#include "TraceList.h"
-#include <stdio.h>
+#include <iostream>
+#include <iomanip>
namespace Trace {
@@ -20,7 +21,7 @@ namespace Trace {
traceRange_t t;
t.lowAddress = lowAddressArg;
- t.length = highAddressArg - lowAddressArg;
+ t.length = highAddressArg - lowAddressArg;
t.exitReason = why;
set.push_back( t );
@@ -28,12 +29,9 @@ namespace Trace {
void TraceList::ShowTrace( traceRange_t *t)
{
- printf(
- "Start 0x%x, length 0x%03x Reason %d\n",
- t->lowAddress,
- t->length,
- t->exitReason
- );
+ std::cout << std::hex << "Start 0x" << t->lowAddress
+ << ", length 0x" << std::setfill( '0' ) << std::setw( 3 )
+ << t->length << " Reason " << t->exitReason << std::endl;
}
void TraceList::ShowList()