On Sa, 14 Apr 2018, Bram Moolenaar wrote:

> 
> Christian wrote:
> 
> > here is a patch that fixes and enhances the termdebug plugin.
> > 
> > Changes:
> >      - Make :Termdebug (without argument) an error
> >        After all, if no argument is given, what should you debug?
> 
> You can start gdb without a program name and then use ":file cmd" to
> debug an executable.  I don't think we should disallow that.

Ah, that actually makes sense. I did not think of that.

>  
> >      - If you run :Termdebug several times, the plugin throws "E174: 
> >        command already exists", so add the bang argument to it".
> >        In addition, make the commands buffer-local.
> 
> I don't like making them buffer-local, because it's not unusual to split
> the window to look at other parts of the source code.
> 
> I do think we should disallow running two debuggers, the plugin isn't
> prepared for that.

> >      - Arguments supplied to the command line were not used 
> >      correctly.
> >        So in case additional runtime arguments are given, use the
> >        "set args" command of gdb to set those arguments. This allows to 
> >        run e.g. :Termdebug vim --clean -c ":set nu". Currently I believe
> >        gdb will try to literally run "vim --clean -c ":set nu"" which 
> >        fails obviously.
> 
> The arguments for running the command are to be added to the "run" gdb
> command.  The arguments for gdb can be a core file name or a process id.
> But that doesn't work now, I'll use part of your change to make that
> work.

I am not convinced :)

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. 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.

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.

Best,
Christian
-- 
Drinnen ist es genauso wie drau├čen, nur anders.

-- 
-- 
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..f689a9782 100644
--- a/runtime/doc/terminal.txt
+++ b/runtime/doc/terminal.txt
@@ -656,6 +656,14 @@ arguments.  E.g.: >
 	:Termdebug vim core
 	:Termdebug vim 98343
 
+To separate gdb arguments from process specific arguments use the `--`
+separator, e.g.: >
+        :Termdebug vim -- --clean -c ':set nu'
+
+Will attach gdb to Vim and use the `--clean -c ':set nu'` arguments for Vim.
+
+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..f35ce1266 100644
--- a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
+++ b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
@@ -95,7 +95,8 @@ 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] = s:Split(a:000)
+  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 +110,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")
 
@@ -181,6 +187,7 @@ func s:StartDebug(...)
   augroup TermDebug
     au BufRead * call s:BufRead()
     au BufUnload * call s:BufUnloaded()
+    au BufUnload <buffer> call s:DeleteCommands()
   augroup END
 endfunc
 
@@ -574,3 +581,26 @@ func s:BufUnloaded()
   endfor
 endfunc
 
+func s:Split(list)
+  let gdb_args=[]
+  let prc_args=[]
+  " Check for '--' argument as separator for gdb options and process options
+  " Returns a list with 2 entries:
+  "   [ [gdb_args], [proc_args] ]
+  let idx = index(a:list, '--')
+  if idx == -1
+    return [a:list, []]
+  else
+    if idx == 0
+      let gdb_args = []
+    else
+      let gdb_args = a:list[0: (idx - 1)]
+    endif
+    if idx == len(a:list)-1
+      let prc_args = []
+    else
+      let prc_args = a:list[(idx+1):]
+    endif
+  endif
+  return [gdb_args, prc_args]
+endfunc

Raspunde prin e-mail lui