Skip to content

Commit 60e73f2

Browse files
committed
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.
1 parent d327b0c commit 60e73f2

3 files changed

Lines changed: 83 additions & 34 deletions

File tree

runtime/doc/terminal.txt

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*terminal.txt* For Vim version 8.0. Last change: 2017 Nov 09
1+
*terminal.txt* For Vim version 8.0. Last change: 2017 Nov 12
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -60,7 +60,7 @@ the job. This uses a pty when possible. You can click outside of the
6060
terminal window to move keyboard focus elsewhere.
6161

6262
CTRL-W can be used to navigate between windows and other CTRL-W commands, e.g.:
63-
CTRL-W CTRL-W move focus to the next window
63+
CTRL-W CTRL-W move focus to the next window
6464
CTRL-W : enter an Ex command
6565
See |CTRL-W| for more commands.
6666

@@ -80,7 +80,7 @@ the job. For example:
8080
'termkey' : enter an Ex command
8181
'termkey' 'termkey' send 'termkey' to the job in the terminal
8282
'termkey' . send a CTRL-W to the job in the terminal
83-
'termkey' N go to terminal Normal mode, see below
83+
'termkey' N go to terminal Normal mode, see below
8484
'termkey' CTRL-N same as CTRL-W N
8585
'termkey' CTRL-C same as |t_CTRL-W_CTRL-C|
8686
*t_CTRL-\_CTRL-N*
@@ -286,10 +286,10 @@ both Vim and xterm recognize will be available in the terminal window. If you
286286
want to pass on other escape sequences to the job running in the terminal you
287287
need to set up forwarding. Example: >
288288
tmap <expr> <Esc>]b SendToTerm("\<Esc>]b")
289-
func SendToTerm(what)
290-
call term_sendkeys('', a:what)
291-
return ''
292-
endfunc
289+
func SendToTerm(what)
290+
call term_sendkeys('', a:what)
291+
return ''
292+
endfunc
293293
294294
295295
Unix ~
@@ -447,29 +447,35 @@ a deeper level.
447447
Stepping through code ~
448448
*termdebug-stepping*
449449
Put focus on the gdb window to type commands there. Some common ones are:
450-
- CTRL-C interrupt the program
451-
- next execute the current line and stop at the next line
452-
- step execute the current line and stop at the next statement, entering
453-
functions
454-
- finish execute until leaving the current function
455-
- where show the stack
456-
- frame N go to the Nth stack frame
457-
- continue continue execution
458-
459-
In the window showing the source code some commands can used to control gdb:
460-
:Break set a breakpoint at the current line; a sign will be displayed
461-
:Delete delete a breakpoint at the current line
462-
:Step execute the gdb "step" command
463-
:Over execute the gdb "next" command (:Next is a Vim command)
464-
:Finish execute the gdb "finish" command
465-
:Continue execute the gdb "continue" command
450+
- CTRL-C interrupt the program
451+
- next execute the current line and stop at the next line
452+
- step execute the current line and stop at the next statement,
453+
entering functions
454+
- finish execute until leaving the current function
455+
- where show the stack
456+
- frame N go to the Nth stack frame
457+
- continue continue execution
458+
459+
In the window showing the source code these commands can used to control gdb:
460+
:Run [args] run the program with [args] or the previous arguments
461+
:Arguments {args} set arguments for the next :Run
462+
463+
:Break set a breakpoint at the current line; a sign will be displayed
464+
:Delete delete a breakpoint at the current line
465+
466+
:Step execute the gdb "step" command
467+
:Over execute the gdb "next" command (:Next is a Vim command)
468+
:Finish execute the gdb "finish" command
469+
:Continue execute the gdb "continue" command
470+
:Stop interrupt the program
466471

467472
The plugin adds a window toolbar with these entries:
468-
Step :Step
469-
Next :Over
470-
Finish :Finish
471-
Cont :Continue
472-
Eval :Evaluate
473+
Step :Step
474+
Next :Over
475+
Finish :Finish
476+
Cont :Continue
477+
Stop :Stop
478+
Eval :Evaluate
473479
This way you can use the mouse to perform the most common commands.
474480

475481

runtime/pack/dist/opt/termdebug/plugin/termdebug.vim

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ if exists(':Termdebug')
2020
finish
2121
endif
2222

23+
" Uncomment this line to write logging in "debuglog".
24+
" call ch_logfile('debuglog', 'w')
25+
2326
" The command that starts debugging, e.g. ":Termdebug vim".
2427
" To end type "quit" in the gdb window.
2528
command -nargs=* -complete=file Termdebug call s:StartDebug(<q-args>)
@@ -31,6 +34,7 @@ endif
3134

3235
let s:pc_id = 12
3336
let s:break_id = 13
37+
let s:stopped = 1
3438

3539
if &background == 'light'
3640
hi default debugPC term=reverse ctermbg=lightblue guibg=lightblue
@@ -83,11 +87,11 @@ func s:StartDebug(cmd)
8387
" Add -quiet to avoid the intro message causing a hit-enter prompt.
8488
let cmd = [g:termdebugger, '-quiet', '-tty', pty, a:cmd]
8589
echomsg 'executing "' . join(cmd) . '"'
86-
let gdbbuf = term_start(cmd, {
90+
let s:gdbbuf = term_start(cmd, {
8791
\ 'exit_cb': function('s:EndDebug'),
8892
\ 'term_finish': 'close',
8993
\ })
90-
if gdbbuf == 0
94+
if s:gdbbuf == 0
9195
echoerr 'Failed to open the gdb terminal window'
9296
exe 'bwipe! ' . s:ptybuf
9397
exe 'bwipe! ' . s:commbuf
@@ -97,7 +101,12 @@ func s:StartDebug(cmd)
97101

98102
" Connect gdb to the communication pty, using the GDB/MI interface
99103
" If you get an error "undefined command" your GDB is too old.
100-
call term_sendkeys(gdbbuf, 'new-ui mi ' . commpty . "\r")
104+
call term_sendkeys(s:gdbbuf, 'new-ui mi ' . commpty . "\r")
105+
106+
" Interpret commands while the target is running. This should usualy only be
107+
" exec-interrupt, since many commands don't work properly while the target is
108+
" running.
109+
call s:SendCommand('-gdb-set mi-async on')
101110

102111
" Sign used to highlight the line where the program has stopped.
103112
" There can be only one.
@@ -170,6 +179,9 @@ func s:InstallCommands()
170179
command Step call s:SendCommand('-exec-step')
171180
command Over call s:SendCommand('-exec-next')
172181
command Finish call s:SendCommand('-exec-finish')
182+
command -nargs=* Run call s:Run(<q-args>)
183+
command -nargs=* Arguments call s:SendCommand('-exec-arguments ' . <q-args>)
184+
command Stop call s:SendCommand('-exec-interrupt')
173185
command Continue call s:SendCommand('-exec-continue')
174186
command -range -nargs=* Evaluate call s:Evaluate(<range>, <q-args>)
175187
command Gdb call win_gotoid(s:gdbwin)
@@ -183,6 +195,7 @@ func s:InstallCommands()
183195
nnoremenu WinBar.Next :Over<CR>
184196
nnoremenu WinBar.Finish :Finish<CR>
185197
nnoremenu WinBar.Cont :Continue<CR>
198+
nnoremenu WinBar.Stop :Stop<CR>
186199
nnoremenu WinBar.Eval :Evaluate<CR>
187200
endif
188201
endfunc
@@ -194,6 +207,9 @@ func s:DeleteCommands()
194207
delcommand Step
195208
delcommand Over
196209
delcommand Finish
210+
delcommand Run
211+
delcommand Arguments
212+
delcommand Stop
197213
delcommand Continue
198214
delcommand Evaluate
199215
delcommand Gdb
@@ -206,6 +222,7 @@ func s:DeleteCommands()
206222
aunmenu WinBar.Next
207223
aunmenu WinBar.Finish
208224
aunmenu WinBar.Cont
225+
aunmenu WinBar.Stop
209226
aunmenu WinBar.Eval
210227
endif
211228

@@ -220,8 +237,19 @@ endfunc
220237

221238
" :Break - Set a breakpoint at the cursor position.
222239
func s:SetBreakpoint()
223-
call term_sendkeys(s:commbuf, '-break-insert --source '
224-
\ . fnameescape(expand('%:p')) . ' --line ' . line('.') . "\r")
240+
" Setting a breakpoint may not work while the program is running.
241+
" Interrupt to make it work.
242+
let do_continue = 0
243+
if !s:stopped
244+
let do_continue = 1
245+
call s:SendCommand('-exec-interrupt')
246+
sleep 10m
247+
endif
248+
call s:SendCommand('-break-insert --source '
249+
\ . fnameescape(expand('%:p')) . ' --line ' . line('.'))
250+
if do_continue
251+
call s:SendCommand('-exec-continue')
252+
endif
225253
endfunc
226254

227255
" :Delete - Delete a breakpoint at the cursor position.
@@ -244,6 +272,13 @@ func s:SendCommand(cmd)
244272
call term_sendkeys(s:commbuf, a:cmd . "\r")
245273
endfunc
246274

275+
func s:Run(args)
276+
if a:args != ''
277+
call s:SendCommand('-exec-arguments ' . a:args)
278+
endif
279+
call s:SendCommand('-exec-run')
280+
endfunc
281+
247282
" :Evaluate - evaluate what is under the cursor
248283
func s:Evaluate(range, arg)
249284
if a:arg != ''
@@ -259,7 +294,7 @@ func s:Evaluate(range, arg)
259294
else
260295
let expr = expand('<cexpr>')
261296
endif
262-
call term_sendkeys(s:commbuf, '-data-evaluate-expression "' . expr . "\"\r")
297+
call s:SendCommand('-data-evaluate-expression "' . expr . '"')
263298
let s:evalexpr = expr
264299
endfunc
265300

@@ -286,6 +321,12 @@ endfunc
286321
func s:HandleCursor(msg)
287322
let wid = win_getid(winnr())
288323

324+
if a:msg =~ '^\*stopped'
325+
let s:stopped = 1
326+
elseif a:msg =~ '^\*running'
327+
let s:stopped = 0
328+
endif
329+
289330
if win_gotoid(s:startwin)
290331
let fname = substitute(a:msg, '.*fullname="\([^"]*\)".*', '\1', '')
291332
if a:msg =~ '^\(\*stopped\|=thread-selected\)' && filereadable(fname)

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1293,
764766
/**/
765767
1292,
766768
/**/

0 commit comments

Comments
 (0)