Skip to content

Fix PSES crash on debug start when function breakpoint defined #624

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

Merged
merged 2 commits into from
Feb 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 54 additions & 6 deletions src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -631,7 +645,27 @@ protected async Task HandleSetExceptionBreakpointsRequest(
SetExceptionBreakpointsRequestArguments setExceptionBreakpointsParams,
RequestContext<object> 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;

// try
// {
// // Set exception breakpoints in DebugService
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we need this commented out code? If so, can you supply a reason in the comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hoping we will eventually get support for breaking on unhandled exceptions (maybe even first thrown). When we do, I don't want to have the same mistake of not setting the setBreakpointInProgress flag. That was the one of the causes of the crash. I can add a comment along those lines.

// }
// 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);
}
Expand Down Expand Up @@ -1034,8 +1068,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;

Expand Down