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
135 changes: 5 additions & 130 deletions src/System.Management.Automation/engine/debugger/debugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,12 @@ public enum DebugModes
Default = 0x1,

/// <summary>
/// PowerShell script debugging including workflow script.
/// PowerShell script debugging.
/// </summary>
LocalScript = 0x2,

/// <summary>
/// PowerShell remote script and workflow debugging.
/// PowerShell remote script debugging.
/// </summary>
RemoteScript = 0x4
};
Expand Down Expand Up @@ -3333,18 +3333,6 @@ private DebuggerCommandResults ProcessCommandForActiveDebugger(PSCommand command
_lastActiveDebuggerAction = dbgCommand.ResumeAction.Value;
return new DebuggerCommandResults(dbgCommand.ResumeAction, true);
}

// If active debugger is Workflow debugger then process command here (for "list" and "help").
if (activeDebugger.GetType().FullName.Equals("Microsoft.PowerShell.Workflow.PSWorkflowDebugger", StringComparison.OrdinalIgnoreCase))
{
DebuggerCommand results = _commandProcessor.ProcessCommand(null, commandText, stopArgs.InvocationInfo, output);

if ((results != null) &&
results.ExecutedByDebugger)
{
return new DebuggerCommandResults(results.ResumeAction, true);
}
}
}

return activeDebugger.ProcessCommand(command, output);
Expand Down Expand Up @@ -3545,39 +3533,6 @@ private void HandleMonitorRunningRSDebuggerStop(object sender, DebuggerStopEvent

PSMonitorRunspaceType runspaceType = nestedDebugger.RunspaceType;

// If this is a workflow debugger then ensure that there is a current active
// debugger that is the associated job debugger for this inline script WF runspace.
if (runspaceType == PSMonitorRunspaceType.WorkflowInlineScript)
{
bool needToPushAssociatedWFDebugger = true;
if (_activeDebuggers.TryPeek(out activeDebugger))
{
needToPushAssociatedWFDebugger = (activeDebugger.InstanceId != nestedDebugger.ParentDebuggerId);
if (needToPushAssociatedWFDebugger)
{
// Pop incorrect active debugger.
PopActiveDebugger();
}
}

if (needToPushAssociatedWFDebugger)
{
PSJobStartEventArgs wfJobArgs = null;
lock (_syncObject)
{
_runningJobs.TryGetValue(nestedDebugger.ParentDebuggerId, out wfJobArgs);
}

if (wfJobArgs == null)
{
Diagnostics.Assert(false, "We should never get a WF job InlineScript debugger without an associated WF parent job.");
return;
}

PushActiveDebugger(wfJobArgs.Debugger, _jobCallStackOffset);
}
}

// Fix up invocation info script extents for embedded nested debuggers where the script source is
// from the parent.
args.InvocationInfo = nestedDebugger.FixupInvocationInfo(args.InvocationInfo);
Expand Down Expand Up @@ -4239,7 +4194,7 @@ protected virtual bool HandleListCommand(PSDataCollection<PSObject> output)
/// Attempts to fix up the debugger stop invocation information so that
/// the correct stack and source can be displayed in the debugger, for
/// cases where the debugged runspace is called inside a parent sccript,
/// such as with Workflow InlineScripts and script Invoke-Command cases.
/// such as with script Invoke-Command cases.
/// </summary>
/// <param name="debugStopInvocationInfo"></param>
/// <returns>InvocationInfo.</returns>
Expand Down Expand Up @@ -4405,8 +4360,7 @@ private void RestoreRemoteOutput(object runningCmd)

/// <summary>
/// Wrapper class for runspace debugger where the runspace is being used in an
/// embedded scenario such as Workflow InlineScript or Invoke-Command command
/// inside script.
/// embedded scenario such as Invoke-Command command inside script.
/// </summary>
internal sealed class EmbeddedRunspaceDebugger : NestedRunspaceDebugger
{
Expand Down Expand Up @@ -4515,7 +4469,7 @@ protected override bool HandleListCommand(PSDataCollection<PSObject> output)
/// Attempts to fix up the debugger stop invocation information so that
/// the correct stack and source can be displayed in the debugger, for
/// cases where the debugged runspace is called inside a parent sccript,
/// such as with Workflow InlineScripts and script Invoke-Command cases.
/// such as with script Invoke-Command cases.
/// </summary>
/// <param name="debugStopInvocationInfo">Invocation information from debugger stop.</param>
/// <returns>InvocationInfo.</returns>
Expand Down Expand Up @@ -5360,65 +5314,6 @@ namespace System.Management.Automation.Internal
[SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes", Justification = "Needed Internal use only")]
public static class DebuggerUtils
{
/// <summary>
/// Set-DebuggerVariable function.
/// </summary>
public const string SetVariableFunction = @"function Set-DebuggerVariable
{
[CmdletBinding()]
param(
[Parameter(Position=0)]
[HashTable]
$Variables
)

foreach($key in $Variables.Keys)
{
microsoft.powershell.utility\set-variable -Name $key -Value $Variables[$key] -Scope global
}

Set-StrictMode -Off
}";

/// <summary>
/// Remove-DebuggerVariable function.
/// </summary>
public const string RemoveVariableFunction = @"function Remove-DebuggerVariable
{
[CmdletBinding()]
param(
[Parameter(Position=0)]
[string[]]
$Name
)

foreach ($item in $Name)
{
microsoft.powershell.utility\remove-variable -name $item -scope global
}

Set-StrictMode -Off
}";

/// <summary>
/// Get-PSCallStack override function.
/// </summary>
public const string GetPSCallStackOverrideFunction = @"function Get-PSCallStack
{
[CmdletBinding()]
param()

if ($null -ne $PSWorkflowDebugger)
{
foreach ($frame in $PSWorkflowDebugger.GetCallStack())
{
Write-Output $frame
}
}

Set-StrictMode -Off
}";

internal const string SetDebugModeFunctionName = "__Set-PSDebugMode";
internal const string SetDebuggerActionFunctionName = "__Set-PSDebuggerAction";
internal const string GetDebuggerStopArgsFunctionName = "__Get-PSDebuggerStopArgs";
Expand Down Expand Up @@ -5453,21 +5348,6 @@ public static bool ShouldAddCommandToHistory(string command)
}
}

/// <summary>
/// Helper method to return an enumeration of workflow debugger
/// functions.
/// </summary>
/// <returns></returns>
public static IEnumerable<string> GetWorkflowDebuggerFunctions()
{
return new Collection<string>()
{
SetVariableFunction,
RemoveVariableFunction,
GetPSCallStackOverrideFunction
};
}

/// <summary>
/// Start monitoring a runspace on the target debugger.
/// </summary>
Expand Down Expand Up @@ -5526,11 +5406,6 @@ public enum PSMonitorRunspaceType
/// Runspace from remote Invoke-Command script.
/// </summary>
InvokeCommand,

/// <summary>
/// Runspace from Workflow activity inline script.
/// </summary>
WorkflowInlineScript
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion test/powershell/SDK/PSDebugging.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Describe "Runspace Debugging API tests" -tag CI {
Context "PSStandaloneMonitorRunspaceInfo tests" {
BeforeAll {
$runspace = [runspacefactory]::CreateRunspace()
$runspaceType = [PSMonitorRunspaceType]::WorkflowInlineScript
$runspaceType = [PSMonitorRunspaceType]::InvokeCommand
$monitorInfo = [PSStandaloneMonitorRunspaceInfo]::new($runspace)
$instanceId = $runspace.InstanceId
$parentDebuggerId = [guid]::newguid()
Expand Down