WIP: Support remote startup commands, e.g. gdbserver
This commit is contained in:
parent
aed3f459a6
commit
1ca88ad332
2 changed files with 87 additions and 11 deletions
|
|
@ -61,6 +61,25 @@ function! s:_Send( msg ) abort
|
||||||
return 1
|
return 1
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! vimspector#internal#job#RunCommand( cmd ) abort
|
||||||
|
return job_start( a:cmd,
|
||||||
|
\ {
|
||||||
|
\ 'in_mode': 'raw',
|
||||||
|
\ 'out_mode': 'raw',
|
||||||
|
\ 'err_mode': 'raw',
|
||||||
|
\ 'out_cb': funcref( 's:_OnServerError' ),
|
||||||
|
\ 'err_cb': funcref( 's:_OnServerError' ),
|
||||||
|
\ 'stoponexit': 'term',
|
||||||
|
\ }
|
||||||
|
\ )
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! vimspector#internal#job#KillCommand( job ) abort
|
||||||
|
if job_status( a:job ) == 'run'
|
||||||
|
call job_stop( a:job, 'term' )
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! vimspector#internal#job#StartDebugSession( config ) abort
|
function! vimspector#internal#job#StartDebugSession( config ) abort
|
||||||
if exists( 's:job' )
|
if exists( 's:job' )
|
||||||
echom "Not starging: Job is already running"
|
echom "Not starging: Job is already running"
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import vim
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import functools
|
import functools
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
|
|
@ -55,6 +56,8 @@ class DebugSession( object ):
|
||||||
self._func_breakpoints = []
|
self._func_breakpoints = []
|
||||||
self._configuration = None
|
self._configuration = None
|
||||||
|
|
||||||
|
self._attach_process = None
|
||||||
|
|
||||||
vim.command( 'sign define vimspectorBP text==> texthl=Error' )
|
vim.command( 'sign define vimspectorBP text==> texthl=Error' )
|
||||||
vim.command( 'sign define vimspectorBPDisabled text=!> texthl=Warning' )
|
vim.command( 'sign define vimspectorBPDisabled text=!> texthl=Warning' )
|
||||||
|
|
||||||
|
|
@ -221,6 +224,11 @@ class DebugSession( object ):
|
||||||
self._Reset()
|
self._Reset()
|
||||||
|
|
||||||
def _Reset( self ):
|
def _Reset( self ):
|
||||||
|
if self._attach_process:
|
||||||
|
vim.eval( 'vimspector#internal#job#KillCommand( {} )'.format(
|
||||||
|
json.dumps( self._attach_process ) ) )
|
||||||
|
self._attach_process = None
|
||||||
|
|
||||||
if self._uiTab:
|
if self._uiTab:
|
||||||
self._stackTraceView.Reset()
|
self._stackTraceView.Reset()
|
||||||
self._variablesView.Reset()
|
self._variablesView.Reset()
|
||||||
|
|
@ -456,17 +464,64 @@ class DebugSession( object ):
|
||||||
},
|
},
|
||||||
}, failure_handler = handler, timeout = 5000 )
|
}, failure_handler = handler, timeout = 5000 )
|
||||||
|
|
||||||
def _SelectProcess( self, adapter_config, launch_config ):
|
def _PrepareAttach( self, adapter_config, launch_config ):
|
||||||
atttach_config = adapter_config[ 'attach' ]
|
|
||||||
if atttach_config[ 'pidSelect' ] == 'ask':
|
|
||||||
pid = utils.AskForInput( 'Enter PID to attach to: ' )
|
|
||||||
launch_config[ atttach_config[ 'pidProperty' ] ] = pid
|
|
||||||
return
|
|
||||||
elif atttach_config[ 'pidSelect' ] == 'none':
|
|
||||||
return
|
|
||||||
|
|
||||||
raise ValueError( 'Unrecognised pidSelect {0}'.format(
|
atttach_config = adapter_config[ 'attach' ]
|
||||||
atttach_config[ 'pidSelect' ] ) )
|
|
||||||
|
if 'remote' in atttach_config:
|
||||||
|
remote = atttach_config[ 'remote' ]
|
||||||
|
ssh = [ 'ssh' ]
|
||||||
|
|
||||||
|
if 'account' in remote:
|
||||||
|
ssh.append( remote[ 'account' ] + '@' + remote[ 'host' ] )
|
||||||
|
else:
|
||||||
|
ssh.append( remote[ 'host' ] )
|
||||||
|
|
||||||
|
cmd = ssh + remote[ 'pidCommand' ]
|
||||||
|
|
||||||
|
self._logger.debug( 'Getting PID: %s', cmd )
|
||||||
|
pid = subprocess.check_output( ssh + remote[ 'pidCommand' ] ).decode(
|
||||||
|
'utf-8' ).strip()
|
||||||
|
self._logger.debug( 'Got PID: %s', pid )
|
||||||
|
|
||||||
|
cmd = ssh + remote[ 'attachCommand' ][:]
|
||||||
|
|
||||||
|
for index, item in enumerate( cmd ):
|
||||||
|
cmd[ index ] = item.replace( '%PID%', pid )
|
||||||
|
|
||||||
|
# TODO: Log files, etc. ?
|
||||||
|
self._logger.debug( 'Running remote app: %s', cmd )
|
||||||
|
self._attach_process = vim.eval(
|
||||||
|
'vimspector#internal#job#RunCommand( {} )'.format(
|
||||||
|
json.dumps( cmd ) ) )
|
||||||
|
else:
|
||||||
|
if atttach_config[ 'pidSelect' ] == 'ask':
|
||||||
|
pid = utils.AskForInput( 'Enter PID to attach to: ' )
|
||||||
|
launch_config[ atttach_config[ 'pidProperty' ] ] = pid
|
||||||
|
return
|
||||||
|
elif atttach_config[ 'pidSelect' ] == 'none':
|
||||||
|
return
|
||||||
|
|
||||||
|
raise ValueError( 'Unrecognised pidSelect {0}'.format(
|
||||||
|
atttach_config[ 'pidSelect' ] ) )
|
||||||
|
|
||||||
|
|
||||||
|
def _PrepareRun( self, adapter_config, launch_config ):
|
||||||
|
run_config = adapter_config.get( 'launch', {} )
|
||||||
|
|
||||||
|
if 'remote' in run_config:
|
||||||
|
remote = run_config[ 'remote' ]
|
||||||
|
ssh = [ 'ssh' ]
|
||||||
|
if 'account' in remote:
|
||||||
|
ssh.append( remote[ 'account' ] + '@' + remote[ 'host' ] )
|
||||||
|
else:
|
||||||
|
ssh.append( remote[ 'host' ] )
|
||||||
|
|
||||||
|
cmd = ssh + remote[ 'runCommand' ][:]
|
||||||
|
self._logger.debug( 'Running remote app: %s', cmd )
|
||||||
|
self._attach_process = vim.eval(
|
||||||
|
'vimspector#internal#job#RunCommand( {} )'.format(
|
||||||
|
json.dumps( cmd ) ) )
|
||||||
|
|
||||||
|
|
||||||
def _Initialise( self ):
|
def _Initialise( self ):
|
||||||
|
|
@ -499,7 +554,9 @@ class DebugSession( object ):
|
||||||
launch_config = self._configuration[ 'configuration' ]
|
launch_config = self._configuration[ 'configuration' ]
|
||||||
|
|
||||||
if launch_config.get( 'request' ) == "attach":
|
if launch_config.get( 'request' ) == "attach":
|
||||||
self._SelectProcess( adapter_config, launch_config )
|
self._PrepareAttach( adapter_config, launch_config )
|
||||||
|
elif launch_config.get( 'request' ) == "run":
|
||||||
|
self._PrepareRun( adapter_config, launch_config )
|
||||||
|
|
||||||
# FIXME: name is mandatory. Forcefully add it (we should really use the
|
# FIXME: name is mandatory. Forcefully add it (we should really use the
|
||||||
# _actual_ name, but that isn't actually remembered at this point)
|
# _actual_ name, but that isn't actually remembered at this point)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue