Add explicit test for stepping over branches/jumps.
authorTim Newsome <tim@sifive.com>
Thu, 16 Jun 2016 20:03:19 +0000 (13:03 -0700)
committerTim Newsome <tim@sifive.com>
Tue, 19 Jul 2016 01:51:54 +0000 (18:51 -0700)
debug/gdbserver.py
debug/programs/step.S [new file with mode: 0644]

index a527ad0baad63488ebabfbd1207749cd44897a27..f45baedad38672325e5da9d6cc44d2c67f7aa8b3 100755 (executable)
@@ -177,11 +177,21 @@ class DebugTest(DeleteServer):
         """Single step a bunch of times."""
         self.gdb.command("p i=0");
         last_pc = None
+        advances = 0
+        jumps = 0
         for _ in range(100):
             self.gdb.stepi()
-            pc = self.gdb.command("p $pc")
+            pc = self.gdb.p("$pc")
             self.assertNotEqual(last_pc, pc)
+            if (last_pc and pc > last_pc and pc - last_pc <= 4):
+                advances += 1
+            else:
+                jumps += 1
             last_pc = pc
+        # Some basic sanity that we're not running between breakpoints or
+        # something.
+        self.assertGreater(jumps, 10)
+        self.assertGreater(advances, 50)
 
     def test_exit(self):
         self.exit()
@@ -268,6 +278,24 @@ class DebugTest(DeleteServer):
         self.gdb.p("i=0");
         self.exit()
 
+class StepTest(DeleteServer):
+    def setUp(self):
+        self.binary = target.compile("programs/step.S")
+        self.server = target.server()
+        self.gdb = testlib.Gdb()
+        self.gdb.command("file %s" % self.binary)
+        self.gdb.command("target extended-remote localhost:%d" % self.server.port)
+        self.gdb.load()
+        self.gdb.b("main")
+        self.gdb.c()
+
+    def test_step(self):
+        main = self.gdb.p("$pc")
+        for expected in (4, 0xc, 0x10, 0x18, 0x14, 0x14):
+            self.gdb.stepi()
+            pc = self.gdb.p("$pc")
+            self.assertEqual(pc - main, expected)
+
 class RegsTest(DeleteServer):
     def setUp(self):
         self.binary = target.compile("programs/regs.S")
diff --git a/debug/programs/step.S b/debug/programs/step.S
new file mode 100644 (file)
index 0000000..49f82d6
--- /dev/null
@@ -0,0 +1,17 @@
+// Test stepping over a variety of instructions.
+
+        .global main
+
+main:
+        li      t0, 5                   // 0
+        beq     zero, zero, one         // 0x4
+        nop                             // 0x8
+one:
+        beq     zero, t0, one           // 0xc
+        jal     two                     // 0x10
+
+three:
+        j       three                   // 0x14
+
+two:
+        ret                             // 0x18