Skip to content

Commit 096a78f

Browse files
KirkMunroiSazonov
authored andcommitted
Remove the event handler that was causing breakpoint changes to be erroneously replicated to the host runspace debugger (PowerShell#10503)
* fix PowerShell#10167 * Update test/powershell/SDK/Breakpoint.Tests.ps1 Co-Authored-By: Ilya <[email protected]>
1 parent 139cd94 commit 096a78f

File tree

2 files changed

+8
-33
lines changed

2 files changed

+8
-33
lines changed

src/System.Management.Automation/engine/debugger/debugger.cs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3013,7 +3013,6 @@ private void AddToJobRunningList(PSJobStartEventArgs jobArgs, DebuggerResumeActi
30133013

30143014
_runningJobs.Add(jobArgs.Job.InstanceId, jobArgs);
30153015
jobArgs.Debugger.DebuggerStop += HandleMonitorRunningJobsDebuggerStop;
3016-
jobArgs.Debugger.BreakpointUpdated += HandleBreakpointUpdated;
30173016

30183017
newJob = true;
30193018
}
@@ -3090,7 +3089,6 @@ private void RemoveFromRunningJobList(Job job)
30903089
if (_runningJobs.TryGetValue(job.InstanceId, out jobArgs))
30913090
{
30923091
jobArgs.Debugger.DebuggerStop -= HandleMonitorRunningJobsDebuggerStop;
3093-
jobArgs.Debugger.BreakpointUpdated -= HandleBreakpointUpdated;
30943092
_runningJobs.Remove(job.InstanceId);
30953093
}
30963094
}
@@ -3308,28 +3306,6 @@ private bool IsJobDebuggingMode()
33083306
(((DebugMode & DebugModes.RemoteScript) == DebugModes.RemoteScript) && !IsLocalSession));
33093307
}
33103308

3311-
private void HandleBreakpointUpdated(object sender, BreakpointUpdatedEventArgs e)
3312-
{
3313-
switch (e.UpdateType)
3314-
{
3315-
case BreakpointUpdateType.Set:
3316-
AddNewBreakpoint(e.Breakpoint);
3317-
break;
3318-
3319-
case BreakpointUpdateType.Removed:
3320-
RemoveBreakpoint(e.Breakpoint);
3321-
break;
3322-
3323-
case BreakpointUpdateType.Enabled:
3324-
EnableBreakpoint(e.Breakpoint);
3325-
break;
3326-
3327-
case BreakpointUpdateType.Disabled:
3328-
DisableBreakpoint(e.Breakpoint);
3329-
break;
3330-
}
3331-
}
3332-
33333309
private bool IsRunningWFJobsDebugger(Debugger debugger)
33343310
{
33353311
lock (_syncObject)
@@ -3528,7 +3504,6 @@ private void RemoveFromRunningRunspaceList(Runspace runspace)
35283504
if (nestedDebugger != null)
35293505
{
35303506
nestedDebugger.DebuggerStop -= HandleMonitorRunningRSDebuggerStop;
3531-
nestedDebugger.BreakpointUpdated -= HandleBreakpointUpdated;
35323507
nestedDebugger.Dispose();
35333508

35343509
// If current active debugger, then pop.
@@ -3698,7 +3673,6 @@ private bool SetUpDebuggerOnRunspace(Runspace runspace)
36983673
runspaceInfo.NestedDebugger = nestedDebugger;
36993674

37003675
nestedDebugger.DebuggerStop += HandleMonitorRunningRSDebuggerStop;
3701-
nestedDebugger.BreakpointUpdated += HandleBreakpointUpdated;
37023676

37033677
if (((_lastActiveDebuggerAction == DebuggerResumeAction.StepInto) || (_currentDebuggerAction == DebuggerResumeAction.StepInto)) &&
37043678
!nestedDebugger.IsActive)

test/powershell/SDK/Breakpoint.Tests.ps1

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ Describe 'Breakpoint SDK Unit Tests' -Tags 'CI' {
7777

7878
Context 'Managing breakpoints in a remote runspace via the SDK' {
7979

80-
AfterAll {
81-
# Get rid of any breakpoints that were created in the default runspace.
82-
# This is necessary due to a known bug that causes breakpoints with the
83-
# same id to be created or updated in the default runspace.
84-
Get-PSBreakpoint | Remove-PSBreakpoint
85-
}
86-
8780
It 'Can set command breakpoints' {
8881
$jobRunspace.Debugger.SetCommandBreakpoint('Write-Verbose', { break }) | Should -BeOfType [System.Management.Automation.CommandBreakpoint]
8982
}
@@ -115,6 +108,14 @@ Describe 'Breakpoint SDK Unit Tests' -Tags 'CI' {
115108
}
116109
}
117110

111+
It 'Doesn''t manipulate any breakpoints in the default runspace' {
112+
# Issue https://github.com/PowerShell/PowerShell/issues/10167 fix:
113+
# Ensure that breakpoints were not created in the default runspace.
114+
# Prior to this issue being fixed, breakpoints with the same id
115+
# would be created or updated in the default runspace.
116+
$host.Runspace.Debugger.GetBreakpoints() | Should -BeNullOrEmpty
117+
}
118+
118119
It 'Can remove breakpoints' {
119120
foreach ($bp in $jobRunspace.Debugger.GetBreakpoints()) {
120121
$jobRunspace.Debugger.RemoveBreakpoint($bp) | Should -BeTrue

0 commit comments

Comments
 (0)