Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/44618 )

Change subject: arch,base,sim: Construct the GDB stub with no threads.
......................................................................

arch,base,sim: Construct the GDB stub with no threads.

By moving the installation of even the first ThreadContext out of the
constructor, it's possible to construct the stub separately. We can then
move the code that creates the stub out of the base class and into
architecture specific sub-classes.

Change-Id: I0dfd53a3135ebc98ec49acf81d83e58830bc365c
---
M src/arch/arm/remote_gdb.cc
M src/arch/arm/remote_gdb.hh
M src/arch/mips/remote_gdb.cc
M src/arch/mips/remote_gdb.hh
M src/arch/power/remote_gdb.cc
M src/arch/power/remote_gdb.hh
M src/arch/riscv/remote_gdb.cc
M src/arch/riscv/remote_gdb.hh
M src/arch/sparc/remote_gdb.cc
M src/arch/sparc/remote_gdb.hh
M src/arch/x86/remote_gdb.cc
M src/arch/x86/remote_gdb.hh
M src/base/remote_gdb.cc
M src/base/remote_gdb.hh
M src/sim/system.cc
M src/sim/workload.cc
M src/sim/workload.hh
17 files changed, 44 insertions(+), 33 deletions(-)



diff --git a/src/arch/arm/remote_gdb.cc b/src/arch/arm/remote_gdb.cc
index 96344a9..c0c1e0f 100644
--- a/src/arch/arm/remote_gdb.cc
+++ b/src/arch/arm/remote_gdb.cc
@@ -184,8 +184,8 @@
            mmu->translateFunctional(req, tc, BaseTLB::Execute) == NoFault;
 }

-RemoteGDB::RemoteGDB(System *_system, ThreadContext *tc, int _port)
-    : BaseRemoteGDB(_system, tc, _port), regCache32(this), regCache64(this)
+RemoteGDB::RemoteGDB(System *_system, int _port)
+    : BaseRemoteGDB(_system, _port), regCache32(this), regCache64(this)
 {
 }

diff --git a/src/arch/arm/remote_gdb.hh b/src/arch/arm/remote_gdb.hh
index 112056a..84859da 100644
--- a/src/arch/arm/remote_gdb.hh
+++ b/src/arch/arm/remote_gdb.hh
@@ -115,7 +115,7 @@
     AArch64GdbRegCache regCache64;

   public:
-    RemoteGDB(System *_system, ThreadContext *tc, int _port);
+    RemoteGDB(System *_system, int _port);
     BaseGdbRegCache *gdbRegs();
     std::vector<std::string>
     availableFeatures() const
diff --git a/src/arch/mips/remote_gdb.cc b/src/arch/mips/remote_gdb.cc
index 30efb36..6f869fc 100644
--- a/src/arch/mips/remote_gdb.cc
+++ b/src/arch/mips/remote_gdb.cc
@@ -148,8 +148,8 @@

 using namespace MipsISA;

-RemoteGDB::RemoteGDB(System *_system, ThreadContext *tc, int _port)
-    : BaseRemoteGDB(_system, tc, _port), regCache(this)
+RemoteGDB::RemoteGDB(System *_system, int _port)
+    : BaseRemoteGDB(_system, _port), regCache(this)
 {
 }

diff --git a/src/arch/mips/remote_gdb.hh b/src/arch/mips/remote_gdb.hh
index a8e7c1f..8fb54f7 100644
--- a/src/arch/mips/remote_gdb.hh
+++ b/src/arch/mips/remote_gdb.hh
@@ -77,7 +77,7 @@
     MipsGdbRegCache regCache;

   public:
-    RemoteGDB(System *_system, ThreadContext *tc, int _port);
+    RemoteGDB(System *_system, int _port);
     BaseGdbRegCache *gdbRegs();
     std::vector<std::string>
     availableFeatures() const
diff --git a/src/arch/power/remote_gdb.cc b/src/arch/power/remote_gdb.cc
index ce9976f..860a233 100644
--- a/src/arch/power/remote_gdb.cc
+++ b/src/arch/power/remote_gdb.cc
@@ -145,8 +145,8 @@

 using namespace PowerISA;

-RemoteGDB::RemoteGDB(System *_system, ThreadContext *tc, int _port)
-    : BaseRemoteGDB(_system, tc, _port), regCache(this)
+RemoteGDB::RemoteGDB(System *_system, int _port)
+    : BaseRemoteGDB(_system, _port), regCache(this)
 {
 }

