PowerShell / vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code
https://marketplace.visualstudio.com/items/ms-vscode.PowerShell
MIT License
1.69k stars 487 forks source link

Background Runspace Does not Break with Wait-Debugger #2783

Open adamdriscoll opened 4 years ago

adamdriscoll commented 4 years ago

System Details

System Details Output

### VSCode version: 1.46.1 cd9ea6488829f560dc949a8b2fb789f3cdc05f5d x64

### VSCode extensions:
eamodio.gitlens@10.2.2
Equinusocio.vsc-community-material-theme@1.4.1
Equinusocio.vsc-material-theme@32.8.0
equinusocio.vsc-material-theme-icons@1.1.4    
Hyzeta.vscode-theme-github-light@7.14.2
k--kato.docomment@0.1.13
ms-dotnettools.csharp@1.22.1
ms-vscode-remote.remote-wsl@0.44.4
ms-vscode.powershell@2020.6.0
PKief.material-icon-theme@4.2.0

### PSES version: 2.2.0.0

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      7.0.2
PSEdition                      Core
GitCommitId                    7.0.2
OS                             Microsoft Windows 10.0.19041
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Issue Description

When creating a background runspace and then attempting to debug it with Debug-Runspace causes the debugger to just continue through and never stop within the background runspace.

Steps to reproduce:

PS C:\src\universal> start-threadjob { Wait-Debugger; Get-Process }

Id     Name            PSJobTypeName   State         HasMoreData     Location             Command
--     ----            -------------   -----         -----------     --------             -------
1      Job1            ThreadJob       NotStarted    False           PowerShell            Wait-Debugger; Get-Proc…

PS C:\src\universal> get-runspace

 Id Name            ComputerName    Type          State         Availability
 -- ----            ------------    ----          -----         ------------
  1 Runspace1       localhost       Local         Opened        Available
  4 Runspace4       localhost       Local         Opened        Busy
  6 Runspace6       localhost       Local         Opened        Available
  7 Runspace7       localhost       Local         Opened        Available
  8 Runspace8       localhost       Local         Opened        Available
  9 Runspace9       localhost       Local         Opened        InBreakpoint

PS C:\src\universal> get-runspace 9 | Debug-runspace

Debugging Runspace: Runspace9
To end the debugging session type the 'Detach' command at the debugger prompt, or type 'Ctrl+C' otherwise.

Entering debugged runspace on local machine LAPTOP-496LAUK8
[DBG]: [Process:11676]: [Runspace9]: PS C:\src\universal>>
Command or script completed.
To end the debugging session type the 'Detach' command at the debugger prompt, or type 'Ctrl+C' otherwise.

I also cannot end the debugging session. This happens.

image

I have this error in the logs.

[Info  - 13:45:30] Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: PowerShell runtime version: 7.0.2, edition: Core | 
[Info  - 13:45:30] Microsoft.PowerShell.EditorServices.Handlers.PsesDocumentHighlightHandler: highlight handler loaded | 
[Info  - 13:45:33] Microsoft.PowerShell.EditorServices.Services.AnalysisService: Unable to find PSSA settings file at 'c:\src\universal\PSScriptAnalyzerSettings.psd1'. Loading default rules. | 
[Info  - 13:45:33] Microsoft.PowerShell.EditorServices.Services.AnalysisService: PSScriptAnalyzer settings file not found. Falling back to default rules | 
[Error - 13:46:07] Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Exception occurred while executing debugger command:

System.Management.Automation.CommandNotFoundException: The term '__Invoke-ReadLineForEditorServices' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke[T](IEnumerable input, IList`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.InvokeWithDebugger(IEnumerable`1 input, IList`1 output, PSInvocationSettings settings, Boolean invokeMustRun)
   at System.Management.Automation.ScriptDebugger.ProcessCommand(PSCommand command, PSDataCollection`1 output)
   at System.Management.Automation.NestedRunspaceDebugger.ProcessCommand(PSCommand command, PSDataCollection`1 output)
   at System.Management.Automation.ScriptDebugger.ProcessCommandForActiveDebugger(PSCommand command, PSDataCollection`1 output)
   at System.Management.Automation.ScriptDebugger.ProcessCommand(PSCommand command, PSDataCollection`1 output)
   at Microsoft.PowerShell.EditorServices.Services.PowerShellContext.PowerShell5Operations.ExecuteCommandInDebugger[TResult](PowerShellContextService powerShellContext, Runspace currentRunspace, PSCommand psCommand, Boolean sendOutputToHost, Nullable`1& debuggerResumeAction) in D:\a\1\s\src\PowerShellEditorServices\Services\PowerShellContext\Session\PowerShell5Operations.cs:line 61
   at Microsoft.PowerShell.EditorServices.Services.PowerShellContextService.ExecuteCommandInDebugger[TResult](PSCommand psCommand, Boolean sendOutputToHost) in D:\a\1\s\src\PowerShellEditorServices\Services\PowerShellContext\PowerShellContextService.cs:line 1955
   at Microsoft.PowerShell.EditorServices.Services.PowerShellContextService.ExecuteCommandAsync[TResult](PSCommand psCommand, StringBuilder errorMessages, ExecutionOptions executionOptions) in D:\a\1\s\src\PowerShellEditorServices\Services\PowerShellContext\PowerShellContextService.cs:line 713 | 

Expected Behaviour

Correctly debug the runspace.

Actual Behaviour

Just drops out of the runspace without breaking.

rjmholt commented 4 years ago

Interesting. The fix to this will almost certainly come from work toward https://github.com/PowerShell/PowerShellEditorServices/issues/1295. Debugging and remoting are next on the list there.