Skip to content

Commit

Permalink
Merge branch 'dbg-runstate-enum' of https://github.com/wnayes/mupen64…
Browse files Browse the repository at this point in the history
…plus-core into wnayes-dbg-runstate-enum
  • Loading branch information
richard42 committed Feb 14, 2015
2 parents 951a8d3 + 9aa274e commit 4abfbaf
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 28 deletions.
4 changes: 2 additions & 2 deletions doc/emuwiki-api-doc/Mupen64Plus-v2.0-Core-Debugger.mediawiki
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ Most libmupen64plus functions return an <tt>m64p_error</tt> return code, which i
<br />
{| border="1"
|Prototype
|'''<tt>m64p_error DebugSetRunState(int runstate)</tt>'''
|'''<tt>m64p_error DebugSetRunState(m64p_dbg_runstate runstate)</tt>'''
|-
|Input Parameters
|'''<tt>runstate</tt>''' 0 == pause, 1 == single instruction step, 2 == run
|'''<tt>runstate</tt>''' An <tt>m64p_dbg_runstate</tt> enumerated type specifying the debugging state of the emulator. <tt>M64P_DBG_RUNSTATE_RUNNING</tt> continues execution until a breakpoint is hit or a different state is chosen. <tt>M64P_DBG_RUNSTATE_STEPPING</tt> enters a single step running mode that sends callbacks as each step is performed. <tt>M64P_DBG_RUNSTATE_PAUSED</tt> pauses execution to allow manual stepping.
|-
|Requirements
|The Mupen64Plus library must be built with debugger support and must be initialized before calling this function.
Expand Down
6 changes: 6 additions & 0 deletions doc/emuwiki-api-doc/Mupen64Plus-v2.0-headers.mediawiki
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/api/debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/api/m64p_debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions src/api/m64p_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 6 additions & 8 deletions src/debugger/dbg_breakpoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
18 changes: 8 additions & 10 deletions src/debugger/debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 */

Expand All @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/debugger/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 4abfbaf

Please sign in to comment.