@@ -104,6 +104,11 @@ func s:StartDebug(cmd)
104104 call win_gotoid (s: gdbwin )
105105
106106 let s: breakpoints = {}
107+
108+ augroup TermDebug
109+ au BufRead * call s: BufRead ()
110+ au BufUnload * call s: BufUnloaded ()
111+ augroup END
107112endfunc
108113
109114func s: EndDebug (job, status)
@@ -120,6 +125,8 @@ func s:EndDebug(job, status)
120125 if s: save_columns > 0
121126 let &columns = s: save_columns
122127 endif
128+
129+ au ! TermDebug
123130endfunc
124131
125132" Handle a message received from gdb on the GDB/MI interface.
@@ -132,7 +139,7 @@ func s:CommOutput(chan, msg)
132139 let msg = msg[1 :]
133140 endif
134141 if msg != ' '
135- if msg = ~ ' ^\*\( stopped\|running\)'
142+ if msg = ~ ' ^\(\* stopped\|\* running\|=thread-selected \)'
136143 call s: HandleCursor (msg)
137144 elseif msg = ~ ' ^\^done,bkpt=' || msg = ~ ' ^=breakpoint-created,'
138145 call s: HandleNewBreakpoint (msg)
@@ -161,6 +168,14 @@ func s:InstallCommands()
161168
162169 " TODO: can the K mapping be restored?
163170 nnoremap K :Evaluate<CR>
171+
172+ if has (' menu' )
173+ amenu WinBar.Step :Step <CR>
174+ amenu WinBar.Next :Over <CR>
175+ amenu WinBar.Finish :Finish <CR>
176+ amenu WinBar.Cont :Continue <CR>
177+ amenu WinBar.Eval :Evaluate <CR>
178+ endif
164179endfunc
165180
166181" Delete installed debugger commands in the current window.
@@ -176,6 +191,15 @@ func s:DeleteCommands()
176191 delcommand Program
177192
178193 nunmap K
194+
195+ if has (' menu' )
196+ aunmenu WinBar.Step
197+ aunmenu WinBar.Next
198+ aunmenu WinBar.Finish
199+ aunmenu WinBar.Cont
200+ aunmenu WinBar.Eval
201+ endif
202+
179203 exe ' sign unplace ' . s: pc_id
180204 for key in keys (s: breakpoints )
181205 exe ' sign unplace ' . (s: break_id + key )
@@ -232,7 +256,15 @@ endfunc
232256
233257" Handle the result of data-evaluate-expression
234258func s: HandleEvaluate (msg)
235- echomsg ' "' . s: evalexpr . ' ": ' . substitute (a: msg , ' .*value="\(.*\)"' , ' \1' , ' ' )
259+ let value = substitute (a: msg , ' .*value="\(.*\)"' , ' \1' , ' ' )
260+ let value = substitute (value, ' \\"' , ' "' , ' g' )
261+ echomsg ' "' . s: evalexpr . ' ": ' . value
262+
263+ if s: evalexpr [0 ] != ' *' && value = ~ ' ^0x' && value !~ ' "$'
264+ " Looks like a pointer, also display what it points to.
265+ let s: evalexpr = ' *' . s: evalexpr
266+ call term_sendkeys (s: commbuf , ' -data-evaluate-expression "' . s: evalexpr . " \" \r " )
267+ endif
236268endfunc
237269
238270" Handle an error.
@@ -247,10 +279,10 @@ func s:HandleCursor(msg)
247279
248280 if win_gotoid (s: startwin )
249281 let fname = substitute (a: msg , ' .*fullname="\([^"]*\)".*' , ' \1' , ' ' )
250- if a: msg = ~ ' ^\*stopped' && filereadable (fname)
282+ if a: msg = ~ ' ^\(\ *stopped\|=thread-selected\) ' && filereadable (fname)
251283 let lnum = substitute (a: msg , ' .*line="\([^"]*\)".*' , ' \1' , ' ' )
252284 if lnum = ~ ' ^[0-9]*$'
253- if expand (' %:h ' ) != fname
285+ if expand (' %:p ' ) != fnamemodify ( fname, ' :p ' )
254286 if &modified
255287 " TODO: find existing window
256288 exe ' split ' . fnameescape (fname)
@@ -260,7 +292,7 @@ func s:HandleCursor(msg)
260292 endif
261293 endif
262294 exe lnum
263- exe ' sign place ' . s: pc_id . ' line=' . lnum . ' name=debugPC file=' . fnameescape ( fname)
295+ exe ' sign place ' . s: pc_id . ' line=' . lnum . ' name=debugPC file=' . fname
264296 setlocal signcolumn = yes
265297 endif
266298 else
@@ -288,11 +320,17 @@ func s:HandleNewBreakpoint(msg)
288320
289321 let fname = substitute (a: msg , ' .*fullname="\([^"]*\)".*' , ' \1' , ' ' )
290322 let lnum = substitute (a: msg , ' .*line="\([^"]*\)".*' , ' \1' , ' ' )
291-
292- exe ' sign place ' . (s: break_id + nr) . ' line=' . lnum . ' name=debugBreakpoint file=' . fnameescape (fname)
293-
294323 let entry[' fname' ] = fname
295324 let entry[' lnum' ] = lnum
325+
326+ if bufloaded (fname)
327+ call s: PlaceSign (nr, entry)
328+ endif
329+ endfunc
330+
331+ func s: PlaceSign (nr, entry)
332+ exe ' sign place ' . (s: break_id + a: nr ) . ' line=' . a: entry [' lnum' ] . ' name=debugBreakpoint file=' . a: entry [' fname' ]
333+ let a: entry [' placed' ] = 1
296334endfunc
297335
298336" Handle deleting a breakpoint
@@ -302,6 +340,33 @@ func s:HandleBreakpointDelete(msg)
302340 if nr == 0
303341 return
304342 endif
305- exe ' sign unplace ' . (s: break_id + nr)
306- unlet s: breakpoints [nr]
343+ if has_key (s: breakpoints , nr)
344+ let entry = s: breakpoints [nr]
345+ if has_key (entry, ' placed' )
346+ exe ' sign unplace ' . (s: break_id + nr)
347+ unlet entry[' placed' ]
348+ endif
349+ unlet s: breakpoints [nr]
350+ endif
307351endfunc
352+
353+ " Handle a BufRead autocommand event: place any signs.
354+ func s: BufRead ()
355+ let fname = expand (' <afile>:p' )
356+ for [nr, entry] in items (s: breakpoints )
357+ if entry[' fname' ] == fname
358+ call s: PlaceSign (nr, entry)
359+ endif
360+ endfor
361+ endfunc
362+
363+ " Handle a BufUnloaded autocommand event: unplace any signs.
364+ func s: BufUnloaded ()
365+ let fname = expand (' <afile>:p' )
366+ for [nr, entry] in items (s: breakpoints )
367+ if entry[' fname' ] == fname
368+ let entry[' placed' ] = 0
369+ endif
370+ endfor
371+ endfunc
372+
0 commit comments