GoLand Remote Debugger unable to set breakpoints

485 views Asked by At

I'm trying to debug something in a go microservce, but when I go set a breakpoint, it comes up with the breakpoint unavailable and get the following error

cannot find debugger path for <PATH TO FILE>

I have checked the go modules in the settings. Doesn't matter where the breakpoint is. I've done invalidate caches and restart. This used to work.

My Docker file to build the debug service:

FROM golang:1.21-alpine

WORKDIR /user-service

# Install dependencies in go.mod and go.sum
COPY user_service/go.mod user_service/go.sum ./
COPY ./proto ../proto
COPY ./common ../common
RUN go mod download

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

# Copy rest of the application source code
COPY ./user_service ./

# Compile the application to /app.
# Skaffold passes in debug-oriented compiler flags
ARG SKAFFOLD_GO_GCFLAGS
ARG PORT=8081
RUN echo "Go gcflags: ${SKAFFOLD_GO_GCFLAGS}"
RUN go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -mod=readonly -v -o app

# Run the app
EXPOSE ${PORT} 40002
CMD ["dlv", "--listen=:40002", "--headless=true", "--api-version=2", "--accept-multiclient", "exec", "app"] 

Go Modules Enabled

EDIT:

Here's my project structure

└── Project Root/
    ├── docker-compose.yml
    ├── go.work/
    │   └── ....
    ├── common/
    │   └── pkg/
    │       └── ...
    ├── proto/
    │   └── ....
    └── <Microservice>/
        ├── docker/
        │   ├── cloud/
        │   │   └── Dockerfile
        │   ├── debug/
        │   │   └── Dockerfile
        │   └── local/
        │       └── Dockerfile
        └── internal/
            └── main.go
            └── (go code)

Try opening user_service

This doesn't work. This messes up the relative paths I have in the project. For more context, it's a mono-repo for microservice application. We're a really small team so distributed repos don't make sense, so I have everything in one.

I'll explain the difference in the docker files.

cloud is meant to build image for the cloud

local is meant to be an image for local development

debug is meant to be local, with the debugger attached.

ensure relative paths are available

They are. I can run the local docker-compose file just fine, and the only difference between the two docker files is the presence of dlv

Path mappings

I'm not sure where I should be looking here, nor what the paths should be. I'm relatively new to go (coming from Java) so I'm not 100% familiar with what the paths should be. I did try several variations of docker volumes but still nothing.

- ${PROJECT_ROOT}/user_service:[./ | / | ${PROJECT_ROOT}]/user_service 

What's odd to me is this used to work like a month ago. I haven't touched those dockerfiles, so I'm not sure what's up there.

It's also worth noting that the paths reported by goland are correct and there. So I don't know why it's saying it cant' find a file that's clearly there? Meaning it can't find it in the docker container? But then adding the volume doesn't solve it?

1

There are 1 answers

2
VonC On

Check first if this is similar to issue GO-15059, which has the same kind of issue without docker, but using a remote development environment.

It looks like its trying to find source code and searching the same path as the source system, a truncated suffix path on the remote system, and a root-based path on the remote system.

Will it work if you open arista project as a root project in the IDE instead of ~/go/src (File | Open) and make sure that the remote machine has the same file structure (arista/vendor/<...>) as you did for a quick test?

In your case, the error message cannot find debugger path for <PATH TO FILE> should be the result of a difference between the path that GoLand is using to reference your files and the actual file system path within the Docker container.

When debugging a Go application in a container via GoLand, the IDE needs to map the local source code to the corresponding code inside the container.

So make sure the Path Mappings in your GoLand run/debug configuration are set up correctly. These mappings tell GoLand how to correlate files in your project with files in the Docker container.
In GoLand, go to Run -> Edit Configurations, then select your debug configuration. Under Docker container settings, ensure that Path Mappings are correct.

Your Docker configuration should mount your project directory to the correct path in the container, matching the working directory (/user-service) as mentioned in your Dockerfile. If you are using docker-compose, make sure the volumes section is correctly configured to mount your local directory to /user-service in the container.

Your Dockerfile shows the installation of Delve and its configuration. Make sure the --listen and --headless flags are correctly set, and that the dlv command is correctly pointing to your compiled application.

Double-check also that your source code and its dependencies are correctly placed and referenced. Your Dockerfile shows copying of certain directories like ./proto and ./common to ../proto and ../common respectively, which are outside the working directory /user-service. If these paths are incorrect or not accessible, it might cause issues.