[PATCH 18/22] covoar: Add option to create named objdumps

Alex White alexanderjwhite at gmail.com
Mon Mar 1 20:01:25 UTC 2021


This adds a new macro USE_TEMPLFILE which allows the creation of named
objdump outputs in the /tmp directory. This allows the outputs to be
reused on subsequent runs of covoar rather than running objdump again.
---
 rtemstoolkit/rld-process.cpp      | 12 ++++++++++++
 rtemstoolkit/rld-process.h        |  9 +++++++++
 tester/covoar/ObjdumpProcessor.cc | 16 +++++++++++-----
 tester/covoar/app_common.cc       | 10 ++++++++++
 tester/covoar/app_common.h        |  1 +
 tester/covoar/covoar.cc           | 20 ++++++++++++++++++++
 6 files changed, 63 insertions(+), 5 deletions(-)

diff --git a/rtemstoolkit/rld-process.cpp b/rtemstoolkit/rld-process.cpp
index 30e0605..d0352cb 100644
--- a/rtemstoolkit/rld-process.cpp
+++ b/rtemstoolkit/rld-process.cpp
@@ -169,6 +169,18 @@ namespace rld
       _name = temporaries.get (suffix, _keep);
     }
 
+    tempfile::tempfile (
+      const std::string& name,
+      const std::string& suffix,
+      bool _keep
+    ) : _name(name + suffix),
+        suffix(suffix),
+        overridden (false),
+        fd (-1),
+        level (0)
+    {
+    }
+
     tempfile::~tempfile ()
     {
       try
diff --git a/rtemstoolkit/rld-process.h b/rtemstoolkit/rld-process.h
index fc9b7bc..16e0322 100644
--- a/rtemstoolkit/rld-process.h
+++ b/rtemstoolkit/rld-process.h
@@ -114,6 +114,15 @@ namespace rld
        */
       tempfile (const std::string& suffix = ".rldxx", bool keep = false);
 
+      /**
+       * Get a temporary file name given a name and a suffix.
+       */
+      tempfile (
+        const std::string& name,
+        const std::string& suffix,
+        bool _keep = false
+      );
+
       /**
        * Clean up the temporary file.
        */
diff --git a/tester/covoar/ObjdumpProcessor.cc b/tester/covoar/ObjdumpProcessor.cc
index 00824f1..f130819 100644
--- a/tester/covoar/ObjdumpProcessor.cc
+++ b/tester/covoar/ObjdumpProcessor.cc
@@ -245,12 +245,18 @@ namespace Coverage {
                                          fileName };
     try
     {
-      status = rld::process::execute( TargetInfo->getObjdump(),
-                                      args, objdumpFile.name(), err.name() );
-      if ( (status.type != rld::process::status::normal)
-           || (status.code != 0) ) {
-        throw rld::error( "Objdump error", "generating objdump" );
+      #ifndef USE_TEMPFILE
+      if (FileIsNewer( fileName.c_str(), objdumpFile.name().c_str() )) {
+      #endif
+        status = rld::process::execute( TargetInfo->getObjdump(),
+                                        args, objdumpFile.name(), err.name() );
+        if ( (status.type != rld::process::status::normal)
+             || (status.code != 0) ) {
+          throw rld::error( "Objdump error", "generating objdump" );
+        }
+      #ifndef USE_TEMPFILE
       }
+      #endif
     } catch( rld::error& err )
       {
         std::cout << "Error while running " << TargetInfo->getObjdump()
diff --git a/tester/covoar/app_common.cc b/tester/covoar/app_common.cc
index 8b490ed..0f3c8e2 100644
--- a/tester/covoar/app_common.cc
+++ b/tester/covoar/app_common.cc
@@ -116,3 +116,13 @@ bool ReadUntilFound( FILE *file, const char *line )
   } while (1);
 }
 
+std::string GetFileNameFromPath( const std::string& path )
+{
+  size_t idx = path.rfind('/', path.length());
+  if (idx == std::string::npos) {
+    return "";
+  }
+
+  return path.substr(idx + 1, path.length() - idx);
+}
+
diff --git a/tester/covoar/app_common.h b/tester/covoar/app_common.h
index ac32bbd..21e8cfa 100644
--- a/tester/covoar/app_common.h
+++ b/tester/covoar/app_common.h
@@ -30,5 +30,6 @@ extern char                         inputBuffer2[MAX_LINE_LENGTH];
 bool FileIsNewer( const char *f1, const char *f2 );
 bool FileIsReadable( const char *f1 );
 bool ReadUntilFound( FILE *file, const char *line );
+std::string GetFileNameFromPath( const std::string& path );
 
 #endif
diff --git a/tester/covoar/covoar.cc b/tester/covoar/covoar.cc
index bf95cb4..bc1b7cf 100644
--- a/tester/covoar/covoar.cc
+++ b/tester/covoar/covoar.cc
@@ -162,7 +162,9 @@ int covoar(
   FILE*                         gcnosFile = NULL;
   Gcov::GcovData*               gcovFile;
   const char*                   singleExecutable = NULL;
+  #ifdef USE_TEMPFILE
   rld::process::tempfile        objdumpFile( ".dmp" );
+  #endif
   rld::process::tempfile        err( ".err" );
   rld::process::tempfile        syms( ".syms" );
   bool                          debug = false;
@@ -373,6 +375,22 @@ int covoar(
       exe->setLoadAddress( objdumpProcessor->determineLoadAddress( exe ) );
     }
 
+    #ifndef USE_TEMPFILE
+    std::string name;
+    
+    if ( !exe->hasDynamicLibrary() ) {
+      name = exe->getFileName();
+    } else {
+      name = exe->getLibraryName();
+    }
+
+    name = GetFileNameFromPath( name );
+    name = buildTarget + "-" + name;
+    name.insert( 0, "/tmp/" );
+
+    rld::process::tempfile objdumpFile( name, ".dmp", true );
+    #endif
+
     // Load the objdump for the symbols in this executable.
     objdumpProcessor->load( exe, objdumpFile, err );
   }
@@ -486,8 +504,10 @@ int covoar(
 
   //Leave tempfiles around if debug flag (-d) is enabled.
   if ( debug ) {
+    #ifdef USE_TEMPFILE
     objdumpFile.override( "objdump_file" );
     objdumpFile.keep();
+    #endif
     err.override( "objdump_exec_log" );
     err.keep();
     syms.override( "symbols_list" );
-- 
2.27.0



More information about the devel mailing list