Instead of gdbtui
or ctrl+x
under gdb
which shows source code on top of the screen I would like to see this in my Vim editor that would jump between tabs, and buffers accordingly.
How can I do this?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityInstead of gdbtui
or ctrl+x
under gdb
which shows source code on top of the screen I would like to see this in my Vim editor that would jump between tabs, and buffers accordingly.
How can I do this?
Among all the plugins I have tried, I found ConqueGDB to be the best approach. ConqueGDB uses Conque Shell to embed an interactive shell inside vim, that is used by GDB.
The workflow with ConqueGDB consists not entering GDB commands on the GDB terminal, you use shortcuts on the vim source code. But you can continue using the GDB prompt if you want, for more advanced commands, or scroll to see the whole debug session.
Some ConqueGDB default mappings, for example:
Notice how the vim cursor line has been used to issue a GDB 'print row', the current execution of code is in another line (14) and there's a breakpoint on line 10.
To install with Vundle for example:
Plugin 'vim-scripts/Conque-GDB'
I use these plugin options:
let g:ConqueTerm_Color = 2 " 1: strip color after 200 lines, 2: always with color
let g:ConqueTerm_CloseOnEnd = 1 " close conque when program ends running
let g:ConqueTerm_StartMessages = 0 " display warning messages if conqueTerm is configured incorrectly
<leader>r
means <kbd>\</kbd>+<kbd>r</kbd> on my computers. Vim manual has an entry for it: :help leader
<Leader>b
. It sets a breakpoint at the cursor position. However, it is NOT a toggle, so you cannot use it to remove it again. Rather, you will have to write 'clear' on the GDB prompt.
:term
is available in vim), instead writes its own, user need to define key map manually separately from tmap
. // See also terminal - Is there an upgraded version of the Conque plugin? - Vi and Vim Stack Exchange
Jan 21, 2022 at 10:05
You have several plugins that integrates gdb.
And there is also a plugin that integrates lldb (from LLVM project)
It seems that Bram is currently (september 2017) working on the integration of gdb from within vim thanks to the new :terminal
feature. To use it, we need to load termdebug
packet (with :packadd termdebug
), then we'll be able to start a gdb console in a vim window with :TermDebug (+options)
. IMO, we can consider it to be the future of GDB integration under Vim.
Vim 8.1 adds debugger integration, see :help terminal-debug
. The summary is that you run
:packadd termdebug
:Termdebug myprogram
And then you can set breakpads either in the gdb buffer using b myfunc
, or in the vim window with :Break
, or by right-clicking a line and picking "Set breakpoint". Similarly, there are 3 methods for running the program, stepping, etc. You can hit K
in the vim source buffer to see the value of the expression under the cursor in the status bar (:messages
gives you a history as usual).
https://www.dannyadam.com/blog/2019/05/debugging-in-vim/ has a full worked example.
frame.select()
Python API is used to switch frame, vim will not highlight the current line, even if the user call frame <current frame number>
afterwards, because the thread-selected
message is not sent to gdb.
Jan 21, 2022 at 14:20
tty
on gdb)
Jan 21, 2022 at 14:27
GDB edit
command
Opens an editor on the current line using the command:
$EDITOR +<current-line> <current-file>
The default editor
is ex
, but vim
also understands the +<current-line>
format.
When you quit the editor, you get back into gdb
.
This allows you to browse the source freely and is specially powerfull if you have ctags
integration.
This is a poor-man's built-in one way gdb to vim integration: the main missing thing is setting breakpoints from Vim.
edit
and center
edit
does not center Vim by default around the source, so I've created a Python script that does it: https://stackoverflow.com/questions/43557405/how-to-open-the-current-file-at-the-current-line-in-a-text-editor-from-gdb/43557406#43557406
Breakpoint command to clipboard helper
This vim command copies a breakpoint specifier of type:
b <file-path>:<line-number>
to the clipboard:
command! Xg :let @+ = 'b ' . expand('%:p') . ':' . line('.')
Then you can just paste that into gdb
.
This is a poor man's vim to gdb integration to ease setting breakpoints.
See also: https://stackoverflow.com/questions/3536600/do-you-debug-c-code-in-vim-how
Although not technically vim. cgdb is a curses version of gdb with vim-like keybindings. It's been my goto debugger for years: