9 class DebugTest(unittest
.TestCase
):
11 self
.binary
= testlib
.compile("debug.c")
12 self
.spike
= testlib
.spike(self
.binary
, halted
=False)
13 self
.gdb
= testlib
.Gdb()
14 self
.gdb
.command("file %s" % self
.binary
)
15 self
.gdb
.command("target extended-remote localhost:9824")
16 self
.gdb
.command("p i=0");
22 def test_turbostep(self
):
23 """Single step a bunch of times."""
26 self
.gdb
.command("stepi")
27 pc
= self
.gdb
.command("p $pc")
28 self
.assertNotEqual(last_pc
, pc
)
32 output
= self
.gdb
.command("c")
33 self
.assertIn("Continuing", output
)
34 self
.assertIn("Remote connection closed", output
)
36 def test_breakpoint(self
):
37 self
.gdb
.command("b print_row")
38 # The breakpoint should be hit exactly 10 times.
40 output
= self
.gdb
.command("c")
41 self
.assertIn("Continuing", output
)
42 self
.assertIn("Breakpoint 1", output
)
43 output
= self
.gdb
.command("c")
44 self
.assertIn("Continuing", output
)
45 self
.assertIn("Remote connection closed", output
)
47 def test_registers(self
):
48 # Try both forms to test gdb.
49 for cmd
in ("info all-registers", "info registers all"):
50 output
= self
.gdb
.command(cmd
)
51 self
.assertNotIn("Could not", output
)
52 for reg
in ('zero', 'ra', 'sp', 'gp', 'tp'):
53 self
.assertIn(reg
, output
)
54 # mcpuid is one of the few registers that should have the high bit set
56 self
.assertRegexpMatches(output
, ".*mcpuid *0x80")
58 # The time register should always be changing.
61 time
= self
.gdb
.p("$time")
62 self
.assertNotEqual(time
, last_time
)
64 self
.gdb
.command("stepi")
66 class RegsTest(unittest
.TestCase
):
68 self
.binary
= testlib
.compile("regs.s")
69 self
.spike
= testlib
.spike(self
.binary
, halted
=False)
70 self
.gdb
= testlib
.Gdb()
71 self
.gdb
.command("file %s" % self
.binary
)
72 self
.gdb
.command("target extended-remote localhost:9824")
78 def test_write_gprs(self
):
79 # Note a0 is missing from this list since it's used to hold the
81 regs
= ("ra", "sp", "gp", "tp", "t0", "t1", "t2", "fp", "s1",
82 "a1", "a2", "a3", "a4", "a5", "a6", "a7", "s2", "s3", "s4",
83 "s5", "s6", "s7", "s8", "s9", "s10", "s11", "t3", "t4", "t5",
86 self
.gdb
.command("p $pc=write_regs")
87 for i
, r
in enumerate(regs
):
88 self
.gdb
.command("p $%s=%d" % (r
, i
*0xdeadbeef+17))
89 self
.gdb
.command("p $a0=data")
90 self
.gdb
.command("b all_done")
91 output
= self
.gdb
.command("c")
92 self
.assertIn("Breakpoint 1", output
)
94 for n
in range(len(regs
)):
95 self
.assertEqual(self
.gdb
.x("data+%d" % (8*n
), 'g'),
98 def test_write_csrs(self
):
99 # As much a test of gdb as of the simulator.
100 self
.gdb
.p("$mscratch=0")
102 self
.assertEqual(self
.gdb
.p("$mscratch"), 0)
103 self
.gdb
.p("$mscratch=123")
105 self
.assertEqual(self
.gdb
.p("$mscratch"), 123)
107 if __name__
== '__main__':