Only halt on ebreak if a debugger is attached.
authorTim Newsome <tim@sifive.com>
Thu, 24 Mar 2016 00:42:17 +0000 (17:42 -0700)
committerTim Newsome <tim@sifive.com>
Mon, 23 May 2016 19:12:10 +0000 (12:12 -0700)
riscv/gdbserver.h
riscv/processor.cc
tests/ebreak.py

index 0c923722f46a3543bf5b2c89bcf54c8a1b15ea73..7e7ccbca5c8720c6e8995cca8f63259795f33c68 100644 (file)
@@ -80,6 +80,8 @@ public:
   void handle_register_write(const std::vector<uint8_t> &packet);
   void handle_step(const std::vector<uint8_t> &packet);
 
+  bool connected() const { return client_fd > 0; }
+
 private:
   sim_t *sim;
   int socket_fd;
index 4537c183b850dfb2bdc47773d33f34d925d2e307..b12efe85e4c8dfaa1fd8424ccbb09e70f661d01b 100644 (file)
@@ -209,8 +209,8 @@ void processor_t::take_trap(trap_t& t, reg_t epc)
     fprintf(stderr, "core %3d: exception %s, epc 0x%016" PRIx64 "\n",
             id, t.name(), epc);
 
-  if (t.cause() == CAUSE_BREAKPOINT) {
-    // TODO: Only do this if there is a debugger attached.
+  if (t.cause() == CAUSE_BREAKPOINT &&
+          sim->gdbserver && sim->gdbserver->connected()) {
     set_halted(true, HR_SWBP);
     return;
   }
index 6c3ffdb71beec9779f3934ce2031c4eb00b73125..4b41f7db4fce20ba6b820f77b4227f1a9e354326 100755 (executable)
@@ -10,12 +10,17 @@ class EbreakTest(unittest.TestCase):
     def setUp(self):
         self.binary = testlib.compile("ebreak.s")
 
-    def test_ebreak(self):
-        """Make sure that we can run past ebreak without halting when a
-        debugger isn't attached."""
+    def test_noport(self):
+        """Make sure that we can run past ebreak when --gdb-port isn't used."""
         spike = testlib.spike(self.binary, with_gdb=False, timeout=10)
         result = spike.wait()
         self.assertEqual(result, 0)
 
+    def test_nogdb(self):
+        """Make sure that we can run past ebreak when gdb isn't attached."""
+        spike, port = testlib.spike(self.binary, timeout=10)
+        result = spike.wait()
+        self.assertEqual(result, 0)
+
 if __name__ == '__main__':
     unittest.main()