Substitute paths when connecting to remote headless dlv server #43

Closed
opened 2023-04-07 21:49:23 +03:00 by nnarayen · 8 comments
nnarayen commented 2023-04-07 21:49:23 +03:00 (Migrated from github.com)

I'm currently using nvim-dap and nvim-dap-go to connect to a headless dlv server running remotely in k8s. Unfortunately, the source code during compilation of the remote binary is different than my local source code, so by default most breakpoint functionality does not work.

As far as I understand, path transformations occur client side and not on the dlv server. I can get this to work via dlv connect on my local machine either with config substitute-path <from> <to> or via the dlv config.yml file. Unfortunately, I haven't found a way to have the nvim dap client perform any path substitutions.

This issue is more of an open question, but do you know if that's currently possible? Thanks in advance!

Build information

Remote dlv server

Delve Debugger
Version: 1.20.1
Build: $Id: 96e65b6c615845d42e0e31d903f6475b0e4ece6e $

nvim-dap: v0.5.0
nvim-dap-go: sha b4ded7de579b4e2a85c203388233b54bf1028816

I'm currently using `nvim-dap` and `nvim-dap-go` to connect to a headless `dlv` server running remotely in k8s. Unfortunately, the source code during compilation of the remote binary is different than my local source code, so by default most breakpoint functionality does not work. As far as [I](https://github.com/go-delve/delve/issues/2203#issuecomment-710480859) [understand](https://github.com/go-delve/delve/issues/3265), path transformations occur _client_ side and not on the `dlv` server. I can get this to work via `dlv connect` on my local machine either with `config substitute-path <from> <to>` or via the `dlv` config.yml file. Unfortunately, I haven't found a way to have the nvim dap client perform any path substitutions. This issue is more of an open question, but do you know if that's currently possible? Thanks in advance! Build information Remote `dlv` server ``` Delve Debugger Version: 1.20.1 Build: $Id: 96e65b6c615845d42e0e31d903f6475b0e4ece6e $ ``` `nvim-dap`: v0.5.0 `nvim-dap-go`: sha `b4ded7de579b4e2a85c203388233b54bf1028816`
guruor commented 2023-04-24 04:54:03 +03:00 (Migrated from github.com)

I am not a user of nvim-dap-go, but came across this issue with custom nvim-dap config.
For me I use substitutePath with vscode launch.json, that works pretty well, maybe you can try using that.

launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Golang: Remote Attach delve launch.json",
      "type": "go",
      "debugAdapter": "dlv-dap",
      "request": "attach",
      "mode": "remote",
      "preLaunchTask": "debug-attach",
      "postDebugTask": "debug-stop",
      "connect": {
        "host": "127.0.0.1",
        "port": 38697
      },
      "logToFile": true,
      "cwd": "${workspaceFolder}",
      "pathMappings": [
        {
          "localRoot": "${workspaceFolder}",
          "remoteRoot": "/app"
        }
      ],
      "substitutePath": [{ "from": "${workspaceFolder}", "to": "/app" }]
    }
  ]
}

I am not a user of `nvim-dap-go`, but came across this issue with custom nvim-dap config. For me I use `substitutePath` with vscode `launch.json`, that works pretty well, maybe you can try using that. <details> <summary> launch.json</summary> <p> ``` { "version": "0.2.0", "configurations": [ { "name": "Golang: Remote Attach delve launch.json", "type": "go", "debugAdapter": "dlv-dap", "request": "attach", "mode": "remote", "preLaunchTask": "debug-attach", "postDebugTask": "debug-stop", "connect": { "host": "127.0.0.1", "port": 38697 }, "logToFile": true, "cwd": "${workspaceFolder}", "pathMappings": [ { "localRoot": "${workspaceFolder}", "remoteRoot": "/app" } ], "substitutePath": [{ "from": "${workspaceFolder}", "to": "/app" }] } ] } ``` </p> </details>
leoluz commented 2023-05-19 21:30:43 +03:00 (Migrated from github.com)

Unfortunately, I haven't found a way to have the nvim dap client perform any path substitutions.

@nnarayen I am also unaware of such configuration. Have you tried asking in the nvim-dap project?

> Unfortunately, I haven't found a way to have the nvim dap client perform any path substitutions. @nnarayen I am also unaware of such configuration. Have you tried asking in the [nvim-dap project](https://github.com/mfussenegger/nvim-dap)?
ryutah commented 2023-10-04 11:50:16 +03:00 (Migrated from github.com)

I was able to set the substitutionPath from configurations as described at https://github.com/mfussenegger/nvim-dap/issues/905.

It requires some ingenuity as the substitutePath needs to match the remote path, but I have been able to debug applications running on Docker with the configuration below.

local dap_go = require('dap-go')
local dap = require('dap')

dap_go.setup()
table.insert(dap.configurations.go, {
  type = 'delve',
  name = 'Attach remote',
  mode = 'remote',
  request = 'attach',
  substitutePath = {
    { from = '${workspaceFolder}', to = '/app' },
  },
})
dap.adapters.delve = {
  type = 'server',
  host = 'localhost',
  port = '38697'
}

It works like this.

sample

