[PATCH v2 03/13] Remove objdumpProcessor global variable

Ryan Long ryan.long at oarcorp.com
Mon Aug 2 20:44:19 UTC 2021


- Replaced objdumpProcessor in app_common with a local variable in
  TraceConverter.cc and covoar.cc
- Added objdumpProcessor as a parameter for GenerateReports() and
  the processFile() member function of TraceReaderBase and its derived
  classes
- Changed previous objdumpProcessor member functions calls from pointer
  to direct call syntax
---
 tester/covoar/ReportsBase.h         | 2 +-
 tester/covoar/TraceConverter.cc     | 9 ++++-----
 tester/covoar/TraceReaderBase.h     | 7 ++++---
 tester/covoar/TraceReaderLogQEMU.cc | 7 ++++---
 tester/covoar/TraceReaderLogQEMU.h  | 6 +++---
 tester/covoar/app_common.cc         | 1 -
 tester/covoar/app_common.h          | 1 -
 tester/covoar/covoar.cc             | 8 +++-----
 8 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/tester/covoar/ReportsBase.h b/tester/covoar/ReportsBase.h
index a2856e3..efc110d 100644
--- a/tester/covoar/ReportsBase.h
+++ b/tester/covoar/ReportsBase.h
@@ -402,7 +402,7 @@ class ReportsBase {
  *  @param[in] allExplanations is the explanations to report on.
  */
 void GenerateReports(
-  const std::string& symbolSetName,
+  const std::string&      symbolSetName,
   Coverage::Explanations& allExplanations
 );
 
diff --git a/tester/covoar/TraceConverter.cc b/tester/covoar/TraceConverter.cc
index 7015e28..cd64faf 100644
--- a/tester/covoar/TraceConverter.cc
+++ b/tester/covoar/TraceConverter.cc
@@ -89,6 +89,7 @@ int main(
   Coverage::ExecutableInfo*    executableInfo;
   rld::process::tempfile       objdumpFile( ".dmp" );
   rld::process::tempfile       err( ".err" );
+  Coverage::ObjdumpProcessor   objdumpProcessor;
 
   setup_signals();
 
@@ -133,14 +134,12 @@ int main(
   else
     executableInfo = new Coverage::ExecutableInfo( executable );
 
-  objdumpProcessor = new Coverage::ObjdumpProcessor();
-
   // If a dynamic library was specified, determine the load address.
   if (dynamicLibrary)
     executableInfo->setLoadAddress(
-      objdumpProcessor->determineLoadAddress( executableInfo )
+      objdumpProcessor.determineLoadAddress( executableInfo )
     );
-  objdumpProcessor->loadAddressTable( executableInfo, objdumpFile, err );
-  log.processFile( logname );
+  objdumpProcessor.loadAddressTable( executableInfo, objdumpFile, err );
+  log.processFile( logname, objdumpProcessor );
   trace.writeFile( tracefile, &log );
 }
diff --git a/tester/covoar/TraceReaderBase.h b/tester/covoar/TraceReaderBase.h
index 6ad488e..3005c62 100644
--- a/tester/covoar/TraceReaderBase.h
+++ b/tester/covoar/TraceReaderBase.h
@@ -8,6 +8,7 @@
 #define __TRACE_READER_BASE_H__
 
 #include "TraceList.h"
+#include "ObjdumpProcessor.h"
 
 namespace Trace {
 
@@ -41,13 +42,13 @@ namespace Trace {
      *  @a file and adds it to the specified @a executableInformation.
      *
      *  @param[in] file is the coverage file to process
-     *  @param[in] executableInformation is the information for an
-     *             associated executable
+     *  @param[in] objdumpProcessor the processor for the object dump
      *
      *  @return Returns TRUE if the method succeeded and FALSE if it failed.
      */
     virtual bool processFile(
-      const char* const     file
+      const char* const           file,
+      Coverage::ObjdumpProcessor& objdumpProcessor
     ) = 0;
   };
 
diff --git a/tester/covoar/TraceReaderLogQEMU.cc b/tester/covoar/TraceReaderLogQEMU.cc
index b64a149..0a61ea5 100644
--- a/tester/covoar/TraceReaderLogQEMU.cc
+++ b/tester/covoar/TraceReaderLogQEMU.cc
@@ -72,7 +72,8 @@ namespace Trace {
   }
 
   bool TraceReaderLogQEMU::processFile(
-    const char* const     file
+    const char* const           file,
+    Coverage::ObjdumpProcessor& objdumpProcessor
   )
   {
     bool                done          = false;
@@ -160,7 +161,7 @@ namespace Trace {
         );
       } while( result > 1);
 
-      nextlogical = objdumpProcessor->getAddressAfter(last.address);
+      nextlogical = objdumpProcessor.getAddressAfter(last.address);
 
       if (! ReadUntilFound( logFile, QEMU_LOG_IN_KEY )) {
         done = true;
@@ -185,7 +186,7 @@ namespace Trace {
       if (nextlogical != 0) {
         TraceList::exitReason_t reason = TraceList::EXIT_REASON_OTHER;
 
-        if ( objdumpProcessor->IsBranch( last.instruction ) ) {
+        if ( objdumpProcessor.IsBranch( last.instruction ) ) {
           if ( nextExecuted.address == nextlogical ) {
             reason = TraceList::EXIT_REASON_BRANCH_NOT_TAKEN;
           }  else {
diff --git a/tester/covoar/TraceReaderLogQEMU.h b/tester/covoar/TraceReaderLogQEMU.h
index fb1d020..8ee5651 100644
--- a/tester/covoar/TraceReaderLogQEMU.h
+++ b/tester/covoar/TraceReaderLogQEMU.h
@@ -38,13 +38,13 @@ namespace Trace {
      *  @a file and adds it to the specified @a executableInformation.
      *
      *  @param[in] file is the coverage file to process
-     *  @param[in] executableInformation is the information for an
-     *             associated executable
+     *  @param[in] objdumpProcessor the processor for the object dump
      *
      *  @return Returns TRUE if the method succeeded and FALSE if it failed.
      */
     virtual bool processFile(
-      const char* const     file
+      const char* const           file,
+      Coverage::ObjdumpProcessor& objdumpProcessor
     );
   };
 
diff --git a/tester/covoar/app_common.cc b/tester/covoar/app_common.cc
index f878fb6..1c49c72 100644
--- a/tester/covoar/app_common.cc
+++ b/tester/covoar/app_common.cc
@@ -56,7 +56,6 @@
 /*
  *  Global variables for the program
  */
-Coverage::ObjdumpProcessor* objdumpProcessor    = NULL;
 Coverage::DesiredSymbols*   SymbolsToAnalyze    = NULL;
 bool                        Verbose             = false;
 const char*                 outputDirectory     = ".";
diff --git a/tester/covoar/app_common.h b/tester/covoar/app_common.h
index 921bb71..eb250e8 100644
--- a/tester/covoar/app_common.h
+++ b/tester/covoar/app_common.h
@@ -12,7 +12,6 @@
 #include "Explanations.h"
 #include "TargetBase.h"
 
-extern Coverage::ObjdumpProcessor*  objdumpProcessor;
 extern Coverage::DesiredSymbols*    SymbolsToAnalyze;
 extern bool                         Verbose;
 extern const char*                  outputDirectory;
diff --git a/tester/covoar/covoar.cc b/tester/covoar/covoar.cc
index 9295519..46ba348 100644
--- a/tester/covoar/covoar.cc
+++ b/tester/covoar/covoar.cc
@@ -175,6 +175,7 @@ int covoar(
   std::string                   option;
   int                           opt;
   Coverage::Explanations        allExplanations;
+  Coverage::ObjdumpProcessor    objdumpProcessor;
 
   //
   // Process command line options.
@@ -364,9 +365,6 @@ int covoar(
   if (!coverageReader)
     throw rld::error( "Unable to create coverage file reader", "covoar" );
 
-  // Create the objdump processor.
-  objdumpProcessor = new Coverage::ObjdumpProcessor();
-
   // Prepare each executable for analysis.
   for (auto& exe : executablesToAnalyze) {
     if (Verbose)
@@ -375,11 +373,11 @@ int covoar(
 
     // If a dynamic library was specified, determine the load address.
     if (dynamicLibrary) {
-      exe->setLoadAddress( objdumpProcessor->determineLoadAddress( exe ) );
+      exe->setLoadAddress( objdumpProcessor.determineLoadAddress( exe ) );
     }
 
     // Load the objdump for the symbols in this executable.
-    objdumpProcessor->load( exe, objdumpFile, err );
+    objdumpProcessor.load( exe, objdumpFile, err );
   }
 
   //
-- 
1.8.3.1



More information about the devel mailing list