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+kokoro@google.com>
Reviewed-by: Gabe Black <gabe.black@gmail.com>
Maintainer: Gabe Black <gabe.black@gmail.com>
This commit is contained in:
Gabe Black
2021-04-19 03:14:19 -07:00
parent 2c75e58cac
commit b6d4e871ef
17 changed files with 44 additions and 33 deletions

View File

@@ -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)
{
}

View File

@@ -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<std::string>
availableFeatures() const

View File

@@ -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)
{
}

View File

@@ -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<std::string>
availableFeatures() const

View File

@@ -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)
{
}

View File

@@ -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<std::string>
availableFeatures() const

View File

@@ -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)
{
}

View File

@@ -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

View File

@@ -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)
{}
///////////////////////////////////////////////////////////

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -349,12 +349,10 @@ std::map<Addr, HardBreakpoint *> 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

View File

@@ -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();

View File

@@ -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);

View File

@@ -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
}

View File

@@ -71,11 +71,15 @@ class Workload : public SimObject
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 @@ 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);