Skip to content

Commit c4b533e

Browse files
committed
patch 8.0.1668: terminal debugger: can't re-open source code window
Problem: Terminal debugger: can't re-open source code window. Solution: Add the :Source command. Also create the window if needed when gdb stops at a source line.
1 parent 3680bab commit c4b533e

3 files changed

Lines changed: 50 additions & 29 deletions

File tree

‎runtime/doc/terminal.txt‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,11 @@ to have the 'mouse' option set to enable mouse clicks.
731731
You can add the window toolbar in other windows you open with: >
732732
:Winbar
733733
734+
If gdb stops at a source line and there is no window currently showing the
735+
source code, a new window will be created for the source code. This also
736+
happens if the buffer in the source code window has been modified and can't be
737+
abandoned.
738+
734739

735740
Inspecting variables ~
736741
*termdebug-variables*
@@ -745,8 +750,10 @@ You can usually shorten `:Evaluate` to `:Ev`.
745750

746751
Other commands ~
747752
*termdebug-commands*
748-
:Gdb jump to the gdb window
749-
:Program jump to the window with the running program
753+
:Gdb jump to the gdb window
754+
:Program jump to the window with the running program
755+
:Source jump to the window with the source code, create it if there
756+
isn't one
750757

751758

752759
Communication ~

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

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ func s:InstallCommands()
246246
command -range -nargs=* Evaluate call s:Evaluate(<range>, <q-args>)
247247
command Gdb call win_gotoid(s:gdbwin)
248248
command Program call win_gotoid(s:ptywin)
249+
command Source call s:GotoStartwinOrCreateIt()
249250
command Winbar call s:InstallWinbar()
250251

251252
" TODO: can the K mapping be restored?
@@ -269,13 +270,15 @@ let s:winbar_winids = []
269270

270271
" Install the window toolbar in the current window.
271272
func s:InstallWinbar()
272-
nnoremenu WinBar.Step :Step<CR>
273-
nnoremenu WinBar.Next :Over<CR>
274-
nnoremenu WinBar.Finish :Finish<CR>
275-
nnoremenu WinBar.Cont :Continue<CR>
276-
nnoremenu WinBar.Stop :Stop<CR>
277-
nnoremenu WinBar.Eval :Evaluate<CR>
278-
call add(s:winbar_winids, win_getid(winnr()))
273+
if has('menu') && &mouse != ''
274+
nnoremenu WinBar.Step :Step<CR>
275+
nnoremenu WinBar.Next :Over<CR>
276+
nnoremenu WinBar.Finish :Finish<CR>
277+
nnoremenu WinBar.Cont :Continue<CR>
278+
nnoremenu WinBar.Stop :Stop<CR>
279+
nnoremenu WinBar.Eval :Evaluate<CR>
280+
call add(s:winbar_winids, win_getid(winnr()))
281+
endif
279282
endfunc
280283

281284
" Delete installed debugger commands in the current window.
@@ -450,6 +453,14 @@ func s:HandleError(msg)
450453
echoerr substitute(a:msg, '.*msg="\(.*\)"', '\1', '')
451454
endfunc
452455

456+
func s:GotoStartwinOrCreateIt()
457+
if !win_gotoid(s:startwin)
458+
new
459+
let s:startwin = win_getid(winnr())
460+
call s:InstallWinbar()
461+
endif
462+
endfunc
463+
453464
" Handle stopping and running message from gdb.
454465
" Will update the sign that shows the current position.
455466
func s:HandleCursor(msg)
@@ -461,31 +472,32 @@ func s:HandleCursor(msg)
461472
let s:stopped = 0
462473
endif
463474

464-
if win_gotoid(s:startwin)
465-
let fname = substitute(a:msg, '.*fullname="\([^"]*\)".*', '\1', '')
466-
if a:msg =~ '^\(\*stopped\|=thread-selected\)' && filereadable(fname)
467-
let lnum = substitute(a:msg, '.*line="\([^"]*\)".*', '\1', '')
468-
if lnum =~ '^[0-9]*$'
469-
if expand('%:p') != fnamemodify(fname, ':p')
470-
if &modified
471-
" TODO: find existing window
472-
exe 'split ' . fnameescape(fname)
473-
let s:startwin = win_getid(winnr())
474-
else
475-
exe 'edit ' . fnameescape(fname)
476-
endif
475+
call s:GotoStartwinOrCreateIt()
476+
477+
let fname = substitute(a:msg, '.*fullname="\([^"]*\)".*', '\1', '')
478+
if a:msg =~ '^\(\*stopped\|=thread-selected\)' && filereadable(fname)
479+
let lnum = substitute(a:msg, '.*line="\([^"]*\)".*', '\1', '')
480+
if lnum =~ '^[0-9]*$'
481+
if expand('%:p') != fnamemodify(fname, ':p')
482+
if &modified
483+
" TODO: find existing window
484+
exe 'split ' . fnameescape(fname)
485+
let s:startwin = win_getid(winnr())
486+
call s:InstallWinbar()
487+
else
488+
exe 'edit ' . fnameescape(fname)
477489
endif
478-
exe lnum
479-
exe 'sign unplace ' . s:pc_id
480-
exe 'sign place ' . s:pc_id . ' line=' . lnum . ' name=debugPC file=' . fname
481-
setlocal signcolumn=yes
482490
endif
483-
else
491+
exe lnum
484492
exe 'sign unplace ' . s:pc_id
493+
exe 'sign place ' . s:pc_id . ' line=' . lnum . ' name=debugPC file=' . fname
494+
setlocal signcolumn=yes
485495
endif
486-
487-
call win_gotoid(wid)
496+
else
497+
exe 'sign unplace ' . s:pc_id
488498
endif
499+
500+
call win_gotoid(wid)
489501
endfunc
490502

491503
" Handle setting a breakpoint

‎src/version.c‎

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

763763
static int included_patches[] =
764764
{ /* Add new patch number below this line */
765+
/**/
766+
1668,
765767
/**/
766768
1667,
767769
/**/

0 commit comments

Comments
 (0)