Gabe Black has submitted this change. ( 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
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/44618
Tested-by: kokoro <noreply+kok...@google.com>
Reviewed-by: Gabe Black <gabe.bl...@gmail.com>
Maintainer: Gabe Black <gabe.bl...@gmail.com>
---
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(-)

Approvals:
  Gabe Black: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/arch/arm/remote_gdb.cc b/src/arch/arm/remote_gdb.cc
index 5a6720c..da53654 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 ea6cd05..80d06d0 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 681a39d..b8549e2 100644
--- a/src/arch/riscv/remote_gdb.cc
+++ b/src/arch/riscv/remote_gdb.cc
@@ -152,8 +152,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 e57504b..565a773 100644
--- a/src/arch/riscv/remote_gdb.hh
+++ b/src/arch/riscv/remote_gdb.hh
@@ -142,7 +142,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 f370675..9f8495d 100644
--- a/src/arch/x86/remote_gdb.cc
+++ b/src/arch/x86/remote_gdb.cc
@@ -63,8 +63,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 7ba91ae..3d5909f 100644
--- a/src/arch/x86/remote_gdb.hh
+++ b/src/arch/x86/remote_gdb.hh
@@ -143,7 +143,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 0592b77..8ec8641 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);

@@ -445,6 +443,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 231ca62..b5870e0 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 2abebdb..e2c42a9 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 d1ce8b5..ba9a738 100644
--- a/src/sim/workload.cc
+++ b/src/sim/workload.cc
@@ -33,6 +33,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;
@@ -42,13 +54,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 b634525..b2cb4a7 100644
--- a/src/sim/workload.hh
+++ b/src/sim/workload.hh
@@ -71,11 +71,15 @@
     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++; }

@@ -83,8 +87,6 @@
     // system object, this helper can be removed.
     bool trapToGdb(int signal, ContextID ctx_id);

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




7 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
--
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: 9
Gerrit-Owner: Gabe Black <gabe.bl...@gmail.com>
Gerrit-Reviewer: Bobby R. Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Boris Shingarov <shinga...@gmail.com>
Gerrit-Reviewer: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-Reviewer: Gabe Black <gabe.bl...@gmail.com>
Gerrit-Reviewer: Jason Lowe-Power <ja...@lowepower.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
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