diff --git a/src/arch/arm/remote_gdb.cc b/src/arch/arm/remote_gdb.cc index 5a6720cb70..da536544f5 100644 --- a/src/arch/arm/remote_gdb.cc +++ b/src/arch/arm/remote_gdb.cc @@ -184,8 +184,8 @@ tryTranslate(ThreadContext *tc, Addr addr) 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 ea6cd05771..80d06d03aa 100644 --- a/src/arch/arm/remote_gdb.hh +++ b/src/arch/arm/remote_gdb.hh @@ -115,7 +115,7 @@ class RemoteGDB : public BaseRemoteGDB AArch64GdbRegCache regCache64; public: - RemoteGDB(System *_system, ThreadContext *tc, int _port); + RemoteGDB(System *_system, int _port); BaseGdbRegCache *gdbRegs(); std::vector availableFeatures() const diff --git a/src/arch/mips/remote_gdb.cc b/src/arch/mips/remote_gdb.cc index 30efb36e80..6f869fcaf6 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 a8e7c1f592..8fb54f7d5e 100644 --- a/src/arch/mips/remote_gdb.hh +++ b/src/arch/mips/remote_gdb.hh @@ -77,7 +77,7 @@ class RemoteGDB : public BaseRemoteGDB MipsGdbRegCache regCache; public: - RemoteGDB(System *_system, ThreadContext *tc, int _port); + RemoteGDB(System *_system, int _port); BaseGdbRegCache *gdbRegs(); std::vector availableFeatures() const diff --git a/src/arch/power/remote_gdb.cc b/src/arch/power/remote_gdb.cc index ce9976fac6..860a23338e 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 4f46ca51d1..ab5037e4e8 100644 --- a/src/arch/power/remote_gdb.hh +++ b/src/arch/power/remote_gdb.hh @@ -76,7 +76,7 @@ class RemoteGDB : public BaseRemoteGDB PowerGdbRegCache regCache; public: - RemoteGDB(System *_system, ThreadContext *tc, int _port); + RemoteGDB(System *_system, int _port); BaseGdbRegCache *gdbRegs(); std::vector availableFeatures() const diff --git a/src/arch/riscv/remote_gdb.cc b/src/arch/riscv/remote_gdb.cc index 681a39d341..b8549e266e 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 e57504b048..565a7738e9 100644 --- a/src/arch/riscv/remote_gdb.hh +++ b/src/arch/riscv/remote_gdb.hh @@ -142,7 +142,7 @@ class RemoteGDB : public BaseRemoteGDB 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 1a1042da2f..53d2250a10 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 b646fbbc4a..d6abf32994 100644 --- a/src/arch/sparc/remote_gdb.hh +++ b/src/arch/sparc/remote_gdb.hh @@ -105,7 +105,7 @@ class RemoteGDB : public BaseRemoteGDB 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 f370675d1c..9f8495d442 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 7ba91aeae0..3d5909fb86 100644 --- a/src/arch/x86/remote_gdb.hh +++ b/src/arch/x86/remote_gdb.hh @@ -143,7 +143,7 @@ class RemoteGDB : public BaseRemoteGDB 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 0592b7799d..8ec8641bdd 100644 --- a/src/base/remote_gdb.cc +++ b/src/base/remote_gdb.cc @@ -349,12 +349,10 @@ std::map hardBreakMap; } -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 @@ void 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 @@ BaseRemoteGDB::addThreadContext(ThreadContext *_tc) // 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 231ca62b54..b5870e049b 100644 --- a/src/base/remote_gdb.hh +++ b/src/base/remote_gdb.hh @@ -149,7 +149,7 @@ class BaseRemoteGDB /** * 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 2abebdb326..e2c42a9e6a 100644 --- a/src/sim/system.cc +++ b/src/sim/system.cc @@ -212,7 +212,7 @@ System::System(const Params &p) 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 d1ce8b554b..ba9a7387be 100644 --- a/src/sim/workload.cc +++ b/src/sim/workload.cc @@ -32,6 +32,18 @@ #include "cpu/thread_context.hh" #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) { @@ -42,13 +54,8 @@ Workload::registerThreadContext(ThreadContext *tc) 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 b6345257f1..b2cb4a72d8 100644 --- a/src/sim/workload.hh +++ b/src/sim/workload.hh @@ -71,11 +71,15 @@ class Workload : public SimObject bool waitForRemoteGDB = false; std::set threads; + System *system = nullptr; + public: Workload(const WorkloadParams ¶ms) : 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 @@ class Workload : public SimObject // 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);