[PATCH 1/2] covoar/CoverageReaderQEMU: Fix infinite loop

Alex White alex.white at oarcorp.com
Thu Mar 11 18:30:45 UTC 2021


There was a potential that the branch info loop never terminated.
This has been fixed by adding a more reliable termination condition
and logging an error if it cannot find the branch target.
---
 tester/covoar/CoverageReaderQEMU.cc | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/tester/covoar/CoverageReaderQEMU.cc b/tester/covoar/CoverageReaderQEMU.cc
index 7c344e4..fb1709d 100644
--- a/tester/covoar/CoverageReaderQEMU.cc
+++ b/tester/covoar/CoverageReaderQEMU.cc
@@ -76,7 +76,7 @@ namespace Coverage {
     //
     // Read ENTRIES number of trace entries.
     //
-#define ENTRIES 1024
+#define ENTRIES 20000
     while (true) {
       CoverageMapBase     *aCoverageMap = NULL;
       struct trace_entry  entries[ENTRIES];
@@ -118,8 +118,15 @@ namespace Coverage {
         // Determine if additional branch information is available.
         if ( (entry->op & branchInfo) != 0 ) {
           uint32_t  a = entry->pc + entry->size - 1;
-            while (!aCoverageMap->isStartOfInstruction(a))
+            while (a > entry->pc && !aCoverageMap->isStartOfInstruction(a))
               a--;
+            if (a == entry->pc && !aCoverageMap->isStartOfInstruction(a)) {
+              // Something went wrong parsing the objdump.
+              std::ostringstream what;
+              what << "Reached beginning of range in " << file
+                << " at " << entry->pc << " with no start of instruction.";
+              throw rld::error( what, "CoverageReaderQEMU::processFile" );
+            }
             if (entry->op & taken) {
               aCoverageMap->setWasTaken( a );
             } else if (entry->op & notTaken) {
-- 
2.27.0



More information about the devel mailing list