Skip to content

Conversation

@rkeithhill
Copy link
Contributor

Fix for Get-Variable -Scope doesn't always work.

Ideally we should be using CallStackFrame.GetFrameVariables() but it currently seems to be broken. We've been informed that using Get-Variable -Scope isn't great because scope numbers and frames don't always line up. For instance, dot source introducing a new stack frame but not a new scope. But until GetFrameVariables is fixed in a future drop, we have no option but to use Get-Variable -Scope . This will result in stack frames that have no Auto or Local variables. But the good news is that the debug host will no longer crash. :-)

BTW this commit introduces a new optional parameter on PowerShellContext.ExecuteCommand(). While there is a parameter to suppress "output" there was no parameter to suppress "errors" from being written to the debug console. I see no benefit in littering the user's debug console with a bunch of "get-variable : The scope number '#' exceeds the number of active scopes". So there is now a "sendErrorToHost" parameter that defaults to true. However, even when that parameter is set to false, the error info shows up in the DebugAdapter.log file.

Ideally we should be using CallStackFrame.GetFrameVariables() but it currently seems to be broken. We've been informed that using Get-Variable -Scope <num> isn't great because scope numbers and frames don't always line up. For instance, dot source introducing a new stack frame but not a new scope. But until GetFrameVariables is fixed in a future drop, we have no option but to use Get-Variable -Scope <num>. This will result in stack frames that have no Auto or Local variables. But the good news is that the debug host will no longer crash. :-) BTW this commit introduces a new optional parameter on PowerShellContext.ExecuteCommand(). While there is a parameter to suppress "output" there was no parameter to suppress "errors" from being written to the debug console. I see no benefit in littering the user's debug console with a bunch of "get-variable : The scope number '#' exceeds the number of active scopes". So there is now a "sendErrorToHost" parameter that defaults to true. However, even when that parameter is set to false, the error info shows up in the DebugAdapter.log file.
Ideally we should be using CallStackFrame.GetFrameVariables() but it currently seems to be broken. We've been informed that using Get-Variable -Scope <num> isn't great because scope numbers and frames don't always line up. For instance, dot source introducing a new stack frame but not a new scope. But until GetFrameVariables is fixed in a future drop, we have no option but to use Get-Variable -Scope <num>. This will result in stack frames that have no Auto or Local variables. But the good news is that the debug host will no longer crash. :-) BTW this commit introduces a new optional parameter on PowerShellContext.ExecuteCommand(). While there is a parameter to suppress "output" there was no parameter to suppress "errors" from being written to the debug console. I see no benefit in littering the user's debug console with a bunch of "get-variable : The scope number '#' exceeds the number of active scopes". So there is now a "sendErrorToHost" parameter that defaults to true. However, even when that parameter is set to false, the error info shows up in the DebugAdapter.log file.
@daviwil
Copy link
Contributor

daviwil commented Jan 8, 2016

Argh, looks like the test failure is a timeout due to a DebugAdapter test hang, sorry about that. The second run just passed so I'm going to go ahead and merge this. Thanks for the fix!

daviwil added a commit that referenced this pull request Jan 8, 2016
…ailed Rkeithhill/fix getvariables failed
@daviwil daviwil merged commit 5958b44 into PowerShell:master Jan 8, 2016
@rkeithhill rkeithhill deleted the rkeithhill/fix-getvariables-failed branch January 8, 2016 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants