From 84e33dedc7bed53f49dfc6425eba17a5eb2e55e6 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Thu, 15 Feb 2018 22:05:34 -0700 Subject: [PATCH 1/2] Fix PSES crash on debug start when function breakpoint defined Fixex https://github.com/PowerShell/vscode-powershell/issues/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 --- .../Server/DebugAdapter.cs | 56 +++++++++++++++++-- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs b/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs index 77c0ad29a..d74de90cc 100644 --- a/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs +++ b/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs @@ -613,9 +613,23 @@ protected async Task HandleSetFunctionBreakpointsRequest( CommandBreakpointDetails[] updatedBreakpointDetails = breakpointDetails; if (!this.noDebug) { - updatedBreakpointDetails = - await editorSession.DebugService.SetCommandBreakpoints( - breakpointDetails); + this.setBreakpointInProgress = true; + + try + { + updatedBreakpointDetails = + await editorSession.DebugService.SetCommandBreakpoints( + breakpointDetails); + } + catch (Exception e) + { + // Log whatever the error is + Logger.WriteException($"Caught error while setting command breakpoints", e); + } + finally + { + this.setBreakpointInProgress = false; + } } await requestContext.SendResult( @@ -632,6 +646,24 @@ protected async Task HandleSetExceptionBreakpointsRequest( RequestContext requestContext) { // TODO: Handle this appropriately + //if (!this.noDebug) + //{ + // this.setBreakpointInProgress = true; + + // try + // { + // // Set exception breakpoints in DebugService + // } + // catch (Exception e) + // { + // // Log whatever the error is + // Logger.WriteException($"Caught error while setting exception breakpoints", e); + // } + // finally + // { + // this.setBreakpointInProgress = false; + // } + //} await requestContext.SendResult(null); } @@ -1034,8 +1066,22 @@ private async void DebugService_BreakpointUpdated(object sender, BreakpointUpdat break; } - var breakpoint = Protocol.DebugAdapter.Breakpoint.Create( - BreakpointDetails.Create(e.Breakpoint)); + Protocol.DebugAdapter.Breakpoint breakpoint; + if (e.Breakpoint is LineBreakpoint) + { + breakpoint = Protocol.DebugAdapter.Breakpoint.Create(BreakpointDetails.Create(e.Breakpoint)); + } + else if (e.Breakpoint is CommandBreakpoint) + { + //breakpoint = Protocol.DebugAdapter.Breakpoint.Create(CommandBreakpointDetails.Create(e.Breakpoint)); + Logger.Write(LogLevel.Verbose, "Function breakpoint updated event is not supported yet"); + return; + } + else + { + Logger.Write(LogLevel.Error, $"Unrecognized breakpoint type {e.Breakpoint.GetType().FullName}"); + return; + } breakpoint.Verified = e.UpdateType != BreakpointUpdateType.Disabled; From ce697ce51ee4e797e44e01180154947c1de46d92 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Fri, 16 Feb 2018 09:42:54 -0700 Subject: [PATCH 2/2] Add comment on why code is commented out --- src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs b/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs index d74de90cc..a0b60c369 100644 --- a/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs +++ b/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs @@ -645,7 +645,9 @@ protected async Task HandleSetExceptionBreakpointsRequest( SetExceptionBreakpointsRequestArguments setExceptionBreakpointsParams, RequestContext requestContext) { - // TODO: Handle this appropriately + // TODO: When support for exception breakpoints (unhandled and/or first chance) + // are added to the PowerShell engine, wire up the VSCode exception + // breakpoints here using the pattern below to prevent bug regressions. //if (!this.noDebug) //{ // this.setBreakpointInProgress = true;