Skip to content

Commit 8df688c

Browse files
committed
Clean up PowerShellDebugContext.cs
1 parent 70d100b commit 8df688c

File tree

1 file changed

+30
-65
lines changed

1 file changed

+30
-65
lines changed

src/PowerShellEditorServices/Services/PowerShell/Debugging/PowerShellDebugContext.cs

+30-65
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShell.Debugging
1515
/// </summary>
1616
/// <remarks>
1717
/// <para>
18-
/// Debugging through a PowerShell Host is implemented by registering a handler
19-
/// for the <see cref="System.Management.Automation.Debugger.DebuggerStop"/> event.
20-
/// Registering that handler causes debug actions in PowerShell like Set-PSBreakpoint
21-
/// and Wait-Debugger to drop into the debugger and trigger the handler.
22-
/// The handler is passed a mutable <see cref="System.Management.Automation.DebuggerStopEventArgs"/> object
23-
/// and the debugger stop lasts for the duration of the handler call.
24-
/// The handler sets the <see cref="System.Management.Automation.DebuggerStopEventArgs.ResumeAction"/> property
25-
/// when after it returns, the PowerShell debugger uses that as the direction on how to proceed.
18+
/// Debugging through a PowerShell Host is implemented by registering a handler for the <see
19+
/// cref="Debugger.DebuggerStop"/> event. Registering that handler causes debug actions in
20+
/// PowerShell like Set-PSBreakpoint and Wait-Debugger to drop into the debugger and trigger the
21+
/// handler. The handler is passed a mutable <see cref="DebuggerStopEventArgs"/> object and the
22+
/// debugger stop lasts for the duration of the handler call. The handler sets the <see
23+
/// cref="DebuggerStopEventArgs.ResumeAction"/> property when after it returns, the PowerShell
24+
/// debugger uses that as the direction on how to proceed.
2625
/// </para>
2726
/// <para>
28-
/// When we handle the <see cref="System.Management.Automation.Debugger.DebuggerStop"/> event,
29-
/// we drop into a nested debug prompt and execute things in the debugger with <see cref="System.Management.Automation.Debugger.ProcessCommand(PSCommand, PSDataCollection{PSObject})"/>,
30-
/// which enables debugger commands like <c>l</c>, <c>c</c>, <c>s</c>, etc.
31-
/// <see cref="Microsoft.PowerShell.EditorServices.Services.PowerShell.Debugging.PowerShellDebugContext"/> saves the event args object in its state,
32-
/// and when one of the debugger commands is used, the result returned is used to set <see cref="System.Management.Automation.DebuggerStopEventArgs.ResumeAction"/>
33-
/// on the saved event args object so that when the event handler returns, the PowerShell debugger takes the correct action.
27+
/// When we handle the <see cref="Debugger.DebuggerStop"/> event, we drop into a nested debug
28+
/// prompt and execute things in the debugger with <see cref="Debugger.ProcessCommand(PSCommand,
29+
/// PSDataCollection{PSObject})"/>, which enables debugger commands like <c>l</c>, <c>c</c>,
30+
/// <c>s</c>, etc. <see cref="PowerShellDebugContext"/> saves the event args object in its
31+
/// state, and when one of the debugger commands is used, the result returned is used to set
32+
/// <see cref="DebuggerStopEventArgs.ResumeAction"/> on the saved event args object so that when
33+
/// the event handler returns, the PowerShell debugger takes the correct action.
3434
/// </para>
3535
/// </remarks>
3636
internal class PowerShellDebugContext : IPowerShellDebugContext
@@ -72,42 +72,24 @@ public Task<DscBreakpointCapability> GetDscBreakpointCapabilityAsync(Cancellatio
7272
return _psesHost.CurrentRunspace.GetDscBreakpointCapabilityAsync(_logger, _psesHost, cancellationToken);
7373
}
7474

75+
// This is required by the PowerShell API so that remote debugging works. Without it, a
76+
// runspace may not have these options set and attempting to set breakpoints remotely fails.
7577
public void EnableDebugMode()
7678
{
77-
// This is required by the PowerShell API so that remote debugging works.
78-
// Without it, a runspace may not have these options set and attempting to set breakpoints remotely can fail.
7979
_psesHost.Runspace.Debugger.SetDebugMode(DebugModes.LocalScript | DebugModes.RemoteScript);
8080
}
8181

