Skip to content

Commit b3623a3

Browse files
committed
patch 8.0.1713: terminal debugger doesn't handle arguments
Problem: Terminal debugger doesn't handle arguments. Solution: Use <f-args> and pass all the arguments to gdb, e.g. the core file or process number. (suggested by Christian Brabandt) Disallow starting the debugger twice.
1 parent 8c041b6 commit b3623a3

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

runtime/doc/terminal.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,13 @@ the same as any command running in a terminal window.
649649
When the debugger ends, typically by typing "quit" in the gdb window, the two
650650
opened windows are closed.
651651

652+
Only one debugger can be active at a time.
653+
654+
To attach gdb to an already running executable, or use a core file, pass extra
655+
arguments. E.g.: >
656+
:Termdebug vim core
657+
:Termdebug vim 98343
658+
652659
653660
Example session ~
654661
*termdebug-example*

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ endif
2525

2626
" The command that starts debugging, e.g. ":Termdebug vim".
2727
" To end type "quit" in the gdb window.
28-
command -nargs=* -complete=file Termdebug call s:StartDebug(<q-args>)
28+
command -nargs=* -complete=file Termdebug call s:StartDebug(<f-args>)
2929

3030
" Name of the gdb command, defaults to "gdb".
3131
if !exists('termdebugger')
@@ -43,7 +43,12 @@ else
4343
endif
4444
hi default debugBreakpoint term=reverse ctermbg=red guibg=red
4545

46-
func s:StartDebug(cmd)
46+
func s:StartDebug(...)
47+
if exists('s:gdbwin')
48+
echoerr 'Terminal debugger already running'
49+
return
50+
endif
51+
4752
let s:startwin = win_getid(winnr())
4853
let s:startsigncolumn = &signcolumn
4954

@@ -90,7 +95,7 @@ func s:StartDebug(cmd)
9095

9196
" Open a terminal window to run the debugger.
9297
" Add -quiet to avoid the intro message causing a hit-enter prompt.
93-
let cmd = [g:termdebugger, '-quiet', '-tty', pty, a:cmd]
98+
let cmd = [g:termdebugger, '-quiet', '-tty', pty] + a:000
9499
echomsg 'executing "' . join(cmd) . '"'
95100
let s:gdbbuf = term_start(cmd, {
96101
\ 'exit_cb': function('s:EndDebug'),
@@ -112,7 +117,7 @@ func s:StartDebug(cmd)
112117
let try_count = 0
113118
while 1
114119
let response = ''
115-
for lnum in range(1,20)
120+
for lnum in range(1,200)
116121
if term_getline(s:gdbbuf, lnum) =~ 'new-ui mi '
117122
let response = term_getline(s:gdbbuf, lnum + 1)
118123
if response =~ 'Undefined command'
@@ -182,6 +187,7 @@ endfunc
182187
func s:EndDebug(job, status)
183188
exe 'bwipe! ' . s:ptybuf
184189
exe 'bwipe! ' . s:commbuf
190+
unlet s:gdbwin
185191

186192
let curwinid = win_getid(winnr())
187193

@@ -295,6 +301,7 @@ func s:DeleteCommands()
295301
delcommand Evaluate
296302
delcommand Gdb
297303
delcommand Program
304+
delcommand Source
298305
delcommand Winbar
299306

300307
nunmap K

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+
1713,
765767
/**/
766768
1712,
767769
/**/

0 commit comments

Comments
 (0)