Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
95faef4
added Break to ActionPreference enum
KirkMunro Nov 8, 2018
ff98f41
add Break ActionPreference support
KirkMunro Nov 8, 2018
b2e32be
CodeFactor changes
KirkMunro Nov 8, 2018
37bbbde
updated type accelerator pester test
KirkMunro Nov 8, 2018
f7240d2
Changes requested by @PaulHigin in code review
KirkMunro Nov 13, 2018
f0fcb96
Moving TriggerObject into ScriptDebugger class
KirkMunro Nov 13, 2018
e7a6402
CodeFactor changes
KirkMunro Nov 14, 2018
6549a99
Merge branch 'master' into break-action-preference
KirkMunro Nov 14, 2018
19bbc5b
Merge branch 'break-action-preference' of https://github.com/KirkMunr…
KirkMunro Nov 14, 2018
bdcfd7f
updated typeaccelerator count for test
KirkMunro Nov 15, 2018
d0f8347
fixed job debugging; fixed position message in jobs
KirkMunro Apr 9, 2019
1200839
CodeFactor changes
KirkMunro Apr 9, 2019
dcfe3f2
add break on exception when using EAP.Break
KirkMunro Apr 15, 2019
84f09ad
Merge branch 'master' into break-action-preference
KirkMunro Apr 15, 2019
2d5209b
CodeFactor changes
KirkMunro Apr 15, 2019
9e4c895
CodeFactor changes
KirkMunro Apr 15, 2019
06220cc
Code review change
iSazonov Apr 16, 2019
2af4fff
Code review change
iSazonov Apr 16, 2019
6387110
fixed to break even with trap or try/catch
KirkMunro Apr 26, 2019
4d379cb
merged changes made during code review
KirkMunro Apr 26, 2019
8c4a4ee
Merge branch 'master' into break-action-preference
KirkMunro Apr 26, 2019
2ff53ac
codacy changes
KirkMunro Apr 26, 2019
0127e34
refactor to fix broken Pester tests
KirkMunro Apr 27, 2019
2963303
refactor for code review
KirkMunro May 7, 2019
31c5d52
removed checks for ActionPreference.Ignore and Suspend
KirkMunro May 9, 2019
58afb06
code review changes
KirkMunro May 9, 2019
a5309ce
removed ActionPreference.Suspend (per #9570)
KirkMunro May 16, 2019
ed43f0f
removed EA.Suspend use from tests
KirkMunro May 16, 2019
271d2ea
Merge branch 'master' into break-action-preference
KirkMunro May 23, 2019
c45bff5
Merge branch 'master' into break-action-preference
KirkMunro May 24, 2019
f1b1e51
review feedback; refactored $? reassignments
KirkMunro May 30, 2019
4bbc564
add argument labels for self-documenting code
KirkMunro Jun 3, 2019
ba365b5
Merge branch 'master' into break-action-preference
KirkMunro Jun 13, 2019
53b8a0a
Merge branch 'master' into break-action-preference
KirkMunro Jun 16, 2019
8720567
Merge branch 'master' into break-action-preference
KirkMunro Jul 19, 2019
0885b36
Merge branch 'master' into break-action-preference
KirkMunro Jul 23, 2019
a04796a
Merge branch 'master' into break-action-preference
KirkMunro Jul 29, 2019
b7534d3
Merge branch 'master' into break-action-preference
KirkMunro Aug 4, 2019
3c8cf82
replace AP.Suspend (it's being removed in #10223)
KirkMunro Aug 4, 2019
e840416
remove accidental changes
KirkMunro Aug 4, 2019
f1b226c
minor correction to previous commit
KirkMunro Aug 4, 2019
4c4f20e
CodeFactor
KirkMunro Aug 4, 2019
cf2db5c
replace tests that are updated elsewhere
KirkMunro Aug 5, 2019
f321fb4
replace tests that are removed elsewhere
KirkMunro Aug 5, 2019
e6f8f9b
fix Pester test failure
KirkMunro Aug 5, 2019
f646130
Merge branch 'master' into break-action-preference
KirkMunro Aug 5, 2019
f3fdb35
replace mistakenly removed keywords
KirkMunro Aug 5, 2019
0efbd38
add automated tests for local debugger
KirkMunro Aug 5, 2019
ac2fe73
add job debugging test
KirkMunro Aug 5, 2019
bd631b5
minor change to Pester test
KirkMunro Aug 5, 2019
f2bd96e
remove temporary Pester tag
KirkMunro Aug 6, 2019
2b18ac0
Merge branch 'master' into break-action-preference
KirkMunro Aug 6, 2019
2e0e87b
change stepInto to stepOver in tests
KirkMunro Aug 6, 2019
56c135c
remove $Host.Runspace from Pester test
KirkMunro Aug 6, 2019
65a3b40
Merge branch 'master' into break-action-preference
KirkMunro Aug 8, 2019
df85bd9
replace unused variable with discard
KirkMunro Aug 8, 2019
c35f5b7
add #9474 test and update HelpersDebugger module
KirkMunro Aug 9, 2019
fc1e874
remove lines that shouldn't have been checked in
KirkMunro Aug 9, 2019
fe935c8
Add one space for the named parameter uses
daxian-dbw Aug 16, 2019
d1aca86
changes based on review feedback
KirkMunro Aug 16, 2019
98f1f34
Merge branch 'break-action-preference' of https://github.com/KirkMunr…
KirkMunro Aug 16, 2019
8510eec
Merge branch 'master' into break-action-preference
KirkMunro Aug 16, 2019
2525daa
Merge branch 'master' into break-action-preference
KirkMunro Aug 22, 2019
a5ed191
removed type accelerator; added enum values
KirkMunro Aug 22, 2019
231739f
update test to reflect removal of type accelerator
KirkMunro Aug 22, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public SwitchParameter BreakAll
}

/// <summary>
/// The optional breakpoint objects to use for debugging.
/// Gets or sets the optional breakpoint objects to use for debugging.
/// </summary>
[Experimental("Microsoft.PowerShell.Utility.PSDebugRunspaceWithBreakpoints", ExperimentAction.Show)]
[Parameter(Position = 1,
Expand Down Expand Up @@ -555,19 +555,11 @@ protected override void EndProcessing()
{
Runspace currentRunspace = this.Context.CurrentRunspace;

if ((currentRunspace != null) && (currentRunspace.Debugger != null))
if (currentRunspace != null && currentRunspace.Debugger != null)
{
if (!currentRunspace.Debugger.IsDebugHandlerSubscribed &&
(currentRunspace.Debugger.UnhandledBreakpointMode == UnhandledBreakpointProcessingMode.Ignore))
{
// No debugger attached and runspace debugging is not enabled. Enable runspace debugging here
// so that this command is effective.
currentRunspace.Debugger.UnhandledBreakpointMode = UnhandledBreakpointProcessingMode.Wait;
}

// Set debugger to step mode so that a break occurs immediately.
currentRunspace.Debugger.SetDebuggerStepMode(true);
WriteVerbose(string.Format(CultureInfo.InvariantCulture, Debugger.DebugBreakMessage, MyInvocation.ScriptLineNumber, MyInvocation.ScriptName));

currentRunspace.Debugger.Break();
}
}

Expand Down
22 changes: 15 additions & 7 deletions src/System.Management.Automation/engine/CommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,18 +277,26 @@ namespace System.Management.Automation
public enum ActionPreference
{
/// <summary>Ignore this event and continue</summary>
SilentlyContinue,
SilentlyContinue = 0,

/// <summary>Stop the command</summary>
Stop,
Stop = 1,

/// <summary>Handle this event as normal and continue</summary>
Continue,
Continue = 2,

/// <summary>Ask whether to stop or continue</summary>
Inquire,
Inquire = 3,

/// <summary>Ignore the event completely (not even logging it to the target stream)</summary>
Ignore,
Ignore = 4,

/// <summary>Suspend the command for further diagnosis. Supported only for workflows.</summary>
Suspend,
}
Suspend = 5,

/// <summary>Enter the debugger.</summary>
Break = 6,
} // enum ActionPreference
#endregion ActionPreference

#region ConfirmImpact
Expand Down
16 changes: 7 additions & 9 deletions src/System.Management.Automation/engine/ExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,7 @@ internal void SetVariable(VariablePath path, object newValue)

internal T GetEnumPreference<T>(VariablePath preferenceVariablePath, T defaultPref, out bool defaultUsed)
{
CmdletProviderContext context = null;
SessionStateScope scope = null;
object val = EngineSessionState.GetVariableValue(preferenceVariablePath, out context, out scope);
object val = EngineSessionState.GetVariableValue(preferenceVariablePath, out _, out _);
if (val is T)
{
// We don't want to support "Ignore" as action preferences, as it leads to bad
Expand Down Expand Up @@ -1048,7 +1046,7 @@ internal ActionPreference DebugPreferenceVariable
get
{
bool defaultUsed = false;
return this.GetEnumPreference<ActionPreference>(
return this.GetEnumPreference(
SpecialVariables.DebugPreferenceVarPath,
InitialSessionState.defaultDebugPreference,
out defaultUsed);
Expand All @@ -1069,7 +1067,7 @@ internal ActionPreference VerbosePreferenceVariable
get
{
bool defaultUsed = false;
return this.GetEnumPreference<ActionPreference>(
return this.GetEnumPreference(
SpecialVariables.VerbosePreferenceVarPath,
InitialSessionState.defaultVerbosePreference,
out defaultUsed);
Expand All @@ -1090,7 +1088,7 @@ internal ActionPreference ErrorActionPreferenceVariable
get
{
bool defaultUsed = false;
return this.GetEnumPreference<ActionPreference>(
return this.GetEnumPreference(
SpecialVariables.ErrorActionPreferenceVarPath,
InitialSessionState.defaultErrorActionPreference,
out defaultUsed);
Expand All @@ -1111,7 +1109,7 @@ internal ActionPreference WarningActionPreferenceVariable
get
{
bool defaultUsed = false;
return this.GetEnumPreference<ActionPreference>(
return this.GetEnumPreference(
SpecialVariables.WarningPreferenceVarPath,
InitialSessionState.defaultWarningPreference,
out defaultUsed);
Expand All @@ -1132,7 +1130,7 @@ internal ActionPreference InformationActionPreferenceVariable
get
{
bool defaultUsed = false;
return this.GetEnumPreference<ActionPreference>(
return this.GetEnumPreference(
SpecialVariables.InformationPreferenceVarPath,
InitialSessionState.defaultInformationPreference,
out defaultUsed);
Expand Down Expand Up @@ -1178,7 +1176,7 @@ internal ConfirmImpact ConfirmPreferenceVariable
get
{
bool defaultUsed = false;
return this.GetEnumPreference<ConfirmImpact>(
return this.GetEnumPreference(
SpecialVariables.ConfirmPreferenceVarPath,
InitialSessionState.defaultConfirmPreference,
out defaultUsed);
Expand Down
91 changes: 76 additions & 15 deletions src/System.Management.Automation/engine/MshCommandRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading;
using System.Security;
using System.Management.Automation.Host;
using System.Management.Automation.Internal.Host;
using System.Management.Automation.Internal;
using System.Management.Automation.Internal.Host;
using System.Management.Automation.Remoting;
using System.Management.Automation.Runspaces;
using System.Threading;

using Dbg = System.Management.Automation.Diagnostics;

Expand Down Expand Up @@ -269,14 +268,20 @@ public void WriteObject(object sendToPipeline, bool enumerateCollection)
#endif
}

/// <summary>
/// Writes an object enumerated from a collection to the output pipe.
/// </summary>
/// <param name="sendToPipeline">
/// The enumerated object that needs to be written to the pipeline.
/// </param>
/// <exception cref="System.Management.Automation.PipelineStoppedException">
/// The pipeline has already been terminated, or was terminated
/// during the execution of this method.
/// The Cmdlet should generally just allow PipelineStoppedException
/// to percolate up to the caller of ProcessRecord etc.
/// </exception>
/// <exception cref="System.InvalidOperationException">
/// Not permitted at this time or from this thread
/// Not permitted at this time or from this thread.
/// </exception>
private void DoWriteEnumeratedObject(object sendToPipeline)
{
Expand Down Expand Up @@ -411,6 +416,12 @@ internal void WriteProgress(
if (WriteHelper_ShouldWrite(
preference, lastProgressContinueStatus))
{
// Break into the debugger if requested
if (preference == ActionPreference.Break)
{
CBhost?.Runspace?.Debugger?.Break(progressRecord);
}

ui.WriteProgress(sourceId, progressRecord);
}

Expand Down Expand Up @@ -476,6 +487,12 @@ internal void WriteDebug(DebugRecord record, bool overrideInquire = false)
record.SetInvocationInfo(MyInvocation);
}

// Break into the debugger if requested
if (preference == ActionPreference.Break)
{
CBhost?.Runspace?.Debugger?.Break(record);
}

if (DebugOutputPipe != null)
{
if (CBhost != null && CBhost.InternalUI != null &&
Expand Down Expand Up @@ -564,6 +581,12 @@ internal void WriteVerbose(VerboseRecord record, bool overrideInquire = false)
record.SetInvocationInfo(MyInvocation);
}

// Break into the debugger if requested
if (preference == ActionPreference.Break)
{
CBhost?.Runspace?.Debugger?.Break(record);
}

if (VerboseOutputPipe != null)
{
if (CBhost != null && CBhost.InternalUI != null &&
Expand Down Expand Up @@ -652,6 +675,12 @@ internal void WriteWarning(WarningRecord record, bool overrideInquire = false)
record.SetInvocationInfo(MyInvocation);
}

// Break into the debugger if requested
if (preference == ActionPreference.Break)
{
CBhost?.Runspace?.Debugger?.Break(record);
}

if (WarningOutputPipe != null)
{
if (CBhost != null && CBhost.InternalUI != null &&
Expand Down Expand Up @@ -712,6 +741,12 @@ internal void WriteInformation(InformationRecord record, bool overrideInquire =
if (overrideInquire && preference == ActionPreference.Inquire)
preference = ActionPreference.Continue;

// Break into the debugger if requested
if (preference == ActionPreference.Break)
{
CBhost?.Runspace?.Debugger?.Break(record);
}

if (preference != ActionPreference.Ignore)
{
if (InformationOutputPipe != null)
Expand Down Expand Up @@ -2051,6 +2086,14 @@ public void ThrowTerminatingError(ErrorRecord errorRecord)

CmdletInvocationException e =
new CmdletInvocationException(errorRecord);

// If the error action preference is set to break, break immediately
// into the debugger
if (ErrorAction == ActionPreference.Break)
{
Context.Debugger?.Break(e.InnerException ?? e);
}

// Code sees only that execution stopped
throw ManageException(e);
}
Expand Down Expand Up @@ -2551,8 +2594,12 @@ internal void AppendInformationVarList(object obj)
#region Write
internal bool UseSecurityContextRun = true;

// NOTICE-2004/06/08-JonN 959638
// Use this variant to skip the ThrowIfWriteNotPermitted check
/// <summary>
/// Writes an object to the output pipe, skipping the ThrowIfWriteNotPermitted check.
/// </summary>
/// <param name="sendToPipeline">
/// The object to write to the output pipe.
/// </param>
/// <exception cref="System.Management.Automation.PipelineStoppedException">
/// The pipeline has already been terminated, or was terminated
/// during the execution of this method.
Expand All @@ -2571,8 +2618,12 @@ internal void _WriteObjectSkipAllowCheck(object sendToPipeline)
this.OutputPipe.Add(sendToPipeline);
}

// NOTICE-2004/06/08-JonN 959638
// Use this variant to skip the ThrowIfWriteNotPermitted check
/// <summary>
/// Enumerates and writes an object to the output pipe, skipping the ThrowIfWriteNotPermitted check.
/// </summary>
/// <param name="sendToPipeline">
/// The object to enumerate and write to the output pipe.
/// </param>
/// <exception cref="System.Management.Automation.PipelineStoppedException">
/// The pipeline has already been terminated, or was terminated
/// during the execution of this method.
Expand All @@ -2594,7 +2645,9 @@ internal void _EnumerateAndWriteObjectSkipAllowCheck(object sendToPipeline)
foreach (object toConvert in enumerable)
{
if (AutomationNull.Value == toConvert)
{
continue;
}

object converted = LanguagePrimitives.AsPSObjectOrNull(toConvert);
convertedList.Add(converted);
Expand Down Expand Up @@ -2660,6 +2713,12 @@ internal void WriteError(ErrorRecord errorRecord, bool overrideInquire)
preference = ActionPreference.Continue;
}

// Break into the debugger if requested
if (preference == ActionPreference.Break)
{
CBhost?.Runspace?.Debugger?.Break(errorRecord);
}

#if CORECLR
// SecurityContext is not supported in CoreCLR
DoWriteError(new KeyValuePair<ErrorRecord, ActionPreference>(errorRecord, preference));
Expand Down Expand Up @@ -2898,7 +2957,7 @@ internal ConfirmImpact ConfirmPreference
if (!_isConfirmPreferenceCached)
{
bool defaultUsed = false;
_confirmPreference = Context.GetEnumPreference<ConfirmImpact>(SpecialVariables.ConfirmPreferenceVarPath, _confirmPreference, out defaultUsed);
_confirmPreference = Context.GetEnumPreference(SpecialVariables.ConfirmPreferenceVarPath, _confirmPreference, out defaultUsed);
_isConfirmPreferenceCached = true;
}

Expand Down Expand Up @@ -2933,7 +2992,7 @@ internal ActionPreference DebugPreference
{
bool defaultUsed = false;

_debugPreference = Context.GetEnumPreference<ActionPreference>(SpecialVariables.DebugPreferenceVarPath, _debugPreference, out defaultUsed);
_debugPreference = Context.GetEnumPreference(SpecialVariables.DebugPreferenceVarPath, _debugPreference, out defaultUsed);

// If the host couldn't prompt for the debug action anyways, change it to 'Continue'.
// This lets hosts still see debug output without having to implement the prompting logic.
Expand Down Expand Up @@ -2992,7 +3051,7 @@ internal ActionPreference VerbosePreference
if (!_isVerbosePreferenceCached)
{
bool defaultUsed = false;
_verbosePreference = Context.GetEnumPreference<ActionPreference>(
_verbosePreference = Context.GetEnumPreference(
SpecialVariables.VerbosePreferenceVarPath,
_verbosePreference,
out defaultUsed);
Expand Down Expand Up @@ -3029,7 +3088,7 @@ internal ActionPreference WarningPreference
if (!_isWarningPreferenceCached)
{
bool defaultUsed = false;
_warningPreference = Context.GetEnumPreference<ActionPreference>(SpecialVariables.WarningPreferenceVarPath, _warningPreference, out defaultUsed);
_warningPreference = Context.GetEnumPreference(SpecialVariables.WarningPreferenceVarPath, _warningPreference, out defaultUsed);
}

return _warningPreference;
Expand Down Expand Up @@ -3198,7 +3257,7 @@ internal ActionPreference ErrorAction
if (!_isErrorActionPreferenceCached)
{
bool defaultUsed = false;
_errorAction = Context.GetEnumPreference<ActionPreference>(SpecialVariables.ErrorActionPreferenceVarPath, _errorAction, out defaultUsed);
_errorAction = Context.GetEnumPreference(SpecialVariables.ErrorActionPreferenceVarPath, _errorAction, out defaultUsed);
_isErrorActionPreferenceCached = true;
}

Expand Down Expand Up @@ -3233,7 +3292,7 @@ internal ActionPreference ProgressPreference
if (!_isProgressPreferenceCached)
{
bool defaultUsed = false;
_progressPreference = Context.GetEnumPreference<ActionPreference>(SpecialVariables.ProgressPreferenceVarPath, _progressPreference, out defaultUsed);
_progressPreference = Context.GetEnumPreference(SpecialVariables.ProgressPreferenceVarPath, _progressPreference, out defaultUsed);
_isProgressPreferenceCached = true;
}

Expand Down Expand Up @@ -3265,7 +3324,7 @@ internal ActionPreference InformationPreference
if (!_isInformationPreferenceCached)
{
bool defaultUsed = false;
_informationPreference = Context.GetEnumPreference<ActionPreference>(SpecialVariables.InformationPreferenceVarPath, _informationPreference, out defaultUsed);
_informationPreference = Context.GetEnumPreference(SpecialVariables.InformationPreferenceVarPath, _informationPreference, out defaultUsed);
_isInformationPreferenceCached = true;
}

Expand Down Expand Up @@ -3364,6 +3423,7 @@ internal bool WriteHelper_ShouldWrite(
case ActionPreference.Continue:
case ActionPreference.Stop:
case ActionPreference.Inquire:
case ActionPreference.Break:
return true;

default:
Expand Down Expand Up @@ -3416,6 +3476,7 @@ internal ContinueStatus WriteHelper(
case ActionPreference.Ignore: // YesToAll
case ActionPreference.SilentlyContinue:
case ActionPreference.Continue:
case ActionPreference.Break:
return ContinueStatus.Yes;

case ActionPreference.Stop:
Expand Down
Loading