Allow running a command after remote attach

gdbserver has a bug which means that it can't actually attach to running
processes on some versions due to sending signals to the wrong PID (not
the process group leader, or something). The workaround is to manually
send kill -TRAP to the PID in order for the initial break to be
regiseterd.

Doing this manually is painful, so we allow the remote object to run a
command after having successfully initialized the engine, which is about
the time you need to kick the trap/breakpoint.

https://sourceware.org/bugzilla/show_bug.cgi?id=18945
This commit is contained in:
Ben Jackson 2019-05-01 13:38:25 +01:00
commit de136f5db4

View file

@ -59,6 +59,7 @@ class DebugSession( object ):
self._configuration = None
self._init_complete = False
self._launch_complete = False
self._on_init_complete_handlers = None
self._server_capabilities = {}
def Start( self, launch_variables = {} ):
@ -358,6 +359,7 @@ class DebugSession( object ):
self._adapter ) ) )
self._init_complete = False
self._on_init_complete_handlers = []
self._launch_complete = False
self._run_on_server_exit = None
@ -434,8 +436,7 @@ class DebugSession( object ):
cmd = ssh + remote[ 'pidCommand' ]
self._logger.debug( 'Getting PID: %s', cmd )
pid = subprocess.check_output( ssh + remote[ 'pidCommand' ] ).decode(
'utf-8' ).strip()
pid = subprocess.check_output( cmd ).decode( 'utf-8' ).strip()
self._logger.debug( 'Got PID: %s', pid )
if not pid:
@ -443,6 +444,14 @@ class DebugSession( object ):
utils.UserMessage( 'Unable to get PID', persist = True )
return
if 'initCompleteCommand' in remote:
initcmd = ssh + remote[ 'initCompleteCommand' ][ : ]
for index, item in enumerate( initcmd ):
initcmd[ index ] = item.replace( '%PID%', pid )
self._on_init_complete_handlers.append(
lambda: subprocess.check_call( initcmd ) )
commands = self._GetCommands( remote, 'attach' )
for command in commands:
@ -598,6 +607,11 @@ class DebugSession( object ):
# least it would apear that way.
#
if self._launch_complete and self._init_complete:
for h in self._on_init_complete_handlers:
h()
self._on_init_complete_handlers = None
self._stackTraceView.LoadThreads( True )