Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/44617 )

Change subject: sim,cpu: Move the remote GDB stub into the workload.
......................................................................

sim,cpu: Move the remote GDB stub into the workload.

There are two user visible effects of this change. First, all of the
threads for a particular workload are moved under a single GDB instance.
The GDB session can see all the threads at once, and can let you move
between them as you want.

Second, since there is a GDB instance per workload and not per CPU, the
wait_for_gdb parameter was moved to the workload.

Change-Id: I510410c3cbb56e445b0fbb1def94c769d3a7b2e3
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/44617
Reviewed-by: Daniel Carvalho <oda...@yahoo.com.br>
Maintainer: Gabe Black <gabe.bl...@gmail.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/cpu/BaseCPU.py
M src/cpu/base.cc
M src/cpu/base.hh
M src/sim/Workload.py
M src/sim/system.cc
M src/sim/system.hh
M src/sim/workload.cc
M src/sim/workload.hh
8 files changed, 60 insertions(+), 50 deletions(-)

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



diff --git a/src/cpu/BaseCPU.py b/src/cpu/BaseCPU.py
index cb43419..bd702e2 100644
--- a/src/cpu/BaseCPU.py
+++ b/src/cpu/BaseCPU.py
@@ -146,9 +146,6 @@
     do_statistics_insts = Param.Bool(True,
         "enable statistics pseudo instructions")

-    wait_for_remote_gdb = Param.Bool(False,
-        "Wait for a remote GDB connection");
-
     workload = VectorParam.Process([], "processes to run")

     mmu = Param.BaseMMU(ArchMMU(), "CPU memory management unit")
diff --git a/src/cpu/base.cc b/src/cpu/base.cc
index dffe4c9..317844d 100644
--- a/src/cpu/base.cc
+++ b/src/cpu/base.cc
@@ -725,12 +725,6 @@
     }
 }

-bool
-BaseCPU::waitForRemoteGDB() const
-{
-    return params().wait_for_remote_gdb;
-}
-

 BaseCPU::GlobalStats::GlobalStats(::Stats::Group *parent)
     : ::Stats::Group(parent),
diff --git a/src/cpu/base.hh b/src/cpu/base.hh
index c113829..177d3df 100644
--- a/src/cpu/base.hh
+++ b/src/cpu/base.hh
@@ -609,8 +609,6 @@
         return &addressMonitor[tid];
     }

-    bool waitForRemoteGDB() const;
-
     Cycles syscallRetryLatency;

   // Enables CPU to enter power gating on a configurable cycle count
diff --git a/src/sim/Workload.py b/src/sim/Workload.py
index 4f1b1b5..91c1c55 100644
--- a/src/sim/Workload.py
+++ b/src/sim/Workload.py
@@ -33,6 +33,9 @@
     cxx_header = "sim/workload.hh"
     abstract = True

+    wait_for_remote_gdb = Param.Bool(False,
+        "Wait for a remote GDB connection");
+
 class KernelWorkload(Workload):
     type = 'KernelWorkload'
     cxx_header = "sim/kernel_workload.hh"
diff --git a/src/sim/system.cc b/src/sim/system.cc
index 7f81f51..2abebdb 100644
--- a/src/sim/system.cc
+++ b/src/sim/system.cc
@@ -43,7 +43,6 @@

 #include <algorithm>

-#include "arch/remote_gdb.hh"
 #include "base/compiler.hh"
 #include "base/loader/object_file.hh"
 #include "base/loader/symtab.hh"
@@ -124,13 +123,6 @@
     // been reallocated.
     t.resumeEvent = new EventFunctionWrapper(
             [this, id](){ thread(id).resume(); }, sys->name());
-#   if THE_ISA != NULL_ISA
-    int port = getRemoteGDBPort();
-    if (port) {
-        t.gdb = new TheISA::RemoteGDB(sys, tc, port + id);
-        t.gdb->listen();
-    }
-#   endif
 }

 void