diff --git a/src/arch/power/remote_gdb.hh b/src/arch/power/remote_gdb.hh
index 4f46ca5..ab5037e 100644
--- a/src/arch/power/remote_gdb.hh
+++ b/src/arch/power/remote_gdb.hh
@@ -76,7 +76,7 @@
     PowerGdbRegCache regCache;

   public:
-    RemoteGDB(System *_system, ThreadContext *tc, int _port);
+    RemoteGDB(System *_system, int _port);
     BaseGdbRegCache *gdbRegs();
     std::vector<std::string>
     availableFeatures() const
diff --git a/src/arch/riscv/remote_gdb.cc b/src/arch/riscv/remote_gdb.cc
index da78957..b339892 100644
--- a/src/arch/riscv/remote_gdb.cc
+++ b/src/arch/riscv/remote_gdb.cc
@@ -150,8 +150,8 @@

 using namespace RiscvISA;

-RemoteGDB::RemoteGDB(System *_system, ThreadContext *tc, int _port)
-    : BaseRemoteGDB(_system, tc, _port), regCache(this)
+RemoteGDB::RemoteGDB(System *_system, int _port)
+    : BaseRemoteGDB(_system, _port), regCache(this)
 {
 }

diff --git a/src/arch/riscv/remote_gdb.hh b/src/arch/riscv/remote_gdb.hh
index fe6503b..f1ff6c1 100644
--- a/src/arch/riscv/remote_gdb.hh
+++ b/src/arch/riscv/remote_gdb.hh
@@ -141,7 +141,7 @@
     RiscvGdbRegCache regCache;

   public:
-    RemoteGDB(System *_system, ThreadContext *tc, int _port);
+    RemoteGDB(System *_system, int _port);
     BaseGdbRegCache *gdbRegs() override;
     /**
      * Informs GDB remote serial protocol that XML features are supported
diff --git a/src/arch/sparc/remote_gdb.cc b/src/arch/sparc/remote_gdb.cc
index 1a1042d..53d2250 100644
--- a/src/arch/sparc/remote_gdb.cc
+++ b/src/arch/sparc/remote_gdb.cc
@@ -144,8 +144,8 @@

 using namespace SparcISA;

-RemoteGDB::RemoteGDB(System *_system, ThreadContext *c, int _port)
-    : BaseRemoteGDB(_system, c, _port), regCache32(this), regCache64(this)
+RemoteGDB::RemoteGDB(System *_system, int _port)
+    : BaseRemoteGDB(_system, _port), regCache32(this), regCache64(this)
 {}

 ///////////////////////////////////////////////////////////
diff --git a/src/arch/sparc/remote_gdb.hh b/src/arch/sparc/remote_gdb.hh
index b646fbb..d6abf32 100644
--- a/src/arch/sparc/remote_gdb.hh
+++ b/src/arch/sparc/remote_gdb.hh
@@ -105,7 +105,7 @@
     SPARC64GdbRegCache regCache64;

   public:
-    RemoteGDB(System *_system, ThreadContext *tc, int _port);
+    RemoteGDB(System *_system, int _port);
     BaseGdbRegCache *gdbRegs();
 };
 } // namespace SparcISA
diff --git a/src/arch/x86/remote_gdb.cc b/src/arch/x86/remote_gdb.cc
index 39d467b..32d9faa 100644
--- a/src/arch/x86/remote_gdb.cc
+++ b/src/arch/x86/remote_gdb.cc
@@ -62,8 +62,8 @@

 using namespace X86ISA;

-RemoteGDB::RemoteGDB(System *_system, ThreadContext *c, int _port) :
-    BaseRemoteGDB(_system, c, _port), regCache32(this), regCache64(this)
+RemoteGDB::RemoteGDB(System *_system, int _port) :
+    BaseRemoteGDB(_system, _port), regCache32(this), regCache64(this)
 {}

 bool
diff --git a/src/arch/x86/remote_gdb.hh b/src/arch/x86/remote_gdb.hh
index 4ebaa04..336b16a 100644
--- a/src/arch/x86/remote_gdb.hh
+++ b/src/arch/x86/remote_gdb.hh
@@ -142,7 +142,7 @@
     AMD64GdbRegCache regCache64;

   public:
-    RemoteGDB(System *system, ThreadContext *context, int _port);
+    RemoteGDB(System *system, int _port);
     BaseGdbRegCache *gdbRegs();
 };
 } // namespace X86ISA
diff --git a/src/base/remote_gdb.cc b/src/base/remote_gdb.cc
index 69e28ee..c988fde 100644
--- a/src/base/remote_gdb.cc
+++ b/src/base/remote_gdb.cc
@@ -349,12 +349,10 @@

 }

-BaseRemoteGDB::BaseRemoteGDB(System *_system, ThreadContext *c, int _port) :
+BaseRemoteGDB::BaseRemoteGDB(System *_system, int _port) :
         connectEvent(nullptr), dataEvent(nullptr), _port(_port), fd(-1),
         sys(_system), trapEvent(this), singleStepEvent(*this)
-{
-    addThreadContext(c);
-}
+{}

 BaseRemoteGDB::~BaseRemoteGDB()
 {
@@ -392,7 +390,7 @@
 BaseRemoteGDB::connect()
 {
     panic_if(!listener.islistening(),
-             "Cannot accept GDB connections if we're not listening!");
+             "Can't accept GDB connections without any threads!");

     int sfd = listener.accept(true);

@@ -444,6 +442,10 @@
     // If no ThreadContext is current selected, select this one.
     if (!tc)
         assert(selectThreadContext(_tc->contextId()));
+
+    // Now that we have a thread, we can start listening.
+    if (!listener.islistening())
+        listen();
 }

 void
diff --git a/src/base/remote_gdb.hh b/src/base/remote_gdb.hh
index 3371a95..edc81ed 100644
--- a/src/base/remote_gdb.hh
+++ b/src/base/remote_gdb.hh
@@ -149,7 +149,7 @@
     /**
      * Interface to other parts of the simulator.
      */
