1
0
forked from aniani/vim

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

// vs not act like exception from vim or termdebug

Signed-off-by: shane.xb.qian <shane.qian@foxmail.com>
This commit is contained in:
Shane-XB-Qian 2023-08-21 02:07:49 +08:00 committed by GitHub
parent 19968fc4ec
commit f6fb52b667
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -122,6 +122,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})
@ -134,12 +138,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
@ -238,7 +242,7 @@ endfunc
func s:CheckGdbRunning() func s:CheckGdbRunning()
let gdbproc = term_getjob(s:gdbbuf) let gdbproc = term_getjob(s:gdbbuf)
if gdbproc == v:null || job_status(gdbproc) !=# 'run' if gdbproc == v:null || job_status(gdbproc) !=# 'run'
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
@ -252,7 +256,7 @@ func s:StartDebug_term(dict)
\ 'vertical': s:vertical, \ 'vertical': s:vertical,
\ }) \ })
if s:ptybuf == 0 if s:ptybuf == 0
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(term_getjob(s:ptybuf))['tty_out'] let pty = job_info(term_getjob(s:ptybuf))['tty_out']
@ -274,7 +278,7 @@ func s:StartDebug_term(dict)
\ 'hidden': 1, \ 'hidden': 1,
\ }) \ })
if s:commbuf == 0 if s:commbuf == 0
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
@ -315,7 +319,7 @@ func s:StartDebug_term(dict)
\ 'term_finish': 'close', \ 'term_finish': 'close',
\ }) \ })
if s:gdbbuf == 0 if s:gdbbuf == 0
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
@ -367,7 +371,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
@ -386,7 +390,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
@ -445,7 +449,7 @@ func s:StartDebug_prompt(dict)
\ 'out_cb': function('s:GdbOutCallback'), \ 'out_cb': function('s:GdbOutCallback'),
\ }) \ })
if job_status(s:gdbjob) != "run" if job_status(s:gdbjob) != "run"
echoerr 'Failed to start gdb' call s:Echoerr('Failed to start gdb')
exe 'bwipe! ' . s:promptbuf exe 'bwipe! ' . s:promptbuf
return return
endif endif
@ -464,7 +468,7 @@ func s:StartDebug_prompt(dict)
\ 'term_name': 'debugged program', \ 'term_name': 'debugged program',
\ }) \ })
if s:ptybuf == 0 if s:ptybuf == 0
echoerr 'Failed to open the program terminal window' call s:Echoerr('Failed to open the program terminal window')
call job_stop(s:gdbjob) call job_stop(s:gdbjob)
return return
endif endif
@ -600,7 +604,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
@ -651,7 +655,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
@ -1154,7 +1158,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 . '.'
@ -1305,7 +1309,7 @@ func s:HandleError(msg)
return return
endif endif
let msgVal = substitute(a:msg, '.*msg="\(.*\)"', '\1', '') let msgVal = substitute(a:msg, '.*msg="\(.*\)"', '\1', '')
echoerr substitute(msgVal, '\\"', '"', 'g') call s:Echoerr(substitute(msgVal, '\\"', '"', 'g'))
endfunc endfunc
func s:GotoSourcewinOrCreateIt() func s:GotoSourcewinOrCreateIt()