9
9
using System . Management . Automation ;
10
10
using System . Management . Automation . Language ;
11
11
using System . Reflection ;
12
- using System . Text ;
13
12
using System . Threading . Tasks ;
14
13
using Microsoft . PowerShell . EditorServices . Utility ;
15
14
using System . Threading ;
19
18
using Microsoft . PowerShell . EditorServices . Services . PowerShell ;
20
19
using Microsoft . PowerShell . EditorServices . Services . PowerShell . Execution ;
21
20
using Microsoft . PowerShell . EditorServices . Services . PowerShell . Host ;
21
+ using Microsoft . PowerShell . EditorServices . Services . PowerShell . Debugging ;
22
+ using Microsoft . PowerShell . EditorServices . Services . PowerShell . Runspace ;
22
23
23
24
namespace Microsoft . PowerShell . EditorServices . Services
24
25
{
@@ -67,7 +68,7 @@ internal class DebugService
67
68
/// Gets a boolean that indicates whether the debugger is currently
68
69
/// stopped at a breakpoint.
69
70
/// </summary>
70
- public bool IsDebuggerStopped => _executionService . IsDebuggerStopped ;
71
+ public bool IsDebuggerStopped => _executionService . DebugContext . IsStopped ;
71
72
72
73
/// <summary>
73
74
/// Gets the current DebuggerStoppedEventArgs when the debugger
@@ -116,9 +117,9 @@ public DebugService(
116
117
_executionService = executionService ;
117
118
_breakpointService = breakpointService ;
118
119
_psesHost = psesHost ;
119
- _executionService . DebuggerStopped += this . OnDebuggerStopAsync ;
120
- _executionService . DebuggerResuming += this . OnDebuggerResuming ;
121
- _executionService . BreakpointUpdated += this . OnBreakpointUpdated ;
120
+ _executionService . DebugContext . DebuggerStopped += this . OnDebuggerStopAsync ;
121
+ _executionService . DebugContext . DebuggerResuming += this . OnDebuggerResuming ;
122
+ _executionService . DebugContext . BreakpointUpdated += this . OnBreakpointUpdated ;
122
123
123
124
this . remoteFileManager = remoteFileManager ;
124
125
@@ -145,10 +146,7 @@ public async Task<BreakpointDetails[]> SetLineBreakpointsAsync(
145
146
BreakpointDetails [ ] breakpoints ,
146
147
bool clearExisting = true )
147
148
{
148
- var dscBreakpoints =
149
- this . powerShellContext
150
- . CurrentRunspace
151
- . GetCapability < DscBreakpointCapability > ( ) ;
149
+ DscBreakpointCapability dscBreakpoints = _executionService . CurrentRunspace . DscBreakpointCapability ;
152
150
153
151
string scriptPath = scriptFile . FilePath ;
154
152
// Make sure we're using the remote script path
@@ -166,7 +164,7 @@ public async Task<BreakpointDetails[]> SetLineBreakpointsAsync(
166
164
string mappedPath =
167
165
this . remoteFileManager . GetMappedPath (
168
166
scriptPath ,
169
- this . powerShellContext . CurrentRunspace ) ;
167
+ _executionService . CurrentRunspace ) ;
170
168
171
169
scriptPath = mappedPath ;
172
170
}
@@ -182,8 +180,7 @@ public async Task<BreakpointDetails[]> SetLineBreakpointsAsync(
182
180
183
181
// Fix for issue #123 - file paths that contain wildcard chars [ and ] need to
184
182
// quoted and have those wildcard chars escaped.
185
- string escapedScriptPath =
186
- PowerShellContextService . WildcardEscapePath ( scriptPath ) ;
183
+ string escapedScriptPath = PathUtils . WildcardEscape ( scriptPath ) ;
187
184
188
185
if ( dscBreakpoints == null || ! dscBreakpoints . IsDscResourcePath ( escapedScriptPath ) )
189
186
{
@@ -232,35 +229,31 @@ public async Task<CommandBreakpointDetails[]> SetCommandBreakpointsAsync(
232
229
/// </summary>
233
230
public void Continue ( )
234
231
{
235
- this . powerShellContext . ResumeDebugger (
236
- DebuggerResumeAction . Continue ) ;
232
+ _executionService . DebugContext . Continue ( ) ;
237
233
}
238
234
239
235
/// <summary>
240
236
/// Sends a "step over" action to the debugger when stopped.
241
237
/// </summary>
242
238
public void StepOver ( )
243
239
{
244
- this . powerShellContext . ResumeDebugger (
245
- DebuggerResumeAction . StepOver ) ;
240
+ _executionService . DebugContext . StepOver ( ) ;
246
241
}
247
242
248
243
/// <summary>
249
244
/// Sends a "step in" action to the debugger when stopped.
250
245
/// </summary>
251
246
public void StepIn ( )
252
247
{
253
- this . powerShellContext . ResumeDebugger (
254
- DebuggerResumeAction . StepInto ) ;
248
+ _executionService . DebugContext . StepInto ( ) ;
255
249
}
256
250
257
251
/// <summary>
258
252
/// Sends a "step out" action to the debugger when stopped.
259
253
/// </summary>
260
254
public void StepOut ( )
261
255
{
262
- this . powerShellContext . ResumeDebugger (
263
- DebuggerResumeAction . StepOut ) ;
256
+ _executionService . DebugContext . StepOut ( ) ;
264
257
}
265
258
266
259
/// <summary>
@@ -270,8 +263,7 @@ public void StepOut()
270
263
/// </summary>
271
264
public void Break ( )
272
265
{
273
- // Break execution in the debugger
274
- this . powerShellContext . BreakExecution ( ) ;
266
+ _executionService . DebugContext . BreakExecution ( ) ;
275
267
}
276
268
277
269
/// <summary>
@@ -280,7 +272,7 @@ public void Break()
280
272
/// </summary>
281
273
public void Abort ( )
282
274
{
283
- this . powerShellContext . AbortExecution ( shouldAbortDebugSession : true ) ;
275
+ _executionService . DebugContext . Abort ( ) ;
284
276
}
285
277
286
278
/// <summary>
@@ -817,7 +809,7 @@ private async Task FetchStackFramesAsync(string scriptNameOverride)
817
809
818
810
// When debugging, this is the best way I can find to get what is likely the workspace root.
819
811
// This is controlled by the "cwd:" setting in the launch config.
820
- string workspaceRootPath = this . powerShellContext . InitialWorkingDirectory ;
812
+ string workspaceRootPath = _executionService . PowerShellContext . InitialWorkingDirectory ;
821
813
822
814
this . stackFrameDetails [ i ] =
823
815
StackFrameDetails . Create ( callStackFrames [ i ] , autoVariables , localVariables , workspaceRootPath ) ;
@@ -828,14 +820,14 @@ private async Task FetchStackFramesAsync(string scriptNameOverride)
828
820
{
829
821
this . stackFrameDetails [ i ] . ScriptPath = scriptNameOverride ;
830
822
}
831
- else if ( this . powerShellContext . CurrentRunspace . Location == RunspaceLocation . Remote &&
832
- this . remoteFileManager != null &&
833
- ! string . Equals ( stackFrameScriptPath , StackFrameDetails . NoFileScriptPath ) )
823
+ else if ( _executionService . CurrentRunspace . IsRemote ( )
824
+ && this . remoteFileManager != null
825
+ && ! string . Equals ( stackFrameScriptPath , StackFrameDetails . NoFileScriptPath ) )
834
826
{
835
827
this . stackFrameDetails [ i ] . ScriptPath =
836
828
this . remoteFileManager . GetMappedPath (
837
829
stackFrameScriptPath ,
838
- this . powerShellContext . CurrentRunspace ) ;
830
+ _executionService . CurrentRunspace ) ;
839
831
}
840
832
}
841
833
}
@@ -897,9 +889,9 @@ await _executionService.ExecutePSCommandAsync<PSObject>(
897
889
898
890
this . temporaryScriptListingPath =
899
891
this . remoteFileManager . CreateTemporaryFile (
900
- $ "[{ this . powerShellContext . CurrentRunspace . SessionDetails . ComputerName } ] { TemporaryScriptFileName } ",
892
+ $ "[{ _executionService . CurrentRunspace . SessionDetails . ComputerName } ] { TemporaryScriptFileName } ",
901
893
scriptListing ,
902
- this . powerShellContext . CurrentRunspace ) ;
894
+ _executionService . CurrentRunspace ) ;
903
895
904
896
localScriptPath =
905
897
this . temporaryScriptListingPath
@@ -919,14 +911,14 @@ await this.FetchStackFramesAndVariablesAsync(
919
911
920
912
// If this is a remote connection and the debugger stopped at a line
921
913
// in a script file, get the file contents
922
- if ( this . powerShellContext . CurrentRunspace . Location == RunspaceLocation . Remote &&
923
- this . remoteFileManager != null &&
924
- ! noScriptName )
914
+ if ( _executionService . CurrentRunspace . IsRemote ( )
915
+ && this . remoteFileManager != null
916
+ && ! noScriptName )
925
917
{
926
918
localScriptPath =
927
919
await this . remoteFileManager . FetchRemoteFileAsync (
928
920
e . InvocationInfo . ScriptName ,
929
- powerShellContext . CurrentRunspace ) . ConfigureAwait ( false ) ;
921
+ _executionService . CurrentRunspace ) . ConfigureAwait ( false ) ;
930
922
}
931
923
932
924
if ( this . stackFrameDetails . Length > 0 )
@@ -946,7 +938,7 @@ await this.remoteFileManager.FetchRemoteFileAsync(
946
938
this . CurrentDebuggerStoppedEventArgs =
947
939
new DebuggerStoppedEventArgs (
948
940
e ,
949
- this . powerShellContext . CurrentRunspace ,
941
+ _executionService . CurrentRunspace ,
950
942
localScriptPath ) ;
951
943
952
944
// Notify the host that the debugger is stopped
@@ -975,13 +967,13 @@ private void OnBreakpointUpdated(object sender, BreakpointUpdatedEventArgs e)
975
967
if ( e . Breakpoint is LineBreakpoint lineBreakpoint )
976
968
{
977
969
string scriptPath = lineBreakpoint . Script ;
978
- if ( this . powerShellContext . CurrentRunspace . Location == RunspaceLocation . Remote &&
979
- this . remoteFileManager != null )
970
+ if ( _executionService . CurrentRunspace . IsRemote ( )
971
+ && this . remoteFileManager != null )
980
972
{
981
973
string mappedPath =
982
974
this . remoteFileManager . GetMappedPath (
983
975
scriptPath ,
984
- this . powerShellContext . CurrentRunspace ) ;
976
+ _executionService . CurrentRunspace ) ;
985
977
986
978
if ( mappedPath == null )
987
979
{
0 commit comments