Skip to content

Commit

Permalink
add vscode-dwarf-debug package
Browse files Browse the repository at this point in the history
  • Loading branch information
nokotan committed Jul 3, 2024
1 parent 9d37a19 commit e9b5321
Show file tree
Hide file tree
Showing 67 changed files with 1,374 additions and 22 deletions.
36 changes: 36 additions & 0 deletions ChromeCXXDebugger/AdapterLauncher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Debugger.Interop;
using Microsoft.VisualStudio;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.VisualStudio.ProjectSystem.VS.Debug;
using StreamJsonRpc;

namespace Kamenokosoft.ChromeCXXDebugger
{
internal sealed class DebugEngineLauncher
{
static public async Task LaunchAsync(DebugLaunchSettings setting)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

var obj = Package.GetGlobalService(typeof(SVsShellDebugger)) as IVsDebugger4;
var vsDebugTargetInfo = new VsDebugTargetInfo4
{
LaunchFlags = (uint)setting.LaunchOptions,
dlo = (uint)setting.LaunchOperation,
guidLaunchDebugEngine = setting.LaunchDebugEngineGuid,
bstrExe = setting.Executable,
bstrOptions = setting.Options
};
var _unused = new VsDebugTargetProcessInfo[1];

obj.LaunchDebugTargets4(1, new VsDebugTargetInfo4[1] { vsDebugTargetInfo }, _unused);
}
}
}
98 changes: 98 additions & 0 deletions ChromeCXXDebugger/ChromeCXXDebugger.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MinimumVisualStudioVersion>15.0</MinimumVisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release VS2017|AnyCPU'">
<OutputPath>bin\Release VS2017\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<DeployExtension>True</DeployExtension>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug VS2017|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug VS2017\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<DeployExtension>True</DeployExtension>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectTypeGuids>{82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProjectGuid>{1EDC56A6-1E63-4A9C-9220-971F8AA515A0}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Kamenokosoft.ChromeCXXDebugger</RootNamespace>
<AssemblyName>Kamenokosoft.ChromeCXXDebugger</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<GeneratePkgDefFile>false</GeneratePkgDefFile>
<IncludeAssemblyInVSIXContainer>true</IncludeAssemblyInVSIXContainer>
<IncludeDebugSymbolsInVSIXContainer>false</IncludeDebugSymbolsInVSIXContainer>
<IncludeDebugSymbolsInLocalVSIXDeployment>false</IncludeDebugSymbolsInLocalVSIXDeployment>
<CopyBuildOutputToOutputDirectory>false</CopyBuildOutputToOutputDirectory>
<CopyOutputSymbolsToOutputDirectory>false</CopyOutputSymbolsToOutputDirectory>
<StartAction>Program</StartAction>
<StartProgram Condition="'$(DevEnvDir)' != ''">$(DevEnvDir)devenv.exe</StartProgram>
<StartArguments>/rootsuffix Exp</StartArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DeployExtension>True</DeployExtension>
<CreateVsixContainer>True</CreateVsixContainer>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DeployExtension>False</DeployExtension>
<CreateVsixContainer>True</CreateVsixContainer>
</PropertyGroup>
<ItemGroup>
<None Include="source.extension.vsixmanifest">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="ChromeCXXDebugger.pkgdef">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="DebugAdapter\**\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
</ItemGroup>
<ItemGroup>
<Compile Include="AdapterLauncher.cs" />
<Compile Include="CustomMessageHandler.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
34 changes: 34 additions & 0 deletions ChromeCXXDebugger/ChromeCXXDebugger.pkgdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
; Custom Protocol Extension
[$RootKey$\CLSID\{05EFD122-20D3-4FB8-8C72-E4BBEEA19FD3}]
"Assembly"="Kamenokosoft.ChromeCXXDebugger"
"Class"="Kamenokosoft.ChromeCXXDebugger.StartDebuggingRequestHandler"
"CodeBase"="$PackageFolder$\Kamenokosoft.ChromeCXXDebugger.dll"


[$RootKey$\AD7Metrics\Engine\{9849C080-ECCF-46EE-9758-9F6F9ED68693}]
"Name"="Chrome CXX Debugger"

; Boilerplate
"CLSID"="{DAB324E9-7B35-454C-ACA8-F6BB0D5C8673}"
"AlwaysLoadLocal"=dword:00000001
"Attach"=dword:00000001
"AddressBP"=dword:00000000
"AutoSelectPriority"=dword:00000004
"CallstackBP"=dword:00000000
"ConditionalBP"=dword:00000001
"Exceptions"=dword:00000001
"ExceptionBreakpointCategory"="{1ce4d9f7-faac-42ee-b352-87fdfb6fb37b}"
"UseEngineForNonDebugLaunch"=dword:00000001
"DebugEngineType"="javascript"
@="VSCode Debugger Host"

; Language Info
"Language"="C++ with WebAssembly"
"LanguageId"="{3a12d0b7-c26c-11d0-b442-00a0244a1dd2}"

; Launch Info
"Adapter"=""$PackageFolder$\DebugAdapter\src\dapDebugServer.js""
"AdapterArgs"="8123 127.0.0.1"
"AdapterRuntime"="node-x64-lts"

"CustomProtocolExtension"="{05EFD122-20D3-4FB8-8C72-E4BBEEA19FD3}"
88 changes: 88 additions & 0 deletions ChromeCXXDebugger/CustomMessageHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using Microsoft.VisualStudio.Debugger.DebugAdapterHost.Interfaces;
using Microsoft.VisualStudio.ProjectSystem.Debug;
using Microsoft.VisualStudio.Shared.VSCodeDebugProtocol;
using Microsoft.VisualStudio.Shared.VSCodeDebugProtocol.Messages;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Microsoft.VisualStudio.ProjectSystem.VS.Debug;
using System;
using System.IO;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Threading;

namespace Kamenokosoft.ChromeCXXDebugger
{


public class StartDebuggingRequestHandler : ICustomProtocolExtension
{
private IDebugAdapterHostContext context;

private IProtocolHostOperations host;

public void Initialize(IDebugAdapterHostContext context)
{
// Save the context object provided by the Debug Adapter Host so we can use it to access services later
this.context = context;
}

public void RegisterCustomMessages(ICustomMessageRegistry registry, IProtocolHostOperations hostOperations)
{
host = hostOperations;

// Register our custom request
registry.RegisterClientRequestType<StartDebuggingRequest, StartDebuggingArgs, StartDebuggingResponse>(this.OnStartDebuggingRequest);

// Advertise support for the custom request
registry.SetInitializeRequestProperty("supportsStartDebuggingRequest", true);
}

#region StartDebugging

private void OnStartDebuggingRequest(IRequestResponder<StartDebuggingArgs, StartDebuggingResponse> responder)
{
var settings = new DebugLaunchSettings(DebugLaunchOptions.DetachOnStop);

settings.LaunchOperation = DebugLaunchOperation.CreateProcess;
settings.LaunchDebugEngineGuid = new Guid("9849C080-ECCF-46EE-9758-9F6F9ED68693");
settings.Executable = "WebAssembly DWARF Debug";
responder.Arguments.Config.ConfigurationProperties["$debugServer"] = 8123;
settings.Options = JsonConvert.SerializeObject(responder.Arguments.Config);

ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
{
await DebugEngineLauncher.LaunchAsync(settings);
}).Task.Forget();

responder.SetResponse(new StartDebuggingResponse());
}

internal class ConfigurationProperty
{
[JsonExtensionData(ReadData = true, WriteData = true)]
public JObject ConfigurationProperties { get; set; }
}

internal class StartDebuggingArgs
{
[JsonProperty("request")]
public string Request { get; set; }

[JsonProperty("configuration")]
public ConfigurationProperty Config { get; set; }
}

internal class StartDebuggingResponse : ResponseBody
{
}

internal class StartDebuggingRequest : DebugClientRequestWithResponse<StartDebuggingArgs, StartDebuggingResponse>
{
public StartDebuggingRequest() : base("startDebugging")
{
}
}

#endregion
}
}
4 changes: 4 additions & 0 deletions ChromeCXXDebugger/DebugAdapter/.vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# note: this is moved into `dist` during compilation, and does not actually apply here
**/*.map
src/build/**
src/testRunner.js
21 changes: 21 additions & 0 deletions ChromeCXXDebugger/DebugAdapter/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
Loading

0 comments on commit e9b5321

Please sign in to comment.