Skip to content

Commit cc0fed4

Browse files
KirkMunroadityapatwardhan
authored andcommitted
Add APIs for breakpoint management in runspaces and enable attach to process without BreakAll for PSES (PowerShell#10338)
1 parent cfdbd71 commit cc0fed4

File tree

23 files changed

+1068
-796
lines changed

23 files changed

+1068
-796
lines changed

src/Microsoft.PowerShell.Commands.Utility/commands/utility/DebugRunspaceCommand.cs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,11 @@ public Guid InstanceId
101101
}
102102

103103
/// <summary>
104-
/// The optional breakpoint objects to use for debugging.
104+
/// Gets or sets a flag that tells PowerShell to automatically perform a BreakAll when the debugger is attached to the remote target.
105105
/// </summary>
106-
[Experimental("Microsoft.PowerShell.Utility.PSDebugRunspaceWithBreakpoints", ExperimentAction.Show)]
107-
[Parameter(Position = 1,
108-
ParameterSetName = DebugRunspaceCommand.InstanceIdParameterSet)]
109-
[Parameter(ParameterSetName = DebugRunspaceCommand.RunspaceParameterSet)]
110-
[Parameter(ParameterSetName = DebugRunspaceCommand.IdParameterSet)]
111-
[Parameter(ParameterSetName = DebugRunspaceCommand.NameParameterSet)]
112-
public Breakpoint[] Breakpoint
113-
{
114-
get;
115-
set;
116-
}
106+
[Experimental("Microsoft.PowerShell.Utility.PSManageBreakpointsInRunspace", ExperimentAction.Show)]
107+
[Parameter]
108+
public SwitchParameter BreakAll { get; set; }
117109

118110
#endregion
119111

@@ -275,7 +267,7 @@ private void WaitAndReceiveRunspaceOutput()
275267
_debugger.SetDebugMode(DebugModes.LocalScript | DebugModes.RemoteScript);
276268

277269
// Set up host script debugger to debug the runspace.
278-
_debugger.DebugRunspace(_runspace, disableBreakAll: Breakpoint?.Length > 0);
270+
_debugger.DebugRunspace(_runspace, breakAll: BreakAll);
279271

280272
while (_debugging)
281273
{
@@ -532,10 +524,6 @@ private void PrepareRunspace(Runspace runspace)
532524
{
533525
SetLocalMode(runspace.Debugger, true);
534526
EnableHostDebugger(runspace, false);
535-
if (Breakpoint?.Length > 0)
536-
{
537-
runspace.Debugger?.SetBreakpoints(Breakpoint);
538-
}
539527
}
540528

541529
private void RestoreRunspace(Runspace runspace)

src/Microsoft.PowerShell.Commands.Utility/commands/utility/EnableDisableRunspaceDebugCommand.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -350,22 +350,6 @@ public SwitchParameter BreakAll
350350
set;
351351
}
352352

353-
/// <summary>
354-
/// Gets or sets the optional breakpoint objects to use for debugging.
355-
/// </summary>
356-
[Experimental("Microsoft.PowerShell.Utility.PSDebugRunspaceWithBreakpoints", ExperimentAction.Show)]
357-
[Parameter(Position = 1,
358-
ParameterSetName = CommonRunspaceCommandBase.RunspaceParameterSet)]
359-
[Parameter(Position = 1,
360-
ParameterSetName = CommonRunspaceCommandBase.RunspaceNameParameterSet)]
361-
[Parameter(Position = 1,
362-
ParameterSetName = CommonRunspaceCommandBase.RunspaceIdParameterSet)]
363-
public Breakpoint[] Breakpoint
364-
{
365-
get;
366-
set;
367-
}
368-
369353
#endregion
370354

371355
#region Overrides
@@ -428,12 +412,6 @@ protected override void ProcessRecord()
428412
debugger.SetDebuggerStepMode(false);
429413
}
430414
}
431-
432-
// If any breakpoints were provided, set those in the debugger.
433-
if (Breakpoint?.Length > 0)
434-
{
435-
debugger.SetBreakpoints(Breakpoint);
436-
}
437415
}
438416
}
439417

src/Microsoft.PowerShell.Commands.Utility/commands/utility/New-PSBreakpoint.cs

Lines changed: 0 additions & 101 deletions
This file was deleted.