-    BaseRemoteGDB(System *system, ThreadContext *context, int _port);
+    BaseRemoteGDB(System *system, int _port);
     virtual ~BaseRemoteGDB();

     std::string name();
diff --git a/src/sim/system.cc b/src/sim/system.cc
index 1d39f36..8106d33 100644
--- a/src/sim/system.cc
+++ b/src/sim/system.cc
@@ -212,7 +212,7 @@
       redirectPaths(p.redirect_paths)
 {
     if (workload)
-        workload->system = this;
+        workload->setSystem(this);

     // add self to global system list
     systemList.push_back(this);
diff --git a/src/sim/workload.cc b/src/sim/workload.cc
index 989305b..962c60a 100644
--- a/src/sim/workload.cc
+++ b/src/sim/workload.cc
@@ -32,6 +32,18 @@
 #include "sim/debug.hh"

 void
+Workload::setSystem(System *sys)
+{
+    system = sys;
+
+#   if THE_ISA != NULL_ISA
+    int port = getRemoteGDBPort();
+    if (port)
+        gdb = new TheISA::RemoteGDB(system, port);
+#   endif
+}
+
+void
 Workload::registerThreadContext(ThreadContext *tc)
 {
     std::set<ThreadContext *>::iterator it;
@@ -41,13 +53,8 @@
             tc->contextId());

 #   if THE_ISA != NULL_ISA
-    int port = getRemoteGDBPort();
-    if (port && !gdb) {
-        gdb = new TheISA::RemoteGDB(system, tc, port);
-        gdb->listen();
-    } else if (gdb) {
+    if (gdb)
         gdb->addThreadContext(tc);
-    }
 #   endif
 }

diff --git a/src/sim/workload.hh b/src/sim/workload.hh
index 3418a7d..3a63838 100644
--- a/src/sim/workload.hh
+++ b/src/sim/workload.hh
@@ -71,16 +71,18 @@
     bool waitForRemoteGDB = false;
     std::set<ThreadContext *> threads;

+    System *system = nullptr;
+
   public:
Workload(const WorkloadParams &params) : SimObject(params), stats(this),
             waitForRemoteGDB(params.wait_for_remote_gdb)
     {}

+    void setSystem(System *sys);
+
     void recordQuiesce() { stats.instStats.quiesce++; }
     void recordArm() { stats.instStats.arm++; }

-    System *system = nullptr;
-
     virtual void registerThreadContext(ThreadContext *tc);
     virtual void replaceThreadContext(ThreadContext *tc);


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/44618
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I0dfd53a3135ebc98ec49acf81d83e58830bc365c
Gerrit-Change-Number: 44618
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <gabe.bl...@gmail.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to