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.
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()
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;
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()
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")
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):
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)
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")
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)