Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3a699a7

Browse filesBrowse files
kwon-youngjustinmk
authored andcommitted
runtime/termdebug.vim #8364
* commit 36257d0 Author: Kwon-Young Choi <kwon-young.choi@hotmail.fr> Date: Sat May 5 16:57:45 2018 +0200 Port of the termdebug.vim plugin to neovim terminal feature. For neovim compatibility, The vim specific calls were replaced with neovim specific calls: term_start -> term_open term_sendkeys -> jobsend term_getline -> getbufline job_info && term_getjob -> using linux command ps to get the tty fix1: forgot to port EndDebug callback to neovim fix2: use nvim_get_chan_info to get pty of job remove the use of communication buffer by using jobstart instead of termopen fix3: get gdbbuf using nvim_get_chan_info * cleaned up if has('nvim') to remove vim support. added neovim floating window support for expression evaluation * improvred documentation, cleaned up vim menu code, fixed bug when floating window feature is not available
1 parent 94f78cc commit 3a699a7
Copy full SHA for 3a699a7

File tree

Expand file treeCollapse file tree

2 files changed

+956
-124
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+956
-124
lines changed

‎runtime/doc/nvim_terminal_emulator.txt

Copy file name to clipboardExpand all lines: runtime/doc/nvim_terminal_emulator.txt
+253Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,257 @@ a local 'statusline'. Example: >
131131
:autocmd TermOpen * setlocal statusline=%{b:term_title}
132132
<
133133
==============================================================================
134+
5. Debugging *terminal-debug* *terminal-debugger*
135+
136+
The Terminal debugging plugin can be used to debug a program with gdb and view
137+
the source code in a Vim window. Since this is completely contained inside
138+
Vim this also works remotely over an ssh connection.
139+
140+
Starting ~
141+
*termdebug-starting*
142+
Load the plugin with this command: >
143+
packadd termdebug
144+
< *:Termdebug*
145+
To start debugging use `:Termdebug` or `:TermdebugCommand` followed by the
146+
command name, for example: >
147+
:Termdebug vim
148+
149+
This opens two windows:
150+
151+
gdb window A terminal window in which "gdb vim" is executed. Here you
152+
can directly interact with gdb. The buffer name is "!gdb".
153+
154+
program window A terminal window for the executed program. When "run" is
155+
used in gdb the program I/O will happen in this window, so
156+
that it does not interfere with controlling gdb. The buffer
157+
name is "gdb program".
158+
159+
The current window is used to show the source code. When gdb pauses the
160+
source file location will be displayed, if possible. A sign is used to
161+
highlight the current position, using highlight group debugPC.
162+
163+
If the buffer in the current window is modified, another window will be opened
164+
to display the current gdb position.
165+
166+
Focus the terminal of the executed program to interact with it. This works
167+
the same as any command running in a terminal window.
168+
169+
When the debugger ends, typically by typing "quit" in the gdb window, the two
170+
opened windows are closed.
171+
172+
Only one debugger can be active at a time.
173+
*:TermdebugCommand*
174+
If you want to give specific commands to the command being debugged, you can
175+
use the `:TermdebugCommand` command followed by the command name and
176+
additional parameters. >
177+
:TermdebugCommand vim --clean -c ':set nu'
178+
179+
Both the `:Termdebug` and `:TermdebugCommand` support an optional "!" bang
180+
argument to start the command right away, without pausing at the gdb window
181+
(and cursor will be in the debugged window). For example: >
182+
:TermdebugCommand! vim --clean
183+
184+
To attach gdb to an already running executable or use a core file, pass extra
185+
arguments. E.g.: >
186+
:Termdebug vim core
187+
:Termdebug vim 98343
188+
189+
If no argument is given, you'll end up in a gdb window, in which you need to
190+
specify which command to run using e.g. the gdb `file` command.
191+
192+
193+
Example session ~
194+
*termdebug-example*
195+
Start in the Vim "src" directory and build Vim: >
196+
% make
197+
Start Vim: >
198+
% ./vim
199+
Load the termdebug plugin and start debugging Vim: >
200+
:packadd termdebug
201+
:Termdebug vim
202+
You should now have three windows:
203+
source - where you started
204+
gdb - you can type gdb commands here
205+
program - the executed program will use this window
206+
207+
Put focus on the gdb window and type: >
208+
break ex_help
209+
run
210+
Vim will start running in the program window. Put focus there and type: >
211+
:help gui
212+
Gdb will run into the ex_help breakpoint. The source window now shows the
213+
ex_cmds.c file. A red "1 " marker will appear in the signcolumn where the
214+
breakpoint was set. The line where the debugger stopped is highlighted. You
215+
can now step through the program. You will see the highlighting move as the
216+
debugger executes a line of source code.
217+
218+
Run ":Next" a few times until the for loop is highlighted. Put the cursor on
219+
the end of "eap->arg", then call ":Eval". You will see this displayed:
220+
"eap->arg": 0x555555e68855 "gui" ~
221+
This way you can inspect the value of local variables. You can also focus the
222+
gdb window and use a "print" command, e.g.: >
223+
print *eap
224+
If mouse pointer movements are working, Vim will also show a balloon when the
225+
mouse rests on text that can be evaluated by gdb.
226+
You can also use the "K" mapping that will either use neovim floating windows
227+
if available to show the results or print below the status bar.
228+
229+
Now go back to the source window and put the cursor on the first line after
230+
the for loop, then type: >
231+
:Break
232+
You will see a "1" marker appear, this indicates the new breakpoint. Now
233+
run ":Cont" command and the code until the breakpoint will be executed.
234+
235+
You can type more advanced commands in the gdb window. For example, type: >
236+
watch curbuf
237+
Now run ":Cont" (or type "cont" in the gdb window). Execution
238+
will now continue until the value of "curbuf" changes, which is in do_ecmd().
239+
To remove this watchpoint again type in the gdb window: >
240+
delete 3
241+
242+
You can see the stack by typing in the gdb window: >
243+
where
244+
Move through the stack frames, e.g. with: >
245+
frame 3
246+
The source window will show the code, at the point where the call was made to
247+
a deeper level.
248+
249+
250+
Stepping through code ~
251+
*termdebug-stepping*
252+
Put focus on the gdb window to type commands there. Some common ones are:
253+
- CTRL-C interrupt the program
254+
- next execute the current line and stop at the next line
255+
- step execute the current line and stop at the next statement,
256+
entering functions
257+
- finish execute until leaving the current function
258+
- where show the stack
259+
- frame N go to the Nth stack frame
260+
- continue continue execution
261+
262+
*:Run* *:Arguments*
263+
In the window showing the source code these commands can be used to control
264+
gdb:
265+
`:Run` [args] run the program with [args] or the previous arguments
266+
`:Arguments` {args} set arguments for the next `:Run`
267+
268+
*:Break* set a breakpoint at the current line; a sign will be displayed
269+
*:Clear* delete the breakpoint at the current line
270+
271+
*:Step* execute the gdb "step" command
272+
*:Over* execute the gdb "next" command (`:Next` is a Vim command)
273+
*:Finish* execute the gdb "finish" command
274+
*:Continue* execute the gdb "continue" command
275+
*:Stop* interrupt the program
276+
277+
If gdb stops at a source line and there is no window currently showing the
278+
source code, a new window will be created for the source code. This also
279+
happens if the buffer in the source code window has been modified and can't be
280+
abandoned.
281+
282+
Gdb gives each breakpoint a number. In Vim the number shows up in the sign
283+
column, with a red background. You can use these gdb commands:
284+
- info break list breakpoints
285+
- delete N delete breakpoint N
286+
You can also use the `:Clear` command if the cursor is in the line with the
287+
breakpoint, or use the "Clear breakpoint" right-click menu entry.
288+
289+
290+
Inspecting variables ~
291+
*termdebug-variables* *:Evaluate*
292+
`:Evaluate` evaluate the expression under the cursor
293+
`K` same
294+
`:Evaluate` {expr} evaluate {expr}
295+
`:'<,'>Evaluate` evaluate the Visually selected text
296+
297+
This is similar to using "print" in the gdb window.
298+
You can usually shorten `:Evaluate` to `:Ev`.
299+
300+
301+
Other commands ~
302+
*termdebug-commands*
303+
*:Gdb* jump to the gdb window
304+
*:Program* jump to the window with the running program
305+
*:Source* jump to the window with the source code, create it if there
306+
isn't one
307+
308+
309+
Communication ~
310+
*termdebug-communication*
311+
There is another, hidden, buffer, which is used for Vim to communicate with
312+
gdb. The buffer name is "gdb communication". Do not delete this buffer, it
313+
will break the debugger.
314+
315+
Gdb has some weird behavior, the plugin does its best to work around that.
316+
For example, after typing "continue" in the gdb window a CTRL-C can be used to
317+
interrupt the running program. But after using the MI command
318+
"-exec-continue" pressing CTRL-C does not interrupt. Therefore you will see
319+
"continue" being used for the `:Continue` command, instead of using the
320+
communication channel.
321+
322+
323+
Customizing ~
324+
325+
GDB command *termdebug-customizing*
326+
327+
To change the name of the gdb command, set the "termdebugger" variable before
328+
invoking `:Termdebug`: >
329+
let termdebugger = "mygdb"
330+
331+
To use neovim floating windows for previewing variable evaluation, set the
332+
`g:termdebug_useFloatingHover` variable like this: >
333+
let g:termdebug_useFloatingHover = 1
334+
335+
If you are a mouse person, you can also define a mapping using your right
336+
click to one of the terminal command like evaluate the variable under the
337+
cursor: >
338+
nnoremap <RightMouse> :Evaluate<CR>
339+
or set/unset a breakpoint: >
340+
nnoremap <RightMouse> :Break<CR>
341+
342+
< *gdb-version*
343+
Only debuggers fully compatible with gdb will work. Vim uses the GDB/MI
344+
interface. The "new-ui" command requires gdb version 7.12 or later. if you
345+
get this error:
346+
Undefined command: "new-ui". Try "help".~
347+
Then your gdb is too old.
348+
349+
350+
Colors *hl-debugPC* *hl-debugBreakpoint*
351+
352+
The color of the signs can be adjusted with these highlight groups:
353+
- debugPC the current position
354+
- debugBreakpoint a breakpoint
355+
356+
The defaults are, when 'background' is "light":
357+
hi debugPC term=reverse ctermbg=lightblue guibg=lightblue
358+
hi debugBreakpoint term=reverse ctermbg=red guibg=red
359+
360+
When 'background' is "dark":
361+
hi debugPC term=reverse ctermbg=darkblue guibg=darkblue
362+
hi debugBreakpoint term=reverse ctermbg=red guibg=red
363+
364+
365+
Shorcuts *termdebug_shortcuts*
366+
367+
You can define your own shortcuts (mappings) to control gdb, that can work in
368+
any window, using the TermDebugSendCommand() function. Example: >
369+
map ,w :call TermDebugSendCommand('where')<CR>
370+
The argument is the gdb command.
371+
372+
373+
Vim window width *termdebug_wide*
374+
375+
To change the width of the Vim window when debugging starts, and use a
376+
vertical split: >
377+
let g:termdebug_wide = 163
378+
This will set &columns to 163 when `:Termdebug` is used. The value is restored
379+
when quitting the debugger.
380+
If g:termdebug_wide is set and &columns is already larger than
381+
g:termdebug_wide then a vertical split will be used without changing &columns.
382+
Set it to 1 to get a vertical split without every changing &columns (useful
383+
for when the terminal can't be resized by Vim).
384+
385+
386+
134387
vim:tw=78:ts=8:noet:ft=help:norl:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.