why nakama can not debug in goland

i clone source code
and config like this。

whe i run go build main.go and set a breakpoint .
then i get error like this。
image

We can’t debug Nakama’s source code directly. We can only embed it in a Docker runtime.
why? why?

Hello @jiangben,

Are you trying to debug Nakama or a Nakama plugin?

Are you getting any errors in the console?

I believe your config is insufficient, the Run Kind should be directory, and you need to add -trimpath -mod=vendor to the Go tool arguments.

You also need to be running the database and specify the database via config file or directly in the Program arguments.

If you’re trying to debug a plugin I’m not sure how to do it in Goland, but we have a guide to debug in VSCode.

Hope this helps.

the error happen when i try to debug nakama。

when i debug nakama plugins ,it was stack too.

i have go.mod


module tri-match-nakama-server

go 1.23

require (
	github.com/heroiclabs/nakama-common v1.28.1 // indirect
	google.golang.org/protobuf v1.31.0 // indirect
)

and
Dockerfile

FROM heroiclabs/nakama-pluginbuilder:3.16.0 AS go-builder
ENV GO111MODULE on
ENV CGO_ENABLED 1
WORKDIR /backend

RUN apt-get update && \
    apt-get -y upgrade && \
    apt-get install -y --no-install-recommends gcc libc6-dev

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

COPY go.mod .
COPY vendor/ vendor/
COPY *.go .

RUN go build --trimpath --gcflags "all=-N -l" --mod=vendor --buildmode=plugin -o ./backend.so

FROM eroiclabs/nakama-dsym:3.16.0

COPY --from=go-builder /go/bin/dlv /nakama
COPY --from=go-builder /backend/backend.so /nakama/data/modules/
COPY local.yml /nakama/data/

and launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Delve into Docker",
            "type": "go",
            "request": "attach",
            "mode": "remote",
            "port": 4000,
            "host": "127.0.0.1",
            "showLog": true,
            "debugAdapter": "dlv-dap",  
            "apiVersion": 2,
            "trace": "verbose",
            "substitutePath": [
                { 
                    "from": "${workspaceFolder}/",
                    "to": "tri-match-nakama-server"
                },
            ]
        }
    ]
}

then i run docker-compose up
get

nakama_1    | {"level":"info","ts":"2023-10-07T14:06:42.723Z","caller":"migrate/migrate.go:155","msg":"Database connection","dsn":"postgres://postgres:xxxxx@postgres:5432/nakama?sslmode=prefer"}
nakama_1    | {"level":"info","ts":"2023-10-07T14:06:42.733Z","caller":"migrate/migrate.go:203","msg":"Database information","version":"PostgreSQL 12.2 on x86_64-pc-linux-musl, compiled by gcc (Alpine 9.2.0) 9.2.0, 64-bit"}
nakama_1    | {"level":"info","ts":"2023-10-07T14:06:42.738Z","caller":"migrate/migrate.go:226","msg":"Successfully applied migration","count":0}
nakama_1    | + /nakama/dlv --log --log-output=debugger --listen=:4000 --headless=true --api-version=2 exec nakama -- --config /nakama/data/local.yml --database.address postgres:localdb@postgres:5432/nakama
nakama_1    | API server listening at: [::]:4000
nakama_1    | 2023-10-07T14:06:42Z warning layer=rpc Listening for remote connections (connections are not authenticated nor encrypted)
nakama_1    | 2023-10-07T14:06:42Z info layer=debugger launching process with args: [nakama --config /nakama/data/local.yml --database.address postgres:localdb@postgres:5432/nakama]

the i run debug
nothing happen why?

image


error all the same~help me

i try to debug nakama and nakama plugins

Hello @jiangben,

To debug the plugin code you should follow the guide and use VSCode as Goland doesn’t seem to support remote debugging of plugins very well. Locally I was able to successfully set and hit a breakpoint within a custom RPC. However I was unable to set a breakpoint in the main plugin function via VSCode that would be hit upon restarting the debug session.

Unfortunately debugging Go plugins via dlv doesn’t seem to be very well supported by existing IDEs. You might be more successful in using the dlv command line from a docker container directly, but it’s something you’ll have to experiment with - your mileage may vary.

Best

I have released a goland plugin in the jetbrain plugin repo.

It fixes the flaw of the current jetbrain#IDE dlv remote debugging features.

You can find the video on YouTube

Welcome to use it :slight_smile: Accept any different thoughts.

1 Like

Here is the plugin link

1 Like