2022-09-21 05:16:07 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
2021-09-03 05:11:04 +00:00
|
|
|
#include "ScriptAPI.h"
|
|
|
|
#include <Project64-core/Settings/DebugSettings.h>
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
void ScriptAPI::Define_debug(duk_context * ctx)
|
2021-09-03 05:11:04 +00:00
|
|
|
{
|
|
|
|
const DukPropListEntry props[] = {
|
2022-09-21 05:16:07 +00:00
|
|
|
{"breakhere", DukCFunction(js_debug_breakhere)},
|
|
|
|
{"step", DukCFunction(js_debug_step)},
|
|
|
|
{"skip", DukCFunction(js_debug_skip)},
|
|
|
|
{"resume", DukCFunction(js_debug_resume)},
|
|
|
|
{"showmemory", DukCFunction(js_debug_showmemory)},
|
|
|
|
{"showcommands", DukCFunction(js_debug_showcommands)},
|
2022-09-26 02:31:54 +00:00
|
|
|
{"paused", DukGetter(js_debug__get_paused)},
|
|
|
|
{nullptr},
|
2021-09-03 05:11:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DefineGlobalInterface(ctx, "debug", props);
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
duk_ret_t ScriptAPI::js_debug_breakhere(duk_context * ctx)
|
2021-09-03 05:11:04 +00:00
|
|
|
{
|
2022-09-21 05:16:07 +00:00
|
|
|
CheckArgs(ctx, {Arg_OptBoolean});
|
2021-09-03 05:11:04 +00:00
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
if (duk_get_boolean_default(ctx, 0, (duk_bool_t) false) == 1)
|
2021-09-03 05:11:04 +00:00
|
|
|
{
|
|
|
|
g_Settings->SaveBool(Debugger_SilentBreak, true);
|
|
|
|
}
|
|
|
|
g_Settings->SaveBool(Debugger_SteppingOps, true);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
duk_ret_t ScriptAPI::js_debug_step(duk_context * ctx)
|
2021-09-03 05:11:04 +00:00
|
|
|
{
|
|
|
|
CheckArgs(ctx, {});
|
|
|
|
|
2022-09-26 02:31:54 +00:00
|
|
|
if (g_Settings->LoadBool(Debugger_SteppingOps) && CDebugSettings::WaitingForStep())
|
2021-09-03 05:11:04 +00:00
|
|
|
{
|
|
|
|
g_Settings->SaveBool(Debugger_SilentBreak, true);
|
|
|
|
GetInstance(ctx)->Debugger()->StepEvent().Trigger();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
duk_ret_t ScriptAPI::js_debug_skip(duk_context * ctx)
|
2021-09-03 05:11:04 +00:00
|
|
|
{
|
|
|
|
CheckArgs(ctx, {});
|
|
|
|
|
|
|
|
g_Settings->SaveBool(Debugger_SkipOp, true);
|
|
|
|
|
2022-09-26 02:31:54 +00:00
|
|
|
if (g_Settings->LoadBool(Debugger_SteppingOps) && CDebugSettings::WaitingForStep())
|
2021-09-03 05:11:04 +00:00
|
|
|
{
|
|
|
|
GetInstance(ctx)->Debugger()->StepEvent().Trigger();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
duk_ret_t ScriptAPI::js_debug_showmemory(duk_context * ctx)
|
2021-09-03 05:11:04 +00:00
|
|
|
{
|
2022-09-21 05:16:07 +00:00
|
|
|
CheckArgs(ctx, {Arg_Number, Arg_OptBoolean});
|
2021-09-03 05:11:04 +00:00
|
|
|
|
|
|
|
uint32_t address = duk_get_uint(ctx, 0);
|
|
|
|
bool bPhysical = duk_get_boolean_default(ctx, 1, 0) ? true : false;
|
|
|
|
|
|
|
|
GetInstance(ctx)->Debugger()->Debug_ShowMemoryLocation(address, !bPhysical);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
duk_ret_t ScriptAPI::js_debug_showcommands(duk_context * ctx)
|
2021-09-03 05:11:04 +00:00
|
|
|
{
|
2022-09-21 05:16:07 +00:00
|
|
|
CheckArgs(ctx, {Arg_Number});
|
2021-09-03 05:11:04 +00:00
|
|
|
uint32_t address = duk_get_uint(ctx, 0);
|
|
|
|
GetInstance(ctx)->Debugger()->Debug_ShowCommandsLocation(address, true);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
duk_ret_t ScriptAPI::js_debug_resume(duk_context * ctx)
|
2021-09-03 05:11:04 +00:00
|
|
|
{
|
|
|
|
CheckArgs(ctx, {});
|
|
|
|
|
|
|
|
g_Settings->SaveBool(Debugger_SteppingOps, false);
|
|
|
|
|
|
|
|
if (CDebugSettings::WaitingForStep())
|
|
|
|
{
|
|
|
|
GetInstance(ctx)->Debugger()->StepEvent().Trigger();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
duk_ret_t ScriptAPI::js_debug__get_paused(duk_context * ctx)
|
2021-09-03 05:11:04 +00:00
|
|
|
{
|
|
|
|
duk_push_boolean(ctx, CDebugSettings::WaitingForStep() && g_Settings->LoadBool(Debugger_SteppingOps));
|
|
|
|
return 1;
|
|
|
|
}
|