@@ -69,6 +69,11 @@ func s:StartDebug(cmd)
6969 endif
7070 let pty = job_info (term_getjob (s: ptybuf ))[' tty_out' ]
7171 let s: ptywin = win_getid (winnr ())
72+ if vertical
73+ " Assuming the source code window will get a signcolumn, use two more
74+ " columns for that, thus one less for the terminal window.
75+ exe (&columns / 2 - 1 ) . " wincmd |"
76+ endif
7277
7378 " Create a hidden terminal window to communicate with gdb
7479 let s: commbuf = term_start (' NONE' , {
@@ -121,6 +126,15 @@ func s:StartDebug(cmd)
121126 call s: InstallCommands ()
122127 call win_gotoid (s: gdbwin )
123128
129+ " Enable showing a balloon with eval info
130+ if has (" balloon_eval" )
131+ set ballooneval
132+ set balloonexpr = TermDebugBalloonExpr ()
133+ if has (" balloon_eval_term" )
134+ set balloonevalterm
135+ endif
136+ endif
137+
124138 let s: breakpoints = {}
125139
126140 augroup TermDebug
@@ -144,6 +158,14 @@ func s:EndDebug(job, status)
144158 let &columns = s: save_columns
145159 endif
146160
161+ if has (" balloon_eval" )
162+ set noballooneval
163+ set balloonexpr =
164+ if has (" balloon_eval_term" )
165+ set noballoonevalterm
166+ endif
167+ endif
168+
147169 au ! TermDebug
148170endfunc
149171
@@ -279,6 +301,11 @@ func s:Run(args)
279301 call s: SendCommand (' -exec-run' )
280302endfunc
281303
304+ func s: SendEval (expr )
305+ call s: SendCommand (' -data-evaluate-expression "' . a: expr . ' "' )
306+ let s: evalexpr = a: expr
307+ endfunc
308+
282309" :Evaluate - evaluate what is under the cursor
283310func s: Evaluate (range , arg)
284311 if a: arg != ' '
@@ -294,25 +321,54 @@ func s:Evaluate(range, arg)
294321 else
295322 let expr = expand (' <cexpr>' )
296323 endif
297- call s: SendCommand (' -data-evaluate-expression "' . expr . ' "' )
298- let s: evalexpr = expr
324+ call s: SendEval (expr )
299325endfunc
300326
327+ let s: evalFromBalloonExpr = 0
328+
301329" Handle the result of data-evaluate-expression
302330func s: HandleEvaluate (msg)
303331 let value = substitute (a: msg , ' .*value="\(.*\)"' , ' \1' , ' ' )
304332 let value = substitute (value, ' \\"' , ' "' , ' g' )
305- echomsg ' "' . s: evalexpr . ' ": ' . value
333+ if s: evalFromBalloonExpr
334+ if s: evalFromBalloonExprResult == ' '
335+ let s: evalFromBalloonExprResult = s: evalexpr . ' : ' . value
336+ else
337+ let s: evalFromBalloonExprResult .= ' = ' . value
338+ endif
339+ call balloon_show (s: evalFromBalloonExprResult )
340+ else
341+ echomsg ' "' . s: evalexpr . ' ": ' . value
342+ endif
306343
307344 if s: evalexpr [0 ] != ' *' && value = ~ ' ^0x' && value != ' 0x0' && value !~ ' "$'
308345 " Looks like a pointer, also display what it points to.
309- let s: evalexpr = ' *' . s: evalexpr
310- call term_sendkeys (s: commbuf , ' -data-evaluate-expression "' . s: evalexpr . " \" \r " )
346+ call s: SendEval (' *' . s: evalexpr )
347+ else
348+ let s: evalFromBalloonExpr = 0
349+ endif
350+ endfunc
351+
352+ " Show a balloon with information of the variable under the mouse pointer,
353+ " if there is any.
354+ func TermDebugBalloonExpr ()
355+ if v: beval_winid != s: startwin
356+ return
311357 endif
358+ call s: SendEval (v: beval_text )
359+ let s: evalFromBalloonExpr = 1
360+ let s: evalFromBalloonExprResult = ' '
361+ return ' '
312362endfunc
313363
314364" Handle an error.
315365func s: HandleError (msg)
366+ if a: msg = ~ ' No symbol .* in current context'
367+ \ || a: msg = ~ ' Cannot access memory at address '
368+ \ || a: msg = ~ ' Attempt to use a type name as an expression'
369+ " Result of s:SendEval() failed, ignore.
370+ return
371+ endif
316372 echoerr substitute (a: msg , ' .*msg="\(.*\)"' , ' \1' , ' ' )
317373endfunc
318374
0 commit comments