src/Microsoft.PowerShell.Commands.Utility/commands/utility/Set-PSBreakpoint.cs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ protected override void ProcessRecord()
7575
foreach (string path in scripts)
7676
{
7777
WriteObject(
78-
Context.Debugger.NewCommandBreakpoint(path.ToString(), Command[i], Action));
78+
Context.Debugger.SetCommandBreakpoint(Command[i], Action, path));
7979
}
8080
}
8181
else
8282
{
8383
WriteObject(
84-
Context.Debugger.NewCommandBreakpoint(Command[i], Action));
84+
Context.Debugger.SetCommandBreakpoint(Command[i], Action));
8585
}
8686
}
8787
}
@@ -97,13 +97,13 @@ protected override void ProcessRecord()
9797
foreach (string path in scripts)
9898
{
9999
WriteObject(
100-
Context.Debugger.NewVariableBreakpoint(path.ToString(), Variable[i], Mode, Action));
100+
Context.Debugger.SetVariableBreakpoint(Variable[i], Mode, Action, path));
101101
}
102102
}
103103
else
104104
{
105105
WriteObject(
106-
Context.Debugger.NewVariableBreakpoint(Variable[i], Mode, Action));
106+
Context.Debugger.SetVariableBreakpoint(Variable[i], Mode, Action));
107107
}
108108
}
109109
}
@@ -130,16 +130,8 @@ protected override void ProcessRecord()
130130

131131
foreach (string path in scripts)
132132
{
133-
if (Column != 0)
134-
{
135-
WriteObject(
136-
Context.Debugger.NewStatementBreakpoint(path, Line[i], Column, Action));
137-
}
138-
else
139-
{
140-
WriteObject(
141-
Context.Debugger.NewLineBreakpoint(path, Line[i], Action));
142-
}
133+
WriteObject(
134+
Context.Debugger.SetLineBreakpoint(path, Line[i], Column, Action));
143135
}
144136
}
145137
}

