Skip to content

Error with Function Breakpoints: Debug adapter process has terminated unexpectedly #1159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jonathanmedd opened this issue Jan 9, 2018 · 10 comments
Labels

Comments

@jonathanmedd
Copy link

System Details

  • Operating system name and version: Windows 10, 10.0.16299
  • VS Code version: 1.19.1
  • PowerShell extension version: 1.5.1
  • Output from $PSVersionTable:
Major  Minor  Build  Revision
-----  -----  -----  --------
1      5      1      0

DotJoshJohnson.xml@1.9.2
eamodio.gitlens@7.2.0
ms-vscode.PowerShell@1.5.1


Name                           Value
----                           -----
PSVersion                      6.0.0-rc.2
PSEdition                      Core
GitCommitId                    v6.0.0-rc.2
OS                             Microsoft Windows 10.0.16299
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0


Name                           Value
----                           -----
PSVersion                      5.1.16299.98
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.98
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Description

I am experiencing a problem with setting a function breakpoint and using the VS Code debugger. The issue occurs in both PS Core 6 RC2 and PS 5.1.

Example code:

1..10 | ForEach-Object {Write-Host "Hello World"}

Create a function breakpoint for Write-Host:

image

will produce the following error on PS Core 6 when starting the debugger. (PS 5.1 does not produce error text)

An error has occurred that was not properly handled. Additional information is shown below. The PowerShell process will exit.

Unhandled Exception: 1..10 | ForEach-Object {Write-Host "Hello World"}
System.ArgumentException: Unexpected breakpoint type: CommandBreakpoint
at Microsoft.PowerShell.EditorServices.BreakpointDetails.Create(Breakpoint breakpoint)
at Microsoft.PowerShell.EditorServices.Protocol.Server.DebugAdapter.<DebugService_BreakpointUpdated>d__47.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadPoolWorkQueue.Dispatch()

Hit Command breakpoint on 'Write-Host'

PowerShell Core 6 RC2

image

PowerShell 5.1

image

Attached Logs

DebugLogs.zip

@rkeithhill
Copy link
Contributor

Can you save the file to disk and try again. Right now, setting breakpoints won't work for "in-memory" files. That said, we should fix the PSES crash.

@jonathanmedd
Copy link
Author

Same problem after saving to disk. I should have mentioned that in the original description, although I think the logs were from a non-saved.

@rkeithhill
Copy link
Contributor

Doh! :-)

@jonathanmedd
Copy link
Author

I can reproduce the error with any saved file. For example opening DebugTest.ps1 which ships as an example as part of the VS Code PowerShell extension. Create a function breakpoint for Write-Host and it will blow up with the same error:

image

Here are the logs for this one:
DebugLogs2.zip

@TylerLeonhardt
Copy link
Member

TylerLeonhardt commented Jan 10, 2018

Thanks for this report, @jonathanmedd!

@rkeithhill: I didn't see too much in the logs but that exception he supplied seems like a good start, would you agree?

@SeeminglyScience
Copy link
Collaborator

@tylerl0706 looks like this line

https://github.com/PowerShell/PowerShellEditorServices/blob/33cb42140d23ac94c28d325d242899b9a39aae7e/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs#L1038

needs to be updated to check for CommandBreakpoint and VariableBreakpoint and create either CommandBreakpointDetails or VariableBreakpointDetails

@realonedet
Copy link

realonedet commented Feb 11, 2018

I've been having the exact same issue (on windows and mac), posted previously with no resolution, has this been root caused or a fix made available yet ?

@rkeithhill
Copy link
Contributor

rkeithhill commented Feb 14, 2018

I've got a fix in the works for this. In the process I found another issue - I think with VSCode's debug protocol. There is a BreakpointEvent that allows the debug adapter to notify VSCode about line breakpoints changes that occur in the debug adapter. I see no equivalent for function breakpoint changes.

I could be missing something in the debug protocol spec but just in case, I've raised an issue with the VSCode folks.

At the very least, this will eliminate the crash when using a function breakpoint.

@rkeithhill
Copy link
Contributor

And it turns out the debug protocol is missing this capability - https://github.com/Microsoft/vscode-debugadapter-node/issues/157

So, in the case of the user creating a command breakpoint in PSIC, I'll not have that send a BreakpointEvent to VSCode.

rkeithhill added a commit to PowerShell/PowerShellEditorServices that referenced this issue Feb 16, 2018
Fixex PowerShell/vscode-powershell#1159

When VSCode passes us a breakpoint to set, we normally set
a flag to indicate "setBreakpointInProgress" so that when
the DebugService_BreakpointUpdated event is fired, we can
tell that we initiated it instead of the user using Set-PSBreakpoint
to set a breakpoint.   Well, the code that handled function
breakpoints msgs sent by VSCode was not setting that flag.

Also, when the user does use Set-PSBreakpoint -Command
there is no debug protocol event for function breakpoints
so we need to ignore this type of breakpoint set by the user
until the debug protocol support it.  See https://github.com/Microsoft/vscode-debugadapter-node/issues/157
@rkeithhill
Copy link
Contributor

The fix for this should be in the upcoming 1.6.0 release.

rkeithhill added a commit to PowerShell/PowerShellEditorServices that referenced this issue Feb 20, 2018
* Fix PSES crash on debug start when function breakpoint defined

Fixex PowerShell/vscode-powershell#1159

When VSCode passes us a breakpoint to set, we normally set
a flag to indicate "setBreakpointInProgress" so that when
the DebugService_BreakpointUpdated event is fired, we can
tell that we initiated it instead of the user using Set-PSBreakpoint
to set a breakpoint.   Well, the code that handled function
breakpoints msgs sent by VSCode was not setting that flag.

Also, when the user does use Set-PSBreakpoint -Command
there is no debug protocol event for function breakpoints
so we need to ignore this type of breakpoint set by the user
until the debug protocol support it.  See https://github.com/Microsoft/vscode-debugadapter-node/issues/157

* Add comment on why code is commented out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants