@@ -15,7 +15,7 @@ vim9script
1515
1616# There are two ways to run gdb:
1717# - In a terminal window ; used if possible, does not work on MS- Windows
18- # Not used when g: termdebug_use_prompt is set to 1 .
18+ # Not used when g: termdebug_use_prompt is set to true .
1919# - Using a " prompt" buffer ; may use a terminal window for the program
2020
2121# For both the current window is used to view source code and shows the
4949# Variables to keep their status among multiple instances of Termdebug
5050# Avoid to source the script twice.
5151if exists (' g:termdebug_loaded' )
52- Echoerr (' Termdebug already loaded.' )
53- finish
52+ Echoerr (' Termdebug already loaded.' )
53+ finish
5454endif
5555g: termdebug_loaded = true
5656g: termdebug_is_running = false
@@ -90,7 +90,7 @@ var varbufname: string
9090var asmbufnr: number
9191var asmbufname: string
9292var promptbufnr: number
93- # This is for the " debugged-program" thing
93+ # ' pty ' refers to the " debugged-program" pty
9494var ptybufnr: number
9595var ptybufname: string
9696var commbufnr: number
@@ -276,6 +276,18 @@ def DeprecationWarnings()
276276 \ is deprecated and will be removed in the future. See ' :h g:termdebug_config' for alternatives." )
277277 endif
278278
279+ # termdebug config types
280+ if exists (' g:termdebug_config' ) && ! empty (g: termdebug_config )
281+ for key in keys (g: termdebug_config )
282+ if index ([' disasm_window' , ' variables_window' , ' use_prompt' , ' map_K' , ' map_minus' , ' map_plus' ], key ) != -1
283+ if typename (g: termdebug_config [key ]) == ' number'
284+ var val = g: termdebug_config [key ]
285+ Echowarn ($ "Deprecation Warning: ' g:termdebug_config[\"{key}\"] = {val}' will be deprecated.
286+ \ Please use ' g:termdebug_config[\"{key}\"] = {val != 0}' " )
287+ endif
288+ endif
289+ endfor
290+ endif
279291enddef
280292
281293# Take a breakpoint number as used by GDB and turn it into an integer.
@@ -353,7 +365,7 @@ def StartDebug_internal(dict: dict<any>)
353365 endif
354366
355367 # Uncomment this line to write logging in " debuglog" .
356- # call ch_logfile (' debuglog' , ' w' )
368+ # ch_logfile (' debuglog' , ' w' )
357369
358370 # Assume current window is the source code window
359371 sourcewin = win_getid ()
@@ -444,7 +456,7 @@ def CreateCommunicationPty(): string
444456 # Create a hidden terminal window to communicate with gdb
445457 commbufnr = term_start (' NONE' , {
446458 term_name: commbufname,
447- out_cb: function ( ' CommOutput' ) ,
459+ out_cb: CommOutput,
448460 hidden : 1
449461 })
450462 if commbufnr == 0
@@ -489,9 +501,9 @@ def CreateGdbConsole(dict: dict<any>, pty: string, commpty: string): string
489501
490502 ch_log ($ ' executing "{join(gdb_cmd)}"' )
491503 gdbbufnr = term_start (gdb_cmd, {
492- term_name: gdbbufname,
493- term_finish: ' close' ,
494- })
504+ term_name: gdbbufname,
505+ term_finish: ' close' ,
506+ })
495507 if gdbbufnr == 0
496508 return ' Failed to open the gdb terminal window'
497509 endif
@@ -603,7 +615,7 @@ def StartDebug_term(dict: dict<any>)
603615 return
604616 endif
605617
606- job_setoptions (term_getjob (gdbbufnr), {exit_cb: function ( ' EndDebug' ) })
618+ job_setoptions (term_getjob (gdbbufnr), {exit_cb: EndDebug})
607619
608620 # Set the filetype , this can be used to add mappings.
609621 set filetype = termdebug
@@ -627,8 +639,8 @@ def StartDebug_prompt(dict: dict<any>)
627639 set buftype = prompt
628640 exe $ " file {gdbbufname}"
629641
630- prompt_setcallback (promptbufnr, function ( ' PromptCallback' ) )
631- prompt_setinterrupt (promptbufnr, function ( ' PromptInterrupt' ) )
642+ prompt_setcallback (promptbufnr, PromptCallback)
643+ prompt_setinterrupt (promptbufnr, PromptInterrupt)
632644
633645 if vvertical
634646 # Assuming the source code window will get a signcolumn , use two more
@@ -655,16 +667,16 @@ def StartDebug_prompt(dict: dict<any>)
655667
656668 ch_log ($ ' executing "{join(gdb_cmd)}"' )
657669 gdbjob = job_start (gdb_cmd, {
658- exit_cb: function ( ' EndDebug' ) ,
659- out_cb: function ( ' GdbOutCallback' ),
670+ exit_cb: EndDebug,
671+ out_cb: GdbOutCallback
660672 })
661673 if job_status (gdbjob) != " run"
662674 Echoerr (' Failed to start gdb' )
663675 exe $ ' bwipe! {promptbufnr}'
664676 return
665677 endif
666678 exe $ ' au BufUnload <buffer={promptbufnr}> ++once ' ..
667- ' call job_stop(gdbjob, '' kill'' )'
679+ ' call job_stop(gdbjob, '' kill'' )'
668680 # Mark the buffer modified so that it's not easy to close .
669681 set modified
670682 gdb_channel = job_getchannel (gdbjob)
@@ -847,7 +859,7 @@ def GdbOutCallback(channel: channel, text: string)
847859 # Drop the gdb prompt , we have our own.
848860 # Drop status and echo 'd commands.
849861 if text == ' (gdb) ' || text == ' ^done' ||
850- (text[0 ] == ' &' && text !~ ' ^&"disassemble' )
862+ (text[0 ] == ' &' && text !~ ' ^&"disassemble' )
851863 return
852864 endif
853865
@@ -890,18 +902,18 @@ def DecodeMessage(quotedText: string, literal: bool): string
890902 return ' '
891903 endif
892904 var msg = quotedText
893- - >substitute (' ^"\|[^\\]\zs".*' , ' ' , ' g' )
894- - >substitute (' \\"' , ' "' , ' g' )
895- #\ multi- byte characters arrive in octal form
896- #\ NULL- values must be kept encoded as those break the string otherwise
897- - >substitute (' \\000' , NullRepl, ' g' )
898- - >substitute (' \\\(\o\o\o\)' , (m ) = > nr2char (str2nr (m [1 ], 8 )), ' g' )
899- # You could also use - >substitute (' \\\\\(\o\o\o\)' , ' \=nr2char(str2nr(submatch(1), 8))' , " g" )
900- #\ Note: GDB docs also mention hex encodings - the translations below work
901- #\ but we keep them out for performance- reasons until we actually see
902- #\ those in mi- returns
903- - >substitute (' \\\\' , ' \' , ' g' )
904- - >substitute (NullRepl, ' \\000' , ' g' )
905+ - >substitute (' ^"\|[^\\]\zs".*' , ' ' , ' g' )
906+ - >substitute (' \\"' , ' "' , ' g' )
907+ #\ multi- byte characters arrive in octal form
908+ #\ NULL- values must be kept encoded as those break the string otherwise
909+ - >substitute (' \\000' , NullRepl, ' g' )
910+ - >substitute (' \\\(\o\o\o\)' , (m ) = > nr2char (str2nr (m [1 ], 8 )), ' g' )
911+ # You could also use - >substitute (' \\\\\(\o\o\o\)' , ' \=nr2char(str2nr(submatch(1), 8))' , " g" )
912+ #\ Note: GDB docs also mention hex encodings - the translations below work
913+ #\ but we keep them out for performance- reasons until we actually see
914+ #\ those in mi- returns
915+ - >substitute (' \\\\' , ' \' , ' g' )
916+ - >substitute (NullRepl, ' \\000' , ' g' )
905917 if ! literal
906918 return msg
907919 - >substitute (' \\t' , " \t " , ' g' )
@@ -1039,11 +1051,11 @@ def HandleDisasmMsg(msg: string)
10391051 endif
10401052 elseif msg !~ ' ^&"disassemble'
10411053 var value = substitute (msg, ' ^\~\"[ ]*' , ' ' , ' ' )
1042- - >substitute (' ^=>[ ]*' , ' ' , ' ' )
1043- - >substitute (' \\n\"\r$' , ' ' , ' ' )
1044- - >substitute (' \\n\"$' , ' ' , ' ' )
1045- - >substitute (' \r' , ' ' , ' ' )
1046- - >substitute (' \\t' , ' ' , ' g' )
1054+ - >substitute (' ^=>[ ]*' , ' ' , ' ' )
1055+ - >substitute (' \\n\"\r$' , ' ' , ' ' )
1056+ - >substitute (' \\n\"$' , ' ' , ' ' )
1057+ - >substitute (' \r' , ' ' , ' ' )
1058+ - >substitute (' \\t' , ' ' , ' g' )
10471059
10481060 if value != ' ' || ! empty (asm_lines)
10491061 add (asm_lines, value)
@@ -1119,9 +1131,9 @@ def CommOutput(chan: channel, message: string)
11191131 if msg = ~ ' ^\(\*stopped\|\*running\|=thread-selected\)'
11201132 HandleCursor (msg)
11211133 elseif msg = ~ ' ^\^done,bkpt=' || msg = ~ ' ^=breakpoint-created,'
1122- HandleNewBreakpoint (msg, 0 )
1134+ HandleNewBreakpoint (msg, false )
11231135 elseif msg = ~ ' ^=breakpoint-modified,'
1124- HandleNewBreakpoint (msg, 1 )
1136+ HandleNewBreakpoint (msg, true )
11251137 elseif msg = ~ ' ^=breakpoint-deleted,'
11261138 HandleBreakpointDelete (msg)
11271139 elseif msg = ~ ' ^=thread-group-started'
@@ -1225,10 +1237,10 @@ def InstallCommands()
12251237 if pup
12261238 &mousemodel = ' popup_setpos'
12271239 an 1.200 PopUp.- SEP3- <Nop>
1228- an 1.210 PopUp.Set\ breakpoint : Break <CR>
1229- an 1.220 PopUp.Clear \ breakpoint : Clear <CR>
1230- an 1.230 PopUp.Run \ until : Until <CR>
1231- an 1.240 PopUp.Evaluate : Evaluate <CR>
1240+ an 1.210 PopUp.Set\ breakpoint <cmd> Break <CR>
1241+ an 1.220 PopUp.Clear \ breakpoint <cmd> Clear <CR>
1242+ an 1.230 PopUp.Run \ until <cmd> Until <CR>
1243+ an 1.240 PopUp.Evaluate <cmd> Evaluate <CR>
12321244 endif
12331245 endif
12341246
@@ -1311,7 +1323,6 @@ def DeleteCommands()
13111323 endif
13121324 endfor
13131325 win_gotoid (curwinid)
1314- # winbar_winids = []
13151326
13161327 &mousemodel = saved_mousemodel
13171328 try
@@ -1526,18 +1537,18 @@ enddef
15261537
15271538def HandleEvaluate (msg: string )
15281539 var value = msg
1529- - >substitute (' .*value="\(.*\)"' , ' \1' , ' ' )
1530- - >substitute (' \\"' , ' "' , ' g' )
1531- - >substitute (' \\\\' , ' \\' , ' g' )
1532- #\ multi- byte characters arrive in octal form, replace everything but NULL values
1533- - >substitute (' \\000' , NullRepl, ' g' )
1534- - >substitute (' \\\(\o\o\o\)' , (m ) = > nr2char (str2nr (m [1 ], 8 )), ' g' )
1535- #\ Note: GDB docs also mention hex encodings - the translations below work
1536- #\ but we keep them out for performance- reasons until we actually see
1537- #\ those in mi- returns
1538- #\ - >substitute (' \\0x00' , NullRep, ' g' )
1539- #\ - >substitute (' \\0x\(\x\x\)' , {- > eval (' "\x' .. submatch (1 ) .. ' "' )}, ' g' )
1540- - >substitute (NullRepl, ' \\000' , ' g' )
1540+ - >substitute (' .*value="\(.*\)"' , ' \1' , ' ' )
1541+ - >substitute (' \\"' , ' "' , ' g' )
1542+ - >substitute (' \\\\' , ' \\' , ' g' )
1543+ #\ multi- byte characters arrive in octal form, replace everything but NULL values
1544+ - >substitute (' \\000' , NullRepl, ' g' )
1545+ - >substitute (' \\\(\o\o\o\)' , (m ) = > nr2char (str2nr (m [1 ], 8 )), ' g' )
1546+ #\ Note: GDB docs also mention hex encodings - the translations below work
1547+ #\ but we keep them out for performance- reasons until we actually see
1548+ #\ those in mi- returns
1549+ #\ - >substitute (' \\0x00' , NullRep, ' g' )
1550+ #\ - >substitute (' \\0x\(\x\x\)' , {- > eval (' "\x' .. submatch (1 ) .. ' "' )}, ' g' )
1551+ - >substitute (NullRepl, ' \\000' , ' g' )
15411552 if evalFromBalloonExpr
15421553 if empty (evalFromBalloonExprResult)
15431554 evalFromBalloonExprResult = $ ' {evalexpr}: {value}'
@@ -1599,14 +1610,17 @@ def GotoSourcewinOrCreateIt()
15991610enddef
16001611
16011612
1602- def GetDisasmWindow (): number
1603- if exists (' g:termdebug_config' )
1604- return get (g: termdebug_config , ' disasm_window' , 0 )
1605- endif
1606- if exists (' g:termdebug_disasm_window' )
1607- return g: termdebug_disasm_window
1613+ def GetDisasmWindow (): bool
1614+ # TODO Remove the deprecated features after 1 Jan 2025 .
1615+ var val: any
1616+ if exists (' g:termdebug_config' ) && has_key (g: termdebug_config , ' disasm_window' )
1617+ val = g: termdebug_config [' disasm_window' ]
1618+ elseif exists (' g:termdebug_disasm_window' )
1619+ val = g: termdebug_disasm_window
1620+ else
1621+ val = false
16081622 endif
1609- return 0
1623+ return typename (val) == ' number ' ? val != 0 : val
16101624enddef
16111625
16121626def GetDisasmWindowHeight (): number
@@ -1669,14 +1683,17 @@ def GotoAsmwinOrCreateIt()
16691683 endif
16701684enddef
16711685
1672- def GetVariablesWindow (): number
1673- if exists (' g:termdebug_config' )
1674- return get (g: termdebug_config , ' variables_window' , 0 )
1675- endif
1676- if exists (' g:termdebug_disasm_window' )
1677- return g: termdebug_variables_window
1686+ def GetVariablesWindow (): bool
1687+ # TODO Remove the deprecated features after 1 Jan 2025 .
1688+ var val: any
1689+ if exists (' g:termdebug_config' ) && has_key (g: termdebug_config , ' variables_window' )
1690+ val = g: termdebug_config [' variables_window' ]
1691+ elseif exists (' g:termdebug_variables_window' )
1692+ val = g: termdebug_variables_window
1693+ else
1694+ val = false
16781695 endif
1679- return 0
1696+ return typename (val) == ' number ' ? val != 0 : val
16801697enddef
16811698
16821699def GetVariablesWindowHeight (): number
@@ -1810,7 +1827,7 @@ def HandleCursor(msg: string)
18101827 normal ! zv
18111828 sign_unplace (' TermDebug' , {id: pc_id})
18121829 sign_place (pc_id, ' TermDebug' , ' debugPC' , fname,
1813- {lnum: str2nr (lnum), priority: 110 })
1830+ {lnum: str2nr (lnum), priority: 110 })
18141831 if ! exists (' b:save_signcolumn' )
18151832 b: save_signcolumn = &signcolumn
18161833 add (signcolumn_buflist, bufnr ())
@@ -1857,7 +1874,7 @@ enddef
18571874
18581875# Handle setting a breakpoint
18591876# Will update the sign that shows the breakpoint
1860- def HandleNewBreakpoint (msg: string , modifiedFlag: any )
1877+ def HandleNewBreakpoint (msg: string , modifiedFlag: bool )
18611878 var nr = ' '
18621879
18631880 if msg !~ ' fullname='
0 commit comments