-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
218 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,78 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using Microsoft.VisualStudio.Shell; | ||
using Microsoft.VisualStudio.Shell.Interop; | ||
using Task = System.Threading.Tasks.Task; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Runtime; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Emscripten.DebuggerLauncher; | ||
using Microsoft.VisualStudio.Debugger.DebugAdapterHost.Interfaces; | ||
using Microsoft.VisualStudio.ProjectSystem.Debug; | ||
using Microsoft.VisualStudio.ProjectSystem.VS.Debug; | ||
using StreamJsonRpc; | ||
using Microsoft.VisualStudio.Shell; | ||
using Microsoft.VisualStudio.Threading; | ||
using Newtonsoft.Json; | ||
using static System.Windows.Forms.Design.AxImporter; | ||
|
||
namespace Kamenokosoft.Emscripten.Debugger.VSCodeDwarfDebug | ||
{ | ||
internal sealed class DebugEngineLauncher | ||
public class AdapterLauncher : IAdapterLauncher, IDebugAdapterHostComponent | ||
{ | ||
static public async Task LaunchAsync(DebugLaunchSettings setting) | ||
private IDebugAdapterHostContext context; | ||
|
||
private Process debugServerProcess; | ||
|
||
public void Initialize(IDebugAdapterHostContext context) | ||
{ | ||
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); | ||
// Save the context object provided by the Debug Adapter Host so we can use it to access services later | ||
this.context = context; | ||
|
||
context.Events.DebuggingEnded += OnDebugSessionEnded; | ||
} | ||
|
||
public void UpdateLaunchOptions(IAdapterLaunchInfo launchInfo) | ||
{ | ||
if (launchInfo.LaunchJson.Contains("__pendingTarget")) | ||
{ | ||
// child target. ignore | ||
} | ||
else | ||
{ | ||
LaunchDebugServer(launchInfo); | ||
} | ||
} | ||
|
||
var obj = Package.GetGlobalService(typeof(SVsShellDebugger)) as IVsDebugger4; | ||
var vsDebugTargetInfo = new VsDebugTargetInfo4 | ||
private void OnDebugSessionEnded(object sender, EventArgs e) | ||
{ | ||
if (debugServerProcess != null && !debugServerProcess.HasExited) | ||
{ | ||
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); | ||
debugServerProcess.Kill(); | ||
} | ||
} | ||
|
||
private void LaunchDebugServer(IAdapterLaunchInfo launchInfo) | ||
{ | ||
var AdapterExecutable = launchInfo.GetMetricString("Adapter"); | ||
var AdapterArguments = launchInfo.GetMetricString("AdapterArgs"); | ||
|
||
var AdapterServerProcess = new Process(); | ||
|
||
AdapterServerProcess.StartInfo.FileName = AdapterExecutable; | ||
AdapterServerProcess.StartInfo.Arguments = AdapterArguments; | ||
AdapterServerProcess.StartInfo.WorkingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
// AdapterServerProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; | ||
|
||
AdapterServerProcess.Start(); | ||
|
||
debugServerProcess = AdapterServerProcess; | ||
} | ||
|
||
public ITargetHostProcess LaunchAdapter(IAdapterLaunchInfo launchInfo, ITargetHostInterop targetInterop) | ||
{ | ||
// nop | ||
return null; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
Emscripten.Debugger.VSCodeDwarfDebug/DebugAdapter/src/dapDebugServer.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
101 changes: 101 additions & 0 deletions
101
Emscripten.Debugger.VSCodeDwarfDebug/DebugEngineLauncher.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// 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.ProjectSystem.VS.Debug; | ||
using Microsoft.VisualStudio.Debugger.DebugAdapterHost.Interfaces; | ||
using System.IO; | ||
using System.Diagnostics; | ||
|
||
namespace Kamenokosoft.Emscripten.Debugger.VSCodeDwarfDebug | ||
{ | ||
internal class LaunchedTarget : ITargetHostProcess, IDisposable | ||
{ | ||
private Process target; | ||
|
||
public IntPtr Handle => target.Handle; | ||
|
||
public Stream StandardInput => target.StandardInput.BaseStream; | ||
|
||
public Stream StandardOutput => target.StandardOutput.BaseStream; | ||
|
||
public bool HasExited => target.HasExited; | ||
|
||
public event EventHandler Exited; | ||
public event DataReceivedEventHandler ErrorDataReceived; | ||
|
||
public LaunchedTarget(Process process) | ||
{ | ||
target = process; | ||
|
||
target.Exited += OnExited; | ||
target.ErrorDataReceived += OnErrorDataReceived; | ||
} | ||
|
||
public void Terminate() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
target.Exited -= OnExited; | ||
target.ErrorDataReceived -= OnErrorDataReceived; | ||
|
||
((IDisposable)target).Dispose(); | ||
} | ||
|
||
private void OnExited(object sender, EventArgs e) | ||
{ | ||
Exited(sender, e); | ||
} | ||
|
||
private void OnErrorDataReceived(object sender, DataReceivedEventArgs e) | ||
{ | ||
ErrorDataReceived(sender, e); | ||
} | ||
} | ||
|
||
internal sealed class DebugEngineLauncher | ||
{ | ||
static public async System.Threading.Tasks.Task<ITargetHostProcess> 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 launchedProcess = new VsDebugTargetProcessInfo[1]; | ||
|
||
obj.LaunchDebugTargets4(1, new VsDebugTargetInfo4[1] { vsDebugTargetInfo }, launchedProcess); | ||
|
||
return new LaunchedTarget(Process.GetProcessById((int)launchedProcess[0].dwProcessId)); | ||
} | ||
|
||
static public ITargetHostProcess Launch(DebugLaunchSettings setting) | ||
{ | ||
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 launchedProcess = new VsDebugTargetProcessInfo[1]; | ||
|
||
obj.LaunchDebugTargets4(1, new VsDebugTargetInfo4[1] { vsDebugTargetInfo }, launchedProcess); | ||
|
||
return new LaunchedTarget(Process.GetProcessById((int)launchedProcess[0].dwProcessId)); | ||
} | ||
} | ||
} |
Oops, something went wrong.