Skip to content

Commit

Permalink
initial cppdap implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitalita committed Feb 12, 2023
1 parent 49e8ad1 commit d390277
Show file tree
Hide file tree
Showing 48 changed files with 773 additions and 1,866 deletions.
8 changes: 6 additions & 2 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"${workspaceFolder}/dependencies/MetaStuff/include",
"${workspaceFolder}/dependencies",
"${workspaceFolder}/src/DarkId.Papyrus.DebugServer",
"${workspaceFolder}/vcpkg_installed/skyrim/x64-windows-static/include"
"${workspaceFolder}/src/DarkId.Papyrus.DebugServer/Protocol",
"${workspaceFolder}/vcpkg_installed/skyrim/x64-windows-static/include",
"${workspaceFolder}/vcpkg_installed/skyrim/x64-windows-static/include/Champollion"
],
"defines": [
"WIN32",
Expand All @@ -30,7 +32,9 @@
"${workspaceFolder}/dependencies/MetaStuff/include",
"${workspaceFolder}/dependencies",
"${workspaceFolder}/src/DarkId.Papyrus.DebugServer",
"${workspaceFolder}/vcpkg_installed/fallout4/x64-windows-static/include"
"${workspaceFolder}/src/DarkId.Papyrus.DebugServer/Protocol",
"${workspaceFolder}/vcpkg_installed/fallout4/x64-windows-static/include",
"${workspaceFolder}/vcpkg_installed/skyrim/x64-windows-static/include/Champollion"
],
"defines": [
"WIN32",
Expand Down
19 changes: 12 additions & 7 deletions dependencies/ports/cppdap/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO nikitalita/cppdap
REF d1b698f67abc0da9af072e9d054e2761481c4f86
SHA512 fe12ec3bc3de1f02e6669fd637b86bb07c9878fc012d1d7d28efeb3471e6936956e89de6b31325c70ff86b20bb45627c654f99c92ad276d8512838a19aef17f8
HEAD_REF cmake-install
REPO google/cppdap
REF 0a340c6d71ca00893ca1aefea38f3504e6755196
SHA512 14f8d0438678eb715f171b95ed9733485bdb681bc174642f196b7665aad3157b500ba6e6abccc5adcb8ec17aeffa94ae562dcbd31248244d9c8f4a11b97fc2ea
HEAD_REF main
)
# Check if one or more features are a part of a package installation.
# See /docs/maintainers/vcpkg_check_features.md for more details

vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
use-nlohmann-json CPPDAP_USE_EXTERNAL_NLOHMANN_JSON_PACKAGE
rapidjson CPPDAP_USE_EXTERNAL_RAPID_JSON_PACKAGE
use-rapidjson CPPDAP_USE_EXTERNAL_RAPIDJSON_PACKAGE
)

if (NOT CPPDAP_USE_EXTERNAL_NLOHMANN_JSON_PACKAGE AND NOT CPPDAP_USE_EXTERNAL_RAPIDJSON_PACKAGE)
message(FATAL_ERROR "Must set either \"use-nlohmann-json\" or \"use-rapidjson\" feature.")
elseif(CPPDAP_USE_EXTERNAL_NLOHMANN_JSON_PACKAGE AND CPPDAP_USE_EXTERNAL_RAPIDJSON_PACKAGE)
message(FATAL_ERROR "Cannot set both \"use-nlohmann-json\" and \"use-rapidjson\" feature.")
endif()

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
Expand Down
2 changes: 1 addition & 1 deletion src/DarkId.Papyrus.DebugServer/ArrayStateNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace DarkId::Papyrus::DebugServer
m_type = &_m_inst_type;
}

bool ArrayStateNode::SerializeToProtocol(Variable& variable)
bool ArrayStateNode::SerializeToProtocol(dap::Variable& variable)
{
variable.variablesReference = m_value ? GetId() : 0;
variable.indexedVariables = m_value ? m_value->size() : 0;
Expand Down
4 changes: 2 additions & 2 deletions src/DarkId.Papyrus.DebugServer/ArrayStateNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "GameInterfaces.h"

#include "Protocol/protocol.h"
#include <dap/protocol.h>
#include "StateNodeBase.h"

namespace DarkId::Papyrus::DebugServer
Expand All @@ -20,7 +20,7 @@ namespace DarkId::Papyrus::DebugServer

virtual ~ArrayStateNode() override = default;

bool SerializeToProtocol(Variable& variable) override;
bool SerializeToProtocol(dap::Variable& variable) override;

bool GetChildNames(std::vector<std::string>& names) override;
bool GetChildNode(std::string name, std::shared_ptr<StateNodeBase>& node) override;
Expand Down
32 changes: 13 additions & 19 deletions src/DarkId.Papyrus.DebugServer/BreakpointManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
#endif
namespace DarkId::Papyrus::DebugServer
{
PDError BreakpointManager::SetBreakpoints(Source& source, const std::vector<SourceBreakpoint>& srcBreakpoints, std::vector<Breakpoint>& breakpoints)
dap::ResponseOrError<dap::SetBreakpointsResponse> BreakpointManager::SetBreakpoints(dap::Source& source, const std::vector<dap::SourceBreakpoint>& srcBreakpoints)
{
dap::SetBreakpointsResponse response;
std::set<int> breakpointLines;

auto scriptName = NormalizeScriptName(source.name);
auto scriptName = NormalizeScriptName(source.name.value(""));
auto binary = m_pexCache->GetScript(scriptName.c_str());
if (!binary) {
logger::error("Could not find PEX data for script {}", scriptName);
} // Continue on to set the breakpoints as unverified
return dap::Error("Could not find PEX data for script %s", scriptName);
}
const auto sourceReference = m_pexCache->GetScriptReference(scriptName.c_str());
source.sourceReference = sourceReference;

Expand All @@ -28,11 +29,10 @@ namespace DarkId::Papyrus::DebugServer
logger::error("Could not save PEX dump for {}"sv, scriptName);
}
#endif
bool hasDebugInfo = binary && binary->getDebugInfo().getFunctionInfos().size() > 0;
// only log error if PEX is loaded
if (binary && !hasDebugInfo) {
logger::error("No debug info in script {}"sv, scriptName);
} // Continue on to set the breakpoints as unverified
bool hasDebugInfo = binary->getDebugInfo().getFunctionInfos().size() > 0;
if (!hasDebugInfo) {
return dap::Error("Could not find PEX data for script %s", scriptName);
}

for (const auto& srcBreakpoint : srcBreakpoints)
{
Expand Down Expand Up @@ -60,22 +60,16 @@ namespace DarkId::Papyrus::DebugServer

breakpointLines.emplace(srcBreakpoint.line);

Breakpoint breakpoint;
dap::Breakpoint breakpoint;
breakpoint.source = source;
breakpoint.verified = foundLine;
breakpoint.line = srcBreakpoint.line;

breakpoints.push_back(breakpoint);
response.breakpoints.push_back(breakpoint);
}

m_breakpoints[sourceReference] = breakpointLines;
if (!binary) {
return PDError::NO_PEX_DATA;
}
else if (!hasDebugInfo) {
return PDError::NO_DEBUG_INFO;
}
return PDError::OK;
return response;
}

bool BreakpointManager::GetExecutionIsAtValidBreakpoint(RE::BSScript::Internal::CodeTasklet* tasklet)
Expand Down
6 changes: 3 additions & 3 deletions src/DarkId.Papyrus.DebugServer/BreakpointManager.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#pragma once
#include <map>
#include <set>
#include "Protocol/protocol.h"
#include <dap/protocol.h>
#include <dap/session.h>

#include "GameInterfaces.h"

#include "PexCache.h"
#include "PDError.h"

