Debugger: Lua - Fixed crash when calling emu.reset() outside callbacks
This commit is contained in:
parent
4869051117
commit
73ef5f21e9
4 changed files with 15 additions and 0 deletions
|
@ -36,6 +36,7 @@
|
|||
#define errorCond(cond, text) if(cond) { luaL_error(lua, text); return 0; }
|
||||
#define checkparams() if(!l.CheckParamCount()) { return 0; }
|
||||
#define checkminparams(x) if(!l.CheckParamCount(x)) { return 0; }
|
||||
#define checkinitdone() if(!_context->CheckInitDone()) { error("This function cannot be called outside a callback"); return 0; }
|
||||
#define checksavestateconditions() if(!_context->CheckInStartFrameEvent() && !_context->CheckInExecOpEvent()) { error("This function must be called inside a StartFrame event callback or a CpuExec memory operation callback"); return 0; }
|
||||
|
||||
enum class ExecuteCountType
|
||||
|
@ -532,6 +533,7 @@ int LuaApi::Reset(lua_State *lua)
|
|||
{
|
||||
LuaCallHelper l(lua);
|
||||
checkparams();
|
||||
checkinitdone();
|
||||
_console->Reset(true);
|
||||
return l.ReturnCount();
|
||||
}
|
||||
|
@ -541,6 +543,7 @@ int LuaApi::Stop(lua_State *lua)
|
|||
LuaCallHelper l(lua);
|
||||
int32_t stopCode = l.ReadInteger(0);
|
||||
checkminparams(0);
|
||||
checkinitdone();
|
||||
_console->Stop(stopCode);
|
||||
return l.ReturnCount();
|
||||
}
|
||||
|
@ -549,6 +552,7 @@ int LuaApi::Break(lua_State *lua)
|
|||
{
|
||||
LuaCallHelper l(lua);
|
||||
checkparams();
|
||||
checkinitdone();
|
||||
_debugger->Step(1);
|
||||
return l.ReturnCount();
|
||||
}
|
||||
|
@ -557,6 +561,7 @@ int LuaApi::Resume(lua_State *lua)
|
|||
{
|
||||
LuaCallHelper l(lua);
|
||||
checkparams();
|
||||
checkinitdone();
|
||||
_debugger->Run();
|
||||
return l.ReturnCount();
|
||||
}
|
||||
|
@ -567,6 +572,7 @@ int LuaApi::Execute(lua_State *lua)
|
|||
ExecuteCountType type = (ExecuteCountType)l.ReadInteger();
|
||||
int count = l.ReadInteger();
|
||||
checkparams();
|
||||
checkinitdone();
|
||||
errorCond(count <= 0, "count must be >= 1");
|
||||
errorCond(type < ExecuteCountType::CpuCycles || type > ExecuteCountType::CpuInstructions, "type is invalid");
|
||||
|
||||
|
|
|
@ -83,6 +83,7 @@ bool LuaScriptingContext::LoadScript(string scriptName, string scriptContent, De
|
|||
if((iErr = lua_pcall(_lua, 0, LUA_MULTRET, 0)) == 0) {
|
||||
//Script loaded properly
|
||||
Log("Script loaded successfully.");
|
||||
_initDone = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -90,6 +91,7 @@ bool LuaScriptingContext::LoadScript(string scriptName, string scriptContent, De
|
|||
if(lua_isstring(_lua, -1)) {
|
||||
Log(lua_tostring(_lua, -1));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,11 @@ int ScriptingContext::CallEventCallback(EventType type)
|
|||
return returnValue;
|
||||
}
|
||||
|
||||
bool ScriptingContext::CheckInitDone()
|
||||
{
|
||||
return _initDone;
|
||||
}
|
||||
|
||||
bool ScriptingContext::CheckInStartFrameEvent()
|
||||
{
|
||||
return _inStartFrameEvent;
|
||||
|
|
|
@ -36,6 +36,7 @@ private:
|
|||
|
||||
protected:
|
||||
string _scriptName;
|
||||
bool _initDone = false;
|
||||
|
||||
vector<int> _callbacks[5][0x10000];
|
||||
vector<int> _eventCallbacks[(int)EventType::EventTypeSize];
|
||||
|
@ -65,6 +66,7 @@ public:
|
|||
|
||||
void CallMemoryCallback(uint16_t addr, uint8_t &value, CallbackType type);
|
||||
int CallEventCallback(EventType type);
|
||||
bool CheckInitDone();
|
||||
bool CheckInStartFrameEvent();
|
||||
bool CheckInExecOpEvent();
|
||||
bool CheckStateLoadedFlag();
|
||||
|
|
Loading…
Add table
Reference in a new issue