Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Substitute paths when connecting to remote headless dlv server #43

Open
nnarayen opened this issue Apr 7, 2023 · 8 comments
Open

Substitute paths when connecting to remote headless dlv server #43

nnarayen opened this issue Apr 7, 2023 · 8 comments
Labels
wontfix This will not be worked on

Comments

@nnarayen
Copy link

nnarayen commented Apr 7, 2023

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

@guruor
Copy link

guruor commented Apr 24, 2023

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" }]
    }
  ]
}

@leoluz
Copy link
Owner

leoluz commented May 19, 2023

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?

@ryutah
Copy link

ryutah commented Oct 4, 2023

I was able to set the substitutionPath from configurations as described at mfussenegger/nvim-dap#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

@leoluz
Copy link
Owner

leoluz commented Oct 4, 2023

@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
Copy link

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

Copy link

stale bot commented May 30, 2024

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.

@stale stale bot added the wontfix This will not be worked on label May 30, 2024
@ddaniel27
Copy link

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

@stale stale bot removed the wontfix This will not be worked on label Jun 2, 2024
Copy link

stale bot commented Dec 4, 2024

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.

@stale stale bot added the wontfix This will not be worked on label Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

6 participants