🐞 Debugging Extra
Debug C and C++ programs inside Neovim with breakpoints, stepping and variable inspection, using nvim-dap.
Enabling
Included in the 42 extra. To enable it on its own, select dap in :FtVimExtras or add:
{ import = "ftvim.plugins.extras.dap" },
Requirements
- Linux: gdb 14 or newer (it speaks the debug adapter protocol natively)
- macOS / no gdb: codelldb, installed automatically with Mason when gdb is not found
:checkhealth ftvim shows which debugger is used.
tip
Compile with -g to get breakpoints and variable names. For example, add it to CFLAGS in your Makefile while debugging (and remove it before submitting).
Usage
- Build your program with
-g - Put the cursor on a line and press
<leader>dbto set a breakpoint - Press
<F5>(or<leader>dc). The program defaults to the Makefile'sNAME, and you are asked for its arguments - The debugger UI opens with variables, the call stack and breakpoints. Step with
<leader>do/<leader>di/<leader>dO
Variable values are also shown inline, next to your code.
Keymaps
| Keymap | Description |
|---|---|
<F5> / <leader>dc | Run / Continue |
<leader>db | Toggle breakpoint |
<leader>dB | Conditional breakpoint |
<leader>dC | Run to cursor |
<leader>do | Step over |
<leader>di | Step into |
<leader>dO | Step out |
<leader>dl | Run last |
<leader>dr | Toggle REPL |
<leader>dt | Terminate |
<leader>du | Toggle debugger UI |
<leader>de | Evaluate expression (normal and visual mode) |
Included Plugins
| Plugin | Description |
|---|---|
| nvim-dap | Debug Adapter Protocol client |
| nvim-dap-ui | Debugger UI |
| nvim-dap-virtual-text | Inline variable values |