diff --git a/src/ARM.cpp b/src/ARM.cpp index b7b703da..0d93dc45 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -109,21 +109,13 @@ const u32 ARM::ConditionTable[16] = ARM::ARM(u32 num, bool jit, std::optional gdb, melonDS::NDS& nds) : #ifdef GDBSTUB_ENABLED - GdbStub(this, gdb ? (num ? gdb->PortARM7 : gdb->PortARM9) : 0), - BreakOnStartup(gdb ? (num ? gdb->ARM7BreakOnStartup : gdb->ARM9BreakOnStartup) : false), + GdbStub(this), + BreakOnStartup(false), #endif Num(num), // well uh NDS(nds) { -#ifdef GDBSTUB_ENABLED - if (gdb -#ifdef JIT_ENABLED - && !jit // TODO: Should we support toggling the GdbStub without destroying the ARM? -#endif - ) - GdbStub.Init(); - IsSingleStep = false; -#endif + SetGdbArgs(jit ? gdb : std::nullopt); } ARM::~ARM() @@ -148,6 +140,20 @@ ARMv5::~ARMv5() // DTCM is owned by Memory, not going to delete it } +void ARM::SetGdbArgs(std::optional gdb) +{ +#ifdef GDBSTUB_ENABLED + GdbStub.Close(); + if (gdb) + { + int port = Num ? gdb->PortARM7 : gdb->PortARM9; + GdbStub.Init(port); + BreakOnStartup = Num ? gdb->ARM7BreakOnStartup : gdb->ARM9BreakOnStartup; + } + IsSingleStep = false; +#endif +} + void ARM::Reset() { Cycles = 0; diff --git a/src/ARM.h b/src/ARM.h index 1403d91a..f18d7650 100644 --- a/src/ARM.h +++ b/src/ARM.h @@ -68,6 +68,8 @@ public: ARM(u32 num, bool jit, std::optional gdb, NDS& nds); virtual ~ARM(); // destroy shit + void SetGdbArgs(std::optional gdb); + virtual void Reset(); virtual void DoSavestate(Savestate* file); diff --git a/src/NDS.cpp b/src/NDS.cpp index e553dd5d..d8e1d216 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -227,6 +227,15 @@ void NDS::SetJITArgs(std::optional args) noexcept } #endif +#ifdef GDBSTUB_ENABLED +void NDS::SetGdbArgs(std::optional args) noexcept +{ + ARM9.SetGdbArgs(args); + ARM7.SetGdbArgs(args); + EnableGDBStub = args.has_value(); +} +#endif + void NDS::InitTimings() { // TODO, eventually: diff --git a/src/NDS.h b/src/NDS.h index 5e474807..da68799f 100644 --- a/src/NDS.h +++ b/src/NDS.h @@ -476,6 +476,12 @@ public: // TODO: Encapsulate the rest of these members void SetJITArgs(std::optional args) noexcept {} #endif +#ifdef GDBSTUB_ENABLED + void SetGdbArgs(std::optional args) noexcept; +#else + void SetGdbArgs(std::optional args) noexcept {} +#endif + private: void InitTimings(); u32 SchedListMask; diff --git a/src/debug/GdbStub.cpp b/src/debug/GdbStub.cpp index b055794a..7ce7693b 100644 --- a/src/debug/GdbStub.cpp +++ b/src/debug/GdbStub.cpp @@ -51,16 +51,17 @@ static int SocketSetBlocking(int fd, bool block) namespace Gdb { -GdbStub::GdbStub(StubCallbacks* cb, int port) - : Cb(cb), Port(port) +GdbStub::GdbStub(StubCallbacks* cb) + : Cb(cb), Port(0) , SockFd(0), ConnFd(0) , Stat(TgtStatus::None), CurBkpt(0), CurWatchpt(0), StatFlag(false), NoAck(false) , ServerSA((void*)new struct sockaddr_in()) , ClientSA((void*)new struct sockaddr_in()) { } -bool GdbStub::Init() +bool GdbStub::Init(int port) { + Port = port; Log(LogLevel::Info, "[GDB] initializing GDB stub for core %d on port %d\n", Cb->GetCPU(), Port); diff --git a/src/debug/GdbStub.h b/src/debug/GdbStub.h index 3e4a0efe..85934327 100644 --- a/src/debug/GdbStub.h +++ b/src/debug/GdbStub.h @@ -115,10 +115,10 @@ public: int kind; }; - GdbStub(StubCallbacks* cb, int port); + GdbStub(StubCallbacks* cb); ~GdbStub(); - bool Init(); + bool Init(int port); void Close(); StubState Poll(bool wait = false); diff --git a/src/frontend/qt_sdl/EmuInstance.cpp b/src/frontend/qt_sdl/EmuInstance.cpp index ce9912e1..1af8a887 100644 --- a/src/frontend/qt_sdl/EmuInstance.cpp +++ b/src/frontend/qt_sdl/EmuInstance.cpp @@ -1362,7 +1362,7 @@ bool EmuInstance::updateConsole() noexcept nds->SetARM9BIOS(*args->ARM9BIOS); nds->SetFirmware(std::move(args->Firmware)); nds->SetJITArgs(args->JIT); - // TODO GDB stub shit + nds->SetGdbArgs(args->GDB); nds->SPU.SetInterpolation(args->Interpolation); nds->SPU.SetDegrade10Bit(args->BitDepth);