[rtems-tools commit] Remove TargetInfo global variable

Joel Sherrill joel at rtems.org
Tue Aug 3 21:00:44 UTC 2021


Module:    rtems-tools
Branch:    master
Commit:    7f7ad0391739ac277682e951d4e79d46a82a89bd
Changeset: http://git.rtems.org/rtems-tools/commit/?id=7f7ad0391739ac277682e951d4e79d46a82a89bd

Author:    Ryan Long <ryan.long at oarcorp.com>
Date:      Wed Jul 28 15:39:17 2021 -0400

Remove TargetInfo global variable

- 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.h  |  5 +++++
 tester/covoar/CoverageReaderQEMU.cc |  4 ++--
 tester/covoar/ObjdumpProcessor.cc   | 31 ++++++++++++++++++++-----------
 tester/covoar/ObjdumpProcessor.h    | 20 +++++++++++++++++++-
 tester/covoar/TraceConverter.cc     |  6 ++++--
 tester/covoar/TraceWriterBase.h     |  5 +++++
 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             |  9 +++++++--
 11 files changed, 70 insertions(+), 23 deletions(-)

diff --git a/tester/covoar/CoverageReaderBase.h b/tester/covoar/CoverageReaderBase.h
index ba909e6..332fc4d 100644
--- a/tester/covoar/CoverageReaderBase.h
+++ b/tester/covoar/CoverageReaderBase.h
@@ -52,6 +52,11 @@ namespace Coverage {
    * This member variable tells whether the branch info is available.
    */
   bool branchInfoAvailable_m = false;
+
+  /*!
+   * This member variable points to the target's info
+   */
+  std::shared_ptr<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..90620aa 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,
+    std::shared_ptr<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,11 @@ namespace Coverage {
       }
     }
   }
+
+  void ObjdumpProcessor::setTargetInfo(
+    std::shared_ptr<Target::TargetBase>& targetInfo
+  )
+  {
+    targetInfo_m = targetInfo;
+  }
 }
diff --git a/tester/covoar/ObjdumpProcessor.h b/tester/covoar/ObjdumpProcessor.h
index 53671c6..ed36981 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,
+      std::shared_ptr<Target::TargetBase>& targetInfo
     );
 
     /*!
@@ -153,6 +154,13 @@ namespace Coverage {
       const char* const line
     );
 
+    /*!
+     * This method sets the targetInfo_m variable.
+     *
+     * @param[in] targetInfo the pointer to set targetInfo_m to
+     */
+    void setTargetInfo( std::shared_ptr<Target::TargetBase>& targetInfo );
+
   private:
 
     /*!
@@ -176,9 +184,19 @@ namespace Coverage {
     );
 
     /*!
+     * 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
+     */
+    std::shared_ptr<Target::TargetBase>& targetInfo_m;
   };
 }
 #endif
diff --git a/tester/covoar/TraceConverter.cc b/tester/covoar/TraceConverter.cc
index 67edd11..244d0f7 100644
--- a/tester/covoar/TraceConverter.cc
+++ b/tester/covoar/TraceConverter.cc
@@ -92,7 +92,6 @@ int main(
   Coverage::DesiredSymbols     symbolsToAnalyze;
   bool                         verbose = false;
   std::string                  dynamicLibrary;
-  Coverage::ObjdumpProcessor   objdumpProcessor( symbolsToAnalyze );
 
   setup_signals();
 
@@ -130,7 +129,10 @@ int main(
   }
 
   // Create toolnames.
-  TargetInfo = Target::TargetFactory( cpuname );
+  std::shared_ptr<Target::TargetBase>
+    targetInfo( Target::TargetFactory( cpuname ) );
+
+  Coverage::ObjdumpProcessor objdumpProcessor( symbolsToAnalyze, targetInfo );
 
   if ( !dynamicLibrary.empty() )
     executableInfo = new Coverage::ExecutableInfo(
diff --git a/tester/covoar/TraceWriterBase.h b/tester/covoar/TraceWriterBase.h
index 070dcca..9e80dbc 100644
--- a/tester/covoar/TraceWriterBase.h
+++ b/tester/covoar/TraceWriterBase.h
@@ -45,6 +45,11 @@ namespace Trace {
        Trace::TraceReaderBase    *log,
        bool                       verbose
      ) =  0;
+
+    /*!
+     * This member variable points to the target's info
+     */
+    std::shared_ptr<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..5ef2fe0 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..e0dc341 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,10 @@ int covoar(
   //
 
   // Create data based on target.
-  TargetInfo = Target::TargetFactory( buildTarget );
+  std::shared_ptr<Target::TargetBase>
+    targetInfo( Target::TargetFactory( buildTarget ) );
+
+  Coverage::ObjdumpProcessor objdumpProcessor( symbolsToAnalyze, targetInfo );
 
   //
   // Read symbol configuration file and load needed symbols.
@@ -380,6 +383,8 @@ int covoar(
   if (!coverageReader)
     throw rld::error( "Unable to create coverage file reader", "covoar" );
 
+  coverageReader->targetInfo_m = targetInfo;
+
   // Prepare each executable for analysis.
   for (auto& exe : executablesToAnalyze) {
     if (verbose)



More information about the vc mailing list