Home

Awesome

Test Codacy Badge

GDB for neovim

Gdb, LLDB, pdb/pdb++ and BASHDB integration with NeoVim.

Table of contents

Overview

Taken from the neovim: neovim_gdb.vim

It is instantly usable: type <leader>dd, edit GDB launching command, hit <cr>. Or type <leader>dl to do the same with LLDB backend. Or type <leader>dp to start debugging a python program. Or type <leader>db to start debugging a BASH script.

Also you can record the execution of a program with rr record, and then replay its execution systematically with <leader>dr.

Supported debuggers and operating systems:

DebuggerLinuxDarwinWindows
GNU gdb
lldb
pdb
BashDB
rr

nvim-gdb

Installation

Check the prerequisites in the script test/prerequisites.py.

Use the branch master for NeoVim ≥ 0.7 or the branch devel to benefit from the latest NeoVim features.

If you use vim-plug, add the following line to your vimrc file:

Plug 'sakhnik/nvim-gdb'

Options

To disable the plugin

let g:loaded_nvimgdb = 1

:GdbStart and :GdbStartLLDB use find and the cmake file API to try to tab-complete the command with the executable for the current file. To disable this set g:nvimgdb_use_find_executables or g:nvimgdb_use_cmake_to_find_executables to 0.

The behaviour of the plugin can be tuned by defining specific variables. For instance, you could overload some command keymaps:

" We're going to define single-letter keymaps, so don't try to define them
" in the terminal window.  The debugger CLI should continue accepting text commands.
function! NvimGdbNoTKeymaps()
  tnoremap <silent> <buffer> <esc> <c-\><c-n>
endfunction

let g:nvimgdb_config_override = {
  \ 'key_next': 'n',
  \ 'key_step': 's',
  \ 'key_finish': 'f',
  \ 'key_continue': 'c',
  \ 'key_until': 'u',
  \ 'key_breakpoint': 'b',
  \ 'set_tkeymaps': "NvimGdbNoTKeymaps",
  \ }

Likewise, you could define your own hooks to be called when the source window is entered and left. Please refer to the online NeoVim help: :help nvimgdb.

Usage

See :help nvimgdb for the complete online documentation. Most notable commands:

MappingCommandDescription
<Leader>dd:GdbStart gdb -q ./a.outStart debugging session, allows editing the launching command
<Leader>dl:GdbStartLLDB lldb ./a.outStart debugging session, allows editing the launching command
<Leader>dp:GdbStartPDB python -m pdb main.pyStart Python debugging session, allows editing the launching command
<Leader>db:GdbStartBashDB bashdb main.shStart BASH debugging session, allows editing the launching command
<Leader>dr:GdbStartRRStart debugging session with rr replay.
<F8>:GdbBreakpointToggleToggle breakpoint in the coursor line
<F4>:GdbUntilContinue execution until a given line (until in gdb)
<F5>:GdbContinueContinue execution (continue in gdb)
<F10>:GdbNextStep over the next statement (next in gdb)
<F11>:GdbStepStep into the next statement (step in gdb)
<F12>:GdbFinishStep out the current frame (finish in gdb)
<c-p>:GdbFrameUpNavigate one frame up (up in gdb)
<c-n>:GdbFrameDownNavigate one frame down (down in gdb)

You can create a watch window evaluating a backend command on every step. Try :GdbCreateWatch info locals in GDB, for istance.

You can open the list of breakpoints or backtrace locations into the location list. Try :GdbLopenBacktrace or :GdbLopenBreakpoints.

Development

The goal is to have a thin wrapper around GDB, LLDB, pdb/pdb++ and BASHDB, just like the official TUI. NeoVim will enhance debugging with syntax highlighting and source code navigation.

The project uses GitHub actions to run the test suite on every commit automatically. The plugin, proxy and screen logs can be downloaded as the artifacts to be analyzed locally.

To ease reproduction of an issue, set the environment variable CI, and launch NeoVim with the auxiliary script test/nvim.py. The screen cast will be written to the log file spy_ui.log. Alternatively, consider recording the terminal script with the ubiquitous command script.

To support development, consider donating:

References

Showcase

GdbStartRR

nvim-gdb + llvm

clone + test