From 114e73ffc9a7e51bd9e2b06500393db063bb8eba Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 16 Jan 2021 17:41:42 -0800 Subject: [PATCH] Headless: Allow connecting the web debugger. --- headless/Headless.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/headless/Headless.cpp b/headless/Headless.cpp index 52331451aebb..003bb396df2c 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -24,6 +24,7 @@ #include "Core/Core.h" #include "Core/CoreTiming.h" #include "Core/System.h" +#include "Core/WebServer.h" #include "Core/HLE/sceUtility.h" #include "Core/Host.h" #include "Core/SaveState.h" @@ -106,6 +107,7 @@ int printUsage(const char *progname, const char *reason) fprintf(stderr, " -m, --mount umd.cso mount iso on umd1:\n"); fprintf(stderr, " -r, --root some/path mount path on host0: (elfs must be in here)\n"); fprintf(stderr, " -l, --log full log output, not just emulated printfs\n"); + fprintf(stderr, " --debugger=PORT enable websocket debugger and break at start\n"); #if defined(HEADLESSHOST_CLASS) { @@ -177,8 +179,8 @@ bool RunAutoTest(HeadlessHost *headlessHost, CoreParameter &coreParameter, bool if (coreParameter.graphicsContext && coreParameter.graphicsContext->GetDrawContext()) coreParameter.graphicsContext->GetDrawContext()->BeginFrame(); - coreState = CORE_RUNNING; - while (coreState == CORE_RUNNING) + coreState = coreParameter.startBreak ? CORE_STEPPING : CORE_RUNNING; + while (coreState == CORE_RUNNING || coreState == CORE_STEPPING) { int blockTicks = usToCycles(1000000 / 10); PSP_RunLoopFor(blockTicks); @@ -188,6 +190,9 @@ bool RunAutoTest(HeadlessHost *headlessHost, CoreParameter &coreParameter, bool coreState = CORE_RUNNING; headlessHost->SwapBuffers(); } + if (coreState == CORE_STEPPING && !coreParameter.startBreak) { + break; + } if (time_now_d() > deadline) { // Don't compare, print the output at least up to this point, and bail. printf("%s", output.c_str()); @@ -230,6 +235,7 @@ int main(int argc, const char* argv[]) const char *stateToLoad = 0; GPUCore gpuCore = GPUCORE_SOFTWARE; CPUCore cpuCore = CPUCore::JIT; + int debuggerPort = -1; std::vector testFilenames; const char *mountIso = 0; @@ -291,6 +297,8 @@ int main(int argc, const char* argv[]) screenshotFilename = argv[i] + strlen("--screenshot="); else if (!strncmp(argv[i], "--timeout=", strlen("--timeout=")) && strlen(argv[i]) > strlen("--timeout=")) timeout = strtod(argv[i] + strlen("--timeout="), NULL); + else if (!strncmp(argv[i], "--debugger=", strlen("--debugger=")) && strlen(argv[i]) > strlen("--debugger=")) + debuggerPort = (int)strtoul(argv[i] + strlen("--debugger="), NULL, 10); else if (!strcmp(argv[i], "--teamcity")) teamCityMode = true; else if (!strncmp(argv[i], "--state=", strlen("--state=")) && strlen(argv[i]) > strlen("--state=")) @@ -420,6 +428,14 @@ int main(int argc, const char* argv[]) } #endif + UpdateUIState(UISTATE_INGAME); + + if (debuggerPort > 0) { + g_Config.iRemoteISOPort = debuggerPort; + coreParameter.startBreak = true; + StartWebServer(WebServerFlags::DEBUGGER); + } + if (stateToLoad != NULL) SaveState::Load(stateToLoad, -1); @@ -456,6 +472,10 @@ int main(int argc, const char* argv[]) } } + if (debuggerPort > 0) { + ShutdownWebServer(); + } + host->ShutdownGraphics(); delete host; host = nullptr;