22"
33" Author: Bram Moolenaar
44" Copyright: Vim license applies, see ":help license"
5- " Last Change: 2022 Nov 10
5+ " Last Change: 2023 Jun 24
66"
77" WORK IN PROGRESS - The basics works stable, more to come
88" Note: In general you need at least GDB 7.12 because this provides the
@@ -81,6 +81,8 @@ func s:Breakpoint2SignNumber(id, subid)
8181 return s: break_id + a: id * 1000 + a: subid
8282endfunction
8383
84+ " Define or adjust the default highlighting, using background "new".
85+ " When the 'background' option is set then "old" has the old value.
8486func s: Highlight (init, old, new )
8587 let default = a: init ? ' default ' : ' '
8688 if a: new == # ' light' && a: old !=# ' light'
@@ -90,9 +92,21 @@ func s:Highlight(init, old, new)
9092 endif
9193endfunc
9294
93- call s: Highlight (1 , ' ' , &background )
94- hi default debugBreakpoint term = reverse ctermbg= red guibg= red
95- hi default debugBreakpointDisabled term = reverse ctermbg= gray guibg= gray
95+ " Define the default highlighting, using the current 'background' value.
96+ func s: InitHighlight ()
97+ call s: Highlight (1 , ' ' , &background )
98+ hi default debugBreakpoint term = reverse ctermbg= red guibg= red
99+ hi default debugBreakpointDisabled term = reverse ctermbg= gray guibg= gray
100+ endfunc
101+
102+ " Setup an autocommand to redefine the default highlight when the colorscheme
103+ " is changed.
104+ func s: InitAutocmd ()
105+ augroup TermDebug
106+ autocmd !
107+ autocmd ColorScheme * call s: InitHighlight ()
108+ augroup END
109+ endfunc
96110
97111" Get the command to execute the debugger as a list, defaults to ["gdb"].
98112func s: GetCommand ()
@@ -588,14 +602,14 @@ func s:GdbOutCallback(channel, text)
588602 return
589603 endif
590604 if a: text = ~ ' ^\^error,msg='
591- let text = s: DecodeMessage (a: text [11 :])
605+ let text = s: DecodeMessage (a: text [11 :], v: false )
592606 if exists (' s:evalexpr' ) && text = ~ ' A syntax error in expression, near\|No symbol .* in current context'
593607 " Silently drop evaluation errors.
594608 unlet s: evalexpr
595609 return
596610 endif
597611 elseif a: text [0 ] == ' ~'
598- let text = s: DecodeMessage (a: text [1 :])
612+ let text = s: DecodeMessage (a: text [1 :], v: false )
599613 else
600614 call s: CommOutput (a: channel , a: text )
601615 return
@@ -611,21 +625,20 @@ func s:GdbOutCallback(channel, text)
611625 call win_gotoid (curwinid)
612626endfunc
613627
614- " Decode a message from gdb. quotedText starts with a ", return the text up
628+ " Decode a message from gdb. " quotedText" starts with a ", return the text up
615629" to the next ", unescaping characters:
616- " - remove line breaks
617- " - change \\t to \t
630+ " - remove line breaks (unless "literal" is v:true)
631+ " - change \\t to \t (unless "literal" is v:true)
618632" - change \0xhh to \xhh (disabled for now)
619633" - change \ooo to octal
620634" - change \\ to \
621- func s: DecodeMessage (quotedText)
635+ func s: DecodeMessage (quotedText, literal )
622636 if a: quotedText [0 ] != ' "'
623637 echoerr ' DecodeMessage(): missing quote in ' . a: quotedText
624638 return
625639 endif
626- return a: quotedText
627- \ - >substitute (' ^"\|".*\|\\n' , ' ' , ' g' )
628- \ - >substitute (' \\t' , " \t " , ' g' )
640+ let msg = a: quotedText
641+ \ - >substitute (' ^"\|".*' , ' ' , ' g' )
629642 " multi-byte characters arrive in octal form
630643 " NULL-values must be kept encoded as those break the string otherwise
631644 \ - >substitute (' \\000' , s: NullRepl , ' g' )
@@ -637,6 +650,13 @@ func s:DecodeMessage(quotedText)
637650 " \ ->substitute('\\0x00', s:NullRepl, 'g')
638651 \ - >substitute (' \\\\' , ' \' , ' g' )
639652 \ - >substitute (s: NullRepl , ' \\000' , ' g' )
653+ if ! a: literal
654+ return msg
655+ \ - >substitute (' \\t' , " \t " , ' g' )
656+ \ - >substitute (' \\n' , ' ' , ' g' )
657+ else
658+ return msg
659+ endif
640660endfunc
641661const s: NullRepl = ' XXXNULLXXX'
642662
@@ -645,7 +665,7 @@ func s:GetFullname(msg)
645665 if a: msg !~ ' fullname'
646666 return ' '
647667 endif
648- let name = s: DecodeMessage (substitute (a: msg , ' .*fullname=' , ' ' , ' ' ))
668+ let name = s: DecodeMessage (substitute (a: msg , ' .*fullname=' , ' ' , ' ' ), v: true )
649669 if has (' win32' ) && name = ~ ' :\\\\'
650670 " sometimes the name arrives double-escaped
651671 let name = substitute (name, ' \\\\' , ' \\' , ' g' )
@@ -658,7 +678,7 @@ func s:GetAsmAddr(msg)
658678 if a: msg !~ ' addr='
659679 return ' '
660680 endif
661- let addr = s: DecodeMessage (substitute (a: msg , ' .*addr=' , ' ' , ' ' ))
681+ let addr = s: DecodeMessage (substitute (a: msg , ' .*addr=' , ' ' , ' ' ), v: false )
662682 return addr
663683endfunc
664684
@@ -1381,9 +1401,19 @@ func s:CreateBreakpoint(id, subid, enabled)
13811401 else
13821402 let hiName = " debugBreakpoint"
13831403 endif
1404+ let label = ' '
1405+ if exists (' g:termdebug_config' )
1406+ let label = get (g: termdebug_config , ' sign' , ' ' )
1407+ endif
1408+ if label == ' '
1409+ let label = substitute (nr, ' \..*' , ' ' , ' ' )
1410+ if strlen (label ) > 2
1411+ let label = strpart (label , strlen (label ) - 2 )
1412+ endif
1413+ endif
13841414 call sign_define (' debugBreakpoint' .. nr,
1385- \ #{text: substitute (nr, ' \..* ' , ' ' , ' ' ),
1386- \ texthl: hiName})
1415+ \ #{text: strpart ( label , 0 , 2 ),
1416+ \ texthl: hiName})
13871417 endif
13881418endfunc
13891419
@@ -1522,5 +1552,8 @@ func s:BufUnloaded()
15221552 endfor
15231553endfunc
15241554
1555+ call s: InitHighlight ()
1556+ call s: InitAutocmd ()
1557+
15251558let &cpo = s: keepcpo
15261559unlet s: keepcpo
0 commit comments