82-
public void Abort()
83-
{
84-
SetDebugResuming(DebuggerResumeAction.Stop);
85-
}
82+
public void Abort() => SetDebugResuming(DebuggerResumeAction.Stop);
8683

87-
public void BreakExecution()
88-
{
89-
_psesHost.Runspace.Debugger.SetDebuggerStepMode(enabled: true);
90-
}
84+
public void BreakExecution() => _psesHost.Runspace.Debugger.SetDebuggerStepMode(enabled: true);
9185

92-
public void Continue()
93-
{
94-
SetDebugResuming(DebuggerResumeAction.Continue);
95-
}
86+
public void Continue() => SetDebugResuming(DebuggerResumeAction.Continue);
9687

97-
public void StepInto()
98-
{
99-
SetDebugResuming(DebuggerResumeAction.StepInto);
100-
}
88+
public void StepInto() => SetDebugResuming(DebuggerResumeAction.StepInto);
10189

102-
public void StepOut()
103-
{
104-
SetDebugResuming(DebuggerResumeAction.StepOut);
105-
}
90+
public void StepOut() => SetDebugResuming(DebuggerResumeAction.StepOut);
10691

107-
public void StepOver()
108-
{
109-
SetDebugResuming(DebuggerResumeAction.StepOver);
110-
}
92+
public void StepOver() => SetDebugResuming(DebuggerResumeAction.StepOver);
11193

11294
public void SetDebugResuming(DebuggerResumeAction debuggerResumeAction)
11395
{
@@ -132,27 +114,19 @@ public void SetDebugResuming(DebuggerResumeAction debuggerResumeAction)
132114
}
133115

134116
// This must be called AFTER the new PowerShell has been pushed
135-
public void EnterDebugLoop()
136-
{
137-
RaiseDebuggerStoppedEvent();
138-
}
117+
public void EnterDebugLoop() => RaiseDebuggerStoppedEvent();
139118

140119
// This must be called BEFORE the debug PowerShell has been popped
141120
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "This method may acquire an implementation later, at which point it will need instance data")]
142-
public void ExitDebugLoop()
143-
{
144-
}
121+
public void ExitDebugLoop() { }
145122

146-
public void SetDebuggerStopped(DebuggerStopEventArgs debuggerStopEventArgs)
123+
public void SetDebuggerStopped(DebuggerStopEventArgs args)
147124
{
148125
IsStopped = true;
149-
LastStopEventArgs = debuggerStopEventArgs;
126+
LastStopEventArgs = args;
150127
}
151128

152-
public void SetDebuggerResumed()
153-
{
154-
IsStopped = false;
155-
}
129+
public void SetDebuggerResumed() { IsStopped = false; }
156130

157131
public void ProcessDebuggerResult(DebuggerCommandResults debuggerResult)
158132
{
@@ -163,19 +137,10 @@ public void ProcessDebuggerResult(DebuggerCommandResults debuggerResult)
163137
}
164138
}
165139

166-
public void HandleBreakpointUpdated(BreakpointUpdatedEventArgs breakpointUpdatedEventArgs)
167-
{
168-
BreakpointUpdated?.Invoke(this, breakpointUpdatedEventArgs);
169-
}
140+
public void HandleBreakpointUpdated(BreakpointUpdatedEventArgs args) => BreakpointUpdated?.Invoke(this, args);
170141

171-
private void RaiseDebuggerStoppedEvent()
172-
{
173-
DebuggerStopped?.Invoke(this, LastStopEventArgs);
174-
}
142+
private void RaiseDebuggerStoppedEvent() => DebuggerStopped?.Invoke(this, LastStopEventArgs);
175143

176-
private void RaiseDebuggerResumingEvent(DebuggerResumingEventArgs debuggerResumingEventArgs)
177-
{
178-
DebuggerResuming?.Invoke(this, debuggerResumingEventArgs);
179-
}
144+
private void RaiseDebuggerResumingEvent(DebuggerResumingEventArgs args) => DebuggerResuming?.Invoke(this, args);
180145
}
181146
}

0 commit comments

Comments
 (0)