diff --git a/trunk/src/debug.cpp b/trunk/src/debug.cpp index 304aa82a..d3a28c9e 100644 --- a/trunk/src/debug.cpp +++ b/trunk/src/debug.cpp @@ -440,6 +440,7 @@ int u; //deleteme int skipdebug; //deleteme int numWPs; +bool break_asap = false; // for CPU cycles and Instructions counters uint64 total_cycles_base = 0; uint64 delta_cycles_base = 0; @@ -455,8 +456,16 @@ static DebuggerState dbgstate; DebuggerState &FCEUI_Debugger() { return dbgstate; } void ResetDebugStatisticsCounters() +{ + ResetCyclesCounter(); + ResetInstructionsCounter(); +} +void ResetCyclesCounter() { total_cycles_base = delta_cycles_base = timestampbase + (uint64)timestamp; +} +void ResetInstructionsCounter() +{ total_instructions = delta_instructions = 0; } void ResetDebugStatisticsDeltaCounters() @@ -470,12 +479,13 @@ void IncrementInstructionsCounters() delta_instructions++; } -void BreakHit(int bp_num, bool force = false) +void BreakHit(int bp_num, bool force) { - if(!force) { - + if(!force) + { //check to see whether we fall in any forbid zone - for (int i = 0; i < numWPs; i++) { + for (int i = 0; i < numWPs; i++) + { watchpointinfo& wp = watchpoint[i]; if(!(wp.flags & WP_F) || !(wp.flags & WP_E)) continue; @@ -510,6 +520,12 @@ static void breakpoint(uint8 *opcode, uint16 A, int size) { uint8 stackop=0; uint8 stackopstartaddr,stackopendaddr; + if (break_asap) + { + break_asap = false; + BreakHit(BREAK_TYPE_LUA, true); + } + if (break_on_cycles && ((timestampbase + (uint64)timestamp - total_cycles_base) > break_cycles_limit)) BreakHit(BREAK_TYPE_CYCLES_EXCEED, true); if (break_on_instructions && (total_instructions > break_instructions_limit)) @@ -773,7 +789,7 @@ void DebugCycle() case 8: A = opcode[1] + _Y; break; } - if (numWPs || dbgstate.step || dbgstate.runline || dbgstate.stepout || watchpoint[64].flags || dbgstate.badopbreak || break_on_cycles || break_on_instructions) + if (numWPs || dbgstate.step || dbgstate.runline || dbgstate.stepout || watchpoint[64].flags || dbgstate.badopbreak || break_on_cycles || break_on_instructions || break_asap) breakpoint(opcode, A, size); if(debug_loggingCD) diff --git a/trunk/src/debug.h b/trunk/src/debug.h index 957c3bed..2e9e703a 100644 --- a/trunk/src/debug.h +++ b/trunk/src/debug.h @@ -20,6 +20,7 @@ #define BREAK_TYPE_BADOP -2 #define BREAK_TYPE_CYCLES_EXCEED -3 #define BREAK_TYPE_INSTRUCTIONS_EXCEED -4 +#define BREAK_TYPE_LUA -5 //opbrktype is used to grab the breakpoint type that each instruction will cause. //WP_X is not used because ALL opcodes will have the execute bit set. @@ -94,6 +95,21 @@ static INLINE int FCEUI_GetLoggingCD() { return debug_loggingCD; } extern int iaPC; extern uint32 iapoffset; //mbg merge 7/18/06 changed from int void DebugCycle(); +void BreakHit(int bp_num, bool force = false); + +extern bool break_asap; +extern uint64 total_cycles_base; +extern uint64 delta_cycles_base; +extern bool break_on_cycles; +extern uint64 break_cycles_limit; +extern uint64 total_instructions; +extern uint64 delta_instructions; +extern bool break_on_instructions; +extern uint64 break_instructions_limit; +extern void ResetDebugStatisticsCounters(); +extern void ResetCyclesCounter(); +extern void ResetInstructionsCounter(); +extern void ResetDebugStatisticsDeltaCounters(); //------------- //internal variables that debuggers will want access to diff --git a/trunk/src/drivers/win/debugger.cpp b/trunk/src/drivers/win/debugger.cpp index 117e6283..a2f06cae 100644 --- a/trunk/src/drivers/win/debugger.cpp +++ b/trunk/src/drivers/win/debugger.cpp @@ -54,17 +54,6 @@ extern int vblankScanLines; extern int vblankPixel; extern bool DebuggerWasUpdated; -extern uint64 total_cycles_base; -extern uint64 delta_cycles_base; -extern bool break_on_cycles; -extern uint64 break_cycles_limit; -extern uint64 total_instructions; -extern uint64 delta_instructions; -extern bool break_on_instructions; -extern uint64 break_instructions_limit; -extern void ResetDebugStatisticsCounters(); -extern void ResetDebugStatisticsDeltaCounters(); - int childwnd; extern readfunc ARead[0x10000]; diff --git a/trunk/src/drivers/win/tracer.cpp b/trunk/src/drivers/win/tracer.cpp index e442aa47..48b281a5 100644 --- a/trunk/src/drivers/win/tracer.cpp +++ b/trunk/src/drivers/win/tracer.cpp @@ -43,9 +43,6 @@ using namespace std; //#define LOG_SKIP_UNMAPPED 4 //#define LOG_ADD_PERIODS 8 -extern uint64 total_cycles_base; -extern uint64 total_instructions; - // ################################## Start of SP CODE ########################### #include "debuggersp.h" diff --git a/trunk/src/lua-engine.cpp b/trunk/src/lua-engine.cpp index 04284eac..09fd9d78 100644 --- a/trunk/src/lua-engine.cpp +++ b/trunk/src/lua-engine.cpp @@ -13,6 +13,7 @@ #include "types.h" #include "fceu.h" #include "video.h" +#include "debug.h" #include "sound.h" #include "drawing.h" #include "state.h" @@ -4343,6 +4344,43 @@ static int sound_get(lua_State *L) return 1; } +// Debugger functions library + +// debugger.hitbreakpoint() +static int debugger_hitbreakpoint(lua_State *L) +{ + break_asap = true; + return 0; +} + +// debugger.getcyclescount() +static int debugger_getcyclescount(lua_State *L) +{ + lua_pushinteger(L, (timestampbase + (uint64)timestamp - total_cycles_base)); + return 1; +} + +// debugger.getinstructionscount() +static int debugger_getinstructionscount(lua_State *L) +{ + lua_pushinteger(L, total_instructions); + return 1; +} + +// debugger.resetcyclescount() +static int debugger_resetcyclescount(lua_State *L) +{ + ResetCyclesCounter(); + return 0; +} + +// debugger.resetinstructionscount() +static int debugger_resetinstructionscount(lua_State *L) +{ + ResetInstructionsCounter(); + return 0; +} + // TAS Editor functions library // bool taseditor.registerauto() @@ -5406,6 +5444,16 @@ static const struct luaL_reg soundlib[] = { {NULL,NULL} }; +static const struct luaL_reg debuggerlib[] = { + + {"hitbreakpoint", debugger_hitbreakpoint}, + {"getcyclescount", debugger_getcyclescount}, + {"getinstructionscount", debugger_getinstructionscount}, + {"resetcyclescount", debugger_resetcyclescount}, + {"resetinstructionscount", debugger_resetinstructionscount}, + {NULL,NULL} +}; + static const struct luaL_reg taseditorlib[] = { {"registerauto", taseditor_registerauto}, @@ -5567,6 +5615,7 @@ int FCEU_LoadLuaCode(const char *filename, const char *arg) { luaL_register(L, "movie", movielib); luaL_register(L, "gui", guilib); luaL_register(L, "sound", soundlib); + luaL_register(L, "debugger", debuggerlib); luaL_register(L, "taseditor", taseditorlib); luaL_register(L, "bit", bit_funcs); // LuaBitOp library lua_settop(L, 0); // clean the stack, because each call to luaL_register leaves a table on top @@ -5675,9 +5724,27 @@ int FCEU_LoadLuaCode(const char *filename, const char *arg) { void FCEU_ReloadLuaCode() { if (!luaScriptName) - FCEU_DispMessage("There's no script to reload.",0); - else + { +#ifdef WIN32 + // no script currently running, then try loading the most recent + extern char *recent_lua[]; + char*& fname = recent_lua[0]; + extern void UpdateLuaConsole(const char* fname); + if (fname) + { + UpdateLuaConsole(fname); + FCEU_LoadLuaCode(fname); + } else + { + FCEU_DispMessage("There's no script to reload.", 0); + } +#else + FCEU_DispMessage("There's no script to reload.", 0); +#endif + } else + { FCEU_LoadLuaCode(luaScriptName); + } }