Skip to content

Fix DebuggerVariableProcessObjDisplaysCorrectly scenario #1863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andyleejordan opened this issue Jul 26, 2022 · 1 comment
Closed

Fix DebuggerVariableProcessObjDisplaysCorrectly scenario #1863

andyleejordan opened this issue Jul 26, 2022 · 1 comment
Assignees
Labels

Comments

@andyleejordan
Copy link
Member

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.

@andyleejordan
Copy link
Member Author

Yay, fixed this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants