Skip to content

Commit 71137fe

Browse files
committed
patch 8.0.1562: the terminal debugger can't set a breakpoint with the mouse
Problem: The terminal debugger can't set a breakpoint with the mouse. Solution: Add popup menu entries.
1 parent 069dafc commit 71137fe

File tree

3 files changed

+103
-43
lines changed

3 files changed

+103
-43
lines changed

runtime/doc/terminal.txt

+49-27
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
Terminal window support *terminal*
88

99

10-
WARNING: THIS IS ONLY PARTLY IMPLEMENTED, ANYTHING CAN STILL CHANGE
11-
1210
The terminal feature is optional, use this to check if your Vim has it: >
1311
echo has('terminal')
1412
If the result is "1" you have it.
@@ -40,7 +38,6 @@ If the result is "1" you have it.
4038

4139
{Vi does not have any of these commands}
4240
{only available when compiled with the |+terminal| feature}
43-
4441
The terminal feature requires the |+multi_byte|, |+job| and |+channel| features.
4542

4643
==============================================================================
@@ -481,7 +478,7 @@ program window A terminal window for the executed program. When "run" is
481478

482479
The current window is used to show the source code. When gdb pauses the
483480
source file location will be displayed, if possible. A sign is used to
484-
highlight the current position (using highlight group debugPC).
481+
highlight the current position, using highlight group debugPC.
485482

486483
If the buffer in the current window is modified, another window will be opened
487484
to display the current gdb position.
@@ -506,6 +503,7 @@ You should now have three windows:
506503
source - where you started, has a window toolbar with buttons
507504
gdb - you can type gdb commands here
508505
program - the executed program will use this window
506+
509507
You can use CTRL-W CTRL-W or the mouse to move focus between windows.
510508
Put focus on the gdb window and type: >
511509
break ex_help
@@ -526,6 +524,8 @@ displayed:
526524
This way you can inspect the value of local variables. You can also focus the
527525
gdb window and use a "print" command, e.g.: >
528526
print *eap
527+
If mouse pointer movements are working, Vim will also show a balloon when the
528+
mouse rests on text that can be evaluated by gdb.
529529

530530
Now go back to the source window and put the cursor on the first line after
531531
the for loop, then type: >
@@ -561,38 +561,42 @@ Put focus on the gdb window to type commands there. Some common ones are:
561561
- frame N go to the Nth stack frame
562562
- continue continue execution
563563

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

568-
:Break set a breakpoint at the current line; a sign will be displayed
569-
:Delete delete a breakpoint at the current line
568+
`:Break` set a breakpoint at the current line; a sign will be displayed
569+
`:Clear` delete the breakpoint at the current line
570570

571-
:Step execute the gdb "step" command
572-
:Over execute the gdb "next" command (:Next is a Vim command)
573-
:Finish execute the gdb "finish" command
574-
:Continue execute the gdb "continue" command
575-
:Stop interrupt the program
571+
`:Step` execute the gdb "step" command
572+
`:Over` execute the gdb "next" command (`:Next` is a Vim command)
573+
`:Finish` execute the gdb "finish" command
574+
`:Continue` execute the gdb "continue" command
575+
`:Stop` interrupt the program
576576

577577
If 'mouse' is set the plugin adds a window toolbar with these entries:
578-
Step :Step
579-
Next :Over
580-
Finish :Finish
581-
Cont :Continue
582-
Stop :Stop
583-
Eval :Evaluate
578+
Step `:Step`
579+
Next `:Over`
580+
Finish `:Finish`
581+
Cont `:Continue`
582+
Stop `:Stop`
583+
Eval `:Evaluate`
584584
This way you can use the mouse to perform the most common commands. You need
585585
to have the 'mouse' option set to enable mouse clicks.
586586

587+
You can add the window toolbar in other windows you open with: >
588+
:Winbar
589+
587590
588591
Inspecting variables ~
589592
*termdebug-variables*
590-
:Evaluate evaluate the expression under the cursor
591-
K same
592-
:Evaluate {expr} evaluate {expr}
593-
:'<,'>Evaluate evaluate the Visually selected text
593+
`:Evaluate` evaluate the expression under the cursor
594+
`K` same
595+
`:Evaluate` {expr} evaluate {expr}
596+
`:'<,'>Evaluate` evaluate the Visually selected text
594597

595598
This is similar to using "print" in the gdb window.
599+
You can usually shorten `:Evaluate` to `:Ev`.
596600

597601

598602
Other commands ~
@@ -609,17 +613,21 @@ will break the debugger.
609613

610614

611615
Customizing ~
612-
*termdebug-customizing*
616+
617+
GDB command *termdebug-customizing*
618+
613619
To change the name of the gdb command, set the "termdebugger" variable before
614620
invoking `:Termdebug`: >
615621
let termdebugger = "mygdb"
616-
< *gdb-version*
622+
< *gdb-version*
617623
Only debuggers fully compatible with gdb will work. Vim uses the GDB/MI
618624
interface. This probably requires gdb version 7.12. if you get this error:
619625
Undefined command: "new-ui". Try "help".~
620626
Then your gdb is too old.
621627

622-
*hl-debugPC* *hl-debugBreakpoint*
628+
629+
Colors *hl-debugPC* *hl-debugBreakpoint*
630+
623631
The color of the signs can be adjusted with these highlight groups:
624632
- debugPC the current position
625633
- debugBreakpoint a breakpoint
@@ -632,6 +640,20 @@ When 'background' is "dark":
632640
hi debugPC term=reverse ctermbg=darkblue guibg=darkblue
633641
hi debugBreakpoint term=reverse ctermbg=red guibg=red
634642

643+
644+
Popup menu *termdebug_popup*
645+
646+
By default the Termdebug plugin sets 'mousemodel' to "popup_setpos" and adds
647+
these entries to the popup menu:
648+
Set breakpoint `:Break`
649+
Clear breakpoint `:Clear`
650+
Evaluate `:Evaluate`
651+
If you don't want this then disable it with: >
652+
let g:termdebug_popup = 0
653+
654+
655+
Vim window width *termdebug_wide*
656+
635657
To change the width of the Vim window when debugging starts, and use a
636658
vertical split: >
637659
let g:termdebug_wide = 163

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

+52-16
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ endfunc
201201
" Install commands in the current window to control the debugger.
202202
func s:InstallCommands()
203203
command Break call s:SetBreakpoint()
204-
command Delete call s:DeleteBreakpoint()
204+
command Clear call s:ClearBreakpoint()
205205
command Step call s:SendCommand('-exec-step')
206206
command Over call s:SendCommand('-exec-next')
207207
command Finish call s:SendCommand('-exec-finish')
@@ -212,24 +212,42 @@ func s:InstallCommands()
212212
command -range -nargs=* Evaluate call s:Evaluate(<range>, <q-args>)
213213
command Gdb call win_gotoid(s:gdbwin)
214214
command Program call win_gotoid(s:ptywin)
215+
command Winbar call s:InstallWinbar()
215216

216217
" TODO: can the K mapping be restored?
217218
nnoremap K :Evaluate<CR>
218219
219220
if has('menu') && &mouse != ''
220-
nnoremenu WinBar.Step :Step<CR>
221-
nnoremenu WinBar.Next :Over<CR>
222-
nnoremenu WinBar.Finish :Finish<CR>
223-
nnoremenu WinBar.Cont :Continue<CR>
224-
nnoremenu WinBar.Stop :Stop<CR>
225-
nnoremenu WinBar.Eval :Evaluate<CR>
221+
call s:InstallWinbar()
222+
223+
if !exists('g:termdebug_popup') || g:termdebug_popup != 0
224+
let s:saved_mousemodel = &mousemodel
225+
let &mousemodel = 'popup_setpos'
226+
an 1.200 PopUp.-SEP3- <Nop>
227+
an 1.210 PopUp.Set\ breakpoint :Break<CR>
228+
an 1.220 PopUp.Clear\ breakpoint :Clear<CR>
229+
an 1.230 PopUp.Evaluate :Evaluate<CR>
230+
endif
226231
endif
227232
endfunc
228233

234+
let s:winbar_winids = []
235+
236+
" Install the window toolbar in the current window.
237+
func s:InstallWinbar()
238+
nnoremenu WinBar.Step :Step<CR>
239+
nnoremenu WinBar.Next :Over<CR>
240+
nnoremenu WinBar.Finish :Finish<CR>
241+
nnoremenu WinBar.Cont :Continue<CR>
242+
nnoremenu WinBar.Stop :Stop<CR>
243+
nnoremenu WinBar.Eval :Evaluate<CR>
244+
call add(s:winbar_winids, win_getid(winnr()))
245+
endfunc
246+
229247
" Delete installed debugger commands in the current window.
230248
func s:DeleteCommands()
231249
delcommand Break
232-
delcommand Delete
250+
delcommand Clear
233251
delcommand Step
234252
delcommand Over
235253
delcommand Finish
@@ -240,16 +258,34 @@ func s:DeleteCommands()
240258
delcommand Evaluate
241259
delcommand Gdb
242260
delcommand Program
261+
delcommand Winbar
243262

244263
nunmap K
245264

246265
if has('menu')
247-
aunmenu WinBar.Step
248-
aunmenu WinBar.Next
249-
aunmenu WinBar.Finish
250-
aunmenu WinBar.Cont
251-
aunmenu WinBar.Stop
252-
aunmenu WinBar.Eval
266+
" Remove the WinBar entries from all windows where it was added.
267+
let curwinid = win_getid(winnr())
268+
for winid in s:winbar_winids
269+
if win_gotoid(winid)
270+
aunmenu WinBar.Step
271+
aunmenu WinBar.Next
272+
aunmenu WinBar.Finish
273+
aunmenu WinBar.Cont
274+
aunmenu WinBar.Stop
275+
aunmenu WinBar.Eval
276+
endif
277+
endfor
278+
call win_gotoid(curwinid)
279+
let s:winbar_winids = []
280+
281+
if exists('s:saved_mousemodel')
282+
let &mousemodel = s:saved_mousemodel
283+
unlet s:saved_mousemodel
284+
aunmenu PopUp.-SEP3-
285+
aunmenu PopUp.Set\ breakpoint
286+
aunmenu PopUp.Clear\ breakpoint
287+
aunmenu PopUp.Evaluate
288+
endif
253289
endif
254290

255291
exe 'sign unplace ' . s:pc_id
@@ -278,8 +314,8 @@ func s:SetBreakpoint()
278314
endif
279315
endfunc
280316

281-
" :Delete - Delete a breakpoint at the cursor position.
282-
func s:DeleteBreakpoint()
317+
" :Clear - Delete a breakpoint at the cursor position.
318+
func s:ClearBreakpoint()
283319
let fname = fnameescape(expand('%:p'))
284320
let lnum = line('.')
285321
for [key, val] in items(s:breakpoints)

src/version.c

+2
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,8 @@ static char *(features[]) =
778778

779779
static int included_patches[] =
780780
{ /* Add new patch number below this line */
781+
/**/
782+
1562,
781783
/**/
782784
1561,
783785
/**/

0 commit comments

Comments
 (0)