From dd0c2409bd2f4681fc67c73eec09a1adef6b5cb4 Mon Sep 17 00:00:00 2001 From: nikitalita <69168929+nikitalita@users.noreply.github.com> Date: Sun, 19 Feb 2023 01:16:38 -0800 Subject: [PATCH] add launch handler in debugger --- .../BreakpointManager.cpp | 9 +++++- .../PapyrusDebugger.cpp | 24 +++++++++++++++- .../PapyrusDebugger.h | 1 + .../Protocol/struct_extensions.cpp | 13 ++++++++- .../Protocol/struct_extensions.h | 28 +++++++++++++++++++ src/DarkId.Papyrus.DebugServer/main.cpp | 2 +- 6 files changed, 73 insertions(+), 4 deletions(-) diff --git a/src/DarkId.Papyrus.DebugServer/BreakpointManager.cpp b/src/DarkId.Papyrus.DebugServer/BreakpointManager.cpp index f4d2c5cd..efbd57b9 100644 --- a/src/DarkId.Papyrus.DebugServer/BreakpointManager.cpp +++ b/src/DarkId.Papyrus.DebugServer/BreakpointManager.cpp @@ -30,7 +30,14 @@ namespace DarkId::Papyrus::DebugServer #endif bool hasDebugInfo = binary->getDebugInfo().getFunctionInfos().size() > 0; if (!hasDebugInfo) { - return dap::Error("Could not find PEX data for script %s", scriptName); + +#if FALLOUT + const std::string gameName = "Fallout4"; +#else + const std::string gameName = "Skyrim" +#endif + + return dap::Error("No debug data for script %s. Ensure that `bLoadDebugInformation=1` is set under `[Papyrus]` in %s.ini", scriptName, gameName); } for (const auto& srcBreakpoint : srcBreakpoints) diff --git a/src/DarkId.Papyrus.DebugServer/PapyrusDebugger.cpp b/src/DarkId.Papyrus.DebugServer/PapyrusDebugger.cpp index c1899935..f09e2da7 100644 --- a/src/DarkId.Papyrus.DebugServer/PapyrusDebugger.cpp +++ b/src/DarkId.Papyrus.DebugServer/PapyrusDebugger.cpp @@ -108,7 +108,9 @@ namespace DarkId::Papyrus::DebugServer // Client wants to disconnect. return dap::DisconnectResponse{}; }); - + m_session->registerHandler([&](const dap::PDSLaunchRequest& request) { + return Launch(request); + }); m_session->registerHandler([&](const dap::PDSAttachRequest& request) { return Attach(request); }); @@ -297,6 +299,24 @@ namespace DarkId::Papyrus::DebugServer return dap::ResponseOrError(); } + dap::ResponseOrError PapyrusDebugger::Launch(const dap::PDSLaunchRequest& request) + { + auto resp = Attach(dap::PDSAttachRequest{ + .name = request.name, + .type = request.type, + .request = request.request, + .game = request.game, + .projectPath = request.projectPath, + .modDirectory = request.modDirectory, + .projectSources = request.projectSources + }); + if (resp.error) { + return dap::Error(resp.error); + } + return dap::ResponseOrError(); + } + + dap::ResponseOrError PapyrusDebugger::Attach(const dap::PDSAttachRequest& request) { m_projectPath = request.projectPath.value(""); @@ -551,6 +571,8 @@ namespace DarkId::Papyrus::DebugServer } } } + // TODO: Make this check to see if we've loaded any scripts from the project + // and if not, emit a message to the user that no project scripts have been loaded return response; } } diff --git a/src/DarkId.Papyrus.DebugServer/PapyrusDebugger.h b/src/DarkId.Papyrus.DebugServer/PapyrusDebugger.h index 1aaee95d..15530467 100644 --- a/src/DarkId.Papyrus.DebugServer/PapyrusDebugger.h +++ b/src/DarkId.Papyrus.DebugServer/PapyrusDebugger.h @@ -52,6 +52,7 @@ namespace DarkId::Papyrus::DebugServer int GetLastStoppedThreadId() { return 0; } dap::ResponseOrError Initialize(const dap::InitializeRequest& request); + dap::ResponseOrError Launch(const dap::PDSLaunchRequest& request); dap::ResponseOrError Attach(const dap::PDSAttachRequest& request); dap::ResponseOrError Continue(const dap::ContinueRequest& request) ; dap::ResponseOrError Pause(const dap::PauseRequest& request) ; diff --git a/src/DarkId.Papyrus.DebugServer/Protocol/struct_extensions.cpp b/src/DarkId.Papyrus.DebugServer/Protocol/struct_extensions.cpp index 459397cb..feaaebac 100644 --- a/src/DarkId.Papyrus.DebugServer/Protocol/struct_extensions.cpp +++ b/src/DarkId.Papyrus.DebugServer/Protocol/struct_extensions.cpp @@ -11,5 +11,16 @@ namespace dap { DAP_FIELD(projectPath, "projectPath"), DAP_FIELD(modDirectory, "modDirectory"), DAP_FIELD(projectSources, "projectSources") - ) + ); + DAP_IMPLEMENT_STRUCT_TYPEINFO_EXT(PDSLaunchRequest, + LaunchRequest, + "launch", + DAP_FIELD(name, "name"), + DAP_FIELD(type, "type"), + DAP_FIELD(request, "request"), + DAP_FIELD(game, "game"), + DAP_FIELD(projectPath, "projectPath"), + DAP_FIELD(modDirectory, "modDirectory"), + DAP_FIELD(projectSources, "projectSources") + ); } \ No newline at end of file diff --git a/src/DarkId.Papyrus.DebugServer/Protocol/struct_extensions.h b/src/DarkId.Papyrus.DebugServer/Protocol/struct_extensions.h index 5886132c..a40615eb 100644 --- a/src/DarkId.Papyrus.DebugServer/Protocol/struct_extensions.h +++ b/src/DarkId.Papyrus.DebugServer/Protocol/struct_extensions.h @@ -7,6 +7,17 @@ namespace dap{ // Extended AttachRequest struct for implementation specific parameters + + struct PDSLaunchOrAttach { + string name; + string type; + string request; + string game; + optional projectPath; + optional modDirectory; + optional> projectSources; + }; + struct PDSAttachRequest : public AttachRequest { using Response = AttachResponse; string name; @@ -17,5 +28,22 @@ namespace dap{ optional modDirectory; optional> projectSources; }; + + struct PDSLaunchRequest : public LaunchRequest { + using Response = LaunchResponse; + string name; + string type; + string request; + string game; + optional projectPath; + optional modDirectory; + optional> projectSources; + optional mo2Config; + optional XSELoaderPath; + optional> args; + }; + DAP_DECLARE_STRUCT_TYPEINFO(PDSAttachRequest); + DAP_DECLARE_STRUCT_TYPEINFO(PDSLaunchRequest); + } diff --git a/src/DarkId.Papyrus.DebugServer/main.cpp b/src/DarkId.Papyrus.DebugServer/main.cpp index cdeec432..dd24cfb5 100644 --- a/src/DarkId.Papyrus.DebugServer/main.cpp +++ b/src/DarkId.Papyrus.DebugServer/main.cpp @@ -79,7 +79,7 @@ extern "C" DLLEXPORT constinit auto SKSEPlugin_Version = []() { return v; }(); #endif -#define _PAUSE_ON_START 1 +//#define _PAUSE_ON_START 1 extern "C" {