From 4f4fe6f80e8cbfcbf8f4a96a74643079e69e8295 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Fri, 31 Jan 2020 16:53:46 -0800 Subject: [PATCH] sim,arch: Move code that waits for a GDB connection to startup(). Currently the System class has a mechanism to wait for a GDB connection for each CPU which has requested it through one of its parameters. Unfortunately, not every thread context/CPU will be ready for GDB at that point, particularly considering that in an FS simulation the kernel won't have been read so there will be no symbols, none of the registers or the entry point will have been set. Also in the fast models, the CPUs haven't had a chance to initialize themselves enough by that point to respond to the API calls which are used to implement GDB support. Change-Id: If27cb3e0259a1f67599ab0493695b2f8af640d8e Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/24963 Reviewed-by: Gabe Black Reviewed-by: Chun-Chen TK Hsu Reviewed-by: Jason Lowe-Power Maintainer: Gabe Black Tested-by: kokoro --- src/arch/arm/freebsd/system.cc | 5 ----- src/arch/arm/freebsd/system.hh | 2 -- src/arch/arm/linux/system.cc | 2 ++ src/sim/system.cc | 35 +++++++++++++++++++++++++--------- src/sim/system.hh | 5 +---- 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/arch/arm/freebsd/system.cc b/src/arch/arm/freebsd/system.cc index 3f38f2e0d0..b77126790b 100644 --- a/src/arch/arm/freebsd/system.cc +++ b/src/arch/arm/freebsd/system.cc @@ -147,8 +147,3 @@ FreebsdArmSystemParams::create() { return new FreebsdArmSystem(this); } - -void -FreebsdArmSystem::startup() -{ -} diff --git a/src/arch/arm/freebsd/system.hh b/src/arch/arm/freebsd/system.hh index 50c405d15c..f4f19a3262 100644 --- a/src/arch/arm/freebsd/system.hh +++ b/src/arch/arm/freebsd/system.hh @@ -74,8 +74,6 @@ class FreebsdArmSystem : public GenericArmSystem void initState(); - void startup(); - /** This function creates a new task Id for the given pid. * @param tc thread context that is currentyl executing */ void mapPid(ThreadContext* tc, uint32_t pid); diff --git a/src/arch/arm/linux/system.cc b/src/arch/arm/linux/system.cc index 1c1ade65ff..30393c43ac 100644 --- a/src/arch/arm/linux/system.cc +++ b/src/arch/arm/linux/system.cc @@ -223,6 +223,8 @@ LinuxArmSystemParams::create() void LinuxArmSystem::startup() { + GenericArmSystem::startup(); + if (enableContextSwitchStatsDump) { if (!highestELIs64()) { dumpStatsPCEvent = diff --git a/src/sim/system.cc b/src/sim/system.cc index 39b9495aaa..51e9d6dfbf 100644 --- a/src/sim/system.cc +++ b/src/sim/system.cc @@ -228,6 +228,31 @@ System::init() panic("System port on %s is not connected.\n", name()); } +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 (auto *tc: threadContexts) { + auto *cpu = tc->getCpuPtr(); + auto id = tc->contextId(); + if (remoteGDB.size() <= id) + continue; + auto *rgdb = remoteGDB[id]; + + if (cpu->waitForRemoteGDB()) { + inform("%s: Waiting for a remote GDB connection on port %d.\n", + cpu->name(), rgdb->port()); + + rgdb->connect(); + } + } +#endif +} + Port & System::getPort(const std::string &if_name, PortID idx) { @@ -276,16 +301,8 @@ System::registerThreadContext(ThreadContext *tc, ContextID assigned) RemoteGDB *rgdb = new RemoteGDB(this, tc, port + id); rgdb->listen(); - BaseCPU *cpu = tc->getCpuPtr(); - if (cpu->waitForRemoteGDB()) { - inform("%s: Waiting for a remote GDB connection on port %d.\n", - cpu->name(), rgdb->port()); - - rgdb->connect(); - } - if (remoteGDB.size() <= id) { + if (remoteGDB.size() <= id) remoteGDB.resize(id + 1); - } remoteGDB[id] = rgdb; } diff --git a/src/sim/system.hh b/src/sim/system.hh index 3e908e01ba..ae96be1a02 100644 --- a/src/sim/system.hh +++ b/src/sim/system.hh @@ -99,11 +99,8 @@ class System : public SimObject, public PCEventScope public: - /** - * After all objects have been created and all ports are - * connected, check that the system port is connected. - */ void init() override; + void startup() override; /** * Get a reference to the system port that can be used by