mfussenegger / nvim-dap

Debug Adapter Protocol client implementation for Neovim
GNU General Public License v3.0
5.1k stars 179 forks source link

Can't set a breakpoint or pause the thread when run without breakpoints #1148

Closed RostyslavBuriak closed 5 months ago

RostyslavBuriak commented 5 months ago

Debug adapter definition and debug configuration

Using NvChad, so installing dap-nvim with Lazy :

local plugins = {
  {
    "mfussenegger/nvim-dap",
    event="VeryLazy",
    config = function(_, _)
      require("core.utils").load_mappings("dap")
      require "custom.configs.dap"
    end
  },
}

custom.configs.dap:

local dap = require("dap")

dap.adapters.gdb = {
  type = "executable",
  command = "gdb",
  args = { "-i", "dap"}
}

dap.configurations.cpp = {
  {
    name = "Launch",
    type = "gdb",
    request = "launch",
    program = function()
      return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
    end,
    args = function()
            local args_str = vim.fn.input({
                prompt = 'Arguments: ',
            })
            return vim.split(args_str, ' +')
    end,
    cwd = "${workspaceFolder}",
  },
  {
    name = "Attach to process (GDB)",
    type = 'gdb',
    request = 'attach',
    pid = function()
      local input_pid = vim.fn.input('Enter process ID: ')
      if input_pid ~= '' then
        return tonumber(input_pid)
      end
      return nil
    end,
  },
}

Debug adapter version

No response

Steps to Reproduce

  1. Build with gcc (for example following code):
    
    #include <iostream>
    #include <thread>

int main(int argc, char *argv[]){ std::cout << "Program name: " << argv[0] << std::endl;

// Print all command-line arguments
std::cout << "Arguments:" << std::endl;
for (int i = 1; i < argc; ++i) {
    std::cout << "  " << i << ": " << argv[i] << std::endl;
}

while(true){ std::this_thread::sleep_for(std::chrono::seconds(1)); std::cout << "woke up" << std::endl; } return 0; }


**g++ test.cpp -o test -g**

2. DapContinue with 'Launch' option
3. Choose any amount of arguments(might be empty)
4. Choose test as target
5. When debugger is attached try to :DapContinue 'Pause thread' or <leader>db (which toggles breakpoint)
6. See "Error setting breakpoints: notStopped" error or "Error requesting threads: notStopped"

### Expected Result

Breakpoint is successfully added and threads are successfully stopped.

### Actual Result

No threads are stopped and added breakpoint does not trigger upon restart.
mfussenegger commented 5 months ago

I can reproduce this, but looks like a debug adapter issue. The same works fine with either codelldb or cppdbg.

You'll have to report this upstream.