mfussenegger / nvim-dap

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

`pick_process` does not work when a filter is passed to it #1173

Closed kyrillh closed 3 months ago

kyrillh commented 3 months ago

Debug adapter definition and debug configuration

    if not dap.adapters["lldb"] then
      require("dap").adapters["lldb"] = {
        type = "executable",
        command = "/opt/homebrew/Cellar/llvm/17.0.6_1/bin/lldb-vscode",
        name = "lldb",
      }
    end

    dap.configurations["cpp"] = {
       {
        name = "Attach",
        type = "lldb",
        request = "attach",
        pid = require("dap.utils").pick_process({ filter = "foo" }),
      },
     }

Debug adapter version

1.10.0

Steps to Reproduce

  1. Launch a C++ program to be debugged
  2. Call require("dap").continue() to select debugging profiles
  3. Select the Attach profile

Expected Result

A list of running processes filtered according to "foo" from which a process to attach to can be selected.

Actual Result

Debugger aborts printing the error message "Error on attach: no process specified, create a target with a file, or specify the --pid or --name". If the filter is left out i.e.

        pid = require("dap.utils").pick_process,

then a process can be selected from a list as would be expected.

mfussenegger commented 3 months ago

In pid = require("dap.utils").pick_process you're passing along a function reference. This function then gets called whenever you start a debug session using that particular configuration. In require("dap.utils").pick_process({ filter = "foo" }) you're calling the function immediately. The result of that first call is then frozen in the configuration definition.

You need to wrap the pick_process call in a function block to get the same kind of behaviour and have lazy evaluation.

kyrillh commented 3 months ago

Okay, thanks a lot for the explanation. I replaced the line with

pid = function()
          require("dap.utils").pick_process({ filter = "foo" })
end,

but am still getting the same behaviour.

mfussenegger commented 3 months ago
pid = function()
          return require("dap.utils").pick_process({ filter = "foo" })
end,
kyrillh commented 3 months ago

Works like a charm now. Thanks for the noob lua tips!