Skip to content

Commit 5eb586e

Browse files
authored
Fix PSES crash on debug start when function breakpoint defined (#624)
* 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
1 parent 6b3ebc5 commit 5eb586e

File tree

1 file changed

+54
-6
lines changed

1 file changed

+54
-6
lines changed

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -613,9 +613,23 @@ protected async Task HandleSetFunctionBreakpointsRequest(
613613
CommandBreakpointDetails[] updatedBreakpointDetails = breakpointDetails;
614614
if (!this.noDebug)
615615
{
616-
updatedBreakpointDetails =
617-
await editorSession.DebugService.SetCommandBreakpoints(
618-
breakpointDetails);
616+
this.setBreakpointInProgress = true;
617+
618+
try
619+
{
620+
updatedBreakpointDetails =
621+
await editorSession.DebugService.SetCommandBreakpoints(
622+
breakpointDetails);
623+
}
624+
catch (Exception e)
625+
{
626+
// Log whatever the error is
627+
Logger.WriteException($"Caught error while setting command breakpoints", e);
628+
}
629+
finally
630+
{
631+
this.setBreakpointInProgress = false;
632+
}
619633
}
620634

621635
await requestContext.SendResult(
@@ -631,7 +645,27 @@ protected async Task HandleSetExceptionBreakpointsRequest(
631645
SetExceptionBreakpointsRequestArguments setExceptionBreakpointsParams,
632646
RequestContext<object> requestContext)
633647
{
634-
// TODO: Handle this appropriately
648+
// TODO: When support for exception breakpoints (unhandled and/or first chance)
649+
// are added to the PowerShell engine, wire up the VSCode exception
650+
// breakpoints here using the pattern below to prevent bug regressions.
651+
//if (!this.noDebug)
652+
//{
653+
// this.setBreakpointInProgress = true;
654+
655+
// try
656+
// {
657+
// // Set exception breakpoints in DebugService
658+
// }
659+
// catch (Exception e)
660+
// {
661+
// // Log whatever the error is
662+
// Logger.WriteException($"Caught error while setting exception breakpoints", e);
663+
// }
664+
// finally
665+
// {
666+
// this.setBreakpointInProgress = false;
667+
// }
668+
//}
635669

636670
await requestContext.SendResult(null);
637671
}
@@ -1034,8 +1068,22 @@ private async void DebugService_BreakpointUpdated(object sender, BreakpointUpdat
10341068
break;
10351069
}
10361070

1037-
var breakpoint = Protocol.DebugAdapter.Breakpoint.Create(
1038-
BreakpointDetails.Create(e.Breakpoint));
1071+
Protocol.DebugAdapter.Breakpoint breakpoint;
1072+
if (e.Breakpoint is LineBreakpoint)
1073+
{
1074+
breakpoint = Protocol.DebugAdapter.Breakpoint.Create(BreakpointDetails.Create(e.Breakpoint));
1075+
}
1076+
else if (e.Breakpoint is CommandBreakpoint)
1077+
{
1078+
//breakpoint = Protocol.DebugAdapter.Breakpoint.Create(CommandBreakpointDetails.Create(e.Breakpoint));
1079+
Logger.Write(LogLevel.Verbose, "Function breakpoint updated event is not supported yet");
1080+
return;
1081+
}
1082+
else
1083+
{
1084+
Logger.Write(LogLevel.Error, $"Unrecognized breakpoint type {e.Breakpoint.GetType().FullName}");
1085+
return;
1086+
}
10391087

10401088
breakpoint.Verified = e.UpdateType != BreakpointUpdateType.Disabled;
10411089

0 commit comments

Comments
 (0)