@@ -138,8 +130,6 @@
 {
     auto &t = thread(id);
     panic_if(!t.context, "Can't replace a context which doesn't exist.");
-    if (t.gdb)
-        t.gdb->replaceThreadContext(tc);
 #   if THE_ISA != NULL_ISA
     if (t.resumeEvent->scheduled()) {
         Tick when = t.resumeEvent->when();
@@ -277,26 +267,6 @@
         delete workItemStats[j];
 }

-void
-System::startup()
-{
-    SimObject::startup();
-
- // Now that we're about to start simulation, wait for GDB connections if
-    // requested.
-#if THE_ISA != NULL_ISA
-    for (int i = 0; i < threads.size(); i++) {
-        auto *gdb = threads.thread(i).gdb;
-        auto *cpu = threads[i]->getCpuPtr();
-        if (gdb && cpu->waitForRemoteGDB()) {
-            inform("%s: Waiting for a remote GDB connection on port %d.",
-                   cpu->name(), gdb->port());
-            gdb->connect();
-        }
-    }
-#endif
-}
-
 Port &
 System::getPort(const std::string &if_name, PortID idx)
 {
@@ -520,11 +490,7 @@
 bool
 System::trapToGdb(int signal, ContextID ctx_id) const
 {
-    auto *gdb = threads.thread(ctx_id).gdb;
-    if (!gdb)
-        return false;
-    gdb->trap(ctx_id, signal);
-    return true;
+    return workload && workload->trapToGdb(signal, ctx_id);
 }

 void
diff --git a/src/sim/system.hh b/src/sim/system.hh
index d04c3d2..cbbd5e5 100644
--- a/src/sim/system.hh
+++ b/src/sim/system.hh
@@ -119,7 +119,6 @@
         {
             ThreadContext *context = nullptr;
             bool active = false;
-            BaseRemoteGDB *gdb = nullptr;
             Event *resumeEvent = nullptr;

             void resume();
@@ -231,8 +230,6 @@
const_iterator end() const { return const_iterator(*this, size()); }
     };

-    void startup() override;
-
     /**
      * Get a reference to the system port that can be used by
      * non-structural simulation objects like processes or threads, or
diff --git a/src/sim/workload.cc b/src/sim/workload.cc
index c7dfcd4..d1ce8b5 100644
--- a/src/sim/workload.cc
+++ b/src/sim/workload.cc
@@ -27,7 +27,10 @@

 #include "sim/workload.hh"

+#include "arch/remote_gdb.hh"
+#include "config/the_isa.hh"
 #include "cpu/thread_context.hh"
+#include "sim/debug.hh"

 void
 Workload::registerThreadContext(ThreadContext *tc)
@@ -37,6 +40,16 @@
     std::tie(it, success) = threads.insert(tc);
     panic_if(!success, "Failed to add thread context %d.",
             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) {
+        gdb->addThreadContext(tc);
+    }
+#   endif
 }

 void
@@ -54,7 +67,39 @@
         std::tie(it, success) = threads.insert(tc);
         panic_if(!success,
                 "Failed to insert replacement thread context %d.", id);
+
+        if (gdb)
+            gdb->replaceThreadContext(tc);
+
         return;
     }
     panic("Replacement thread context %d doesn't match any known id.", id);
 }
+
+bool
+Workload::trapToGdb(int signal, ContextID ctx_id)
+{
+#   if THE_ISA != NULL_ISA
+    if (gdb) {
+        gdb->trap(ctx_id, signal);
+        return true;
+    }
+#   endif
+    return false;
+};
+
+void
+Workload::startup()
+{
+    SimObject::startup();
+
+#   if THE_ISA != NULL_ISA
+ // Now that we're about to start simulation, wait for GDB connections if
+    // requested.
+    if (gdb && waitForRemoteGDB) {
+ inform("%s: Waiting for a remote GDB connection on port %d.", name(),
+                gdb->port());
+        gdb->connect();
+    }
+#   endif
+}
diff --git a/src/sim/workload.hh b/src/sim/workload.hh
index ff29e2d..b634525 100644
--- a/src/sim/workload.hh
+++ b/src/sim/workload.hh
@@ -37,6 +37,7 @@
 #include "sim/sim_object.hh"
 #include "sim/stats.hh"

+class BaseRemoteGDB;
 class System;
 class ThreadContext;

@@ -66,20 +67,29 @@
         {}
     } stats;

+    BaseRemoteGDB *gdb = nullptr;
+    bool waitForRemoteGDB = false;
     std::set<ThreadContext *> threads;

   public:
-    Workload(const WorkloadParams &params) : SimObject(params), stats(this)
+ Workload(const WorkloadParams &params) : SimObject(params), stats(this),
+            waitForRemoteGDB(params.wait_for_remote_gdb)
     {}

     void recordQuiesce() { stats.instStats.quiesce++; }
     void recordArm() { stats.instStats.arm++; }

+ // Once trapping into GDB is no longer a special case routed through the
+    // 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);

+    void startup() override;
+
     virtual Addr getEntry() const = 0;
     virtual Loader::Arch getArch() const = 0;


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/44617
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: I510410c3cbb56e445b0fbb1def94c769d3a7b2e3
Gerrit-Change-Number: 44617
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