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

nvim-dap调试C++时断点始终被拒绝的问题求助

nvim-dap调试C++时断点被忽略问题求助

我在使用nvim-dap进行C++调试时,设置的断点始终被忽略。已确认nvim-dap的配置文件被正确读取,希望有相关经验的开发者帮忙排查问题。

操作流程

  • 创建测试用C++文件main.cpp
  • 通过F2快捷键编译运行,对应的按键映射配置:
    vim.api.nvim_set_keymap('n', '<F2>', ":w<CR>:rightbelow vsp | terminal g++ -g % -o %< && ./%< <CR>i", { noremap = true, silent = true })
    
  • 使用Ctrl + b设置断点,行号右侧会显示🔴标记;F5快捷键对应调试启动,映射配置:
    vim.keymap.set('n', '<F5>', function() require('dap').continue() end)
    
  • 按下F5启动调试,选择可执行文件路径/path/to/main
  • 所有断点被忽略,程序直接运行至结束,断点标记变为⚠️(拒绝状态)

测试用main.cpp代码

#include <iostream>
#include <cmath>


int main(){
  int a,b,c,d;
  a = 3;
  b = 5;
  c = a + b;
  d = b - a;
  std::cout << "c = " << c << std::endl;
  std::cout << "d = " << d << std::endl;

  return 0;
}

nvim-dap配置Lua代码

return
-- nvim-dap
{
  "mfussenegger/nvim-dap",
  config = function()
    local dap = require('dap'),
    vim.fn.sign_define('DapBreakpoint', {text='🔴', texthl='DapBreakpoint', linehl='', numhl=''}),
    vim.fn.sign_define('DapStopped', {text='➡️', texthl='DapStopped', linehl='DebugLineHL', numhl=''}),
    vim.fn.sign_define('DapBreakpointCondition', {text='🔶', texthl='DapBreakpoint', linehl='', numhl=''}),
    vim.fn.sign_define('DapBreakpointRejected', {text='⚠️', texthl='DapBreakpoint', linehl='', numhl=''})
    dap.adapters.lldb = {
      type = 'executable',
      command = '/opt/homebrew/opt/llvm/bin/lldb-dap',
      name = 'lldb'
    }
    dap.configurations.cpp = {
      {
        name = 'Launch',
        type = 'lldb',
        request = 'launch',
        program = function()
          return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
        end,
        cwd = '${workspaceFolder}',
        stopOnEntry = false,
        args = {},
      },
    }
  end
}

已确认事项

  • 配置中的/opt/homebrew/opt/llvm/bin/lldb-dap路径正确
  • lldb-dap --help命令可正常执行

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 01:52:43