GDB stub:
- Added CPU mutex functions gdbstub_mutex_init/destroy/lock/unlock, which govern access to NDS_ARM9 and NDS_ARM7 structs. - Added locking and unlocking of the mutex to gdbstub.cpp/processPacket_gdb() and NDSSystem.cpp/NDS_exec() Cocoa, CLI, GTK, Windows ports: - Added mutex initialization and destruction to main() functions (cocoa/cocoa_core.mm, cli/main.cpp, gtk/main.cpp, windows/main.cpp)
This commit is contained in:
parent
0754569c17
commit
e714ce9e20
|
@ -55,6 +55,10 @@
|
||||||
#include "SPU.h"
|
#include "SPU.h"
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
|
|
||||||
|
#ifdef GDB_STUB
|
||||||
|
#include "gdbstub.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
//int xxctr=0;
|
//int xxctr=0;
|
||||||
//#define LOG_ARM9
|
//#define LOG_ARM9
|
||||||
//#define LOG_ARM7
|
//#define LOG_ARM7
|
||||||
|
@ -1828,6 +1832,10 @@ void NDS_debug_step()
|
||||||
template<bool FORCE>
|
template<bool FORCE>
|
||||||
void NDS_exec(s32 nb)
|
void NDS_exec(s32 nb)
|
||||||
{
|
{
|
||||||
|
#ifdef GDB_STUB
|
||||||
|
gdbstub_mutex_lock();
|
||||||
|
#endif
|
||||||
|
|
||||||
LagFrameFlag=1;
|
LagFrameFlag=1;
|
||||||
|
|
||||||
sequencer.nds_vblankEnded = false;
|
sequencer.nds_vblankEnded = false;
|
||||||
|
@ -1860,7 +1868,13 @@ void NDS_exec(s32 nb)
|
||||||
|
|
||||||
while((NDS_ARM9.stalled || NDS_ARM7.stalled) && execute)
|
while((NDS_ARM9.stalled || NDS_ARM7.stalled) && execute)
|
||||||
{
|
{
|
||||||
|
#ifdef GDB_STUB
|
||||||
|
gdbstub_mutex_unlock();
|
||||||
|
#endif
|
||||||
driver->EMU_DebugIdleUpdate();
|
driver->EMU_DebugIdleUpdate();
|
||||||
|
#ifdef GDB_STUB
|
||||||
|
gdbstub_mutex_lock();
|
||||||
|
#endif
|
||||||
nds_debug_continuing[0] = nds_debug_continuing[1] = true;
|
nds_debug_continuing[0] = nds_debug_continuing[1] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1961,6 +1975,10 @@ void NDS_exec(s32 nb)
|
||||||
DEBUG_Notify.NextFrame();
|
DEBUG_Notify.NextFrame();
|
||||||
if (cheats)
|
if (cheats)
|
||||||
cheats->process();
|
cheats->process();
|
||||||
|
|
||||||
|
#ifdef GDB_STUB
|
||||||
|
gdbstub_mutex_unlock();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
template<int PROCNUM> static void execHardware_interrupts_core()
|
template<int PROCNUM> static void execHardware_interrupts_core()
|
||||||
|
|
|
@ -596,6 +596,8 @@ int main(int argc, char ** argv) {
|
||||||
driver = new BaseDriver();
|
driver = new BaseDriver();
|
||||||
|
|
||||||
#ifdef GDB_STUB
|
#ifdef GDB_STUB
|
||||||
|
gdbstub_mutex_init();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Activate the GDB stubs
|
* Activate the GDB stubs
|
||||||
* This has to come after NDS_Init() where the CPUs are set up.
|
* This has to come after NDS_Init() where the CPUs are set up.
|
||||||
|
@ -826,6 +828,8 @@ int main(int argc, char ** argv) {
|
||||||
|
|
||||||
destroyStub_gdb( arm7_gdb_stub);
|
destroyStub_gdb( arm7_gdb_stub);
|
||||||
arm7_gdb_stub = NULL;
|
arm7_gdb_stub = NULL;
|
||||||
|
|
||||||
|
gdbstub_mutex_destroy();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
|
|
@ -371,6 +371,8 @@ volatile bool execute = true;
|
||||||
#ifdef GDB_STUB
|
#ifdef GDB_STUB
|
||||||
if (theState)
|
if (theState)
|
||||||
{
|
{
|
||||||
|
gdbstub_mutex_init();
|
||||||
|
|
||||||
if ([self enableGdbStubARM9])
|
if ([self enableGdbStubARM9])
|
||||||
{
|
{
|
||||||
const uint16_t arm9Port = (uint16_t)[self gdbStubPortARM9];
|
const uint16_t arm9Port = (uint16_t)[self gdbStubPortARM9];
|
||||||
|
@ -422,6 +424,8 @@ volatile bool execute = true;
|
||||||
|
|
||||||
destroyStub_gdb(gdbStubHandleARM7);
|
destroyStub_gdb(gdbStubHandleARM7);
|
||||||
gdbStubHandleARM7 = NULL;
|
gdbStubHandleARM7 = NULL;
|
||||||
|
|
||||||
|
gdbstub_mutex_destroy();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (gdbStubHandleARM9 == NULL && gdbStubHandleARM7 == NULL)
|
if (gdbStubHandleARM9 == NULL && gdbStubHandleARM7 == NULL)
|
||||||
|
|
|
@ -25,6 +25,11 @@ typedef void *gdbstub_handle_t;
|
||||||
struct armcpu_t;
|
struct armcpu_t;
|
||||||
struct armcpu_memory_iface;
|
struct armcpu_memory_iface;
|
||||||
|
|
||||||
|
void gdbstub_mutex_init();
|
||||||
|
void gdbstub_mutex_destroy();
|
||||||
|
void gdbstub_mutex_lock();
|
||||||
|
void gdbstub_mutex_unlock();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The function interface
|
* The function interface
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -35,6 +35,25 @@
|
||||||
#include "../armcpu.h"
|
#include "../armcpu.h"
|
||||||
#include "../MMU.h"
|
#include "../MMU.h"
|
||||||
|
|
||||||
|
// For cpu_mutex
|
||||||
|
#ifdef HOST_WINDOWS
|
||||||
|
#include <windows.h>
|
||||||
|
#else
|
||||||
|
#include <pthread.h>
|
||||||
|
#if defined HOST_LINUX
|
||||||
|
#include <unistd.h>
|
||||||
|
#elif defined HOST_BSD || defined HOST_DARWIN
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#endif
|
||||||
|
#endif // HOST_WINDOWS
|
||||||
|
|
||||||
|
#ifndef HOST_WINDOWS
|
||||||
|
// to access the CPUs in any way, a thread has to get a lock on this first
|
||||||
|
pthread_mutex_t cpu_mutex;
|
||||||
|
#else
|
||||||
|
HANDLE cpu_mutex;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#define UNUSED_PARM( parm) parm __attribute__((unused))
|
#define UNUSED_PARM( parm) parm __attribute__((unused))
|
||||||
#else
|
#else
|
||||||
|
@ -134,9 +153,53 @@ enum target_signal
|
||||||
TARGET_SIGNAL_PRIO = 44,
|
TARGET_SIGNAL_PRIO = 44,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Try defining/undefining this, if you have problems with the GDB stub on Windows.
|
||||||
|
#define USE_MUTEX_ON_WINDOWS
|
||||||
|
|
||||||
|
void gdbstub_mutex_init()
|
||||||
|
{
|
||||||
|
#ifndef HOST_WINDOWS
|
||||||
|
pthread_mutex_init(&cpu_mutex, NULL);
|
||||||
|
#else
|
||||||
|
#ifdef USE_MUTEX_ON_WINDOWS
|
||||||
|
cpu_mutex = CreateMutex(NULL, FALSE, NULL);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void gdbstub_mutex_destroy()
|
||||||
|
{
|
||||||
|
#ifndef HOST_WINDOWS
|
||||||
|
pthread_mutex_destroy(&cpu_mutex);
|
||||||
|
#else
|
||||||
|
#ifdef USE_MUTEX_ON_WINDOWS
|
||||||
|
CloseHandle(cpu_mutex);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void gdbstub_mutex_lock()
|
||||||
|
{
|
||||||
|
#ifndef HOST_WINDOWS
|
||||||
|
pthread_mutex_lock(&cpu_mutex);
|
||||||
|
#else
|
||||||
|
#ifdef USE_MUTEX_ON_WINDOWS
|
||||||
|
// Maybe we should check the return value, but then again what could we do about it anyway.
|
||||||
|
WaitForSingleObject(cpu_mutex, INFINITE);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void gdbstub_mutex_unlock()
|
||||||
|
{
|
||||||
|
#ifndef HOST_WINDOWS
|
||||||
|
pthread_mutex_unlock(&cpu_mutex);
|
||||||
|
#else
|
||||||
|
#ifdef USE_MUTEX_ON_WINDOWS
|
||||||
|
ReleaseMutex(cpu_mutex);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
causeQuit_gdb( struct gdb_stub_state *stub) {
|
causeQuit_gdb( struct gdb_stub_state *stub) {
|
||||||
|
@ -527,6 +590,7 @@ processPacket_gdb( SOCKET_TYPE sock, const uint8_t *packet,
|
||||||
uint32_t send_size = 0;
|
uint32_t send_size = 0;
|
||||||
|
|
||||||
DEBUG_LOG("Processing packet %c\n", packet[0]);
|
DEBUG_LOG("Processing packet %c\n", packet[0]);
|
||||||
|
gdbstub_mutex_lock();
|
||||||
|
|
||||||
switch( packet[0]) {
|
switch( packet[0]) {
|
||||||
case 3:
|
case 3:
|
||||||
|
@ -899,6 +963,8 @@ processPacket_gdb( SOCKET_TYPE sock, const uint8_t *packet,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gdbstub_mutex_unlock();
|
||||||
|
|
||||||
if ( send_reply) {
|
if ( send_reply) {
|
||||||
return putpacket( sock, out_packet, send_size);
|
return putpacket( sock, out_packet, send_size);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2919,6 +2919,8 @@ common_gtk_main( class configured_features *my_config)
|
||||||
* where the cpus are set up.
|
* where the cpus are set up.
|
||||||
*/
|
*/
|
||||||
#ifdef GDB_STUB
|
#ifdef GDB_STUB
|
||||||
|
gdbstub_mutex_init();
|
||||||
|
|
||||||
gdbstub_handle_t arm9_gdb_stub = NULL;
|
gdbstub_handle_t arm9_gdb_stub = NULL;
|
||||||
gdbstub_handle_t arm7_gdb_stub = NULL;
|
gdbstub_handle_t arm7_gdb_stub = NULL;
|
||||||
|
|
||||||
|
@ -3277,6 +3279,8 @@ common_gtk_main( class configured_features *my_config)
|
||||||
|
|
||||||
destroyStub_gdb( arm7_gdb_stub);
|
destroyStub_gdb( arm7_gdb_stub);
|
||||||
arm7_gdb_stub = NULL;
|
arm7_gdb_stub = NULL;
|
||||||
|
|
||||||
|
gdbstub_mutex_destroy();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
|
@ -3257,6 +3257,8 @@ int _main()
|
||||||
NDS_Init();
|
NDS_Init();
|
||||||
|
|
||||||
#ifdef GDB_STUB
|
#ifdef GDB_STUB
|
||||||
|
gdbstub_mutex_init();
|
||||||
|
|
||||||
// Activate the GDB stubs. This has to come after the NDS_Init() where the CPUs are set up.
|
// Activate the GDB stubs. This has to come after the NDS_Init() where the CPUs are set up.
|
||||||
gdbstub_handle_t arm9_gdb_stub = NULL;
|
gdbstub_handle_t arm9_gdb_stub = NULL;
|
||||||
gdbstub_handle_t arm7_gdb_stub = NULL;
|
gdbstub_handle_t arm7_gdb_stub = NULL;
|
||||||
|
@ -3460,6 +3462,8 @@ int _main()
|
||||||
|
|
||||||
destroyStub_gdb(arm7_gdb_stub);
|
destroyStub_gdb(arm7_gdb_stub);
|
||||||
arm7_gdb_stub = NULL;
|
arm7_gdb_stub = NULL;
|
||||||
|
|
||||||
|
gdbstub_mutex_destroy();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
NDS_DeInit();
|
NDS_DeInit();
|
||||||
|
|
Loading…
Reference in New Issue