1
0
forked from aniani/vim

runtime(termdebug): Use string interpolation instead of string concat

closes: #14972

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Yegappan Lakshmanan
2024-06-12 20:37:05 +02:00
committed by Christian Brabandt
parent 7c57940e3b
commit 83d0028026

View File

@@ -148,9 +148,9 @@ enddef
def Highlight(init: bool, old: string, new: string) def Highlight(init: bool, old: string, new: string)
var default = init ? 'default ' : '' var default = init ? 'default ' : ''
if new ==# 'light' && old !=# 'light' if new ==# 'light' && old !=# 'light'
exe "hi " .. default .. "debugPC term=reverse ctermbg=lightblue guibg=lightblue" exe $"hi {default}debugPC term=reverse ctermbg=lightblue guibg=lightblue"
elseif new ==# 'dark' && old !=# 'dark' elseif new ==# 'dark' && old !=# 'dark'
exe "hi " .. default .. "debugPC term=reverse ctermbg=darkblue guibg=darkblue" exe $"hi {default}debugPC term=reverse ctermbg=darkblue guibg=darkblue"
endif endif
enddef enddef
@@ -183,17 +183,17 @@ def GetCommand(): list<string>
enddef enddef
def Echoerr(msg: string) def Echoerr(msg: string)
echohl ErrorMsg | echom '[termdebug] ' .. msg | echohl None echohl ErrorMsg | echom $'[termdebug] {msg}' | echohl None
enddef enddef
def StartDebug(bang: bool, ...gdb_args: list<string>) def StartDebug(bang: bool, ...gdb_args: list<string>)
# 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.
StartDebug_internal({'gdb_args': gdb_args, 'bang': bang}) StartDebug_internal({gdb_args: gdb_args, bang: bang})
enddef enddef
def StartDebugCommand(bang: bool, ...args: list<string>) def StartDebugCommand(bang: bool, ...args: list<string>)
# First argument is the command to debug, rest are run arguments. # First argument is the command to debug, rest are run arguments.
StartDebug_internal({'gdb_args': [args[0]], 'proc_args': args[1 : ], 'bang': bang}) StartDebug_internal({gdb_args: [args[0]], proc_args: args[1 : ], bang: bang})
enddef enddef
@@ -204,7 +204,7 @@ def StartDebug_internal(dict: dict<any>)
endif endif
var gdbcmd = GetCommand() var gdbcmd = GetCommand()
if !executable(gdbcmd[0]) if !executable(gdbcmd[0])
Echoerr('Cannot execute debugger program "' .. gdbcmd[0] .. '"') Echoerr($'Cannot execute debugger program "{gdbcmd[0]}"')
return return
endif endif
@@ -272,13 +272,13 @@ enddef
# Use when debugger didn't start or ended. # Use when debugger didn't start or ended.
def CloseBuffers() def CloseBuffers()
exe 'bwipe! ' .. ptybuf exe $'bwipe! {ptybuf}'
exe 'bwipe! ' .. commbuf exe $'bwipe! {commbuf}'
if asmbuf > 0 && bufexists(asmbuf) if asmbuf > 0 && bufexists(asmbuf)
exe 'bwipe! ' .. asmbuf exe $'bwipe! {asmbuf}'
endif endif
if varbuf > 0 && bufexists(varbuf) if varbuf > 0 && bufexists(varbuf)
exe 'bwipe! ' .. varbuf exe $'bwipe! {varbuf}'
endif endif
running = 0 running = 0
gdbwin = 0 gdbwin = 0
@@ -292,7 +292,8 @@ def CheckGdbRunning(): string
gdbproc_status = job_status(gdbproc) gdbproc_status = job_status(gdbproc)
endif endif
if gdbproc == v:null || gdbproc_status !=# 'run' if gdbproc == v:null || gdbproc_status !=# 'run'
Echoerr(string(GetCommand()[0]) .. ' exited unexpectedly') var cmd_name = string(GetCommand()[0])
Echoerr($'{cmd_name} exited unexpectedly')
CloseBuffers() CloseBuffers()
return '' return ''
endif endif
@@ -313,7 +314,7 @@ def StartDebug_term(dict: dict<any>)
if vvertical if vvertical
# Assuming the source code window will get a signcolumn, use two more # Assuming the source code window will get a signcolumn, use two more
# columns for that, thus one less for the terminal window. # columns for that, thus one less for the terminal window.
exe ":" .. (&columns / 2 - 1) .. "wincmd |" exe $":{(&columns / 2 - 1)}wincmd |"
if allleft if allleft
# use the whole left column # use the whole left column
wincmd H wincmd H
@@ -328,7 +329,7 @@ def StartDebug_term(dict: dict<any>)
}) })
if commbuf == 0 if commbuf == 0
Echoerr('Failed to open the communication terminal window') Echoerr('Failed to open the communication terminal window')
exe 'bwipe! ' .. ptybuf exe $'bwipe! {ptybuf}'
return return
endif endif
var commpty = job_info(term_getjob(commbuf))['tty_out'] var commpty = job_info(term_getjob(commbuf))['tty_out']
@@ -363,7 +364,7 @@ def StartDebug_term(dict: dict<any>)
# Adding arguments requested by the user # Adding arguments requested by the user
gdb_cmd += gdb_args gdb_cmd += gdb_args
ch_log('executing "' .. join(gdb_cmd) .. '"') ch_log($'executing "{join(gdb_cmd)}"')
gdbbuf = term_start(gdb_cmd, { gdbbuf = term_start(gdb_cmd, {
term_name: 'gdb', term_name: 'gdb',
term_finish: 'close', term_finish: 'close',
@@ -405,12 +406,12 @@ def StartDebug_term(dict: dict<any>)
# ---- gdb started. Next, let's set the MI interface. --- # ---- gdb started. Next, let's set the MI interface. ---
# Set arguments to be run. # Set arguments to be run.
if len(proc_args) if len(proc_args)
term_sendkeys(gdbbuf, 'server set args ' .. join(proc_args) .. "\r") term_sendkeys(gdbbuf, $"server set args {join(proc_args)}\r")
endif endif
# Connect gdb to the communication pty, using the GDB/MI interface. # Connect gdb to the communication pty, using the GDB/MI interface.
# Prefix "server" to avoid adding this to the history. # Prefix "server" to avoid adding this to the history.
term_sendkeys(gdbbuf, 'server new-ui mi ' .. commpty .. "\r") term_sendkeys(gdbbuf, $"server new-ui mi {commpty}\r")
# Wait for the response to show up, users may not notice the error and wonder # Wait for the response to show up, users may not notice the error and wonder
# why the debugger doesn't work. # why the debugger doesn't work.
@@ -456,7 +457,7 @@ def StartDebug_term(dict: dict<any>)
return return
endif endif
job_setoptions(term_getjob(gdbbuf), {'exit_cb': function('EndTermDebug')}) job_setoptions(term_getjob(gdbbuf), {exit_cb: function('EndTermDebug')})
# Set the filetype, this can be used to add mappings. # Set the filetype, this can be used to add mappings.
set filetype=termdebug set filetype=termdebug
@@ -493,7 +494,7 @@ def StartDebug_prompt(dict: dict<any>)
if vvertical if vvertical
# Assuming the source code window will get a signcolumn, use two more # Assuming the source code window will get a signcolumn, use two more
# columns for that, thus one less for the terminal window. # columns for that, thus one less for the terminal window.
exe ":" .. (&columns / 2 - 1) .. "wincmd |" exe $":{(&columns / 2 - 1)}wincmd |"
endif endif
var gdb_args = get(dict, 'gdb_args', []) var gdb_args = get(dict, 'gdb_args', [])
@@ -514,14 +515,14 @@ def StartDebug_prompt(dict: dict<any>)
# Adding arguments requested by the user # Adding arguments requested by the user
gdb_cmd += gdb_args gdb_cmd += gdb_args
ch_log('executing "' .. join(gdb_cmd) .. '"') ch_log($'executing "{join(gdb_cmd)}"')
gdbjob = job_start(gdb_cmd, { gdbjob = job_start(gdb_cmd, {
exit_cb: function('EndPromptDebug'), exit_cb: function('EndPromptDebug'),
out_cb: function('GdbOutCallback'), out_cb: function('GdbOutCallback'),
}) })
if job_status(gdbjob) != "run" if job_status(gdbjob) != "run"
Echoerr('Failed to start gdb') Echoerr('Failed to start gdb')
exe 'bwipe! ' .. promptbuf exe $'bwipe! {promptbuf}'
return return
endif endif
exe $'au BufUnload <buffer={promptbuf}> ++once ' .. exe $'au BufUnload <buffer={promptbuf}> ++once ' ..
@@ -547,16 +548,16 @@ def StartDebug_prompt(dict: dict<any>)
endif endif
ptywin = win_getid() ptywin = win_getid()
var pty = job_info(term_getjob(ptybuf))['tty_out'] var pty = job_info(term_getjob(ptybuf))['tty_out']
SendCommand('tty ' .. pty) SendCommand($'tty {pty}')
# Since GDB runs in a prompt window, the environment has not been set to # Since GDB runs in a prompt window, the environment has not been set to
# match a terminal window, need to do that now. # match a terminal window, need to do that now.
SendCommand('set env TERM = xterm-color') SendCommand('set env TERM = xterm-color')
SendCommand('set env ROWS = ' .. winheight(ptywin)) SendCommand($'set env ROWS = {winheight(ptywin)}')
SendCommand('set env LINES = ' .. winheight(ptywin)) SendCommand($'set env LINES = {winheight(ptywin)}')
SendCommand('set env COLUMNS = ' .. winwidth(ptywin)) SendCommand($'set env COLUMNS = {winwidth(ptywin)}')
SendCommand('set env COLORS = ' .. &t_Co) SendCommand($'set env COLORS = {&t_Co}')
SendCommand('set env VIM_TERMINAL = ' .. v:version) SendCommand($'set env VIM_TERMINAL = {v:version}')
else else
# TODO: open a new terminal, get the tty name, pass on to gdb # TODO: open a new terminal, get the tty name, pass on to gdb
SendCommand('show inferior-tty') SendCommand('show inferior-tty')
@@ -566,7 +567,7 @@ def StartDebug_prompt(dict: dict<any>)
# Set arguments to be run # Set arguments to be run
if len(proc_args) if len(proc_args)
SendCommand('set args ' .. join(proc_args)) SendCommand($'set args {join(proc_args)}')
endif endif
StartDebugCommon(dict) StartDebugCommon(dict)
@@ -576,7 +577,7 @@ enddef
def StartDebugCommon(dict: dict<any>) def StartDebugCommon(dict: dict<any>)
# Sign used to highlight the line where the program has stopped. # Sign used to highlight the line where the program has stopped.
# There can be only one. # There can be only one.
sign_define('debugPC', {'linehl': 'debugPC'}) sign_define('debugPC', {linehl: 'debugPC'})
# Install debugger commands in the text window. # Install debugger commands in the text window.
win_gotoid(sourcewin) win_gotoid(sourcewin)
@@ -610,11 +611,11 @@ enddef
# Send a command to gdb. "cmd" is the string without line terminator. # Send a command to gdb. "cmd" is the string without line terminator.
def SendCommand(cmd: string) def SendCommand(cmd: string)
ch_log('sending to gdb: ' .. cmd) ch_log($'sending to gdb: {cmd}')
if way == 'prompt' if way == 'prompt'
ch_sendraw(gdb_channel, cmd .. "\n") ch_sendraw(gdb_channel, $"{cmd}\n")
else else
term_sendkeys(commbuf, cmd .. "\r") term_sendkeys(commbuf, $"{cmd}\r")
endif endif
enddef enddef
@@ -642,7 +643,7 @@ enddef
# This is global so that a user can create their mappings with this. # This is global so that a user can create their mappings with this.
def TermDebugSendCommand(cmd: string) def TermDebugSendCommand(cmd: string)
if way == 'prompt' if way == 'prompt'
ch_sendraw(gdb_channel, cmd .. "\n") ch_sendraw(gdb_channel, $"{cmd}\n")
else else
var do_continue = 0 var do_continue = 0
if !stopped if !stopped
@@ -651,7 +652,7 @@ def TermDebugSendCommand(cmd: string)
sleep 10m sleep 10m
endif endif
# TODO: should we prepend CTRL-U to clear the command? # TODO: should we prepend CTRL-U to clear the command?
term_sendkeys(gdbbuf, cmd .. "\r") term_sendkeys(gdbbuf, $"{cmd}\r")
if do_continue if do_continue
ContinueCommand() ContinueCommand()
endif endif
@@ -668,7 +669,7 @@ def SendResumingCommand(cmd: string)
ch_log('assume that program is running after this command') ch_log('assume that program is running after this command')
SendCommand(cmd) SendCommand(cmd)
else else
ch_log('dropping command, program is running: ' .. cmd) ch_log($'dropping command, program is running: {cmd}')
endif endif
enddef enddef
@@ -696,7 +697,7 @@ enddef
# Function called when gdb outputs text. # Function called when gdb outputs text.
def GdbOutCallback(channel: channel, text: string) def GdbOutCallback(channel: channel, text: string)
ch_log('received from gdb: ' .. text) ch_log($'received from gdb: {text}')
# Disassembly messages need to be forwarded as-is. # Disassembly messages need to be forwarded as-is.
if parsing_disasm_msg > 0 if parsing_disasm_msg > 0
@@ -746,7 +747,7 @@ enddef
# - change \\ to \ # - change \\ to \
def DecodeMessage(quotedText: string, literal: bool): string def DecodeMessage(quotedText: string, literal: bool): string
if quotedText[0] != '"' if quotedText[0] != '"'
Echoerr('DecodeMessage(): missing quote in ' .. quotedText) Echoerr($'DecodeMessage(): missing quote in {quotedText}')
return '' return ''
endif endif
var msg = quotedText var msg = quotedText
@@ -805,7 +806,7 @@ def EndTermDebug(job: any, status: any)
endif endif
if bufexists(commbuf) if bufexists(commbuf)
exe 'bwipe! ' .. commbuf exe $'bwipe! {commbuf}'
endif endif
gdbwin = 0 gdbwin = 0
EndDebugCommon() EndDebugCommon()
@@ -815,13 +816,13 @@ def EndDebugCommon()
var curwinid = win_getid() var curwinid = win_getid()
if bufexists(ptybuf) if bufexists(ptybuf)
exe 'bwipe! ' .. ptybuf exe $'bwipe! {ptybuf}'
endif endif
if bufexists(asmbuf) if bufexists(asmbuf)
exe 'bwipe! ' .. asmbuf exe $'bwipe! {asmbuf}'
endif endif
if bufexists(varbuf) if bufexists(varbuf)
exe 'bwipe! ' .. varbuf exe $'bwipe! {varbuf}'
endif endif
running = 0 running = 0
@@ -830,7 +831,7 @@ def EndDebugCommon()
var was_buf = bufnr() var was_buf = bufnr()
for bufnr in signcolumn_buflist for bufnr in signcolumn_buflist
if bufexists(bufnr) if bufexists(bufnr)
exe ":" .. bufnr .. "buf" exe $":{bufnr}buf"
if exists('b:save_signcolumn') if exists('b:save_signcolumn')
&signcolumn = b:save_signcolumn &signcolumn = b:save_signcolumn
unlet b:save_signcolumn unlet b:save_signcolumn
@@ -838,7 +839,7 @@ def EndDebugCommon()
endif endif
endfor endfor
if bufexists(was_buf) if bufexists(was_buf)
exe ":" .. was_buf .. "buf" exe $":{was_buf}buf"
endif endif
DeleteCommands() DeleteCommands()
@@ -872,7 +873,7 @@ def EndPromptDebug(job: any, status: any)
endif endif
if bufexists(promptbuf) if bufexists(promptbuf)
exe 'bwipe! ' .. promptbuf exe $'bwipe! {promptbuf}'
endif endif
EndDebugCommon() EndDebugCommon()
@@ -904,10 +905,10 @@ def HandleDisasmMsg(msg: string)
set nomodified set nomodified
set filetype=asm set filetype=asm
var lnum = search('^' .. asm_addr) var lnum = search($'^{asm_addr}')
if lnum != 0 if lnum != 0
sign_unplace('TermDebug', {'id': asm_id}) sign_unplace('TermDebug', {id: asm_id})
sign_place(asm_id, 'TermDebug', 'debugPC', '%', {'lnum': lnum}) sign_place(asm_id, 'TermDebug', 'debugPC', '%', {lnum: lnum})
endif endif
win_gotoid(curwinid) win_gotoid(curwinid)
@@ -966,8 +967,8 @@ def HandleVariablesMsg(msg: string)
if win_gotoid(varwin) if win_gotoid(varwin)
silent! :%delete _ silent! :%delete _
var spaceBuffer = 20 var spaceBuffer = 20
setline(1, 'Type' .. var spaces = repeat(' ', 16)
repeat(' ', 16) .. 'Name' .. repeat(' ', 16) .. 'Value') setline(1, $'Type{spaces}Name{spaces}Value')
var cnt = 1 var cnt = 1
var capture = '{name=".\{-}",\%(arg=".\{-}",\)\{0,1\}type=".\{-}"\%(,value=".\{-}"\)\{0,1\}}' var capture = '{name=".\{-}",\%(arg=".\{-}",\)\{0,1\}type=".\{-}"\%(,value=".\{-}"\)\{0,1\}}'
var varinfo = matchstr(msg, capture, 0, cnt) var varinfo = matchstr(msg, capture, 0, cnt)
@@ -1251,9 +1252,8 @@ def Until(at: string)
ch_log('assume that program is running after this command') ch_log('assume that program is running after this command')
# Use the fname:lnum format # Use the fname:lnum format
var AT = empty(at) ? var AT = empty(at) ? $"{fnameescape(expand('%:p'))}:{line('.')}" : at
fnameescape(expand('%:p')) .. ':' .. line('.') : at SendCommand($'-exec-until {AT}')
SendCommand('-exec-until ' .. AT)
else else
ch_log('dropping command, program is running: exec-until') ch_log('dropping command, program is running: exec-until')
endif endif
@@ -1271,16 +1271,15 @@ def SetBreakpoint(at: string, tbreak=false)
endif endif
# Use the fname:lnum format, older gdb can't handle --source. # Use the fname:lnum format, older gdb can't handle --source.
var AT = empty(at) ? var AT = empty(at) ? $"{fnameescape(expand('%:p'))}:{line('.')}" : at
fnameescape(expand('%:p')) .. ':' .. line('.') : at
var cmd = '' var cmd = ''
if tbreak if tbreak
cmd = '-break-insert -t ' .. AT cmd = $'-break-insert -t {AT}'
else else
cmd = '-break-insert ' .. AT cmd = $'-break-insert {AT}'
endif endif
# OK # OK
# echom "cmsd: " .. cmd # echom $"cmsd: {cmd}"
SendCommand(cmd) SendCommand(cmd)
if do_continue if do_continue
ContinueCommand() ContinueCommand()
@@ -1297,7 +1296,7 @@ def ClearBreakpoint()
for id in breakpoint_locations[bploc] for id in breakpoint_locations[bploc]
if has_key(breakpoints, id) if has_key(breakpoints, id)
# Assume this always works, the reply is simply "^done". # Assume this always works, the reply is simply "^done".
SendCommand('-break-delete ' .. id) SendCommand($'-break-delete {id}')
for subid in keys(breakpoints[id]) for subid in keys(breakpoints[id])
sign_unplace('TermDebug', sign_unplace('TermDebug',
{id: Breakpoint2SignNumber(id, str2nr(subid))}) {id: Breakpoint2SignNumber(id, str2nr(subid))})
@@ -1315,18 +1314,18 @@ def ClearBreakpoint()
if empty(breakpoint_locations[bploc]) if empty(breakpoint_locations[bploc])
remove(breakpoint_locations, bploc) remove(breakpoint_locations, bploc)
endif endif
echomsg 'Breakpoint ' .. nr .. ' cleared from line ' .. lnum .. '.' echomsg $'Breakpoint {nr} cleared from line {lnum}.'
else else
Echoerr('Internal error trying to remove breakpoint at line ' .. lnum .. '!') 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}.'
endif endif
enddef enddef
def Run(args: string) def Run(args: string)
if args != '' if args != ''
SendResumingCommand('-exec-arguments ' .. args) SendResumingCommand($'-exec-arguments {args}')
endif endif
SendResumingCommand('-exec-run') SendResumingCommand('-exec-run')
enddef enddef
@@ -1340,13 +1339,13 @@ def Frame(arg: string)
# already parsed and allows for more formats # already parsed and allows for more formats
if arg =~ '^\d\+$' || arg == '' if arg =~ '^\d\+$' || arg == ''
# specify frame by number # specify frame by number
SendCommand('-interpreter-exec mi "frame ' .. arg .. '"') SendCommand($'-interpreter-exec mi "frame {arg}"')
elseif arg =~ '^0x[0-9a-fA-F]\+$' elseif arg =~ '^0x[0-9a-fA-F]\+$'
# specify frame by stack address # specify frame by stack address
SendCommand('-interpreter-exec mi "frame address ' .. arg .. '"') SendCommand($'-interpreter-exec mi "frame address {arg}"')
else else
# specify frame by function name # specify frame by function name
SendCommand('-interpreter-exec mi "frame function ' .. arg .. '"') SendCommand($'-interpreter-exec mi "frame function {arg}"')
endif endif
enddef enddef
@@ -1373,14 +1372,14 @@ def SendEval(expr: string)
var expr_escaped = expr var expr_escaped = expr
->substitute('\\', '\\\\', 'g') ->substitute('\\', '\\\\', 'g')
->substitute('"', '\\"', 'g') ->substitute('"', '\\"', 'g')
SendCommand('-data-evaluate-expression "' .. expr_escaped .. '"') SendCommand($'-data-evaluate-expression "{expr_escaped}"')
evalexpr = exprLHS evalexpr = exprLHS
enddef enddef
# :Evaluate - evaluate what is specified / under the cursor # :Evaluate - evaluate what is specified / under the cursor
def Evaluate(range: number, arg: string) def Evaluate(range: number, arg: string)
var expr = GetEvaluationExpression(range, arg) var expr = GetEvaluationExpression(range, arg)
#echom "expr:" .. expr #echom $"expr: {expr}"
ignoreEvalError = 0 ignoreEvalError = 0
SendEval(expr) SendEval(expr)
enddef enddef
@@ -1451,19 +1450,19 @@ def HandleEvaluate(msg: string)
\ ->substitute(NullRepl, '\\000', 'g') \ ->substitute(NullRepl, '\\000', 'g')
if evalFromBalloonExpr if evalFromBalloonExpr
if evalFromBalloonExprResult == '' if evalFromBalloonExprResult == ''
evalFromBalloonExprResult = evalexpr .. ': ' .. value evalFromBalloonExprResult = $'{evalexpr}: {value}'
else else
evalFromBalloonExprResult ..= ' = ' .. value evalFromBalloonExprResult ..= $' = {value}'
endif endif
balloon_show(evalFromBalloonExprResult) balloon_show(evalFromBalloonExprResult)
else else
echomsg '"' .. evalexpr .. '": ' .. value echomsg $'"{evalexpr}": {value}'
endif endif
if evalexpr[0] != '*' && value =~ '^0x' && value != '0x0' && value !~ '"$' if evalexpr[0] != '*' && value =~ '^0x' && value != '0x0' && value !~ '"$'
# Looks like a pointer, also display what it points to. # Looks like a pointer, also display what it points to.
ignoreEvalError = 1 ignoreEvalError = 1
SendEval('*' .. evalexpr) SendEval($'*{evalexpr}')
else else
evalFromBalloonExpr = 0 evalFromBalloonExpr = 0
endif endif
@@ -1537,7 +1536,7 @@ def GotoAsmwinOrCreateIt()
# 60 is approx spaceBuffer * 3 # 60 is approx spaceBuffer * 3
if winwidth(0) > (78 + 60) if winwidth(0) > (78 + 60)
mdf = 'vert' mdf = 'vert'
exe mdf .. ' ' .. ':60' .. 'new' exe $'{mdf} :60new'
else else
exe 'rightbelow new' exe 'rightbelow new'
endif endif
@@ -1556,7 +1555,7 @@ def GotoAsmwinOrCreateIt()
setlocal modifiable setlocal modifiable
if asmbuf > 0 && bufexists(asmbuf) if asmbuf > 0 && bufexists(asmbuf)
exe 'buffer' .. asmbuf exe $'buffer {asmbuf}'
elseif empty(glob('Termdebug-asm-listing')) elseif empty(glob('Termdebug-asm-listing'))
silent file Termdebug-asm-listing silent file Termdebug-asm-listing
asmbuf = bufnr('Termdebug-asm-listing') asmbuf = bufnr('Termdebug-asm-listing')
@@ -1567,19 +1566,19 @@ def GotoAsmwinOrCreateIt()
endif endif
if mdf != 'vert' && GetDisasmWindowHeight() > 0 if mdf != 'vert' && GetDisasmWindowHeight() > 0
exe 'resize ' .. GetDisasmWindowHeight() exe $'resize {GetDisasmWindowHeight()}'
endif endif
endif endif
if asm_addr != '' if asm_addr != ''
var lnum = search('^' .. asm_addr) var lnum = search($'^{asm_addr}')
if lnum == 0 if lnum == 0
if stopped if stopped
SendCommand('disassemble $pc') SendCommand('disassemble $pc')
endif endif
else else
sign_unplace('TermDebug', {'id': asm_id}) sign_unplace('TermDebug', {id: asm_id})
sign_place(asm_id, 'TermDebug', 'debugPC', '%', {'lnum': lnum}) sign_place(asm_id, 'TermDebug', 'debugPC', '%', {lnum: lnum})
endif endif
endif endif
enddef enddef
@@ -1612,7 +1611,7 @@ def GotoVariableswinOrCreateIt()
# 60 is approx spaceBuffer * 3 # 60 is approx spaceBuffer * 3
if winwidth(0) > (78 + 60) if winwidth(0) > (78 + 60)
mdf = 'vert' mdf = 'vert'
exe mdf .. ' ' .. ':60' .. 'new' exe $'{mdf} :60new'
else else
exe 'rightbelow new' exe 'rightbelow new'
endif endif
@@ -1630,7 +1629,7 @@ def GotoVariableswinOrCreateIt()
setlocal modifiable setlocal modifiable
if varbuf > 0 && bufexists(varbuf) if varbuf > 0 && bufexists(varbuf)
exe 'buffer' .. varbuf exe $'buffer {varbuf}'
elseif empty(glob('Termdebug-variables-listing')) elseif empty(glob('Termdebug-variables-listing'))
silent file Termdebug-variables-listing silent file Termdebug-variables-listing
varbuf = bufnr('Termdebug-variables-listing') varbuf = bufnr('Termdebug-variables-listing')
@@ -1641,7 +1640,7 @@ def GotoVariableswinOrCreateIt()
endif endif
if mdf != 'vert' && GetVariablesWindowHeight() > 0 if mdf != 'vert' && GetVariablesWindowHeight() > 0
exe 'resize ' .. GetVariablesWindowHeight() exe $'resize {GetVariablesWindowHeight()}'
endif endif
endif endif
@@ -1680,12 +1679,12 @@ def HandleCursor(msg: string)
var curwinid = win_getid() var curwinid = win_getid()
var lnum = 0 var lnum = 0
if win_gotoid(asmwin) if win_gotoid(asmwin)
lnum = search('^' .. asm_addr) lnum = search($'^{asm_addr}')
if lnum == 0 if lnum == 0
SendCommand('disassemble $pc') SendCommand('disassemble $pc')
else else
sign_unplace('TermDebug', {'id': asm_id}) sign_unplace('TermDebug', {id: asm_id})
sign_place(asm_id, 'TermDebug', 'debugPC', '%', {'lnum': lnum}) sign_place(asm_id, 'TermDebug', 'debugPC', '%', {lnum: lnum})
endif endif
win_gotoid(curwinid) win_gotoid(curwinid)
@@ -1702,7 +1701,7 @@ def HandleCursor(msg: string)
if lnum =~ '^[0-9]*$' if lnum =~ '^[0-9]*$'
GotoSourcewinOrCreateIt() GotoSourcewinOrCreateIt()
if expand('%:p') != fnamemodify(fname, ':p') if expand('%:p') != fnamemodify(fname, ':p')
echomsg 'different fname: "' .. expand('%:p') .. '" vs "' .. fnamemodify(fname, ':p') .. '"' echomsg $"different fname: '{expand('%:p')}' vs '{fnamemodify(fname, ':p')}'"
augroup Termdebug augroup Termdebug
# Always open a file read-only instead of showing the ATTENTION # Always open a file read-only instead of showing the ATTENTION
# prompt, since it is unlikely we want to edit the file. # prompt, since it is unlikely we want to edit the file.
@@ -1714,19 +1713,19 @@ def HandleCursor(msg: string)
augroup END augroup END
if &modified if &modified
# TODO: find existing window # TODO: find existing window
exe 'split ' .. fnameescape(fname) exe $'split {fnameescape(fname)}'
sourcewin = win_getid() sourcewin = win_getid()
call InstallWinbar(0) call InstallWinbar(0)
else else
exe 'edit ' .. fnameescape(fname) exe $'edit {fnameescape(fname)}'
endif endif
augroup Termdebug augroup Termdebug
au! SwapExists au! SwapExists
augroup END augroup END
endif endif
exe ":" .. lnum exe $":{lnum}"
normal! zv normal! zv
sign_unplace('TermDebug', {'id': pc_id}) sign_unplace('TermDebug', {id: pc_id})
sign_place(pc_id, 'TermDebug', 'debugPC', fname, sign_place(pc_id, 'TermDebug', 'debugPC', fname,
{lnum: str2nr(lnum), priority: 110}) {lnum: str2nr(lnum), priority: 110})
if !exists('b:save_signcolumn') if !exists('b:save_signcolumn')
@@ -1736,7 +1735,7 @@ def HandleCursor(msg: string)
setlocal signcolumn=yes setlocal signcolumn=yes
endif endif
elseif !stopped || fname != '' elseif !stopped || fname != ''
sign_unplace('TermDebug', {'id': pc_id}) sign_unplace('TermDebug', {id: pc_id})
endif endif
win_gotoid(wid) win_gotoid(wid)
@@ -1762,7 +1761,7 @@ def CreateBreakpoint(id: number, subid: number, enabled: string)
label = 'F+' label = 'F+'
endif endif
endif endif
sign_define('debugBreakpoint' .. nr, sign_define($'debugBreakpoint{nr}',
{text: slice(label, 0, 2), {text: slice(label, 0, 2),
texthl: hiName}) texthl: hiName})
endif endif
@@ -1783,7 +1782,7 @@ def HandleNewBreakpoint(msg: string, modifiedFlag: any)
if msg =~ 'pending=' if msg =~ 'pending='
nr = substitute(msg, '.*number=\"\([0-9.]*\)\".*', '\1', '') nr = substitute(msg, '.*number=\"\([0-9.]*\)\".*', '\1', '')
var target = substitute(msg, '.*pending=\"\([^"]*\)\".*', '\1', '') var target = substitute(msg, '.*pending=\"\([^"]*\)\".*', '\1', '')
echomsg 'Breakpoint ' .. nr .. ' (' .. target .. ') pending.' echomsg $'Breakpoint {nr} ({target}) pending.'
endif endif
return return
endif endif
@@ -1831,9 +1830,9 @@ def HandleNewBreakpoint(msg: string, modifiedFlag: any)
var posMsg = '' var posMsg = ''
if bufloaded(fname) if bufloaded(fname)
PlaceSign(id, subid, entry) PlaceSign(id, subid, entry)
posMsg = ' at line ' .. lnum .. '.' posMsg = $' at line {lnum}.'
else else
posMsg = ' in ' .. fname .. ' at line ' .. lnum .. '.' posMsg = $' in {fname} at line {lnum}.'
endif endif
var actionTaken = '' var actionTaken = ''
if !modifiedFlag if !modifiedFlag
@@ -1843,7 +1842,7 @@ def HandleNewBreakpoint(msg: string, modifiedFlag: any)
else else
actionTaken = 'enabled' actionTaken = 'enabled'
endif endif
echom 'Breakpoint ' .. nr .. ' ' .. actionTaken .. posMsg echom $'Breakpoint {nr} {actionTaken}{posMsg}'
endfor endfor
enddef enddef
@@ -1851,7 +1850,7 @@ enddef
def PlaceSign(id: number, subid: number, entry: dict<any>) def PlaceSign(id: number, subid: number, entry: dict<any>)
var nr = printf('%d.%d', id, subid) var nr = printf('%d.%d', id, subid)
sign_place(Breakpoint2SignNumber(id, subid), 'TermDebug', sign_place(Breakpoint2SignNumber(id, subid), 'TermDebug',
'debugBreakpoint' .. nr, entry['fname'], $'debugBreakpoint{nr}', entry['fname'],
{lnum: entry['lnum'], priority: 110}) {lnum: entry['lnum'], priority: 110})
entry['placed'] = 1 entry['placed'] = 1
enddef enddef
@@ -1867,12 +1866,12 @@ def HandleBreakpointDelete(msg: string)
for [subid, entry] in items(breakpoints[id]) for [subid, entry] in items(breakpoints[id])
if has_key(entry, 'placed') if has_key(entry, 'placed')
sign_unplace('TermDebug', sign_unplace('TermDebug',
{'id': Breakpoint2SignNumber(str2nr(id), str2nr(subid))}) {id: Breakpoint2SignNumber(str2nr(id), str2nr(subid))})
remove(entry, 'placed') remove(entry, 'placed')
endif endif
endfor endfor
remove(breakpoints, id) remove(breakpoints, id)
echomsg 'Breakpoint ' .. id .. ' cleared.' echomsg $'Breakpoint {id} cleared.'
endif endif
enddef enddef
@@ -1884,7 +1883,7 @@ def HandleProgramRun(msg: string)
return return
endif endif
pid = nr pid = nr
ch_log('Detected process ID: ' .. pid) ch_log($'Detected process ID: {pid}')
enddef enddef
# Handle a BufRead autocommand event: place any signs. # Handle a BufRead autocommand event: place any signs.