From 552cbb2a2c2be1c5d45f0859452f960f6395ee38 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 26 Sep 2021 11:56:32 -0700 Subject: [PATCH 1/3] Debugger: Serve local web debugger from assets. --- Core/WebServer.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/Core/WebServer.cpp b/Core/WebServer.cpp index e84de770f1..a55b298ed2 100644 --- a/Core/WebServer.cpp +++ b/Core/WebServer.cpp @@ -26,6 +26,7 @@ #include "Common/Log.h" #include "Common/File/FileUtil.h" #include "Common/File/FileDescriptor.h" +#include "Common/File/VFS/VFS.h" #include "Common/TimeUtil.h" #include "Common/StringUtils.h" #include "Core/Config.h" @@ -227,6 +228,46 @@ static void HandleListing(const http::Request &request) { } } +static bool ServeDebuggerFile(const http::Request &request) { + // Skip the slash at the start of the resource path. + const char *filename = request.resource() + 1; + if (strstr(filename, "..") != nullptr) + return false; + + size_t size; + uint8_t *data = VFSReadFile(filename, &size); + if (!data) + return false; + + std::string ext = Path(filename).GetFileExtension(); + const char *mimeType = "text/plain"; + if (ext == ".html") { + mimeType = "text/html"; + } else if (ext == ".ico") { + mimeType = "image/x-icon"; + } else if (ext == ".js") { + mimeType = "application/javascript"; + } else if (ext == ".svg") { + mimeType = "image/svg"; + } else if (ext == ".png") { + mimeType = "image/png"; + } else if (ext == ".css") { + mimeType = "text/css"; + } + + request.WriteHttpResponseHeader("1.0", 200, (int)size, mimeType); + request.Out()->Push((char *)data, size); + + delete[] data; + return true; +} + +static void RedirectToDebugger(const http::Request &request) { + static const std::string payload = "Redirecting to debugger UI...\r\n"; + request.WriteHttpResponseHeader("1.0", 301, (int)payload.size(), "text/plain", "Location: /debugger/index.html\r\n"); + request.Out()->Push(payload); +} + static void HandleFallback(const http::Request &request) { if (serverFlags & (int)WebServerFlags::DISCS) { Path filename = LocalFromRemotePath(request.resource()); @@ -236,6 +277,16 @@ static void HandleFallback(const http::Request &request) { } } + if ((serverFlags & (int)WebServerFlags::DEBUGGER) != 0) { + if (!strcmp(request.resource(), "/debugger/")) { + RedirectToDebugger(request); + return; + } + + if (startsWith(request.resource(), "/debugger/") && ServeDebuggerFile(request)) + return; + } + static const std::string payload = "404 not found\r\n"; request.WriteHttpResponseHeader("1.0", 404, (int)payload.size(), "text/plain"); request.Out()->Push(payload); @@ -243,7 +294,18 @@ static void HandleFallback(const http::Request &request) { static void ForwardDebuggerRequest(const http::Request &request) { if (serverFlags & (int)WebServerFlags::DEBUGGER) { - HandleDebuggerRequest(request); + // Check if this is a websocket request... + std::string upgrade; + if (!request.GetHeader("upgrade", &upgrade)) { + upgrade = ""; + } + + // Yes - proceed with the socket. + if (strcasecmp(upgrade.c_str(), "websocket") == 0) { + HandleDebuggerRequest(request); + } else { + RedirectToDebugger(request); + } } else { HandleFallback(request); } From 0cf07a8d62570db5167a4dc9ce10c863845cab07 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 26 Sep 2021 12:24:29 -0700 Subject: [PATCH 2/3] Debugger: Add web debugger in assets. This is from the "bundled" branch, which is generated by GitHub Actions. --- .gitmodules | 4 ++++ assets/debugger | 1 + 2 files changed, 5 insertions(+) create mode 160000 assets/debugger diff --git a/.gitmodules b/.gitmodules index 8404074810..a7aa927f9c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -34,3 +34,7 @@ [submodule "SDL/macOS"] path = SDL/macOS url = https://github.com/hrydgard/ppsspp-mac-sdl +[submodule "ppsspp-debugger"] + path = assets/debugger + url = https://github.com/unknownbrackets/ppsspp-debugger.git + branch = bundled diff --git a/assets/debugger b/assets/debugger new file mode 160000 index 0000000000..36ad6b19b2 --- /dev/null +++ b/assets/debugger @@ -0,0 +1 @@ +Subproject commit 36ad6b19b22de2075a01a4f0c765e3ef514dc38f From 6814f5e7af61518492b5d2a85780db436d6f768f Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 26 Sep 2021 12:27:54 -0700 Subject: [PATCH 3/3] Debugger: Add web debugger to build packaging. --- CMakeLists.txt | 7 +++++-- android/ab.sh | 1 + ppsspp.iss | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bf3e1cea7e..c94fa9f423 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2219,6 +2219,7 @@ endif() set(NativeAssets android/assets/ui_atlas.zim android/assets/ui_atlas.meta + assets/debugger assets/lang assets/shaders assets/Roboto-Condensed.ttf @@ -2324,18 +2325,20 @@ if(TargetBin) file(GLOB_RECURSE FLASH0_FILES assets/flash0/*) file(GLOB_RECURSE LANG_FILES assets/lang/*) file(GLOB_RECURSE SHADER_FILES assets/shaders/*) + file(GLOB_RECURSE DEBUGGER_FILES assets/debugger/*) if(NOT IOS) set_source_files_properties(${NativeAssets} PROPERTIES MACOSX_PACKAGE_LOCATION "MacOS/assets") set_source_files_properties(${FLASH0_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION "MacOS/assets/flash0/font") set_source_files_properties(${LANG_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION "MacOS/assets/lang") set_source_files_properties(${SHADER_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION "MacOS/assets/shaders") + set_source_files_properties(${DEBUGGER_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION "MacOS/assets/debugger") endif() if(IOS) - add_executable(${TargetBin} MACOSX_BUNDLE ${ICON_PATH_ABS} ${NativeAssets} ${SHADER_FILES} ${FLASH0_FILES} ${LANG_FILES} ${NativeAppSource} "ios/Settings.bundle" "ios/Launch Screen.storyboard" "ext/vulkan/iOS/Frameworks") + add_executable(${TargetBin} MACOSX_BUNDLE ${ICON_PATH_ABS} ${NativeAssets} ${SHADER_FILES} ${DEBUGGER_FILES} ${FLASH0_FILES} ${LANG_FILES} ${NativeAppSource} "ios/Settings.bundle" "ios/Launch Screen.storyboard" "ext/vulkan/iOS/Frameworks") else() - add_executable(${TargetBin} MACOSX_BUNDLE ${ICON_PATH_ABS} ${NativeAssets} ${SHADER_FILES} ${FLASH0_FILES} ${LANG_FILES} ${NativeAppSource}) + add_executable(${TargetBin} MACOSX_BUNDLE ${ICON_PATH_ABS} ${NativeAssets} ${SHADER_FILES} ${DEBUGGER_FILES} ${FLASH0_FILES} ${LANG_FILES} ${NativeAppSource}) file(INSTALL "${CMAKE_SOURCE_DIR}/ext/vulkan/macOS/Frameworks/libMoltenVK.dylib" DESTINATION "${CMAKE_BINARY_DIR}/PPSSPPSDL.app/Contents/Frameworks/") if(TARGET SDL2::SDL2 AND NOT USING_QT_UI) add_custom_command(TARGET ${TargetBin} POST_BUILD COMMAND /bin/bash "${CMAKE_SOURCE_DIR}/SDL/macbundle.sh" "${CMAKE_BINARY_DIR}/PPSSPPSDL.app") diff --git a/android/ab.sh b/android/ab.sh index 08520d1a28..8f07b59605 100755 --- a/android/ab.sh +++ b/android/ab.sh @@ -1,6 +1,7 @@ cp -r ../assets/flash0 assets/ cp -r ../assets/lang assets/ cp -r ../assets/shaders assets/ +cp -r ../assets/debugger assets/ cp ../assets/langregion.ini assets/langregion.ini cp ../assets/compat.ini assets/compat.ini cp ../assets/Roboto-Condensed.ttf assets/Roboto-Condensed.ttf diff --git a/ppsspp.iss b/ppsspp.iss index 9d37d59206..9aa613f4bc 100644 --- a/ppsspp.iss +++ b/ppsspp.iss @@ -74,6 +74,7 @@ Source: "README.md"; DestName: "README.txt"; DestDir: "{app}"; Flags: isreadme Source: "notinstalled.txt"; DestName: "installed.txt"; DestDir: "{app}"; Source: "assets\*.*"; DestDir: "{app}\assets" Source: "assets\shaders\*.*"; DestDir: "{app}\assets\shaders" +Source: "assets\debugger\*"; DestDir: "{app}\assets\debugger"; Flags: recursesubdirs Source: "assets\lang\*.ini"; DestDir: "{app}\assets\lang" Source: "assets\flash0\font\*.*"; DestDir: "{app}\assets\flash0\font" Source: "dx9sdk\8.1\Redist\D3D\x64\d3dcompiler_47.dll"; DestDir: "{app}"