On So, 15 Apr 2018, Bram Moolenaar wrote:

> 
> Christian wrote:
> 
> > Still when the current session is finished and a new session is run 
> > using `:Termdebug vim` it errors out with E174, because the commands are 
> > already defined.
> 
> I don't see that.  There was an error for one command, it was missing in
> the list of the cleanup function.

Strange I had it yesterday all day long but now cannot reproduce it.

> > How about to delete the commands when the first window 
> > (the one in which you enter the gdb commands) is closed?
> > Alternatively, please use the `!` argument to the `:command` definition.
> 
> I avoid using !, because it would cover up overwriting an existing
> command (that might do something completely different).  It's a bit of
> a risk already, using simple names such as "Finish" and "Step".
> 
> > My use case is usually I want to run with a clean state. How about using 
> > the special separator '--' to separate gdb arguments from process 
> > specific arguments. This way I can actually run
> > `:Termdebug vim -- --clean -c ":call setline('..')"` and start debugging 
> > from a good initial state.
> > 
> > The attached patch does those two things.
> 
> Hmm, it's different from how gdb is normally used.  And it's also not
> how you would start Vim.  Thus introducing a whole new syntax.
> 
> When using a core file or running process the command arguments would
> not be used.  Thus we would need some way to specify "this is the
> command I want to run".
> 
> Perhaps we can use two commands, one to start with gdb arguments, one
> with the command to run.
>       :Termdebug vim core
>       :TermdebugCommand vim --clean
> 
> Something like that?  We could also use a command to make gdb execute
> "run" right away.  Sometimes it's a hassle that one needs to navigate to
> the gdb window to type "run" and then navigate to the program window to
> type something:
>       :TermdebugRun vim --clean test.txt
> This would start the debugger on Vim and do "run --clean test.txt" in
> the gdb window and put the cursor in the command window.

Here is a patch. I did not add the TermdebugRun command, but rather use 
the optional '!' to indicate to run the command.

Best,
Christian
-- 
Vermutlich hat Gott die Frau erschaffen, um den Mann kleinzukriegen.
                -- Fran├žois Marie Voltaire

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
diff --git a/runtime/doc/terminal.txt b/runtime/doc/terminal.txt
index 8deba3922..0cb4a43e6 100644
--- a/runtime/doc/terminal.txt
+++ b/runtime/doc/terminal.txt
@@ -626,6 +626,12 @@ Load the plugin with this command: >
 To start debugging use `:Termdebug` followed by the command name, for example: >
 	:Termdebug vim
 
+<							*:TermdebugCommand*
+If you want to give specific commands to the command being debugged, you can
+use the `:TermdebugCommand` command followed by the command name and
+additional parameters. >
+	:TermdebugCommand vim --clean -c ':set nu'
+
 This opens two windows:
 
 gdb window	A terminal window in which "gdb vim" is executed.  Here you
@@ -636,6 +642,10 @@ program window	A terminal window for the executed program.  When "run" is
 		that it does not interfere with controlling gdb.  The buffer
 		name is "gdb program".
 
+Both the `:Termdebug` and `:TermdebugCommand` support an optional "!" bang
+argument to start the command right away, without pausing at the gdb window
+(and cursor will be in the debugged window).
+
 The current window is used to show the source code.  When gdb pauses the
 source file location will be displayed, if possible.  A sign is used to
 highlight the current position, using highlight group debugPC.	 
@@ -656,6 +666,9 @@ arguments.  E.g.: >
 	:Termdebug vim core
 	:Termdebug vim 98343
 
+If no argument is given, you'll end up in a gdb window, in which you need to
+specify which command to run using e.g. the gdb `file` command.
+
 
 Example session ~
 							*termdebug-example*
diff --git a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
index ded114a2d..87cfe3748 100644
--- 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,18 @@ else
 endif
 hi default debugBreakpoint term=reverse ctermbg=red guibg=red
 
-func s:StartDebug(...)
+func s:StartDebug(bang, ...)
+  let args = {'gdb_args': a:000, 'bang': a:bang}
+  call call('s:StartDebug_internal', a:000)
+endfunc
+
+func s:StartDebugCommand(bang, ...)
+  " first argument is the command to be run
+  let args = {'gdb_args': [a:1], 'proc_args': a:000[1:], 'bang': a:bang}
+  call call('s:StartDebug_internal', [args])
+endfunc
+
+func s:StartDebug_internal(dict)
   if exists('s:gdbwin')
     echoerr 'Terminal debugger already running'
     return
@@ -95,7 +107,11 @@ 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, proc_args] = [
+        \ get(a:dict, 'gdb_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 +125,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 +203,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)

Raspunde prin e-mail lui