cpu, sim: Add param to force CPUs to wait for GDB
authorJose Marinho <jose.marinho@arm.com>
Wed, 28 Jun 2017 10:09:13 +0000 (11:09 +0100)
committerAndreas Sandberg <andreas.sandberg@arm.com>
Wed, 12 Jul 2017 12:29:32 +0000 (12:29 +0000)
By setting the BaseCPU parameter wait_for_dbg_connection, the GDB
server blocks during initialisation waiting for the remote debugger to
connect before starting the simulated CPU.

Change-Id: I4d62c68ce9adf69344bccbb44f66e30b33715a1c
[ Update info message to include remote GDB port, rename param. ]
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/3963
Reviewed-by: Gabe Black <gabeblack@google.com>
Reviewed-by: Anthony Gutierrez <anthony.gutierrez@amd.com>
src/base/remote_gdb.cc
src/base/remote_gdb.hh
src/cpu/BaseCPU.py
src/cpu/base.cc
src/cpu/base.hh
src/sim/system.cc

index f7b0253a52ddfa99299384d5340a7d8b163014cd..3b436cced5d94dd5ca690c4c1cc2d0ba86832448 100644 (file)
@@ -250,6 +250,16 @@ GDBListener::accept()
     }
 }
 
+int
+GDBListener::getPort() const
+{
+    panic_if(!listener.islistening(),
+             "Remote GDB port is unknown until GDBListener::listen() has "
+             "been called.\n");
+
+    return port;
+}
+
 BaseRemoteGDB::InputEvent::InputEvent(BaseRemoteGDB *g, int fd, int e)
     : PollEvent(fd, e), gdb(g)
 {}
index b860f5d334467f5686aa69d5346507d19906dab1..b7de0ae54fec3d2f64cfe9446cf4f83ec892c07c 100644 (file)
@@ -364,6 +364,8 @@ class GDBListener
     void accept();
     void listen();
     std::string name();
+
+    int getPort() const;
 };
 
 #endif /* __REMOTE_GDB_H__ */
index 550ba62ac68afcb5a52d77acce2c4297642450b6..fcae74207532918e306c3d33d009cbd7ed85c923 100644 (file)
@@ -151,6 +151,9 @@ class BaseCPU(MemObject):
     profile = Param.Latency('0ns', "trace the kernel stack")
     do_quiesce = Param.Bool(True, "enable quiesce instructions")
 
+    wait_for_remote_gdb = Param.Bool(False,
+        "Wait for a remote GDB connection");
+
     workload = VectorParam.Process([], "processes to run")
 
     if buildEnv['TARGET_ISA'] == 'sparc':
index 6f460d3af29ce7a50587971b8d3973c7763fcc2e..78b25caf8d3e903abff18833ae357d84386e6085 100644 (file)
@@ -783,3 +783,9 @@ BaseCPU::traceFunctionsInternal(Addr pc)
         functionEntryTick = curTick();
     }
 }
+
+bool
+BaseCPU::waitForRemoteGDB() const
+{
+    return params()->wait_for_remote_gdb;
+}
index 14dfc260bf434b2436c9a8002a51c5ad9b87e9d9..b49f302724c7bf6a25799afa3a137be81adf2004 100644 (file)
@@ -589,6 +589,8 @@ class BaseCPU : public MemObject
         return &addressMonitor[tid];
     }
 
+    bool waitForRemoteGDB() const;
+
     Cycles syscallRetryLatency;
 };
 
index e46c356113fbd103ab61b4134c49f4971e473eda..42cd5e720e0d5c2a92d0059b2e3b82b287e10632 100644 (file)
@@ -58,6 +58,7 @@
 #include "cpu/kvm/base.hh"
 #include "cpu/kvm/vm.hh"
 #endif
+#include "cpu/base.hh"
 #include "cpu/thread_context.hh"
 #include "debug/Loader.hh"
 #include "debug/WorkItems.hh"
@@ -221,13 +222,6 @@ bool System::breakpoint()
     return false;
 }
 
-/**
- * Setting rgdb_wait to a positive integer waits for a remote debugger to
- * connect to that context ID before continuing.  This should really
-   be a parameter on the CPU object or something...
- */
-int rgdb_wait = -1;
-
 ContextID
 System::registerThreadContext(ThreadContext *tc, ContextID assigned)
 {
@@ -259,9 +253,13 @@ System::registerThreadContext(ThreadContext *tc, ContextID assigned)
         GDBListener *gdbl = new GDBListener(rgdb, port + id);
         gdbl->listen();
 
-        if (rgdb_wait != -1 && rgdb_wait == id)
-            gdbl->accept();
+        BaseCPU *cpu = tc->getCpuPtr();
+        if (cpu->waitForRemoteGDB()) {
+            inform("%s: Waiting for a remote GDB connection on port %d.\n",
+                   cpu->name(), gdbl->getPort());
 
+            gdbl->accept();
+        }
         if (remoteGDB.size() <= id) {
             remoteGDB.resize(id + 1);
         }