I was able to set the `substitutionPath` from configurations as described at https://github.com/mfussenegger/nvim-dap/issues/905. It requires some ingenuity as the `substitutePath` needs to match the remote path, but I have been able to debug applications running on Docker with the configuration below. ```lua local dap_go = require('dap-go') local dap = require('dap') dap_go.setup() table.insert(dap.configurations.go, { type = 'delve', name = 'Attach remote', mode = 'remote', request = 'attach', substitutePath = { { from = '${workspaceFolder}', to = '/app' }, }, }) dap.adapters.delve = { type = 'server', host = 'localhost', port = '38697' } ``` It works like this. ![sample](https://github.com/leoluz/nvim-dap-go/assets/6662577/739259cc-e4fb-426c-9102-a77cceda4ad7)
leoluz commented 2023-10-04 16:29:17 +03:00 (Migrated from github.com)

@nnarayen can you please try the suggestion provided by @ryutah and confirm that it is working for you. Maybe we can improve the docs describing it for users with the same requirements.

@nnarayen can you please try the suggestion provided by @ryutah and confirm that it is working for you. Maybe we can improve the docs describing it for users with the same requirements.
gvital3230 commented 2023-11-29 22:30:16 +03:00 (Migrated from github.com)

Hi, debug in remote container in Kubernetes works fine for me.

Here is the full plugin config for Lazy.

      {
        "leoluz/nvim-dap-go",
        opts = {
          dap_configurations = {
            {
              -- Must be "go" or it will be ignored by the plugin
              type = "go",
              name = "Connect remote",
              request = "attach",
              mode = "remote",
              substitutePath = {
                {
                  from = "${workspaceFolder}",
                  to = "/app",
                },
              },
            },
          },
          delve = {
            port = 2345,
          },
        },
      },

I use 2345 port for communication with dlv, so my command in remote container is

dlv debug --headless --listen=:2345 --log --api-version=2
Hi, debug in remote container in Kubernetes works fine for me. Here is the full plugin config for `Lazy`. ```lua { "leoluz/nvim-dap-go", opts = { dap_configurations = { { -- Must be "go" or it will be ignored by the plugin type = "go", name = "Connect remote", request = "attach", mode = "remote", substitutePath = { { from = "${workspaceFolder}", to = "/app", }, }, }, }, delve = { port = 2345, }, }, }, ``` I use 2345 port for communication with dlv, so my command in remote container is ```bash dlv debug --headless --listen=:2345 --log --api-version=2 ```
stale[bot] commented 2024-05-30 05:42:27 +03:00 (Migrated from github.com)

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
ddaniel27 commented 2024-06-02 22:35:18 +03:00 (Migrated from github.com)

I can confirm that setup given from @ryutah works fine for me to debug in a remote container. In my case I use /wd as my application path in docker, so I have to change it. This is my entirely setup:

Dockerfile:

FROM golang:1.20-bullseye

WORKDIR /wd

COPY go.mod .
COPY go.sum .

RUN go mod download -x

RUN go install github.com/go-delve/delve/cmd/dlv@latest

COPY . .

CMD ["dlv", "debug", "--listen=:34567", "--headless", "--build-flags='-buildvcs=false'"]

nvim setup:

local dap_go = require('dap-go')
local dap = require('dap')

dap_go.setup()
table.insert(dap.configurations.go, {
  type = 'delve',
  name = 'Container debugging (/wd:34567)',
  mode = 'remote',
  request = 'attach',
  substitutePath = {
    { from = '${workspaceFolder}', to = '/wd' },
  },
})

dap.adapters.delve = {
  type = 'server',
  host = 'localhost',
  port = '34567'
}

docker-compose:

version: '3'
services:
  app:
    container_name: my-app
    hostname: my-app
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - '3000:3000'
      - '34567:34567'
    restart: unless-stopped
    volumes:
      - ./:/wd
I can confirm that [setup](https://github.com/leoluz/nvim-dap-go/issues/43#issuecomment-1746423867) given from @ryutah works fine for me to debug in a remote container. In my case I use `/wd` as my application path in docker, so I have to change it. This is my entirely setup: Dockerfile: ```Dockerfile FROM golang:1.20-bullseye WORKDIR /wd COPY go.mod . COPY go.sum . RUN go mod download -x RUN go install github.com/go-delve/delve/cmd/dlv@latest COPY . . CMD ["dlv", "debug", "--listen=:34567", "--headless", "--build-flags='-buildvcs=false'"] ``` nvim setup: ```lua local dap_go = require('dap-go') local dap = require('dap') dap_go.setup() table.insert(dap.configurations.go, { type = 'delve', name = 'Container debugging (/wd:34567)', mode = 'remote', request = 'attach', substitutePath = { { from = '${workspaceFolder}', to = '/wd' }, }, }) dap.adapters.delve = { type = 'server', host = 'localhost', port = '34567' } ``` docker-compose: ```yml version: '3' services: app: container_name: my-app hostname: my-app build: context: . dockerfile: Dockerfile ports: - '3000:3000' - '34567:34567' restart: unless-stopped volumes: - ./:/wd ```
stale[bot] commented 2024-12-04 08:05:26 +03:00 (Migrated from github.com)

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
NeonXP/nvim-dap-go#43
No description provided.