patch 8.0.1293: setting a breakpoint in the terminal debugger sometimes fails
Problem: Setting a breakpoint in the terminal debugger sometimes fails.
Solution: Interrupt the program if needed. Set the interface to async.
diff --git a/runtime/doc/terminal.txt b/runtime/doc/terminal.txt
index 54899fc..b3df8ce 100644
--- a/runtime/doc/terminal.txt
+++ b/runtime/doc/terminal.txt
@@ -1,4 +1,4 @@
-*terminal.txt* For Vim version 8.0. Last change: 2017 Nov 09
+*terminal.txt* For Vim version 8.0. Last change: 2017 Nov 12
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -60,7 +60,7 @@
terminal window to move keyboard focus elsewhere.
CTRL-W can be used to navigate between windows and other CTRL-W commands, e.g.:
- CTRL-W CTRL-W move focus to the next window
+ CTRL-W CTRL-W move focus to the next window
CTRL-W : enter an Ex command
See |CTRL-W| for more commands.
@@ -80,7 +80,7 @@
'termkey' : enter an Ex command
'termkey' 'termkey' send 'termkey' to the job in the terminal
'termkey' . send a CTRL-W to the job in the terminal
- 'termkey' N go to terminal Normal mode, see below
+ 'termkey' N go to terminal Normal mode, see below
'termkey' CTRL-N same as CTRL-W N
'termkey' CTRL-C same as |t_CTRL-W_CTRL-C|
*t_CTRL-\_CTRL-N*
@@ -286,10 +286,10 @@
want to pass on other escape sequences to the job running in the terminal you
need to set up forwarding. Example: >
tmap <expr> <Esc>]b SendToTerm("\<Esc>]b")
- func SendToTerm(what)
- call term_sendkeys('', a:what)
- return ''
- endfunc
+ func SendToTerm(what)
+ call term_sendkeys('', a:what)
+ return ''
+ endfunc
Unix ~
@@ -447,29 +447,35 @@
Stepping through code ~
*termdebug-stepping*
Put focus on the gdb window to type commands there. Some common ones are:
-- CTRL-C interrupt the program
-- next execute the current line and stop at the next line
-- step execute the current line and stop at the next statement, entering
- functions
-- finish execute until leaving the current function
-- where show the stack
-- frame N go to the Nth stack frame
-- continue continue execution
+- CTRL-C interrupt the program
+- next execute the current line and stop at the next line
+- step execute the current line and stop at the next statement,
+ entering functions
+- finish execute until leaving the current function
+- where show the stack
+- frame N go to the Nth stack frame
+- continue continue execution
-In the window showing the source code some commands can used to control gdb:
- :Break set a breakpoint at the current line; a sign will be displayed
- :Delete delete a 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
+In the window showing the source code these commands can 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
+ :Delete delete a 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
The plugin adds a window toolbar with these entries:
- Step :Step
- Next :Over
- Finish :Finish
- Cont :Continue
- Eval :Evaluate
+ Step :Step
+ Next :Over
+ Finish :Finish
+ Cont :Continue
+ Stop :Stop
+ Eval :Evaluate
This way you can use the mouse to perform the most common commands.
diff --git a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
index 5704c46..635bf93 100644
--- a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
+++ b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
@@ -20,6 +20,9 @@
finish
endif
+" Uncomment this line to write logging in "debuglog".
+" call ch_logfile('debuglog', 'w')
+
" 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(<q-args>)
@@ -31,6 +34,7 @@
let s:pc_id = 12
let s:break_id = 13
+let s:stopped = 1
if &background == 'light'
hi default debugPC term=reverse ctermbg=lightblue guibg=lightblue
@@ -83,11 +87,11 @@
" Add -quiet to avoid the intro message causing a hit-enter prompt.
let cmd = [g:termdebugger, '-quiet', '-tty', pty, a:cmd]
echomsg 'executing "' . join(cmd) . '"'
- let gdbbuf = term_start(cmd, {
+ let s:gdbbuf = term_start(cmd, {
\ 'exit_cb': function('s:EndDebug'),
\ 'term_finish': 'close',
\ })
- if gdbbuf == 0
+ if s:gdbbuf == 0
echoerr 'Failed to open the gdb terminal window'
exe 'bwipe! ' . s:ptybuf
exe 'bwipe! ' . s:commbuf
@@ -97,7 +101,12 @@
" Connect gdb to the communication pty, using the GDB/MI interface
" If you get an error "undefined command" your GDB is too old.
- call term_sendkeys(gdbbuf, 'new-ui mi ' . commpty . "\r")
+ call term_sendkeys(s:gdbbuf, 'new-ui mi ' . commpty . "\r")
+
+ " Interpret commands while the target is running. This should usualy only be
+ " exec-interrupt, since many commands don't work properly while the target is
+ " running.
+ call s:SendCommand('-gdb-set mi-async on')
" Sign used to highlight the line where the program has stopped.
" There can be only one.
@@ -170,6 +179,9 @@
command Step call s:SendCommand('-exec-step')
command Over call s:SendCommand('-exec-next')
command Finish call s:SendCommand('-exec-finish')
+ command -nargs=* Run call s:Run(<q-args>)
+ command -nargs=* Arguments call s:SendCommand('-exec-arguments ' . <q-args>)
+ command Stop call s:SendCommand('-exec-interrupt')
command Continue call s:SendCommand('-exec-continue')
command -range -nargs=* Evaluate call s:Evaluate(<range>, <q-args>)
command Gdb call win_gotoid(s:gdbwin)
@@ -183,6 +195,7 @@
nnoremenu WinBar.Next :Over<CR>
nnoremenu WinBar.Finish :Finish<CR>
nnoremenu WinBar.Cont :Continue<CR>
+ nnoremenu WinBar.Stop :Stop<CR>
nnoremenu WinBar.Eval :Evaluate<CR>
endif
endfunc
@@ -194,6 +207,9 @@
delcommand Step
delcommand Over
delcommand Finish
+ delcommand Run
+ delcommand Arguments
+ delcommand Stop
delcommand Continue
delcommand Evaluate
delcommand Gdb
@@ -206,6 +222,7 @@
aunmenu WinBar.Next
aunmenu WinBar.Finish
aunmenu WinBar.Cont
+ aunmenu WinBar.Stop
aunmenu WinBar.Eval
endif
@@ -220,8 +237,19 @@
" :Break - Set a breakpoint at the cursor position.
func s:SetBreakpoint()
- call term_sendkeys(s:commbuf, '-break-insert --source '
- \ . fnameescape(expand('%:p')) . ' --line ' . line('.') . "\r")
+ " Setting a breakpoint may not work while the program is running.
+ " Interrupt to make it work.
+ let do_continue = 0
+ if !s:stopped
+ let do_continue = 1
+ call s:SendCommand('-exec-interrupt')
+ sleep 10m
+ endif
+ call s:SendCommand('-break-insert --source '
+ \ . fnameescape(expand('%:p')) . ' --line ' . line('.'))
+ if do_continue
+ call s:SendCommand('-exec-continue')
+ endif
endfunc
" :Delete - Delete a breakpoint at the cursor position.
@@ -244,6 +272,13 @@
call term_sendkeys(s:commbuf, a:cmd . "\r")
endfunc
+func s:Run(args)
+ if a:args != ''
+ call s:SendCommand('-exec-arguments ' . a:args)
+ endif
+ call s:SendCommand('-exec-run')
+endfunc
+
" :Evaluate - evaluate what is under the cursor
func s:Evaluate(range, arg)
if a:arg != ''
@@ -259,7 +294,7 @@
else
let expr = expand('<cexpr>')
endif
- call term_sendkeys(s:commbuf, '-data-evaluate-expression "' . expr . "\"\r")
+ call s:SendCommand('-data-evaluate-expression "' . expr . '"')
let s:evalexpr = expr
endfunc
@@ -286,6 +321,12 @@
func s:HandleCursor(msg)
let wid = win_getid(winnr())
+ if a:msg =~ '^\*stopped'
+ let s:stopped = 1
+ elseif a:msg =~ '^\*running'
+ let s:stopped = 0
+ endif
+
if win_gotoid(s:startwin)
let fname = substitute(a:msg, '.*fullname="\([^"]*\)".*', '\1', '')
if a:msg =~ '^\(\*stopped\|=thread-selected\)' && filereadable(fname)
diff --git a/src/version.c b/src/version.c
index f63b186..871a0e9 100644
--- a/src/version.c
+++ b/src/version.c
@@ -762,6 +762,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1293,
+/**/
1292,
/**/
1291,