Let the GDB stub listen for commands while running

This is needed to send ctrl+C signals while the CPU thread is running.
This commit is contained in:
aldelaro5 2021-09-29 12:57:46 -04:00
parent 39569ed1f8
commit e03ddc2116
3 changed files with 30 additions and 4 deletions

View File

@ -55,6 +55,8 @@ static u32 sig = 0;
static u32 send_signal = 0; static u32 send_signal = 0;
static u32 step_break = 0; static u32 step_break = 0;
static CoreTiming::EventType* m_gdbStubUpdateEvent;
typedef struct typedef struct
{ {
u32 active; u32 active;
@ -114,6 +116,12 @@ static void hex2mem(u8* dst, u8* src, u32 len)
} }
} }
void GDBStubUpdateCallback(u64 userdata, s64 cycles_late)
{
gdb_handle_exception(false);
CoreTiming::ScheduleEvent(GDB_UPDATE_CYCLES, m_gdbStubUpdateEvent);
}
static u8 gdb_read_byte() static u8 gdb_read_byte()
{ {
u8 c = '+'; u8 c = '+';
@ -732,13 +740,20 @@ static void gdb_remove_bp()
gdb_reply("OK"); gdb_reply("OK");
} }
void gdb_handle_exception()
void gdb_handle_exception(bool loop_until_continue)
{ {
while (gdb_active()) while (gdb_active())
{ {
if (!gdb_data_available()) if (!gdb_data_available())
{
if (loop_until_continue)
continue; continue;
else
return;
}
gdb_read_command(); gdb_read_command();
// No more commands
if (cmd_len == 0) if (cmd_len == 0)
continue; continue;
@ -868,6 +883,9 @@ static void gdb_init_generic(int domain, const sockaddr* server_addr, socklen_t
close(tmpsock); close(tmpsock);
#endif #endif
tmpsock = -1; tmpsock = -1;
m_gdbStubUpdateEvent = CoreTiming::RegisterEvent("GDBStubUpdate", GDBStubUpdateCallback);
CoreTiming::ScheduleEvent(GDB_UPDATE_CYCLES, m_gdbStubUpdateEvent);
} }
void gdb_deinit() void gdb_deinit()

View File

@ -6,6 +6,7 @@
#pragma once #pragma once
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Core/CoreTiming.h"
#ifndef MSG_WAITALL #ifndef MSG_WAITALL
#define MSG_WAITALL (8) #define MSG_WAITALL (8)
@ -26,13 +27,17 @@ typedef enum
GDB_BP_TYPE_A GDB_BP_TYPE_A
} gdb_bp_type; } gdb_bp_type;
const s64 GDB_UPDATE_CYCLES = 100000;
void GDBStubUpdateCallback(u64 userdata, s64 cycles_late);
void gdb_init(u32 port); void gdb_init(u32 port);
void gdb_init_local(const char* socket); void gdb_init_local(const char* socket);
void gdb_deinit(); void gdb_deinit();
bool gdb_active(); bool gdb_active();
void gdb_break(); void gdb_break();
void gdb_handle_exception(); void gdb_handle_exception(bool loopUntilContinue);
int gdb_signal(u32 signal); int gdb_signal(u32 signal);
int gdb_bp_x(u32 addr); int gdb_bp_x(u32 addr);
@ -41,3 +46,6 @@ int gdb_bp_w(u32 addr);
int gdb_bp_a(u32 addr); int gdb_bp_a(u32 addr);
bool gdb_add_bp(u32 type, u32 addr, u32 len); bool gdb_add_bp(u32 type, u32 addr, u32 len);
void gdb_handle_exception(bool loop_until_continue);
void SendSignal(u32 signal);
} // namespace GDBStub

View File

@ -158,7 +158,7 @@ int Interpreter::SingleStepInner()
Host_UpdateDisasmDialog(); Host_UpdateDisasmDialog();
gdb_signal(GDB_SIGTRAP); gdb_signal(GDB_SIGTRAP);
gdb_handle_exception(); gdb_handle_exception(true);
} }
#endif #endif