diff runtime/pack/dist/opt/termdebug/plugin/termdebug.vim @ 13706:bfd9249f72e0 v8.0.1725

patch 8.0.1725: terminal debugger doesn't handle command arguments commit https://github.com/vim/vim/commit/32c67ba733abcd4f2d729595fdccb2295445636a Author: Bram Moolenaar <Bram@vim.org> Date: Mon Apr 16 16:21:49 2018 +0200 patch 8.0.1725: terminal debugger doesn't handle command arguments Problem: Terminal debugger doesn't handle command arguments. Solution: Add the :TermdebugCommand command. Use a ! to execute right away. (Christian Brabandt)
author Christian Brabandt <cb@256bit.org>
date Mon, 16 Apr 2018 16:30:08 +0200
parents fc660a6ef37d
children 274c9f1fbfd2
line wrap: on
line diff
--- a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
+++ b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
@@ -25,7 +25,8 @@ endif
 
 " The command that starts debugging, e.g. ":Termdebug vim".
 " To end type "quit" in the gdb window.
-command -nargs=* -complete=file Termdebug call s:StartDebug(<f-args>)
+command -nargs=* -complete=file -bang Termdebug call s:StartDebug(<bang>0, <f-args>)
+command -nargs=+ -complete=file -bang TermdebugCommand call s:StartDebugCommand(<bang>0, <f-args>)
 
 " Name of the gdb command, defaults to "gdb".
 if !exists('termdebugger')
@@ -43,7 +44,17 @@ else
 endif
 hi default debugBreakpoint term=reverse ctermbg=red guibg=red
 
-func s:StartDebug(...)
+func s:StartDebug(bang, ...)
+  " First argument is the command to debug, second core file or process ID.
+  call s:StartDebug_internal({'gdb_args': a:000, 'bang': a:bang})
+endfunc
+
+func s:StartDebugCommand(bang, ...)
+  " First argument is the command to debug, rest are run arguments.
+  call s:StartDebug_internal({'gdb_args': [a:1], 'proc_args': a:000[1:], 'bang': a:bang})
+endfunc
+
+func s:StartDebug_internal(dict)
   if exists('s:gdbwin')
     echoerr 'Terminal debugger already running'
     return
@@ -95,7 +106,10 @@ func s:StartDebug(...)
 
   " Open a terminal window to run the debugger.
   " Add -quiet to avoid the intro message causing a hit-enter prompt.
-  let cmd = [g:termdebugger, '-quiet', '-tty', pty] + a:000
+  let gdb_args = get(a:dict, 'gdb_args', [])
+  let proc_args = get(a:dict, 'proc_args', [])
+
+  let cmd = [g:termdebugger, '-quiet', '-tty', pty] + gdb_args
   echomsg 'executing "' . join(cmd) . '"'
   let s:gdbbuf = term_start(cmd, {
 	\ 'exit_cb': function('s:EndDebug'),
@@ -109,6 +123,11 @@ func s:StartDebug(...)
   endif
   let s:gdbwin = win_getid(winnr())
 
+  " Set arguments to be run
+  if len(proc_args)
+    call term_sendkeys(s:gdbbuf, 'set args ' . join(proc_args) . "\r")
+  endif
+
   " Connect gdb to the communication pty, using the GDB/MI interface
   call term_sendkeys(s:gdbbuf, 'new-ui mi ' . commpty . "\r")
 
@@ -182,6 +201,14 @@ func s:StartDebug(...)
     au BufRead * call s:BufRead()
     au BufUnload * call s:BufUnloaded()
   augroup END
+
+  " Run the command if the bang attribute was given
+  " and got to the window
+  if get(a:dict, 'bang', 0)
+    call s:SendCommand('-exec-run')
+    call win_gotoid(s:ptywin)
+  endif
+
 endfunc
 
 func s:EndDebug(job, status)