Tolerate remotes that return memory read errors.
[riscv-tests.git] / debug / testlib.py
index 0e504d1a7d0fc85a7a270c092936781488b25f9c..8b799e755c411e216cc829b8fda74cdd3e0b8f6f 100644 (file)
@@ -1,4 +1,5 @@
 import os.path
+import re
 import shlex
 import subprocess
 import time
@@ -130,6 +131,7 @@ class Openocd(object):
             cmd.append("-d")
         logfile = open(Openocd.logname, "w")
         logfile.write("+ %s\n" % " ".join(cmd))
+        logfile.flush()
         self.process = subprocess.Popen(cmd, stdin=subprocess.PIPE,
                 stdout=logfile, stderr=logfile)
         # TODO: Pick a random port
@@ -142,6 +144,11 @@ class Openocd(object):
         except OSError:
             pass
 
+class CannotAccess(Exception):
+    def __init__(self, address):
+        Exception.__init__(self)
+        self.address = address
+
 class Gdb(object):
     def __init__(self,
             cmd=os.path.expandvars("$RISCV/bin/riscv64-unknown-elf-gdb")):
@@ -186,6 +193,9 @@ class Gdb(object):
 
     def p(self, obj):
         output = self.command("p/x %s" % obj)
+        m = re.search("Cannot access memory at address (0x[0-9a-f]+)", output)
+        if m:
+            raise CannotAccess(int(m.group(1), 0))
         value = int(output.split('=')[-1].strip(), 0)
         return value
 
@@ -196,7 +206,6 @@ class Gdb(object):
 
     def stepi(self):
         output = self.command("stepi")
-        assert "Cannot" not in output
         return output
 
     def load(self):