diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index 954d2c6..e82febf 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -793,7 +793,12 @@ class DebugSession( object ): arguments = {} if self._server_capabilities.get( 'supportTerminateDebuggee' ): # If we attached, we should _not_ terminate the debuggee - arguments[ 'terminateDebuggee' ] = False + if self._stackTraceView.AnyThreadsRunning(): + choice = utils.AskForInput( "Terminate debugee [Y/N/default]? ", "" ) + if choice == "Y" or choice == "y": + arguments[ 'terminateDebuggee' ] = True + elif choice == "N" or choice == 'n': + arguments[ 'terminateDebuggee' ] = False self._connection.DoRequest( handler, { 'command': 'disconnect', @@ -1164,10 +1169,22 @@ class DebugSession( object ): self._connection.DoResponse( message, None, response ) + def OnEvent_terminated( self, message ): + # The debugging _session_ has terminated. This does not mean that the + # debugee has terminated (that's the exited event). + # + # We will handle this when the server actually exists. + # + # FIXME we should always wait for this event before disconnecting closing + # any socket connection + self.SetCurrentFrame( None ) + + def OnEvent_exited( self, message ): utils.UserMessage( 'The debugee exited with status code: {}'.format( message[ 'body' ][ 'exitCode' ] ) ) - self.SetCurrentFrame( None ) + self._stackTraceView.OnExited( message ) + self._codeView.SetCurrentFrame( None ) def OnEvent_process( self, message ): utils.UserMessage( 'The debugee was started: {}'.format( @@ -1210,11 +1227,6 @@ class DebugSession( object ): else: self._logger.debug( "No server exit handler" ) - def OnEvent_terminated( self, message ): - # We will handle this when the server actually exists - utils.UserMessage( "Debugging was terminated by the server." ) - self.SetCurrentFrame( None ) - def OnEvent_output( self, message ): if self._outputView: self._outputView.OnOutput( message[ 'body' ] ) diff --git a/python3/vimspector/stack_trace.py b/python3/vimspector/stack_trace.py index f38e4ba..177998f 100644 --- a/python3/vimspector/stack_trace.py +++ b/python3/vimspector/stack_trace.py @@ -364,6 +364,14 @@ class StackTraceView( object ): self._JumpToFrame( frame ) + def AnyThreadsRunning( self ): + for thread in self._threads: + if thread.state != Thread.TERMINATED: + return True + + return False + + def _JumpToFrame( self, frame, reason = '' ): def do_jump(): if 'line' in frame and frame[ 'line' ] > 0: @@ -459,6 +467,10 @@ class StackTraceView( object ): self.LoadThreads( infer_current_frame ) + def OnExited( self, event ): + for thread in self._threads: + thread.Exited() + def _DrawStackTrace( self, thread: Thread ): if not thread.IsExpanded(): return