nvim-dap

2025-09-09 00:00    #nvim  

https://github.com/mfussenegger/nvim-dap

Debug Adapter Protocol client implementation for Neovim

安装

1return  {
2    "mfussenegger/nvim-dap",
3    config = function()
4    end
5}

Debug Adapter installation

我使用dap ui,按文档,我在linux下使用 vscode-cpptools,在 macos上使用 codelldb

linux 下安装

  1. 根据系统在github cpp-tools releases下载对应系统的visx
  2. Unpack it. .vsix is a zip file and you can use unzip to extract the contents.
  3. Ensure extension/debugAdapters/bin/OpenDebugAD7 is executable.

Adapter definition

1local dap = require('dap')
2dap.adapters.cppdbg = {
3  id = 'cppdbg',
4  type = 'executable',
5  command = '/absolute/path/to/cpptools/extension/debugAdapters/bin/OpenDebugAD7',
6}

Configuration The VSCode C/C++ documentation contains a full reference for all options supported by the debug adapter.

Common configuration examples:

 1local dap = require('dap')
 2dap.configurations.cpp = {
 3  {
 4    name = "Launch file",
 5    type = "cppdbg",
 6    request = "launch",
 7    program = function()
 8      return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
 9    end,
10    cwd = '${workspaceFolder}',
11    stopAtEntry = true,
12  },
13  {
14    name = 'Attach to gdbserver :1234',
15    type = 'cppdbg',
16    request = 'launch',
17    MIMode = 'gdb',
18    miDebuggerServerAddress = 'localhost:1234',
19    miDebuggerPath = '/usr/bin/gdb',
20    cwd = '${workspaceFolder}',
21    program = function()
22      return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
23    end,
24  },
25}

macos 下安装

Installation

  1. Install codelldb:
  2. Download the VS Code extension.
  3. Unpack it. .vsix is a zip file and you can use unzip to extract the contents

codelldb-darwin-arm64.vsix

配合nvim-dap-ui 使用

FAQ

如何使用display

如何使用条件断点:

设置条件断点的核心是调用 require('dap').set_breakpoint() 函数,并向其传递一个条件表达式字符串。

参考