src/Modules/Unix/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ CmdletsToExport = @(
1818
'Set-MarkdownOption', 'Add-Member', 'Get-Member', 'Compare-Object', 'Group-Object', 'Measure-Object',
1919
'New-Object', 'Select-Object', 'Sort-Object', 'Tee-Object', 'Register-ObjectEvent', 'Write-Output',
2020
'Import-PowerShellDataFile', 'Write-Progress', 'Disable-PSBreakpoint', 'Enable-PSBreakpoint',
21-
'Get-PSBreakpoint', 'Remove-PSBreakpoint', 'Set-PSBreakpoint', 'New-PSBreakpoint', 'Get-PSCallStack', 'Export-PSSession',
21+
'Get-PSBreakpoint', 'Remove-PSBreakpoint', 'Set-PSBreakpoint', 'Get-PSCallStack', 'Export-PSSession',
2222
'Import-PSSession', 'Get-Random', 'Invoke-RestMethod', 'Debug-Runspace', 'Get-Runspace',
2323
'Disable-RunspaceDebug', 'Enable-RunspaceDebug', 'Get-RunspaceDebug', 'Start-Sleep', 'Join-String',
2424
'Out-String', 'Select-String', 'ConvertFrom-StringData', 'Format-Table', 'New-TemporaryFile', 'New-TimeSpan',
@@ -35,8 +35,8 @@ PrivateData = @{
3535
PSData = @{
3636
ExperimentalFeatures = @(
3737
@{
38-
Name = 'Microsoft.PowerShell.Utility.PSDebugRunspaceWithBreakpoints'
39-
Description = "Enables the New-PSBreakpoint cmdlet and the -Breakpoint parameter on Debug-Runspace to set breakpoints in another Runspace upfront."
38+
Name = 'Microsoft.PowerShell.Utility.PSManageBreakpointsInRunspace'
39+
Description = 'Enables -BreakAll parameter on Debug-Runspace and Debug-Job cmdlets to allow users to decide if they want PowerShell to break immediately in the current location when they attach a debugger.'
4040
}
4141
)
4242
}

src/Modules/Windows/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ CmdletsToExport = @(
1717
'Show-Markdown', 'Get-MarkdownOption', 'Set-MarkdownOption', 'Add-Member', 'Get-Member', 'Compare-Object', 'Group-Object',
1818
'Measure-Object', 'New-Object', 'Select-Object', 'Sort-Object', 'Tee-Object', 'Register-ObjectEvent', 'Write-Output',
1919
'Import-PowerShellDataFile', 'Write-Progress', 'Disable-PSBreakpoint', 'Enable-PSBreakpoint', 'Get-PSBreakpoint',
20-
'Remove-PSBreakpoint', 'Set-PSBreakpoint', 'New-PSBreakpoint', 'Get-PSCallStack', 'Export-PSSession', 'Import-PSSession', 'Get-Random',
20+
'Remove-PSBreakpoint', 'Set-PSBreakpoint', 'Get-PSCallStack', 'Export-PSSession', 'Import-PSSession', 'Get-Random',
2121
'Invoke-RestMethod', 'Debug-Runspace', 'Get-Runspace', 'Disable-RunspaceDebug', 'Enable-RunspaceDebug',
2222
'Get-RunspaceDebug', 'ConvertFrom-SddlString', 'Start-Sleep', 'Join-String', 'Out-String', 'Select-String',
2323
'ConvertFrom-StringData', 'Format-Table', 'New-TemporaryFile', 'New-TimeSpan', 'Get-TraceSource', 'Set-TraceSource',
@@ -29,4 +29,14 @@ FunctionsToExport = @()
2929
AliasesToExport = @('fhx')
3030
NestedModules = @("Microsoft.PowerShell.Commands.Utility.dll")
3131
HelpInfoURI = 'https://go.microsoft.com/fwlink/?linkid=855960'
32+
PrivateData = @{
33+
PSData = @{
34+
ExperimentalFeatures = @(
35+
@{
36+
Name = 'Microsoft.PowerShell.Utility.PSManageBreakpointsInRunspace'
37+
Description = 'Enables -BreakAll parameter on Debug-Runspace and Debug-Job cmdlets to allow users to decide if they want PowerShell to break immediately in the current location when they attach a debugger.'
38+
}
39+
)
40+
}
41+
}
3242
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4545,7 +4545,6 @@ internal static SessionStateAliasEntry[] BuiltInAliases
45454545
new SessionStateAliasEntry("mi", "Move-Item", string.Empty, ReadOnly),
45464546
new SessionStateAliasEntry("mp", "Move-ItemProperty", string.Empty, ReadOnly),
45474547
new SessionStateAliasEntry("nal", "New-Alias", string.Empty, ReadOnly),
4548-
new SessionStateAliasEntry("nbp", "New-PSBreakpoint", string.Empty, ReadOnly),
45494548
new SessionStateAliasEntry("ndr", "New-PSDrive", string.Empty, ReadOnly),
45504549
new SessionStateAliasEntry("ni", "New-Item", string.Empty, ReadOnly),
45514550
new SessionStateAliasEntry("nv", "New-Variable", string.Empty, ReadOnly),

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public class PSVersionInfo
6161
private static readonly SemanticVersion s_psV6Version = new SemanticVersion(6, 0, 0, preReleaseLabel: null, buildLabel: null);
6262
private static readonly SemanticVersion s_psV61Version = new SemanticVersion(6, 1, 0, preReleaseLabel: null, buildLabel: null);
6363
private static readonly SemanticVersion s_psV62Version = new SemanticVersion(6, 2, 0, preReleaseLabel: null, buildLabel: null);
64+
private static readonly SemanticVersion s_psV7Version = new SemanticVersion(7, 0, 0, preReleaseLabel: null, buildLabel: null);
6465
private static readonly SemanticVersion s_psSemVersion;
6566
private static readonly Version s_psVersion;
6667

@@ -329,6 +330,11 @@ internal static SemanticVersion PSV6Version
329330
get { return s_psV6Version; }
330331
}
331332

333+
internal static SemanticVersion PSV7Version
334+
{
335+
get { return s_psV7Version; }
336+
}
337+
332338
internal static SemanticVersion PSCurrentVersion
333339
{
334340
get { return s_psSemVersion; }

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,7 @@ internal BreakpointAction Trigger()
128128
return BreakpointAction.Continue;
129129
}
130130

131-
internal virtual void RemoveSelf(ScriptDebugger debugger)
132-
{
133-
}
131+
internal virtual bool RemoveSelf(ScriptDebugger debugger) => false;
134132

135133
#endregion methods
136134

@@ -208,10 +206,8 @@ public override string ToString()
208206
: StringUtil.Format(DebuggerStrings.CommandBreakpointString, Command);
209207
}
210208

211-
internal override void RemoveSelf(ScriptDebugger debugger)
212-
{
209+
internal override bool RemoveSelf(ScriptDebugger debugger) =>
213210
debugger.RemoveCommandBreakpoint(this);
214-
}
215211

216212
private bool CommandInfoMatches(CommandInfo commandInfo)
217213
{
@@ -350,10 +346,8 @@ internal bool Trigger(string currentScriptFile, bool read)
350346
return false;
351347
}
352348

353-
internal override void RemoveSelf(ScriptDebugger debugger)
354-
{
349+
internal override bool RemoveSelf(ScriptDebugger debugger) =>
355350
debugger.RemoveVariableBreakpoint(this);
356-
}
357351
}
358352

359353
/// <summary>
@@ -589,7 +583,7 @@ private void SetBreakpoint(FunctionContext functionContext, int sequencePointInd
589583
this.BreakpointBitArray.Set(SequencePointIndex, true);
590584
}
591585

592-
internal override void RemoveSelf(ScriptDebugger debugger)
586+
internal override bool RemoveSelf(ScriptDebugger debugger)
593587
{
594588
if (this.SequencePoints != null)
595589
{
@@ -612,7 +606,7 @@ internal override void RemoveSelf(ScriptDebugger debugger)
612606
}
613607
}
614608

615-
debugger.RemoveLineBreakpoint(this);
609+
return debugger.RemoveLineBreakpoint(this);
616610
}
617611
}
618612
}

0 commit comments

Comments
 (0)