[rtems-tools commit] covoar: Fix DWARF reading

Joel Sherrill joel at rtems.org
Tue Mar 30 18:20:47 UTC 2021


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

Author:    Alex White <alex.white at oarcorp.com>
Date:      Wed Mar  3 09:37:47 2021 -0600

covoar: Fix DWARF reading

There were a couple of issues with the way the DWARF info was being
read. The first issue was that it inefficiently included all symbols,
even symbols that were not desired. The second issue is that it did
not handle inline functions correctly. These have been fixed.

---

 tester/covoar/ExecutableInfo.cc |  30 +++++++++--
 tester/covoar/covoar.cc         | 110 ++++++++++++++++++++--------------------
 2 files changed, 82 insertions(+), 58 deletions(-)

diff --git a/tester/covoar/ExecutableInfo.cc b/tester/covoar/ExecutableInfo.cc
index ddd2987..c996d75 100644
--- a/tester/covoar/ExecutableInfo.cc
+++ b/tester/covoar/ExecutableInfo.cc
@@ -45,10 +45,34 @@ namespace Coverage {
     try {
       for (auto& cu : debug.get_cus()) {
         for (auto& func : cu.get_functions()) {
-          if (func.has_machine_code() && (!func.is_inlined() || func.is_external())) {
-            createCoverageMap (cu.name(), func.name(),
-                               func.pc_low(), func.pc_high() - 1);
+          if (!func.has_machine_code()) {
+            continue;
           }
+
+          if (!SymbolsToAnalyze->isDesired(func.name())) {
+            continue;
+          }
+
+          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()) {
+              continue;
+            }
+
+            // If the low PC address is zero, the symbol does not appear in
+            // this executable.
+            if (func.pc_low() == 0) {
+              continue;
+            }
+          }
+
+          createCoverageMap (cu.name(), func.name(),
+                              func.pc_low(), func.pc_high() - 1);
         }
       }
     } catch (...) {
diff --git a/tester/covoar/covoar.cc b/tester/covoar/covoar.cc
index cbb0e4f..84d883a 100644
--- a/tester/covoar/covoar.cc
+++ b/tester/covoar/covoar.cc
@@ -222,6 +222,61 @@ int covoar(
   if ( !projectName )
     throw option_error( "project name -p" );
 
+  //
+  // Find the top of the BSP's build tree and if we have found the top
+  // check the executable is under the same path and BSP.
+  //
+  std::string buildPath;
+  std::string buildTarget;
+  std::string buildBSP;
+  createBuildPath(executablesToAnalyze,
+                  buildPath,
+                  buildTarget,
+                  buildBSP);
+
+  //
+  // Use a command line target if provided.
+  //
+  if (!target.empty()) {
+    buildTarget = target;
+  }
+
+  if (Verbose) {
+    if (singleExecutable) {
+      std::cerr << "Processing a single executable and multiple coverage files"
+                << std::endl;
+    } else {
+      std::cerr << "Processing multiple executable/coverage file pairs" << std::endl;
+    }
+    std::cerr << "Coverage Format : " << format << std::endl
+              << "Target          : " << buildTarget.c_str() << std::endl
+              << std::endl;
+
+    // Process each executable/coverage file pair.
+    Executables::iterator eitr = executablesToAnalyze.begin();
+    for (const auto& cname : coverageFileNames) {
+      std::cerr << "Coverage file " << cname
+                << " for executable: " << (*eitr)->getFileName() << std::endl;
+      if (!singleExecutable)
+        eitr++;
+    }
+  }
+
+  //
+  // Create data to support analysis.
+  //
+
+  // Create data based on target.
+  TargetInfo = Target::TargetFactory( buildTarget );
+
+  // Create the set of desired symbols.
+  SymbolsToAnalyze = new Coverage::DesiredSymbols();
+
+  //
+  // Read symbol configuration file and load needed symbols.
+  //
+  SymbolsToAnalyze->load( symbolSet, buildTarget, buildBSP, Verbose );
+
   // If a single executable was specified, process the remaining
   // arguments as coverage file names.
   if (singleExecutable) {
@@ -294,61 +349,6 @@ int covoar(
   if (executablesToAnalyze.size() != coverageFileNames.size())
     throw rld::error( "executables and coverage name size mismatch", "covoar" );
 
-  //
-  // Find the top of the BSP's build tree and if we have found the top
-  // check the executable is under the same path and BSP.
-  //
-  std::string buildPath;
-  std::string buildTarget;
-  std::string buildBSP;
-  createBuildPath(executablesToAnalyze,
-                  buildPath,
-                  buildTarget,
-                  buildBSP);
-
-  //
-  // Use a command line target if provided.
-  //
-  if (!target.empty()) {
-    buildTarget = target;
-  }
-
-  if (Verbose) {
-    if (singleExecutable) {
-      std::cerr << "Processing a single executable and multiple coverage files"
-                << std::endl;
-    } else {
-      std::cerr << "Processing multiple executable/coverage file pairs" << std::endl;
-    }
-    std::cerr << "Coverage Format : " << format << std::endl
-              << "Target          : " << buildTarget.c_str() << std::endl
-              << std::endl;
-
-    // Process each executable/coverage file pair.
-    Executables::iterator eitr = executablesToAnalyze.begin();
-    for (const auto& cname : coverageFileNames) {
-      std::cerr << "Coverage file " << cname
-                << " for executable: " << (*eitr)->getFileName() << std::endl;
-      if (!singleExecutable)
-        eitr++;
-    }
-  }
-
-  //
-  // Create data to support analysis.
-  //
-
-  // Create data based on target.
-  TargetInfo = Target::TargetFactory( buildTarget );
-
-  // Create the set of desired symbols.
-  SymbolsToAnalyze = new Coverage::DesiredSymbols();
-
-  //
-  // Read symbol configuration file and load needed symbols.
-  //
-  SymbolsToAnalyze->load( symbolSet, buildTarget, buildBSP, Verbose );
-
   if ( Verbose )
     std::cerr << "Analyzing " << SymbolsToAnalyze->set.size()
               << " symbols" << std::endl;



More information about the vc mailing list