Add test for gdb function calls.
[riscv-tests.git] / debug / gdbserver.py
index 030b6a17aba70386b8a77fc220a5bcf4e843ef19..d2508533e4866b07e9e00c69584a19bf4ee5db51 100755 (executable)
@@ -157,7 +157,11 @@ class InstantHaltTest(DeleteServer):
 
 class DebugTest(DeleteServer):
     def setUp(self):
-        self.binary = target.compile("programs/debug.c", "programs/checksum.c")
+        # Include malloc so that gdb can make function calls. I suspect this
+        # malloc will silently blow through the memory set aside for it, so be
+        # careful.
+        self.binary = target.compile("programs/debug.c", "programs/checksum.c",
+                "programs/tiny-malloc.c", "-DDEFINE_MALLOC", "-DDEFINE_FREE")
         self.server = target.server()
         self.gdb = testlib.Gdb()
         self.gdb.command("file %s" % self.binary)
@@ -173,6 +177,12 @@ class DebugTest(DeleteServer):
         # Use a0 until gdb can resolve "status"
         self.assertEqual(self.gdb.p("$a0") & 0xffffffff, 0xc86455d4)
 
+    def test_function_call(self):
+        text = "Howdy, Earth!"
+        gdb_length = self.gdb.p('strlen("%s")' % text)
+        self.assertEqual(gdb_length, len(text))
+        self.exit()
+
     def test_turbostep(self):
         """Single step a bunch of times."""
         self.gdb.command("p i=0");
@@ -302,10 +312,10 @@ class StepTest(DeleteServer):
 
     def test_step(self):
         main = self.gdb.p("$pc")
-        for expected in (4, 0xc, 0x10, 0x18, 0x14, 0x14):
+        for expected in (4, 8, 0xc, 0x10, 0x18, 0x1c, 0x28, 0x20, 0x2c, 0x2c):
             self.gdb.stepi()
             pc = self.gdb.p("$pc")
-            self.assertEqual(pc - main, expected)
+            self.assertEqual("%x" % pc, "%x" % (expected + main))
 
 class RegsTest(DeleteServer):
     def setUp(self):