Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
brammool committed Apr 16, 2018
1 parent 06965b8 commit 32c67ba
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 20 deletions.
51 changes: 34 additions & 17 deletions runtime/doc/terminal.txt
Expand Up @@ -623,7 +623,8 @@ Starting ~
Load the plugin with this command: >
packadd termdebug
< *:Termdebug*
To start debugging use `:Termdebug` followed by the command name, for example: >
To start debugging use `:Termdebug` or `:TermdebugCommand`` followed by the
command name, for example: >
:Termdebug vim
This opens two windows:
Expand All @@ -641,7 +642,8 @@ source file location will be displayed, if possible. A sign is used to
highlight the current position, using highlight group debugPC.

If the buffer in the current window is modified, another window will be opened
to display the current gdb position.
to display the current gdb position. You can use `:Winbar` to add a window
toolbar there.

Focus the terminal of the executed program to interact with it. This works
the same as any command running in a terminal window.
Expand All @@ -650,12 +652,25 @@ When the debugger ends, typically by typing "quit" in the gdb window, the two
opened windows are closed.

Only one debugger can be active at a time.

To attach gdb to an already running executable, or use a core file, pass extra
*: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'
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). For example: >
:TermdebugCommand! vim --clean
To attach gdb to an already running executable or use a core file, pass extra
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*
Expand Down Expand Up @@ -728,18 +743,20 @@ Put focus on the gdb window to type commands there. Some common ones are:
- frame N go to the Nth stack frame
- continue continue execution

In the window showing the source code these commands can be used to control gdb:
*:Run* *:Arguments*
In the window showing the source code these commands can be used to control
gdb:
`:Run` [args] run the program with [args] or the previous arguments
`:Arguments` {args} set arguments for the next `:Run`

`:Break` set a breakpoint at the current line; a sign will be displayed
`:Clear` delete the breakpoint at the current line
*:Break* set a breakpoint at the current line; a sign will be displayed
*:Clear* delete the breakpoint at the current line

`:Step` execute the gdb "step" command
`:Over` execute the gdb "next" command (`:Next` is a Vim command)
`:Finish` execute the gdb "finish" command
`:Continue` execute the gdb "continue" command
`:Stop` interrupt the program
*:Step* execute the gdb "step" command
*:Over* execute the gdb "next" command (`:Next` is a Vim command)
*:Finish* execute the gdb "finish" command
*:Continue* execute the gdb "continue" command
*:Stop* interrupt the program

If 'mouse' is set the plugin adds a window toolbar with these entries:
Step `:Step`
Expand All @@ -750,7 +767,7 @@ If 'mouse' is set the plugin adds a window toolbar with these entries:
Eval `:Evaluate`
This way you can use the mouse to perform the most common commands. You need
to have the 'mouse' option set to enable mouse clicks.

*:Winbar*
You can add the window toolbar in other windows you open with: >
:Winbar
Expand All @@ -761,7 +778,7 @@ abandoned.


Inspecting variables ~
*termdebug-variables*
*termdebug-variables* *:Evaluate*
`:Evaluate` evaluate the expression under the cursor
`K` same
`:Evaluate` {expr} evaluate {expr}
Expand All @@ -773,9 +790,9 @@ You can usually shorten `:Evaluate` to `:Ev`.

Other commands ~
*termdebug-commands*
:Gdb jump to the gdb window
:Program jump to the window with the running program
:Source jump to the window with the source code, create it if there
*:Gdb* jump to the gdb window
*:Program* jump to the window with the running program
*:Source* jump to the window with the source code, create it if there
isn't one


Expand Down
33 changes: 30 additions & 3 deletions runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
Expand Up @@ -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')
Expand All @@ -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
Expand Down Expand Up @@ -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'),
Expand All @@ -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")

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -762,6 +762,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1725,
/**/
1724,
/**/
Expand Down

0 comments on commit 32c67ba

Please sign in to comment.