Skip to content
Merged
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
52 changes: 46 additions & 6 deletions src/System.Management.Automation/engine/debugger/debugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,12 +1132,16 @@ private Breakpoint AddCommandBreakpoint(CommandBreakpoint breakpoint)
internal Breakpoint NewCommandBreakpoint(string path, string command, ScriptBlock action)
{
WildcardPattern pattern = WildcardPattern.Get(command, WildcardOptions.Compiled | WildcardOptions.IgnoreCase);

CheckForBreakpointSupport();
return AddCommandBreakpoint(new CommandBreakpoint(path, pattern, command, action));
}

internal Breakpoint NewCommandBreakpoint(string command, ScriptBlock action)
{
WildcardPattern pattern = WildcardPattern.Get(command, WildcardOptions.Compiled | WildcardOptions.IgnoreCase);

CheckForBreakpointSupport();
return AddCommandBreakpoint(new CommandBreakpoint(null, pattern, command, action));
}

Expand Down Expand Up @@ -1175,13 +1179,15 @@ internal Breakpoint NewLineBreakpoint(string path, int line, ScriptBlock action)
{
Diagnostics.Assert(path != null, "caller to verify path is not null");

CheckForBreakpointSupport();
return AddLineBreakpoint(new LineBreakpoint(path, line, action));
}

internal Breakpoint NewStatementBreakpoint(string path, int line, int column, ScriptBlock action)
{
Diagnostics.Assert(path != null, "caller to verify path is not null");

CheckForBreakpointSupport();
return AddLineBreakpoint(new LineBreakpoint(path, line, column, action));
}

Expand All @@ -1201,11 +1207,13 @@ internal VariableBreakpoint AddVariableBreakpoint(VariableBreakpoint breakpoint)

internal Breakpoint NewVariableBreakpoint(string path, string variableName, VariableAccessMode accessMode, ScriptBlock action)
{
CheckForBreakpointSupport();
return AddVariableBreakpoint(new VariableBreakpoint(path, variableName, accessMode, action));
}

internal Breakpoint NewVariableBreakpoint(string variableName, VariableAccessMode accessMode, ScriptBlock action)
{
CheckForBreakpointSupport();
return AddVariableBreakpoint(new VariableBreakpoint(null, variableName, accessMode, action));
}

Expand Down Expand Up @@ -1761,12 +1769,6 @@ private void OnDebuggerStop(InvocationInfo invocationInfo, List<Breakpoint> brea
originalLanguageMode = _context.LanguageMode;
_context.LanguageMode = PSLanguageMode.FullLanguage;
}
else if (System.Management.Automation.Security.SystemPolicy.GetSystemLockdownPolicy() ==
System.Management.Automation.Security.SystemEnforcementMode.Enforce)
{
// If there is a system lockdown in place, enforce it
originalLanguageMode = Utils.EnforceSystemLockDownLanguageMode(this._context);
}

// Update the prompt to the debug prompt
if (hadDefaultPrompt)
Expand Down Expand Up @@ -2060,6 +2062,17 @@ private void SetInternalDebugMode(InternalDebugMode mode)
{
lock (_syncObject)
{
// Disable script debugger when in system lock down mode
if (IsSystemLockedDown)
{
if (_context._debuggingMode != (int)InternalDebugMode.Disabled)
{
_context._debuggingMode = (int)InternalDebugMode.Disabled;
}

return;
}

switch (mode)
{
case InternalDebugMode.InPushedStop:
Expand All @@ -2086,6 +2099,24 @@ private bool CanEnableDebugger
}
}

private static bool IsSystemLockedDown
{
get
{
return (System.Management.Automation.Security.SystemPolicy.GetSystemLockdownPolicy() ==
System.Management.Automation.Security.SystemEnforcementMode.Enforce);
}
}

private static void CheckForBreakpointSupport()
{
if (IsSystemLockedDown)
{
// Local script debugging is not supported in locked down mode
throw new PSNotSupportedException();
}
}

#region Enable debug stepping

[Flags]
Expand Down Expand Up @@ -2323,6 +2354,15 @@ public override void SetDebugMode(DebugModes mode)
{
lock (_syncObject)
{
// Restrict local script debugger mode when in system lock down.
// DebugModes enum flags provide a combination of values. To disable local script debugging
// we have to disallow 'LocalScript' and 'Default' flags and only allow 'None' or 'RemoteScript'
// flags exclusively. This allows only no debugging 'None' or remote debugging 'RemoteScript'.
if (IsSystemLockedDown && (mode != DebugModes.None) && (mode != DebugModes.RemoteScript))
{
mode = DebugModes.RemoteScript;
}

base.SetDebugMode(mode);

if (!CanEnableDebugger)
Expand Down
Loading