diff --git a/doc/emuwiki-api-doc/Mupen64Plus-v2.0-Core-Debugger.mediawiki b/doc/emuwiki-api-doc/Mupen64Plus-v2.0-Core-Debugger.mediawiki
index 839d58fb8..d22897b98 100644
--- a/doc/emuwiki-api-doc/Mupen64Plus-v2.0-Core-Debugger.mediawiki
+++ b/doc/emuwiki-api-doc/Mupen64Plus-v2.0-Core-Debugger.mediawiki
@@ -38,10 +38,10 @@ Most libmupen64plus functions return an m64p_error return code, which i
{| border="1"
|Prototype
-|'''m64p_error DebugSetRunState(int runstate)'''
+|'''m64p_error DebugSetRunState(m64p_dbg_runstate runstate)'''
|-
|Input Parameters
-|'''runstate''' 0 == pause, 1 == single instruction step, 2 == run
+|'''runstate''' An m64p_dbg_runstate enumerated type specifying the debugging state of the emulator. M64P_DBG_RUNSTATE_RUNNING continues execution until a breakpoint is hit or a different state is chosen. M64P_DBG_RUNSTATE_STEPPING enters a single step running mode that sends callbacks as each step is performed. M64P_DBG_RUNSTATE_PAUSED pauses execution to allow manual stepping.
|-
|Requirements
|The Mupen64Plus library must be built with debugger support and must be initialized before calling this function.
diff --git a/doc/emuwiki-api-doc/Mupen64Plus-v2.0-headers.mediawiki b/doc/emuwiki-api-doc/Mupen64Plus-v2.0-headers.mediawiki
index df03f871e..139075b08 100644
--- a/doc/emuwiki-api-doc/Mupen64Plus-v2.0-headers.mediawiki
+++ b/doc/emuwiki-api-doc/Mupen64Plus-v2.0-headers.mediawiki
@@ -191,6 +191,12 @@
M64P_DBG_CPU_NEXT_INTERRUPT
} m64p_dbg_state;
+ typedef enum {
+ M64P_DBG_RUNSTATE_PAUSED = 0,
+ M64P_DBG_RUNSTATE_STEPPING,
+ M64P_DBG_RUNSTATE_RUNNING
+ } m64p_dbg_runstate;
+
typedef enum {
M64P_DBG_MEM_TYPE = 1,
M64P_DBG_MEM_FLAGS,
diff --git a/src/api/debugger.c b/src/api/debugger.c
index ba99b8d16..87aefcb89 100644
--- a/src/api/debugger.c
+++ b/src/api/debugger.c
@@ -112,10 +112,10 @@ EXPORT m64p_error CALL DebugSetCallbacks(void (*dbg_frontend_init)(void), void (
#endif
}
-EXPORT m64p_error CALL DebugSetRunState(int runstate)
+EXPORT m64p_error CALL DebugSetRunState(m64p_dbg_runstate runstate)
{
#ifdef DBG
- run = runstate; /* in debugger/debugger.c */
+ g_dbg_runstate = runstate; /* in debugger/debugger.c */
return M64ERR_SUCCESS;
#else
return M64ERR_UNSUPPORTED;
@@ -128,7 +128,7 @@ EXPORT int CALL DebugGetState(m64p_dbg_state statenum)
switch (statenum)
{
case M64P_DBG_RUN_STATE:
- return run;
+ return g_dbg_runstate;
case M64P_DBG_PREVIOUS_PC:
return previousPC;
case M64P_DBG_NUM_BREAKPOINTS:
diff --git a/src/api/m64p_debugger.h b/src/api/m64p_debugger.h
index 7a5ced32a..c8644d3cc 100644
--- a/src/api/m64p_debugger.h
+++ b/src/api/m64p_debugger.h
@@ -58,9 +58,9 @@ EXPORT m64p_error CALL DebugSetCoreCompare(void (*)(unsigned int), void (*)(int,
*
* This function sets the run state of the R4300 CPU emulator.
*/
-typedef m64p_error (*ptr_DebugSetRunState)(int);
+typedef m64p_error (*ptr_DebugSetRunState)(m64p_dbg_runstate);
#if defined(M64P_CORE_PROTOTYPES)
-EXPORT m64p_error CALL DebugSetRunState(int);
+EXPORT m64p_error CALL DebugSetRunState(m64p_dbg_runstate);
#endif
/* DebugGetState()
diff --git a/src/api/m64p_types.h b/src/api/m64p_types.h
index 10a87c2b5..31ff21f2d 100644
--- a/src/api/m64p_types.h
+++ b/src/api/m64p_types.h
@@ -215,6 +215,12 @@ typedef enum {
M64P_DBG_CPU_NEXT_INTERRUPT
} m64p_dbg_state;
+typedef enum {
+ M64P_DBG_RUNSTATE_PAUSED = 0,
+ M64P_DBG_RUNSTATE_STEPPING,
+ M64P_DBG_RUNSTATE_RUNNING
+} m64p_dbg_runstate;
+
typedef enum {
M64P_DBG_MEM_TYPE = 1,
M64P_DBG_MEM_FLAGS,
diff --git a/src/debugger/dbg_breakpoints.c b/src/debugger/dbg_breakpoints.c
index 84f24745e..fea6fafed 100644
--- a/src/debugger/dbg_breakpoints.c
+++ b/src/debugger/dbg_breakpoints.c
@@ -185,17 +185,15 @@ int check_breakpoints_on_mem_access( uint32 pc, uint32 address, uint32 size, uin
//It automatically stops and updates the debugger on hit, so the memory access
//functions only need to call it and can discard the result.
int bpt;
- if(run == 2)
- {
- bpt=lookup_breakpoint( address, size, flags );
- if(bpt != -1)
- {
+ if (g_dbg_runstate == M64P_DBG_RUNSTATE_RUNNING) {
+ bpt = lookup_breakpoint(address, size, flags);
+ if (bpt != -1) {
if (BPT_CHECK_FLAG(g_Breakpoints[bpt], M64P_BKP_FLAG_LOG))
log_breakpoint(pc, flags, address);
-
- run = 0;
+
+ g_dbg_runstate = M64P_DBG_RUNSTATE_PAUSED;
update_debugger(pc);
-
+
return bpt;
}
}
diff --git a/src/debugger/debugger.c b/src/debugger/debugger.c
index 63e9d0036..d9bdd32f2 100644
--- a/src/debugger/debugger.c
+++ b/src/debugger/debugger.c
@@ -29,11 +29,9 @@
#include "dbg_breakpoints.h"
#include "dbg_memory.h"
-// State of the Emulation Thread:
-// 0 -> pause, 2 -> run.
-
int g_DebuggerActive = 0; // whether the debugger is enabled or not
-int run;
+
+m64p_dbg_runstate g_dbg_runstate;
// Holds the number of pending steps the debugger needs to perform.
static SDL_sem *sem_pending_steps;
@@ -45,7 +43,7 @@ uint32 previousPC;
void init_debugger()
{
g_DebuggerActive = 1;
- run = 0;
+ g_dbg_runstate = M64P_DBG_RUNSTATE_PAUSED;
DebuggerCallback(DEBUG_UI_INIT, 0); /* call front-end to initialize user interface */
@@ -70,20 +68,20 @@ void update_debugger(uint32 pc)
{
int bpt;
- if(run!=0) {//check if we hit a breakpoint
+ if (g_dbg_runstate != M64P_DBG_RUNSTATE_PAUSED) {
bpt = check_breakpoints(pc);
- if( bpt!=-1 ) {
- run = 0;
+ if (bpt != -1) {
+ g_dbg_runstate = M64P_DBG_RUNSTATE_PAUSED;
if (BPT_CHECK_FLAG(g_Breakpoints[bpt], M64P_BKP_FLAG_LOG))
log_breakpoint(pc, M64P_BKP_FLAG_EXEC, 0);
}
}
- if(run!=2) {
+ if (g_dbg_runstate != M64P_DBG_RUNSTATE_RUNNING) {
DebuggerCallback(DEBUG_UI_UPDATE, pc); /* call front-end to notify user interface to update */
}
- if(run==0) {
+ if (g_dbg_runstate == M64P_DBG_RUNSTATE_PAUSED) {
// The emulation thread is blocked until a step call via the API.
SDL_SemWait(sem_pending_steps);
}
diff --git a/src/debugger/debugger.h b/src/debugger/debugger.h
index cc686e2b5..b67927e21 100644
--- a/src/debugger/debugger.h
+++ b/src/debugger/debugger.h
@@ -23,11 +23,11 @@
#ifndef __DEBUGGER_H__
#define __DEBUGGER_H__
+#include "api/m64p_types.h"
+
extern int g_DebuggerActive; /* True if the debugger is running */
-/* State of the Emulation Thread:
- 0 -> pause, 1 -> step, 2 -> run. */
-extern int run;
+extern m64p_dbg_runstate g_dbg_runstate;
extern uint32 previousPC;