Skip to content
Closed
Show file tree
Hide file tree
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,34 @@ namespace Microsoft.PowerShell.Commands
/// </summary>
[Cmdlet(VerbsLifecycle.Disable, "PSBreakpoint", SupportsShouldProcess = true, DefaultParameterSetName = "Breakpoint", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=113294")]
[OutputType(typeof(Breakpoint))]
public class DisablePSBreakpointCommand : PSBreakpointCommandBase
public class DisablePSBreakpointCommand : PSBreakpointUpdaterCommandBase
{
#region parameters

/// <summary>
/// Gets or sets the parameter -passThru which states whether the
/// command should place the breakpoints it processes in the pipeline.
/// </summary>
[Parameter]
public SwitchParameter PassThru
{
get
{
return _passThru;
}
public SwitchParameter PassThru { get; set; }

set
{
_passThru = value;
}
}
#endregion parameters

private bool _passThru;
#region overrides

/// <summary>
/// Disables the given breakpoint.
/// </summary>
protected override void ProcessBreakpoint(Breakpoint breakpoint)
{
this.Context.Debugger.DisableBreakpoint(breakpoint);
breakpoint = Runspace.Debugger.DisableBreakpoint(breakpoint);

if (_passThru)
if (PassThru)
{
WriteObject(breakpoint);
base.ProcessBreakpoint(breakpoint);
}
}

#endregion overrides
}
}
Original file line number Diff line number Diff line change
@@ -1,158 +1,43 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Diagnostics;
using System.Management.Automation;
using System.Management.Automation.Internal;

namespace Microsoft.PowerShell.Commands
{
/// <summary>
/// Base class for Enable/Disable/Remove-PSBreakpoint.
/// </summary>
public abstract class PSBreakpointCommandBase : PSCmdlet
{
/// <summary>
/// The breakpoint to enable.
/// </summary>
[Parameter(ParameterSetName = "Breakpoint", ValueFromPipeline = true, Position = 0, Mandatory = true)]
[ValidateNotNull]
public Breakpoint[] Breakpoint
{
get
{
return _breakpoints;
}

set
{
_breakpoints = value;
}
}

private Breakpoint[] _breakpoints;

/// <summary>
/// The Id of the breakpoint to enable.
/// </summary>
[Parameter(ParameterSetName = "Id", ValueFromPipelineByPropertyName = true, Position = 0, Mandatory = true)]
[ValidateNotNull]
public int[] Id
{
get
{
return _ids;
}

set
{
_ids = value;
}
}

private int[] _ids;

/// <summary>
/// Gathers the list of breakpoints to process and calls ProcessBreakpoints.
/// </summary>
protected override void ProcessRecord()
{
if (ParameterSetName.Equals("Breakpoint", StringComparison.OrdinalIgnoreCase))
{
foreach (Breakpoint breakpoint in _breakpoints)
{
if (ShouldProcessInternal(breakpoint.ToString()))
{
ProcessBreakpoint(breakpoint);
}
}
}
else
{
Debug.Assert(ParameterSetName.Equals("Id", StringComparison.OrdinalIgnoreCase));

foreach (int i in _ids)
{
Breakpoint breakpoint = this.Context.Debugger.GetBreakpoint(i);

if (breakpoint == null)
{
WriteError(
new ErrorRecord(
new ArgumentException(StringUtil.Format(Debugger.BreakpointIdNotFound, i)),
"PSBreakpoint:BreakpointIdNotFound",
ErrorCategory.InvalidArgument,
null));
continue;
}

if (ShouldProcessInternal(breakpoint.ToString()))
{
ProcessBreakpoint(breakpoint);
}
}
}
}

/// <summary>
/// Process the given breakpoint.
/// </summary>
protected abstract void ProcessBreakpoint(Breakpoint breakpoint);

private bool ShouldProcessInternal(string target)
{
// ShouldProcess should be called only if the WhatIf or Confirm parameters are passed in explicitly.
// It should *not* be called if we are in a nested debug prompt and the current running command was
// run with -WhatIf or -Confirm, because this prevents the user from adding/removing breakpoints inside
// a debugger stop.
if (this.MyInvocation.BoundParameters.ContainsKey("WhatIf") || this.MyInvocation.BoundParameters.ContainsKey("Confirm"))
{
return ShouldProcess(target);
}

return true;
}
}

/// <summary>
/// This class implements Enable-PSBreakpoint.
/// </summary>
[Cmdlet(VerbsLifecycle.Enable, "PSBreakpoint", SupportsShouldProcess = true, DefaultParameterSetName = "Id", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=113295")]
[Cmdlet(VerbsLifecycle.Enable, "PSBreakpoint", SupportsShouldProcess = true, DefaultParameterSetName = "Breakpoint", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=113295")]
[OutputType(typeof(Breakpoint))]
public class EnablePSBreakpointCommand : PSBreakpointCommandBase
public class EnablePSBreakpointCommand : PSBreakpointUpdaterCommandBase
{
#region parameters

/// <summary>
/// Gets or sets the parameter -passThru which states whether the
/// command should place the breakpoints it processes in the pipeline.
/// </summary>
[Parameter]
public SwitchParameter PassThru
{
get
{
return _passThru;
}
public SwitchParameter PassThru { get; set; }

set
{
_passThru = value;
}
}
#endregion parameters

private bool _passThru;
#region overrides

/// <summary>
/// Enables the given breakpoint.
/// </summary>
protected override void ProcessBreakpoint(Breakpoint breakpoint)
{
this.Context.Debugger.EnableBreakpoint(breakpoint);
breakpoint = Runspace.Debugger.EnableBreakpoint(breakpoint);

if (_passThru)
if (PassThru)
{
WriteObject(breakpoint);
base.ProcessBreakpoint(breakpoint);
}
}

#endregion overrides
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -350,22 +350,6 @@ public SwitchParameter BreakAll
set;
}

/// <summary>
/// The optional breakpoint objects to use for debugging.
/// </summary>
[Experimental("Microsoft.PowerShell.Utility.PSDebugRunspaceWithBreakpoints", ExperimentAction.Show)]
[Parameter(Position = 1,
ParameterSetName = CommonRunspaceCommandBase.RunspaceParameterSet)]
[Parameter(Position = 1,
ParameterSetName = CommonRunspaceCommandBase.RunspaceNameParameterSet)]
[Parameter(Position = 1,
ParameterSetName = CommonRunspaceCommandBase.RunspaceIdParameterSet)]
public Breakpoint[] Breakpoint
{
get;
set;
}

#endregion

#region Overrides
Expand Down Expand Up @@ -428,12 +412,6 @@ protected override void ProcessRecord()
debugger.SetDebuggerStepMode(false);
}
}

// If any breakpoints were provided, set those in the debugger.
if (Breakpoint?.Length > 0)
{
debugger.SetBreakpoints(Breakpoint);
}
}
}

Expand Down
Loading