Skip to content

Fix DebuggerVariableProcessObjDisplaysCorrectly scenario #1863

Closed
@andyleejordan

Description

@andyleejordan

This unit test is currently skipped, indicating a bug in product code:

// Verifies fix for issue #86, $proc = Get-Process foo displays just the ETS property set
// and not all process properties.
[Fact(Skip = "Length of child vars is wrong now")]
public async Task DebuggerVariableProcessObjDisplaysCorrectly()
{
await debugService.SetLineBreakpointsAsync(
variableScriptFile,
new[] { BreakpointDetails.Create(variableScriptFile.FilePath, 19) }).ConfigureAwait(true);
// Execute the script and wait for the breakpoint to be hit
Task _ = ExecuteVariableScriptFile();
AssertDebuggerStopped(variableScriptFile.FilePath);
StackFrameDetails[] stackFrames = await debugService.GetStackFramesAsync().ConfigureAwait(true);
VariableDetailsBase[] variables = debugService.GetVariables(stackFrames[0].AutoVariables.Id);
VariableDetailsBase var = Array.Find(variables, v => v.Name == "$procVar");
Assert.NotNull(var);
Assert.StartsWith("System.Diagnostics.Process", var.ValueString);
Assert.True(var.IsExpandable);
VariableDetailsBase[] childVars = debugService.GetVariables(var.Id);
Assert.Equal(53, childVars.Length);
}

It turns out that what's happening is that when this is getting the children variables:

// If a PSObject other than a PSCustomObject, unwrap it.
if (psObject != null)
{
// First add the PSObject's ETS properties
childVariables.AddRange(
psObject
.Properties
// Here we check the object's MemberType against the `Properties`
// bit-mask to determine if this is a property. Hence the selection
// will only include properties.
.Where(p => (PSMemberTypes.Properties & p.MemberType) is not 0)
.Select(p => new VariableDetails(p)));
obj = psObject.BaseObject;
}

It throws a GetValueInvocationException:

Exception getting "Path": "There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspace type. The script block you attempted to invoke was: $this.Mainmodule.FileName"

and @JustinGrote actually has a fix in the works with #1688, which @SeeminglyScience wants to rewrite and get in.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions