Skip to content

Commit 5fe47a4

Browse files
committed
Enable debugging of remote and attached runspaces
This change finishes support for Enter-PSSession and Enter-PSHostProcess by wiring up the AttachRequest so that both of these commands can be used to attach to a runspace in a process on a local or remote machine. It also enables the LaunchRequest to be executed without a script file path to enable an interactive debugging session experience.
1 parent ffe7c61 commit 5fe47a4

30 files changed

+1330
-389
lines changed

src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ public static readonly
1616

1717
public class AttachRequestArguments
1818
{
19-
public string Address { get; set; }
19+
public string ComputerName { get; set; }
2020

21-
public int Port { get; set; }
21+
public int ProcessId { get; set; }
22+
23+
public int RunspaceId { get; set; }
2224
}
2325
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol;
7+
8+
namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter
9+
{
10+
public class ContinuedEvent
11+
{
12+
public static readonly
13+
EventType<ContinuedEvent> Type =
14+
EventType<ContinuedEvent>.Create("continued");
15+
16+
public int ThreadId { get; set; }
17+
18+
public bool AllThreadsContinued { get; set; }
19+
}
20+
}

src/PowerShellEditorServices.Protocol/DebugAdapter/TerminatedEvent.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter
1010
public class TerminatedEvent
1111
{
1212
public static readonly
13-
EventType<object> Type =
14-
EventType<object>.Create("terminated");
13+
EventType<TerminatedEvent> Type =
14+
EventType<TerminatedEvent>.Create("terminated");
15+
16+
public bool Restart { get; set; }
1517
}
1618
}
1719

src/PowerShellEditorServices.Protocol/LanguageServer/RunspaceChanged.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ public class RunspaceDetails
1919
{
2020
public PowerShellVersion PowerShellVersion { get; set; }
2121

22-
public RunspaceType RunspaceType { get; set; }
22+
public RunspaceLocation RunspaceType { get; set; }
2323

2424
public string ConnectionString { get; set; }
2525

2626
public RunspaceDetails()
2727
{
2828
}
2929

30-
public RunspaceDetails(RunspaceChangedEventArgs eventArgs)
30+
public RunspaceDetails(Session.RunspaceDetails eventArgs)
3131
{
32-
this.PowerShellVersion = new PowerShellVersion(eventArgs.RunspaceVersion);
33-
this.RunspaceType = eventArgs.RunspaceType;
32+
this.PowerShellVersion = new PowerShellVersion(eventArgs.PowerShellVersion);
33+
this.RunspaceType = eventArgs.Location;
3434
this.ConnectionString = eventArgs.ConnectionString;
3535
}
3636
}

src/PowerShellEditorServices.Protocol/MessageProtocol/Channel/TcpSocketServerChannel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ protected override void Shutdown()
5151
{
5252
if (this.tcpListener != null)
5353
{
54+
this.networkStream.Dispose();
5455
this.tcpListener.Stop();
5556
this.tcpListener = null;
5657

src/PowerShellEditorServices.Protocol/MessageProtocol/MessageDispatcher.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public void Stop()
8989
{
9090
this.messageLoopCancellationToken.Cancel();
9191
this.messageLoopThread.Stop();
92+
SynchronizationContext.SetSynchronizationContext(null);
9293
}
9394
}
9495

src/PowerShellEditorServices.Protocol/MessageProtocol/ProtocolEndpoint.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@ private void MessageDispatcher_UnhandledException(object sender, Exception e)
335335
{
336336
this.endpointExitedTask.SetException(e);
337337
}
338-
339338
else if (this.originalSynchronizationContext != null)
340339
{
341340
this.originalSynchronizationContext.Post(o => { throw e; }, null);

src/PowerShellEditorServices.Protocol/PowerShellEditorServices.Protocol.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<Compile Include="DebugAdapter\AttachRequest.cs" />
5353
<Compile Include="DebugAdapter\Breakpoint.cs" />
5454
<Compile Include="DebugAdapter\ConfigurationDoneRequest.cs" />
55+
<Compile Include="DebugAdapter\ContinuedEvent.cs" />
5556
<Compile Include="DebugAdapter\ContinueRequest.cs" />
5657
<Compile Include="DebugAdapter\SetFunctionBreakpointsRequest.cs" />
5758
<Compile Include="DebugAdapter\SetVariableRequest.cs" />

0 commit comments

Comments
 (0)