aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Newsome <tim@sifive.com>2016-05-05 17:40:02 -0700
committerTim Newsome <tim@sifive.com>2016-05-23 12:12:12 -0700
commit7e5c1b420d0b332d6663a47182f9a472e400f663 (patch)
tree0fe48621d4111db49252522ade4bc3a14ac25905
parentf3c39b00ca73f19b3e9685b06afd7107f338ffa2 (diff)
downloadspike-7e5c1b420d0b332d6663a47182f9a472e400f663.zip
spike-7e5c1b420d0b332d6663a47182f9a472e400f663.tar.gz
spike-7e5c1b420d0b332d6663a47182f9a472e400f663.tar.bz2
Halt when gdb user hits ^C.
-rw-r--r--riscv/gdbserver.cc9
-rw-r--r--riscv/processor.cc1
-rwxr-xr-xtests/gdbserver.py19
-rw-r--r--tests/testlib.py11
4 files changed, 34 insertions, 6 deletions
diff --git a/riscv/gdbserver.cc b/riscv/gdbserver.cc
index fbe0027..f3be272 100644
--- a/riscv/gdbserver.cc
+++ b/riscv/gdbserver.cc
@@ -309,8 +309,11 @@ class halt_op_t : public operation_t
fprintf(stderr, "Internal error. Processor halted without reason.\n");
abort();
- case DCSR_CAUSE_HWBP:
case DCSR_CAUSE_DEBUGINT:
+ gs.send_packet("S02"); // Pretend program received SIGINT.
+ break;
+
+ case DCSR_CAUSE_HWBP:
case DCSR_CAUSE_STEP:
case DCSR_CAUSE_HALT:
// There's no gdb code for this.
@@ -1513,9 +1516,7 @@ void gdbserver_t::handle_packet(const std::vector<uint8_t> &packet)
void gdbserver_t::handle_interrupt()
{
processor_t *p = sim->get_core(0);
- // TODO p->set_halted(true, HR_INTERRUPT);
- send_packet("S02"); // Pretend program received SIGINT.
- // TODO running = false;
+ add_operation(new halt_op_t(*this, true));
}
void gdbserver_t::handle()
diff --git a/riscv/processor.cc b/riscv/processor.cc
index 4c4e3dd..d43defc 100644
--- a/riscv/processor.cc
+++ b/riscv/processor.cc
@@ -279,7 +279,6 @@ static bool validate_vm(int max_xlen, reg_t vm)
void processor_t::set_csr(int which, reg_t val)
{
- fprintf(stderr, "set_csr(0x%x, 0x%lx)\n", which, val);
val = zext_xlen(val);
reg_t delegable_ints = MIP_SSIP | MIP_STIP | MIP_SEIP | (1 << IRQ_COP);
reg_t all_ints = delegable_ints | MIP_MSIP | MIP_MTIP;
diff --git a/tests/gdbserver.py b/tests/gdbserver.py
index ac191d5..2979606 100755
--- a/tests/gdbserver.py
+++ b/tests/gdbserver.py
@@ -13,7 +13,6 @@ class DebugTest(unittest.TestCase):
self.gdb = testlib.Gdb()
self.gdb.command("file %s" % self.binary)
self.gdb.command("target extended-remote localhost:%d" % self.port)
- self.gdb.command("p i=0");
def tearDown(self):
self.spike.kill()
@@ -21,6 +20,7 @@ class DebugTest(unittest.TestCase):
def test_turbostep(self):
"""Single step a bunch of times."""
+ self.gdb.command("p i=0");
last_pc = None
for _ in range(100):
self.gdb.command("stepi")
@@ -29,11 +29,13 @@ class DebugTest(unittest.TestCase):
last_pc = pc
def test_exit(self):
+ self.gdb.command("p i=0");
output = self.gdb.command("c")
self.assertIn("Continuing", output)
self.assertIn("Remote connection closed", output)
def test_breakpoint(self):
+ self.gdb.command("p i=0");
self.gdb.command("b print_row")
# The breakpoint should be hit exactly 10 times.
for i in range(10):
@@ -46,6 +48,7 @@ class DebugTest(unittest.TestCase):
self.assertIn("Remote connection closed", output)
def test_registers(self):
+ self.gdb.command("p i=0");
# Try both forms to test gdb.
for cmd in ("info all-registers", "info registers all"):
output = self.gdb.command(cmd)
@@ -66,6 +69,20 @@ class DebugTest(unittest.TestCase):
last_instret = instret
self.gdb.command("stepi")
+ def test_interrupt(self):
+ """Sending gdb ^C while the program is running should cause it to halt."""
+ self.gdb.c(wait=False)
+ time.sleep(0.1)
+ self.gdb.interrupt()
+ self.gdb.command("p i=123");
+ self.gdb.c(wait=False)
+ time.sleep(0.1)
+ self.gdb.interrupt()
+ self.gdb.command("p i=0");
+ output = self.gdb.c()
+ self.assertIn("Continuing", output)
+ self.assertIn("Remote connection closed", output)
+
class RegsTest(unittest.TestCase):
def setUp(self):
self.binary = testlib.compile("regs.s")
diff --git a/tests/testlib.py b/tests/testlib.py
index 4e05616..6233901 100644
--- a/tests/testlib.py
+++ b/tests/testlib.py
@@ -74,6 +74,17 @@ class Gdb(object):
self.child.expect("\(gdb\)")
return self.child.before.strip()
+ def c(self, wait=True):
+ if wait:
+ return self.command("c")
+ else:
+ self.child.sendline("c")
+ self.child.expect("Continuing")
+
+ def interrupt(self):
+ self.child.send("\003");
+ self.child.expect("\(gdb\)")
+
def x(self, address, size='w'):
output = self.command("x/%s %s" % (size, address))
value = int(output.split(':')[1].strip(), 0)