[PATCH v1 11/13] Remove TargetInfo global variable
Ryan Long
ryan.long at oarcorp.com
Sun Aug 1 23:23:45 UTC 2021
- Remove TargetInfo from app_common
- Created the targetInfo_m member variable in CoverageReaderBase,
TraceWriterBase, and ObjdumpProcessor
- Made functions to set the value of targetInfo_m
---
tester/covoar/CoverageReaderBase.cc | 5 +++++
tester/covoar/CoverageReaderBase.h | 12 ++++++++++++
tester/covoar/CoverageReaderQEMU.cc | 4 ++--
tester/covoar/ObjdumpProcessor.cc | 29 ++++++++++++++++++-----------
tester/covoar/ObjdumpProcessor.h | 20 +++++++++++++++++++-
tester/covoar/TraceConverter.cc | 6 ++++--
tester/covoar/TraceWriterBase.cc | 5 +++++
tester/covoar/TraceWriterBase.h | 12 ++++++++++++
tester/covoar/TraceWriterQEMU.cc | 4 ++--
tester/covoar/app_common.cc | 1 -
tester/covoar/app_common.h | 1 -
tester/covoar/covmerge.cc | 7 ++++++-
tester/covoar/covoar.cc | 8 ++++++--
13 files changed, 91 insertions(+), 23 deletions(-)
diff --git a/tester/covoar/CoverageReaderBase.cc b/tester/covoar/CoverageReaderBase.cc
index e226964..06732a0 100644
--- a/tester/covoar/CoverageReaderBase.cc
+++ b/tester/covoar/CoverageReaderBase.cc
@@ -21,4 +21,9 @@ namespace Coverage {
{
return branchInfoAvailable_m;
}
+
+ void CoverageReaderBase::setTargetInfo( Target::TargetBase* targetInfo )
+ {
+ targetInfo_m = targetInfo;
+ }
}
diff --git a/tester/covoar/CoverageReaderBase.h b/tester/covoar/CoverageReaderBase.h
index ba909e6..6c8cadf 100644
--- a/tester/covoar/CoverageReaderBase.h
+++ b/tester/covoar/CoverageReaderBase.h
@@ -49,9 +49,21 @@ namespace Coverage {
bool getBranchInfoAvailable() const;
/*!
+ * This method sets the targetInfo_m variable
+ *
+ * @param[in] targetInfo the targetInfo to use
+ */
+ void setTargetInfo( Target::TargetBase* targetInfo );
+
+ /*!
* This member variable tells whether the branch info is available.
*/
bool branchInfoAvailable_m = false;
+
+ /*!
+ * This member variable points to the target's info
+ */
+ Target::TargetBase* targetInfo_m = nullptr;
};
}
diff --git a/tester/covoar/CoverageReaderQEMU.cc b/tester/covoar/CoverageReaderQEMU.cc
index 802d862..a3d9d02 100644
--- a/tester/covoar/CoverageReaderQEMU.cc
+++ b/tester/covoar/CoverageReaderQEMU.cc
@@ -51,8 +51,8 @@ namespace Coverage {
uint8_t notTaken;
uint8_t branchInfo;
- taken = TargetInfo->qemuTakenBit();
- notTaken = TargetInfo->qemuNotTakenBit();
+ taken = targetInfo_m->qemuTakenBit();
+ notTaken = targetInfo_m->qemuNotTakenBit();
branchInfo = taken | notTaken;
//
diff --git a/tester/covoar/ObjdumpProcessor.cc b/tester/covoar/ObjdumpProcessor.cc
index f590ece..5e1fb13 100644
--- a/tester/covoar/ObjdumpProcessor.cc
+++ b/tester/covoar/ObjdumpProcessor.cc
@@ -124,8 +124,10 @@ namespace Coverage {
}
ObjdumpProcessor::ObjdumpProcessor(
- DesiredSymbols& symbolsToAnalyze
- ): symbolsToAnalyze_m( symbolsToAnalyze )
+ DesiredSymbols& symbolsToAnalyze,
+ Target::TargetBase* targetInfo
+ ): symbolsToAnalyze_m( symbolsToAnalyze ),
+ targetInfo_m( targetInfo )
{
}
@@ -191,7 +193,7 @@ namespace Coverage {
const char *instruction
)
{
- if ( !TargetInfo ) {
+ if ( !targetInfo_m ) {
fprintf(
stderr,
"ERROR: ObjdumpProcessor::IsBranch - unknown architecture\n"
@@ -200,14 +202,14 @@ namespace Coverage {
return false;
}
- return TargetInfo->isBranch( instruction );
+ return targetInfo_m->isBranch( instruction );
}
bool ObjdumpProcessor::isBranchLine(
const char* const line
)
{
- if ( !TargetInfo ) {
+ if ( !targetInfo_m ) {
fprintf(
stderr,
"ERROR: ObjdumpProcessor::isBranchLine - unknown architecture\n"
@@ -216,7 +218,7 @@ namespace Coverage {
return false;
}
- return TargetInfo->isBranchLine( line );
+ return targetInfo_m->isBranchLine( line );
}
bool ObjdumpProcessor::isNop(
@@ -224,7 +226,7 @@ namespace Coverage {
int& size
)
{
- if ( !TargetInfo ){
+ if ( !targetInfo_m ){
fprintf(
stderr,
"ERROR: ObjdumpProcessor::isNop - unknown architecture\n"
@@ -233,7 +235,7 @@ namespace Coverage {
return false;
}
- return TargetInfo->isNopLine( line, size );
+ return targetInfo_m->isNopLine( line, size );
}
void ObjdumpProcessor::getFile(
@@ -243,12 +245,12 @@ namespace Coverage {
)
{
rld::process::status status;
- rld::process::arg_container args = { TargetInfo->getObjdump(),
+ rld::process::arg_container args = { targetInfo_m->getObjdump(),
"-Cda", "--section=.text", "--source",
fileName };
try
{
- status = rld::process::execute( TargetInfo->getObjdump(),
+ status = rld::process::execute( targetInfo_m->getObjdump(),
args, objdumpFile.name(), err.name() );
if ( (status.type != rld::process::status::normal)
|| (status.code != 0) ) {
@@ -256,7 +258,7 @@ namespace Coverage {
}
} catch( rld::error& err )
{
- std::cout << "Error while running " << TargetInfo->getObjdump()
+ std::cout << "Error while running " << targetInfo_m->getObjdump()
<< " on " << fileName << std::endl;
std::cout << err.what << " in " << err.where << std::endl;
return;
@@ -497,4 +499,9 @@ namespace Coverage {
}
}
}
+
+ void ObjdumpProcessor::setTargetInfo( Target::TargetBase* targetInfo )
+ {
+ targetInfo_m = targetInfo;
+ }
}
diff --git a/tester/covoar/ObjdumpProcessor.h b/tester/covoar/ObjdumpProcessor.h
index c7fc8bb..499af72 100644
--- a/tester/covoar/ObjdumpProcessor.h
+++ b/tester/covoar/ObjdumpProcessor.h
@@ -91,7 +91,8 @@ namespace Coverage {
* This method constructs an ObjdumpProcessor instance.
*/
ObjdumpProcessor(
- DesiredSymbols& symbolsToAnalyze
+ DesiredSymbols& symbolsToAnalyze,
+ Target::TargetBase* targetInfo
);
/*!
@@ -176,9 +177,26 @@ namespace Coverage {
);
/*!
+ * This method sets the targetInfo_m variable.
+ *
+ * @param[in] targetInfo the pointer to set targetInfo_m to
+ */
+ void setTargetInfo( Target::TargetBase* targetInfo );
+
+ /*!
+ * This member variable is a buffer for input
+ */
+ char* inputBuffer_m;
+
+ /*!
* This member variable contains the symbols to be analyzed
*/
DesiredSymbols& symbolsToAnalyze_m;
+
+ /*!
+ * This member variable points to the target's info
+ */
+ Target::TargetBase* targetInfo_m = nullptr;
};
}
#endif
diff --git a/tester/covoar/TraceConverter.cc b/tester/covoar/TraceConverter.cc
index 67edd11..7dcaa63 100644
--- a/tester/covoar/TraceConverter.cc
+++ b/tester/covoar/TraceConverter.cc
@@ -92,7 +92,7 @@ int main(
Coverage::DesiredSymbols symbolsToAnalyze;
bool verbose = false;
std::string dynamicLibrary;
- Coverage::ObjdumpProcessor objdumpProcessor( symbolsToAnalyze );
+ Target::TargetBase* targetInfo;
setup_signals();
@@ -130,7 +130,9 @@ int main(
}
// Create toolnames.
- TargetInfo = Target::TargetFactory( cpuname );
+ targetInfo = Target::TargetFactory( cpuname );
+
+ Coverage::ObjdumpProcessor objdumpProcessor( symbolsToAnalyze, targetInfo );
if ( !dynamicLibrary.empty() )
executableInfo = new Coverage::ExecutableInfo(
diff --git a/tester/covoar/TraceWriterBase.cc b/tester/covoar/TraceWriterBase.cc
index 2fa16dc..b86dc97 100644
--- a/tester/covoar/TraceWriterBase.cc
+++ b/tester/covoar/TraceWriterBase.cc
@@ -17,4 +17,9 @@ namespace Trace {
{
}
+ void TraceWriterBase::setTargetInfo( Target::TargetBase* targetInfo )
+ {
+ targetInfo_m = targetInfo;
+ }
+
}
diff --git a/tester/covoar/TraceWriterBase.h b/tester/covoar/TraceWriterBase.h
index 070dcca..f29dbcf 100644
--- a/tester/covoar/TraceWriterBase.h
+++ b/tester/covoar/TraceWriterBase.h
@@ -45,6 +45,18 @@ namespace Trace {
Trace::TraceReaderBase *log,
bool verbose
) = 0;
+
+ /*!
+ * This method sets the targetInfo_m variable
+ *
+ * @param[in] targetInfo the targetInfo to use
+ */
+ void setTargetInfo( Target::TargetBase* targetInfo );
+
+ /*!
+ * This member variable points to the target's info
+ */
+ Target::TargetBase* targetInfo_m;
};
}
diff --git a/tester/covoar/TraceWriterQEMU.cc b/tester/covoar/TraceWriterQEMU.cc
index 01d9cbc..18a6c68 100644
--- a/tester/covoar/TraceWriterQEMU.cc
+++ b/tester/covoar/TraceWriterQEMU.cc
@@ -83,8 +83,8 @@ namespace Trace {
uint8_t taken;
uint8_t notTaken;
- taken = TargetInfo->qemuTakenBit();
- notTaken = TargetInfo->qemuNotTakenBit();
+ taken = targetInfo_m->qemuTakenBit();
+ notTaken = targetInfo_m->qemuNotTakenBit();
//
// Verify that the TraceList has a non-zero size.
diff --git a/tester/covoar/app_common.cc b/tester/covoar/app_common.cc
index 8f05464..568d108 100644
--- a/tester/covoar/app_common.cc
+++ b/tester/covoar/app_common.cc
@@ -56,7 +56,6 @@
/*
* Global variables for the program
*/
-Target::TargetBase* TargetInfo = NULL;
bool FileIsNewer(
diff --git a/tester/covoar/app_common.h b/tester/covoar/app_common.h
index 6649905..454d389 100644
--- a/tester/covoar/app_common.h
+++ b/tester/covoar/app_common.h
@@ -12,7 +12,6 @@
#include "Explanations.h"
#include "TargetBase.h"
-extern Target::TargetBase* TargetInfo;
bool FileIsNewer( const char *f1, const char *f2 );
diff --git a/tester/covoar/covmerge.cc b/tester/covoar/covmerge.cc
index a200998..966e791 100644
--- a/tester/covoar/covmerge.cc
+++ b/tester/covoar/covmerge.cc
@@ -257,6 +257,7 @@ int main(
int opt;
int i;
char *format = NULL;
+ Target::TargetBase* targetInfo;
progname = argv[0];
@@ -347,7 +348,7 @@ int main(
/*
* Create toolnames based on target
*/
- TargetInfo = Target::TargetFactory( target );
+ targetInfo = Target::TargetFactory( target );
/*
* Create a ranges set
@@ -375,11 +376,15 @@ int main(
exit(-1);
}
+ CoverageReader.setTargetInfo( targetInfo );
+
/*
* Create the objdump processor
*/
ObjdumpProcessor = new Coverage::ObjdumpProcessor();
+ ObjdumpProcessor.setTargetInfo( targetInfo );
+
/*
* Create writer
*
diff --git a/tester/covoar/covoar.cc b/tester/covoar/covoar.cc
index ef22362..5c7833a 100644
--- a/tester/covoar/covoar.cc
+++ b/tester/covoar/covoar.cc
@@ -184,7 +184,7 @@ int covoar(
std::string outputDirectory = ".";
Coverage::DesiredSymbols symbolsToAnalyze;
bool branchInfoAvailable = false;
- Coverage::ObjdumpProcessor objdumpProcessor( symbolsToAnalyze );
+ Target::TargetBase* targetInfo;
//
// Process command line options.
@@ -278,7 +278,9 @@ int covoar(
//
// Create data based on target.
- TargetInfo = Target::TargetFactory( buildTarget );
+ targetInfo = Target::TargetFactory( buildTarget );
+
+ Coverage::ObjdumpProcessor objdumpProcessor( symbolsToAnalyze, targetInfo );
//
// Read symbol configuration file and load needed symbols.
@@ -380,6 +382,8 @@ int covoar(
if (!coverageReader)
throw rld::error( "Unable to create coverage file reader", "covoar" );
+ coverageReader->setTargetInfo( targetInfo );
+
// Prepare each executable for analysis.
for (auto& exe : executablesToAnalyze) {
if (verbose)
--
1.8.3.1
More information about the devel
mailing list