You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

配置nvim-dap调试C++失败:Debug adapter无响应求助

nvim-dap C++调试启动失败的排查与修复

问题现象

配置nvim-dap后启动调试时,出现提示:

Debug adapter didn't respond. Either the adapter is slow (then wait and ignore this) or there is a problem with your adapter or cppdbg configuration. Check the logs for errors (:help dap.set_log_level)

同时弹出控制台显示waiting for v8 protocol on stdin/stdout。

原配置代码:

dap.adapters.cppdbg = {
     name = 'cppdbg',
    type = 'executable',
    command = vim.fn.stdpath('data') .. '/mason/bin/OpenDebugAD7.cmd',
}

dap.configurations.cpp = {
    {
      name = 'Debug Program',
      type = 'cppdbg',
      request = 'launch',
      MIMode = 'lldb',
      cwd = '${workspaceFolder}',
      stopAtEntry = true,
      program = function ()
        return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. '/', 'file')
      end,
    }
}

核心问题与修复步骤

  • 适配系统的命令路径:
    OpenDebugAD7.cmd是Windows平台的启动脚本,如果你在Linux或macOS上,必须去掉.cmd后缀,改为:

    command = vim.fn.stdpath('data') .. '/mason/bin/OpenDebugAD7',
    

    可先执行:echo vim.fn.stdpath('data')确认路径,检查mason/bin下是否存在对应文件。

  • MIMode配置冲突:
    cppdbg对lldb的支持需要额外配置LLDB路径,新手建议先切换为gdb,确保调试流程正常:
    将MIMode = 'lldb'改为MIMode = 'gdb',同时确保系统已安装gdb。

  • lldb模式补充配置:
    若坚持使用lldb,需添加miDebuggerPath指定lldb-mi的路径,比如macOS下可能是/usr/bin/lldb-mi,Linux下根据包管理器安装路径调整:

    MIMode = 'lldb',
    miDebuggerPath = '/usr/bin/lldb-mi',
    

修正后的完整配置示例(Linux/macOS + gdb)

dap.adapters.cppdbg = {
    name = 'cppdbg',
    type = 'executable',
    command = vim.fn.stdpath('data') .. '/mason/bin/OpenDebugAD7',
}

dap.configurations.cpp = {
    {
        name = 'Debug Program',
        type = 'cppdbg',
        request = 'launch',
        MIMode = 'gdb',
        cwd = '${workspaceFolder}',
        stopAtEntry = true,
        program = function ()
            return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. '/', 'file')
        end,
    }
}

额外排查步骤

  1. 执行:DapSetLogLevel trace开启日志,启动调试后查看:DapShowLog里的具体错误信息,定位路径或依赖问题。
  2. 确保编译程序时添加了-g调试符号,否则调试器无法识别断点和代码结构。

内容的提问来源于stack exchange,提问作者narcomoeba

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 08:25:19