-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Updating breakpoints in a nested debugger or in a job debugger results in breakpoints with the same id in the parent being overwritten #10167
Copy link
Copy link
Closed
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aWG-Interactive-Debuggingdebugging PowerShell scriptdebugging PowerShell script
Description
This issue is reproducible in PS 5.1 and 6.2.1 (and presumably 7 preview since the buggy code is still there, although I didn't test that version specifically yet).
If you debug a job, you enter a nested debugging session. From within that session, you can set, enable, disable, or remove breakpoints in the job debugger. Setting or removing breakpoints will result in the same changes made to any breakpoints with the corresponding IDs that were set in the parent debugger.
Steps to reproduce
# Create a job that does some stuff
$job = Start-Job -ScriptBlock {
1..1000 | ForEach-Object {
Start-Sleep -Seconds 1
$_
Write-Error 'boo'
Write-Verbose 'Verbose' -Verbose
$DebugPreference = 'Continue'
Write-Debug 'Debug'
Write-Warning 'Warning'
}
}
# Set some local breakpoints, and remove one
$bp1 = Set-PSBreakpoint -Command Write-Verbose
$bp2 = Set-PSBreakpoint -Command Get-Date
$bp3 = Set-PSBreakpoint -Variable Home -Mode Read -Action {Write-Host 'Read var'}
Remove-PSBreakpoint -Breakpoint $bp2
# Have a look at your local breakpoints (these do not impact the running job).
Get-PSBreakpoint
# Wait for the job and its child job to enter a running state
while ($job.State -ne 'Running' -or $job.ChildJobs[0].State -ne 'Running') {
Start-Sleep -Milliseconds 250
}
# Debug the job
Debug-Job -Job $jobAt this point you will be in the job debugger. From here, run the following commands:
# Create a bunch of breakpoints
$jbp1 = Set-PSBreakpoint -Variable DebugPreference
$jbp2 = Set-PSBreakpoint -Command Write-Debug
$jbp3 = Set-PSBreakpoint -Command Start-Sleep
# Have a look at your job breakpoints
Get-PSBreakpoint
# Disable the second breakpoint
Disable-PSBreakpoint -Breakpoint $jbp2
# Remove the last breakpoint
Remove-PSBreakpoint -Breakpoint $jbp3
# Detach your debugger
dNow you're back in your main runspace, outside of the job. Have a look at your breakpoints by invoking the following command:
Get-PSBreakpointThis output shows that:
- breakpoint 0 was overwritten with a completely different breakpoint (the first one that was set in the job)
- breakpoint 1 was re-created (remember that it was removed before debugging the job), and it's not the same as it was before (note that it is not disabled in the parent even though we disabled it in the job debugger because the code behind that simply disables the breakpoint object again, which is already disabled).
- breakpoint 2 was deleted (remember that it was removed from within the job debugging session)
Expected behavior
ID Script Line Command Variable Action
-- ------ ---- ------- -------- ------
0 Write-Verbose
2 Home Write-Host 'Read var'
Actual behavior
ID Script Line Command Variable Action
-- ------ ---- ------- -------- ------
0 DebugPreference
1 Write-Debug
Environment data
Name Value
---- -----
PSVersion 6.2.1
PSEdition Core
GitCommitId 6.2.1
OS Microsoft Windows 10.0.17763
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aWG-Interactive-Debuggingdebugging PowerShell scriptdebugging PowerShell script