Skip to content

Commit

Permalink
add launch handler in debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitalita committed Sep 1, 2023
1 parent be0bbfe commit dd0c240
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/DarkId.Papyrus.DebugServer/BreakpointManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 23 additions & 1 deletion src/DarkId.Papyrus.DebugServer/PapyrusDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -297,6 +299,24 @@ namespace DarkId::Papyrus::DebugServer
return dap::ResponseOrError<dap::InitializeResponse>();
}

dap::ResponseOrError<dap::LaunchResponse> 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::LaunchResponse>();
}


dap::ResponseOrError<dap::AttachResponse> PapyrusDebugger::Attach(const dap::PDSAttachRequest& request)
{
m_projectPath = request.projectPath.value("");
Expand Down Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions src/DarkId.Papyrus.DebugServer/PapyrusDebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace DarkId::Papyrus::DebugServer

int GetLastStoppedThreadId() { return 0; }
dap::ResponseOrError<dap::InitializeResponse> Initialize(const dap::InitializeRequest& request);
dap::ResponseOrError<dap::LaunchResponse> Launch(const dap::PDSLaunchRequest& request);
dap::ResponseOrError<dap::AttachResponse> Attach(const dap::PDSAttachRequest& request);
dap::ResponseOrError<dap::ContinueResponse> Continue(const dap::ContinueRequest& request) ;
dap::ResponseOrError<dap::PauseResponse> Pause(const dap::PauseRequest& request) ;
Expand Down
13 changes: 12 additions & 1 deletion src/DarkId.Papyrus.DebugServer/Protocol/struct_extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
);
}
28 changes: 28 additions & 0 deletions src/DarkId.Papyrus.DebugServer/Protocol/struct_extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
namespace dap{

// Extended AttachRequest struct for implementation specific parameters

struct PDSLaunchOrAttach {
string name;
string type;
string request;
string game;
optional<string> projectPath;
optional<string> modDirectory;
optional<array<Source>> projectSources;
};

struct PDSAttachRequest : public AttachRequest {
using Response = AttachResponse;
string name;
Expand All @@ -17,5 +28,22 @@ namespace dap{
optional<string> modDirectory;
optional<array<Source>> projectSources;
};

struct PDSLaunchRequest : public LaunchRequest {
using Response = LaunchResponse;
string name;
string type;
string request;
string game;
optional<string> projectPath;
optional<string> modDirectory;
optional<array<Source>> projectSources;
optional<object> mo2Config;
optional<string> XSELoaderPath;
optional<array<string>> args;
};

DAP_DECLARE_STRUCT_TYPEINFO(PDSAttachRequest);
DAP_DECLARE_STRUCT_TYPEINFO(PDSLaunchRequest);

}
2 changes: 1 addition & 1 deletion src/DarkId.Papyrus.DebugServer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
{
Expand Down

0 comments on commit dd0c240

Please sign in to comment.