Ask the user about terminating the debuggee

CodeLLDB seems to actually support the terminateDebugee flag, so rather
than just forcefully killing things, ask the user if they want to.
This commit is contained in:
Ben Jackson 2021-02-24 15:10:57 +00:00
commit 5201995279
2 changed files with 31 additions and 7 deletions

View file

@ -793,6 +793,11 @@ class DebugSession( object ):
arguments = {} arguments = {}
if self._server_capabilities.get( 'supportTerminateDebuggee' ): if self._server_capabilities.get( 'supportTerminateDebuggee' ):
# If we attached, we should _not_ terminate the debuggee # If we attached, we should _not_ terminate the debuggee
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 arguments[ 'terminateDebuggee' ] = False
self._connection.DoRequest( handler, { self._connection.DoRequest( handler, {
@ -1164,10 +1169,22 @@ class DebugSession( object ):
self._connection.DoResponse( message, None, response ) 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 ): def OnEvent_exited( self, message ):
utils.UserMessage( 'The debugee exited with status code: {}'.format( utils.UserMessage( 'The debugee exited with status code: {}'.format(
message[ 'body' ][ 'exitCode' ] ) ) message[ 'body' ][ 'exitCode' ] ) )
self.SetCurrentFrame( None ) self._stackTraceView.OnExited( message )
self._codeView.SetCurrentFrame( None )
def OnEvent_process( self, message ): def OnEvent_process( self, message ):
utils.UserMessage( 'The debugee was started: {}'.format( utils.UserMessage( 'The debugee was started: {}'.format(
@ -1210,11 +1227,6 @@ class DebugSession( object ):
else: else:
self._logger.debug( "No server exit handler" ) 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 ): def OnEvent_output( self, message ):
if self._outputView: if self._outputView:
self._outputView.OnOutput( message[ 'body' ] ) self._outputView.OnOutput( message[ 'body' ] )

View file

@ -364,6 +364,14 @@ class StackTraceView( object ):
self._JumpToFrame( frame ) 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 _JumpToFrame( self, frame, reason = '' ):
def do_jump(): def do_jump():
if 'line' in frame and frame[ 'line' ] > 0: if 'line' in frame and frame[ 'line' ] > 0:
@ -459,6 +467,10 @@ class StackTraceView( object ):
self.LoadThreads( infer_current_frame ) self.LoadThreads( infer_current_frame )
def OnExited( self, event ):
for thread in self._threads:
thread.Exited()
def _DrawStackTrace( self, thread: Thread ): def _DrawStackTrace( self, thread: Thread ):
if not thread.IsExpanded(): if not thread.IsExpanded():
return return