Debugger: Lua - Fixed crash when calling emu.reset() outside callbacks

This commit is contained in:
Sour 2020-04-21 20:24:44 -04:00
parent b09017d17d
commit f7a4fd6dbd
4 changed files with 14 additions and 0 deletions

View file

@ -37,6 +37,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; }
Debugger* LuaApi::_debugger = nullptr;
@ -499,6 +500,7 @@ int LuaApi::Reset(lua_State *lua)
{
LuaCallHelper l(lua);
checkparams();
checkinitdone();
_console->Reset();
return l.ReturnCount();
}
@ -508,6 +510,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();
}
@ -516,6 +519,7 @@ int LuaApi::Break(lua_State *lua)
{
LuaCallHelper l(lua);
checkparams();
checkinitdone();
_debugger->Step(CpuType::Cpu, 1, StepType::Step);
return l.ReturnCount();
}
@ -524,6 +528,7 @@ int LuaApi::Resume(lua_State *lua)
{
LuaCallHelper l(lua);
checkparams();
checkinitdone();
_debugger->Run();
return l.ReturnCount();
}
@ -534,6 +539,7 @@ int LuaApi::Execute(lua_State *lua)
StepType type = (StepType)l.ReadInteger();
int count = l.ReadInteger();
checkparams();
checkinitdone();
errorCond(count <= 0, "count must be >= 1");
errorCond(type != StepType::Step && type != StepType::PpuStep, "type is invalid");

View file

@ -84,6 +84,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;
}
}

View file

@ -59,6 +59,11 @@ int ScriptingContext::CallEventCallback(EventType type)
return returnValue;
}
bool ScriptingContext::CheckInitDone()
{
return _initDone;
}
bool ScriptingContext::CheckInStartFrameEvent()
{
return _inStartFrameEvent;

View file

@ -42,6 +42,7 @@ private:
protected:
string _scriptName;
bool _initDone = false;
vector<MemoryCallback> _callbacks[3];
vector<int> _eventCallbacks[(int)EventType::EventTypeSize];
@ -71,6 +72,7 @@ public:
void CallMemoryCallback(uint32_t addr, uint8_t &value, CallbackType type);
int CallEventCallback(EventType type);
bool CheckInitDone();
bool CheckInStartFrameEvent();
bool CheckInExecOpEvent();
bool CheckStateLoadedFlag();