Skip to content

PSES crashing while debugging #701

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
rjmholt opened this issue Jul 11, 2018 · 2 comments
Closed

PSES crashing while debugging #701

rjmholt opened this issue Jul 11, 2018 · 2 comments
Labels

Comments

@rjmholt
Copy link
Contributor

rjmholt commented Jul 11, 2018

From PowerShell/vscode-powershell#1422 (comment).

Seems to be a crash in the debugger.

Possibly this one:

2018-07-11 10:27:32.478 [VERBOSE] C:\PowerShellEditorServices\src\PowerShellEditorServices\Session\PowerShellContext.cs: In method 'ExecuteCommandInDebugger', line 1224:
    Attempting to execute command(s) in the debugger:
    
        Get-Variable -Scope 2
    

2018-07-11 10:27:32.481 [ERROR] C:\PowerShellEditorServices\src\PowerShellEditorServices\Session\PowerShellContext.cs: In method 'ExecuteCommand', line 586:
    Runtime exception occurred while executing command:
    
    System.Management.Automation.CmdletInvocationException: The scope number '2' exceeds the number of active scopes.
    Parameter name: scopeID
    Actual value was 2. ---> System.Management.Automation.PSArgumentOutOfRangeException: The scope number '2' exceeds the number of active scopes.
    Parameter name: scopeID
    Actual value was 2.
       at System.Management.Automation.SessionStateInternal.GetScopeByID(Int32 scopeID)
       at System.Management.Automation.SessionStateInternal.GetScopeByID(String scopeID)
       at System.Management.Automation.SessionStateInternal.GetVariableTableAtScope(String scopeID)
       at Microsoft.PowerShell.Commands.VariableCommandBase.GetMatchingVariables(String name, String lookupScope, Boolean& wasFiltered, Boolean quiet)
       at Microsoft.PowerShell.Commands.GetVariableCommand.ProcessRecord()
       at System.Management.Automation.Cmdlet.DoProcessRecord()
       at System.Management.Automation.CommandProcessor.ProcessRecord()
       --- End of inner exception stack trace ---
       at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
       at System.Management.Automation.Runspaces.Pipeline.Invoke()
       at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
       at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
       at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
       at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings)
       at System.Management.Automation.PowerShell.Invoke[T](IEnumerable input, IList`1 output, PSInvocationSettings settings)
       at System.Management.Automation.PowerShell.InvokeWithDebugger(IEnumerable`1 input, IList`1 output, PSInvocationSettings settings, Boolean invokeMustRun)
       at System.Management.Automation.ScriptDebugger.ProcessCommand(PSCommand command, PSDataCollection`1 output)
       at Microsoft.PowerShell.EditorServices.Session.PowerShell4Operations.ExecuteCommandInDebugger[TResult](PowerShellContext powerShellContext, Runspace currentRunspace, PSCommand psCommand, Boolean sendOutputToHost, Nullable`1& debuggerResumeAction)
       at Microsoft.PowerShell.EditorServices.PowerShellContext.ExecuteCommandInDebugger[TResult](PSCommand psCommand, Boolean sendOutputToHost)
       at Microsoft.PowerShell.EditorServices.PowerShellContext.<ExecuteCommand>d__48`1.MoveNext()

2018-07-11 10:27:32.481 [VERBOSE] C:\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageWriter.cs: In method 'WriteMessage', line 61:
    Writing Event 'powerShell/executionStatusChanged'

2018-07-11 10:27:32.482 [VERBOSE] C:\PowerShellEditorServices\src\PowerShellEditorServices\Session\PowerShellContext.cs: In method 'ExecuteCommandInDebugger', line 1224:
    Attempting to execute command(s) in the debugger:
    
        Get-Variable -Scope 3
@rjmholt rjmholt added Issue-Bug A bug to squash. Area-Debugging labels Jul 11, 2018
@SeeminglyScience
Copy link
Collaborator

Unfortunately that error is probably unrelated to the crash.

That error is expected when debugging a script where a frame in the call stack is within a module. The number of scopes iterated when getting variables is based on the number of frames in the call stack. But because each SessionState has it's own stack of SessionStateScopes, so the amount of scopes does not equal the amount of frames in a call stack.

A possible fix would be to check the module of the command listed in the scope with frame.InvocationInfo.MyCommand.Module, but invoking Get-Variable in a different session state than the current EngineSessionState is tricky. If the session state belongs to a module we could do . $module { Get-Variable -Scope x }, but there's no publicly accessible way to get the top level session state. Even if we could get the top level session state, the only way to invoke a script within that session state is to create a fake module object and set it's session state.

$fakeModule = [psmoduleinfo]::new($false)
$fakeModule.SessionState = $topLevelSessionState
. $fakeModule { Get-Variable -Scope x }

But that's probably not intended behavior and is likely as dangerous as reflection.

All that said, this error is caught and wouldn't cause any crashes, we just don't get as much info for each frame as we'd like.

@rjmholt
Copy link
Contributor Author

rjmholt commented Jul 27, 2018

Can't remember why I opened this issue. Possible to track the error I saw in the logs there?? Anyway, based on what you say @SeeminglyScience, we probably handle it as well as anything for now.

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

2 participants