From d2ea7cf10a4d026ebd402594d656af7d5c811c24 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sun, 30 May 2021 20:54:13 +0200 Subject: Update runtime files --- .../pack/dist/opt/termdebug/plugin/termdebug.vim | 46 +++++++++++++++++----- 1 file changed, 36 insertions(+), 10 deletions(-) (limited to 'runtime/pack') diff --git a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim index 117322da50..f80d9c396f 100644 --- a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim +++ b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim @@ -2,7 +2,7 @@ " " Author: Bram Moolenaar " Copyright: Vim license applies, see ":help license" -" Last Change: 2021 May 16 +" Last Change: 2021 May 18 " " WORK IN PROGRESS - Only the basics work " Note: On MS-Windows you need a recent version of gdb. The one included with @@ -176,6 +176,16 @@ func s:CloseBuffers() unlet! s:gdbwin endfunc +func s:CheckGdbRunning() + let gdbproc = term_getjob(s:gdbbuf) + if gdbproc == v:null || job_status(gdbproc) !=# 'run' + echoerr string(g:termdebugger) . ' exited unexpectedly' + call s:CloseBuffers() + return '' + endif + return 'ok' +endfunc + func s:StartDebug_term(dict) " Open a terminal window without a job, to run the debugged program in. let s:ptybuf = term_start('NONE', { @@ -216,7 +226,7 @@ func s:StartDebug_term(dict) let gdb_args = get(a:dict, 'gdb_args', []) let proc_args = get(a:dict, 'proc_args', []) - let cmd = [g:termdebugger, '-quiet', '-tty', pty] + gdb_args + let cmd = [g:termdebugger, '-quiet', '-tty', pty, '--eval-command', 'echo startupdone\n'] + gdb_args call ch_log('executing "' . join(cmd) . '"') let s:gdbbuf = term_start(cmd, { \ 'term_finish': 'close', @@ -228,9 +238,28 @@ func s:StartDebug_term(dict) endif let s:gdbwin = win_getid(winnr()) - " Set arguments to be run. First wait a bit to make detecting gdb a bit - " more reliable. - sleep 200m + " Wait for the "startupdone" message before sending any commands. + let try_count = 0 + while 1 + if s:CheckGdbRunning() != 'ok' + return + endif + + for lnum in range(1, 200) + if term_getline(s:gdbbuf, lnum) =~ 'startupdone' + let try_count = 9999 + break + endif + endfor + let try_count += 1 + if try_count > 300 + " done or give up after five seconds + break + endif + sleep 10m + endwhile + + " Set arguments to be run. if len(proc_args) call term_sendkeys(s:gdbbuf, 'set args ' . join(proc_args) . "\r") endif @@ -242,10 +271,7 @@ func s:StartDebug_term(dict) " why the debugger doesn't work. let try_count = 0 while 1 - let gdbproc = term_getjob(s:gdbbuf) - if gdbproc == v:null || job_status(gdbproc) !=# 'run' - echoerr string(g:termdebugger) . ' exited unexpectedly' - call s:CloseBuffers() + if s:CheckGdbRunning() != 'ok' return endif @@ -292,7 +318,7 @@ func s:StartDebug_term(dict) " "Type to continue" prompt. call s:SendCommand('set pagination off') - call job_setoptions(gdbproc, {'exit_cb': function('s:EndTermDebug')}) + call job_setoptions(term_getjob(s:gdbbuf), {'exit_cb': function('s:EndTermDebug')}) call s:StartDebugCommon(a:dict) endfunc -- cgit v1.2.3