From 2fdc96e9df186e2376ac5298defc53ac305a9b3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 1 Oct 2026 13:16:12 -0600 Subject: [PATCH] Headless: Always print the debugger port when --debugger=0 picks one wsdbg --launch learns the port from our output, which without --log was nothing. Also set the port before reporting the server as running, so WebServerWaitForStartup() callers can read it. Co-Authored-By: Claude Opus 5.5 (1M context) --- Core/WebServer.cpp | 3 ++- Tools/wsdbg/src/main.rs | 8 ++++---- headless/Headless.cpp | 6 ++++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Core/WebServer.cpp b/Core/WebServer.cpp index 1b4df8f1ee..7c30f989d2 100644 --- a/Core/WebServer.cpp +++ b/Core/WebServer.cpp @@ -854,9 +854,10 @@ static void WebServerThread() { } } + // Before RUNNING, so WebServerWaitForStartup() callers can read the port. + g_Config.iRemoteISOPort = http->Port(); UpdateStatus(ServerStatus::RUNNING); - g_Config.iRemoteISOPort = http->Port(); RegisterServer(http->Port()); double lastRegister = time_now_d(); diff --git a/Tools/wsdbg/src/main.rs b/Tools/wsdbg/src/main.rs index 8730b7f1dc..daaa1c241c 100644 --- a/Tools/wsdbg/src/main.rs +++ b/Tools/wsdbg/src/main.rs @@ -294,10 +294,10 @@ fn launch_ppsspp(cmd: &[String]) -> Result<(std::process::Child, u16)> { child.kill().ok(); child.wait().ok(); Err(anyhow!( - "PPSSPP never reported a debugger port. It logs that line at NOTICE, so it should \ - survive any --loglevel - but a build predating that change logs it at INFO, where \ - --loglevel=3 hides it. Check the forwarded output above for 'Listening on port'; \ - if it isn't there, either raise --loglevel or pass an explicit --debugger=PORT." + "PPSSPP never reported a debugger port. Headless prints 'Debugger listening on port N' \ + to stderr whenever --debugger=0, with or without --log; other builds (and older \ + headless builds) only log it, so they need --log. Check the forwarded output above, \ + or pass an explicit --debugger=PORT." )) } } diff --git a/headless/Headless.cpp b/headless/Headless.cpp index b7adf0eb9e..06c6177dc4 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -1170,6 +1170,12 @@ int main(int argc, const char* argv[]) { ShutdownWebServer(); return 1; } + // With port 0 the OS picks one, and a client (wsdbg --launch) can only learn it from our + // output. Print it outside the log system so it doesn't depend on --log. + if (cmdLineOptions.DebuggerPort().value() == 0) { + fprintf(stderr, "Debugger listening on port %d\n", WebServerPort()); + fflush(stderr); + } } if (cmdLineOptions.stateToSave.has_value()) {