Skip to content

Commit 84e33de

Browse files
committed
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
1 parent 7588c7a commit 84e33de

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

+51-5
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(
@@ -632,6 +646,24 @@ protected async Task HandleSetExceptionBreakpointsRequest(
632646
RequestContext<object> requestContext)
633647
{
634648
// TODO: Handle this appropriately
649+
//if (!this.noDebug)
650+
//{
651+
// this.setBreakpointInProgress = true;
652+
653+
// try
654+
// {
655+
// // Set exception breakpoints in DebugService
656+
// }
657+
// catch (Exception e)
658+
// {
659+
// // Log whatever the error is
660+
// Logger.WriteException($"Caught error while setting exception breakpoints", e);
661+
// }
662+
// finally
663+
// {
664+
// this.setBreakpointInProgress = false;
665+
// }
666+
//}
635667

636668
await requestContext.SendResult(null);
637669
}
@@ -1034,8 +1066,22 @@ private async void DebugService_BreakpointUpdated(object sender, BreakpointUpdat
10341066
break;
10351067
}
10361068

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

10401086
breakpoint.Verified = e.UpdateType != BreakpointUpdateType.Disabled;
10411087

0 commit comments

Comments
 (0)