vim-patch:f6fb52b667ee

runtime(termdebug): refactor error printing (vim/vim#12856)

// vs not act like exception from vim or termdebug

f6fb52b667

Co-authored-by: Shane-XB-Qian <shane.qian@foxmail.com>
This commit is contained in:
Sean Dewar
2023-08-21 10:34:50 +01:00
parent 949dd14d8b
commit 464472b4f7

View File

@@ -128,6 +128,10 @@ func s:GetCommand()
return type(cmd) == v:t_list ? copy(cmd) : [cmd] return type(cmd) == v:t_list ? copy(cmd) : [cmd]
endfunc endfunc
func s:Echoerr(msg)
echohl ErrorMsg | echom '[termdebug] ' .. a:msg | echohl None
endfunc
func s:StartDebug(bang, ...) func s:StartDebug(bang, ...)
" First argument is the command to debug, second core file or process ID. " First argument is the command to debug, second core file or process ID.
call s:StartDebug_internal({'gdb_args': a:000, 'bang': a:bang}) call s:StartDebug_internal({'gdb_args': a:000, 'bang': a:bang})
@@ -140,12 +144,12 @@ endfunc
func s:StartDebug_internal(dict) func s:StartDebug_internal(dict)
if exists('s:gdbwin') if exists('s:gdbwin')
echoerr 'Terminal debugger already running, cannot run two' call s:Echoerr('Terminal debugger already running, cannot run two')
return return
endif endif
let gdbcmd = s:GetCommand() let gdbcmd = s:GetCommand()
if !executable(gdbcmd[0]) if !executable(gdbcmd[0])
echoerr 'Cannot execute debugger program "' .. gdbcmd[0] .. '"' call s:Echoerr('Cannot execute debugger program "' .. gdbcmd[0] .. '"')
return return
endif endif
@@ -242,7 +246,7 @@ endfunc
func s:CheckGdbRunning() func s:CheckGdbRunning()
if !s:gdb_running if !s:gdb_running
echoerr string(s:GetCommand()[0]) . ' exited unexpectedly' call s:Echoerr(string(s:GetCommand()[0]) . ' exited unexpectedly')
call s:CloseBuffers() call s:CloseBuffers()
return '' return ''
endif endif
@@ -254,10 +258,10 @@ func s:StartDebug_term(dict)
execute s:vertical ? 'vnew' : 'new' execute s:vertical ? 'vnew' : 'new'
let s:pty_job_id = termopen('tail -f /dev/null;#gdb program') let s:pty_job_id = termopen('tail -f /dev/null;#gdb program')
if s:pty_job_id == 0 if s:pty_job_id == 0
echoerr 'invalid argument (or job table is full) while opening terminal window' call s:Echoerr('Invalid argument (or job table is full) while opening terminal window')
return return
elseif s:pty_job_id == -1 elseif s:pty_job_id == -1
echoerr 'Failed to open the program terminal window' call s:Echoerr('Failed to open the program terminal window')
return return
endif endif
let pty_job_info = nvim_get_chan_info(s:pty_job_id) let pty_job_info = nvim_get_chan_info(s:pty_job_id)
@@ -281,11 +285,11 @@ func s:StartDebug_term(dict)
\ }) \ })
" hide terminal buffer " hide terminal buffer
if s:comm_job_id == 0 if s:comm_job_id == 0
echoerr 'invalid argument (or job table is full) while opening communication terminal window' call s:Echoerr('Invalid argument (or job table is full) while opening communication terminal window')
exe 'bwipe! ' . s:ptybuf exe 'bwipe! ' . s:ptybuf
return return
elseif s:comm_job_id == -1 elseif s:comm_job_id == -1
echoerr 'Failed to open the communication terminal window' call s:Echoerr('Failed to open the communication terminal window')
exe 'bwipe! ' . s:ptybuf exe 'bwipe! ' . s:ptybuf
return return
endif endif
@@ -326,11 +330,11 @@ func s:StartDebug_term(dict)
" call ch_log('executing "' . join(gdb_cmd) . '"') " call ch_log('executing "' . join(gdb_cmd) . '"')
let s:gdb_job_id = termopen(gdb_cmd, {'on_exit': function('s:EndTermDebug')}) let s:gdb_job_id = termopen(gdb_cmd, {'on_exit': function('s:EndTermDebug')})
if s:gdb_job_id == 0 if s:gdb_job_id == 0
echoerr 'invalid argument (or job table is full) while opening gdb terminal window' call s:Echoerr('Invalid argument (or job table is full) while opening gdb terminal window')
exe 'bwipe! ' . s:ptybuf exe 'bwipe! ' . s:ptybuf
return return
elseif s:gdb_job_id == -1 elseif s:gdb_job_id == -1
echoerr 'Failed to open the gdb terminal window' call s:Echoerr('Failed to open the gdb terminal window')
call s:CloseBuffers() call s:CloseBuffers()
return return
endif endif
@@ -386,7 +390,7 @@ func s:StartDebug_term(dict)
" response can be in the same line or the next line " response can be in the same line or the next line
let response = line1 . line2 let response = line1 . line2
if response =~ 'Undefined command' if response =~ 'Undefined command'
echoerr 'Sorry, your gdb is too old, gdb 7.12 is required' call s:Echoerr('Sorry, your gdb is too old, gdb 7.12 is required')
" CHECKME: possibly send a "server show version" here " CHECKME: possibly send a "server show version" here
call s:CloseBuffers() call s:CloseBuffers()
return return
@@ -405,7 +409,7 @@ func s:StartDebug_term(dict)
endif endif
let try_count += 1 let try_count += 1
if try_count > 100 if try_count > 100
echoerr 'Cannot check if your gdb works, continuing anyway' call s:Echoerr('Cannot check if your gdb works, continuing anyway')
break break
endif endif
sleep 10m sleep 10m
@@ -464,11 +468,11 @@ func s:StartDebug_prompt(dict)
\ 'on_stdout': function('s:JobOutCallback', {'last_line': '', 'real_cb': function('s:GdbOutCallback')}), \ 'on_stdout': function('s:JobOutCallback', {'last_line': '', 'real_cb': function('s:GdbOutCallback')}),
\ }) \ })
if s:gdbjob == 0 if s:gdbjob == 0
echoerr 'invalid argument (or job table is full) while starting gdb job' call s:Echoerr('Invalid argument (or job table is full) while starting gdb job')
exe 'bwipe! ' . s:ptybuf exe 'bwipe! ' . s:ptybuf
return return
elseif s:gdbjob == -1 elseif s:gdbjob == -1
echoerr 'Failed to start the gdb job' call s:Echoerr('Failed to start the gdb job')
call s:CloseBuffers() call s:CloseBuffers()
return return
endif endif
@@ -484,10 +488,10 @@ func s:StartDebug_prompt(dict)
wincmd x | wincmd j wincmd x | wincmd j
belowright let s:pty_job_id = termopen('tail -f /dev/null;#gdb program') belowright let s:pty_job_id = termopen('tail -f /dev/null;#gdb program')
if s:pty_job_id == 0 if s:pty_job_id == 0
echoerr 'invalid argument (or job table is full) while opening terminal window' call s:Echoerr('Invalid argument (or job table is full) while opening terminal window')
return return
elseif s:pty_job_id == -1 elseif s:pty_job_id == -1
echoerr 'Failed to open the program terminal window' call s:Echoerr('Failed to open the program terminal window')
return return
endif endif
let pty_job_info = nvim_get_chan_info(s:pty_job_id) let pty_job_info = nvim_get_chan_info(s:pty_job_id)
@@ -616,7 +620,7 @@ func s:PromptInterrupt()
" Using job_stop() does not work on MS-Windows, need to send SIGTRAP to " Using job_stop() does not work on MS-Windows, need to send SIGTRAP to
" the debugger program so that gdb responds again. " the debugger program so that gdb responds again.
if s:pid == 0 if s:pid == 0
echoerr 'Cannot interrupt gdb, did not find a process ID' call s:Echoerr('Cannot interrupt gdb, did not find a process ID')
else else
call debugbreak(s:pid) call debugbreak(s:pid)
endif endif
@@ -696,7 +700,7 @@ endfunc
" - change \\ to \ " - change \\ to \
func s:DecodeMessage(quotedText, literal) func s:DecodeMessage(quotedText, literal)
if a:quotedText[0] != '"' if a:quotedText[0] != '"'
echoerr 'DecodeMessage(): missing quote in ' . a:quotedText call s:Echoerr('DecodeMessage(): missing quote in ' . a:quotedText)
return return
endif endif
let msg = a:quotedText let msg = a:quotedText
@@ -1189,7 +1193,7 @@ func s:ClearBreakpoint()
endif endif
echomsg 'Breakpoint ' . id . ' cleared from line ' . lnum . '.' echomsg 'Breakpoint ' . id . ' cleared from line ' . lnum . '.'
else else
echoerr 'Internal error trying to remove breakpoint at line ' . lnum . '!' call s:Echoerr('Internal error trying to remove breakpoint at line ' . lnum . '!')
endif endif
else else
echomsg 'No breakpoint to remove at line ' . lnum . '.' echomsg 'No breakpoint to remove at line ' . lnum . '.'
@@ -1447,7 +1451,7 @@ func s:HandleError(msg)
let s:evalFromBalloonExpr = 0 let s:evalFromBalloonExpr = 0
return return
endif endif
let msgVal = substitute(a:msg, '.*msg="\(.*\)"', '\1', '') let msgVal = substitute(a:msg, '.*msg="\(.*\)"', '\1', '')
call s:Echoerr(substitute(msgVal, '\\"', '"', 'g')) call s:Echoerr(substitute(msgVal, '\\"', '"', 'g'))
endfunc endfunc