Skip to content

Commit

Permalink
Merge pull request hrydgard#13931 from unknownbrackets/headless
Browse files Browse the repository at this point in the history
Headless: Allow connecting the web debugger
  • Loading branch information
hrydgard authored Jan 17, 2021
2 parents 26ab87a + 114e73f commit ab9d46a
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions headless/Headless.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand All @@ -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());
Expand Down Expand Up @@ -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<std::string> testFilenames;
const char *mountIso = 0;
Expand Down Expand Up @@ -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="))
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -456,6 +472,10 @@ int main(int argc, const char* argv[])
}
}

if (debuggerPort > 0) {
ShutdownWebServer();
}

host->ShutdownGraphics();
delete host;
host = nullptr;
Expand Down

0 comments on commit ab9d46a

Please sign in to comment.