Skip to content

Commit

Permalink
make it possible to change gdb stub settings without destroying/recre…
Browse files Browse the repository at this point in the history
…ating a NDS
  • Loading branch information
Arisotura committed Nov 17, 2024
1 parent 99aa567 commit 0ea0af3
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 17 deletions.
28 changes: 17 additions & 11 deletions src/ARM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,13 @@ const u32 ARM::ConditionTable[16] =

ARM::ARM(u32 num, bool jit, std::optional<GDBArgs> 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()
Expand All @@ -148,6 +140,20 @@ ARMv5::~ARMv5()
// DTCM is owned by Memory, not going to delete it
}

void ARM::SetGdbArgs(std::optional<GDBArgs> 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;
Expand Down
2 changes: 2 additions & 0 deletions src/ARM.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class ARM
ARM(u32 num, bool jit, std::optional<GDBArgs> gdb, NDS& nds);
virtual ~ARM(); // destroy shit

void SetGdbArgs(std::optional<GDBArgs> gdb);

virtual void Reset();

virtual void DoSavestate(Savestate* file);
Expand Down
9 changes: 9 additions & 0 deletions src/NDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@ void NDS::SetJITArgs(std::optional<JITArgs> args) noexcept
}
#endif

#ifdef GDBSTUB_ENABLED
void NDS::SetGdbArgs(std::optional<GDBArgs> args) noexcept
{
ARM9.SetGdbArgs(args);
ARM7.SetGdbArgs(args);
EnableGDBStub = args.has_value();
}
#endif

void NDS::InitTimings()
{
// TODO, eventually:
Expand Down
6 changes: 6 additions & 0 deletions src/NDS.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,12 @@ class NDS
void SetJITArgs(std::optional<JITArgs> args) noexcept {}
#endif

#ifdef GDBSTUB_ENABLED
void SetGdbArgs(std::optional<GDBArgs> args) noexcept;
#else
void SetGdbArgs(std::optional<GDBArgs> args) noexcept {}
#endif

private:
void InitTimings();
u32 SchedListMask;
Expand Down
7 changes: 4 additions & 3 deletions src/debug/GdbStub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/debug/GdbStub.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ class GdbStub
int kind;
};

GdbStub(StubCallbacks* cb, int port);
GdbStub(StubCallbacks* cb);
~GdbStub();

bool Init();
bool Init(int port);
void Close();

StubState Poll(bool wait = false);
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/qt_sdl/EmuInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 0ea0af3

Please sign in to comment.