namespace DarkId::Papyrus::DebugServer
{
Expand All @@ -21,7 +21,7 @@ namespace DarkId::Papyrus::DebugServer
{
}

PDError SetBreakpoints(Source& source, const std::vector<SourceBreakpoint>& srcBreakpoints, std::vector<Breakpoint>& breakpoints);
dap::ResponseOrError<dap::SetBreakpointsResponse> SetBreakpoints(dap::Source& source, const std::vector<dap::SourceBreakpoint>& srcBreakpoints);
bool GetExecutionIsAtValidBreakpoint(RE::BSScript::Internal::CodeTasklet* tasklet);
};
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
Expand Down Expand Up @@ -38,14 +37,10 @@
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label="LocalAppDataPlatform" />
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label="LocalAppDataPlatform" />
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
Expand All @@ -56,15 +51,15 @@
<PostBuildEventUseInBuild>false</PostBuildEventUseInBuild>
<PreBuildEventUseInBuild>false</PreBuildEventUseInBuild>
<PreLinkEventUseInBuild>false</PreLinkEventUseInBuild>
<OutDir>$(ProjectDir)bin\$(ProjectName)\$(Platform)\$(Configuration)\</OutDir>
<OutDir>F:\Games\fallout_4_mods_folder\mods\Papyrus Debug Extension\F4SE\Plugins\</OutDir>
<IntDir>$(ProjectDir)obj\$(ProjectName)\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<PostBuildEventUseInBuild>false</PostBuildEventUseInBuild>
<PreBuildEventUseInBuild>false</PreBuildEventUseInBuild>
<PreLinkEventUseInBuild>false</PreLinkEventUseInBuild>
<OutDir>$(ProjectDir)bin\$(ProjectName)\$(Platform)\$(Configuration)\</OutDir>
<OutDir>F:\Games\fallout_4_mods_folder\mods\Papyrus Debug Extension\F4SE\Plugins\</OutDir>
<IntDir>$(ProjectDir)obj\$(ProjectName)\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup>
Expand Down Expand Up @@ -202,7 +197,6 @@
<ClCompile Include="BreakpointManager.cpp" />
<ClCompile Include="DebugExecutionManager.cpp" />
<ClCompile Include="DebugServer.cpp" />
<ClCompile Include="DebugServerSession.cpp" />
<ClCompile Include="GameInterfaces.cpp" />
<ClCompile Include="IdHandleBase.cpp" />
<ClCompile Include="IdMap.cpp" />
Expand All @@ -214,8 +208,8 @@
<ClCompile Include="PapyrusDebugger.cpp" />
<ClCompile Include="Pex.cpp" />
<ClCompile Include="PexCache.cpp" />
<ClCompile Include="protocol\cputil.cpp" />
<ClCompile Include="protocol\vscodeprotocol.cpp" />
<ClCompile Include="Protocol\websocket_reader_writer.cpp" />
<ClCompile Include="Protocol\websocket_server.cpp" />
<ClCompile Include="RuntimeEvents.cpp" />
<ClCompile Include="RuntimeState.cpp" />
<ClCompile Include="StackFrameStateNode.cpp" />
Expand All @@ -236,7 +230,6 @@
<ClInclude Include="BreakpointManager.h" />
<ClInclude Include="DebugExecutionManager.h" />
<ClInclude Include="DebugServer.h" />
<ClInclude Include="DebugServerSession.h" />
<ClInclude Include="FormMetadata.h" />
<ClInclude Include="GameInterfaces.h" />
<ClInclude Include="IdHandleBase.h" />
Expand All @@ -246,14 +239,12 @@
<ClInclude Include="MetaNode.h" />
<ClInclude Include="ObjectStateNode.h" />
<ClInclude Include="PapyrusDebugger.h" />
<ClInclude Include="PDError.h" />
<ClInclude Include="Pex.h" />
<ClInclude Include="PexCache.h" />
<ClInclude Include="protocol\cputil.h" />
<ClInclude Include="protocol\debugger.h" />
<ClInclude Include="protocol\protocol.h" />
<ClInclude Include="protocol\torelease.h" />
<ClInclude Include="protocol\vscodeprotocol.h" />
<ClInclude Include="Protocol\websocket_impl.h" />
<ClInclude Include="Protocol\websocket_reader_writer.h" />
<ClInclude Include="Protocol\websocket_server.h" />
<ClInclude Include="RuntimeEvents.h" />
<ClInclude Include="RuntimeState.h" />
<ClInclude Include="StackFrameStateNode.h" />
Expand All @@ -264,7 +255,6 @@
<ClInclude Include="Utilities.h" />
<ClInclude Include="ValueStateNode.h" />
<ClInclude Include="version.h" />
<ClInclude Include="Websocket.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,12 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="protocol\cputil.cpp">
<Filter>Protocol</Filter>
</ClCompile>
<ClCompile Include="DebugServer.cpp" />
<ClCompile Include="DebugServerSession.cpp" />
<ClCompile Include="Pex.cpp" />
<ClCompile Include="PexCache.cpp" />
<ClCompile Include="RuntimeEvents.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="PapyrusDebugger.cpp" />
<ClCompile Include="protocol\vscodeprotocol.cpp">
<Filter>Protocol</Filter>
</ClCompile>
<ClCompile Include="BreakpointManager.cpp" />
<ClCompile Include="DebugExecutionManager.cpp" />
<ClCompile Include="IdMap.cpp" />
Expand Down Expand Up @@ -59,29 +52,21 @@
<Filter>State</Filter>
</ClCompile>
<ClCompile Include="pdsPCH.cpp" />
<ClCompile Include="Protocol\websocket_server.cpp">
<Filter>Protocol</Filter>
</ClCompile>
<ClCompile Include="Protocol\websocket_reader_writer.cpp">
<Filter>Protocol</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="version.rc" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="protocol\cputil.h">
<Filter>Protocol</Filter>
</ClInclude>
<ClInclude Include="protocol\debugger.h">
<Filter>Protocol</Filter>
</ClInclude>
<ClInclude Include="protocol\protocol.h">
<Filter>Protocol</Filter>
</ClInclude>
<ClInclude Include="protocol\torelease.h">
<Filter>Protocol</Filter>
</ClInclude>
<ClInclude Include="protocol\vscodeprotocol.h">
<Filter>Protocol</Filter>
</ClInclude>
<ClInclude Include="Websocket.h" />
<ClInclude Include="DebugServer.h" />
<ClInclude Include="DebugServerSession.h" />
<ClInclude Include="PapyrusDebugger.h" />
<ClInclude Include="Pex.h" />
<ClInclude Include="PexCache.h" />
Expand Down Expand Up @@ -128,6 +113,14 @@
<Filter>State</Filter>
</ClInclude>
<ClInclude Include="pdsPCH.h" />
<ClInclude Include="PDError.h" />
<ClInclude Include="Protocol\websocket_reader_writer.h">
<Filter>Protocol</Filter>
</ClInclude>
<ClInclude Include="Protocol\websocket_server.h">
<Filter>Protocol</Filter>
</ClInclude>
<ClInclude Include="Protocol\websocket_impl.h">
<Filter>Protocol</Filter>
</ClInclude>
</ItemGroup>
</Project>
Loading

0 comments on commit d390277

Please sign in to comment.