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

Goland breakpoint file line mismatch #21

Open
baledreamcastau opened this issue Apr 3, 2024 · 11 comments
Open

Goland breakpoint file line mismatch #21

baledreamcastau opened this issue Apr 3, 2024 · 11 comments
Labels
good first issue Good for newcomers

Comments

@baledreamcastau
Copy link

Thanks for the plugins!

I managed to breakpoint using Goland based on your plugin and documentation.

I triggered the RpcTest call from the admin local website, however my breakpoint is a bit weird, when the program hit a breakpoint, the Goland breakpoint line doesnt turn to blue like it always does. and the code line from the breakpoint data does not match my actual code file’s line (function call is at line 16 but the breakpoint data shows it is main.go:17)
1

here is my docker compose’s entrypoint config

entrypoint:
      - "/bin/sh"
      - "-ecx"
      - >
        /nakama/nakama migrate up --database.address postgres:localdb@postgres:5432/nakama &&
        /nakama/dlv --log --log-output=debugger --listen=:4000 --headless=true --accept-multiclient --api-version=2 exec nakama -- --config /nakama/data/local.yml --database.address postgres:localdb@postgres:5432/nakama

here is my docker file

FROM heroiclabs/nakama-pluginbuilder:3.21.1 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 src/*.go .
COPY vendor/ vendor/

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

FROM registry.heroiclabs.com/heroiclabs/nakama-dsym:3.21.1

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

can you tell what i did wrongly ? thank you for your time i would really appreciate if you could help me take a look

@baledreamcastau
Copy link
Author

my setup
goland 2023.2.2
go1.21.4
dlxy 1.0.0
namaka: 3.21.1
window 10

@BOFA1ex
Copy link
Owner

BOFA1ex commented Apr 3, 2024

dlv

it works on its setups

goland.version=2023.3.6
go=1.21
nakama=3.20.0
os=window10/macOS

@BOFA1ex
Copy link
Owner

BOFA1ex commented Apr 3, 2024

dlv2

upgrade nakama&plugin-builder, it works yet.

nakama=3.21.1

here is my docker compose’s entrypoint config

entrypoint:
  - "/bin/sh"
  - "-ecx"
  - >
    /nakama/nakama migrate up --database.address postgres:localdb@postgres:5432/nakama &&
    /nakama/dlv --log --log-output=debugger,debuglineerr,gdbwire,lldbout,rpc --accept-multiclient --listen=:4000 --headless=true --api-version=2 exec /nakama/nakama -- --config /nakama/data/local.yml --database.address postgres:localdb@postgres:5432/nakama

it difference with --log-output=rpc, maybe its important.

here is my docker file

FROM heroiclabs/nakama-pluginbuilder:3.21.1 AS go-builder
ENV GO111MODULE on
ENV CGO_ENABLED 1
ENV GOOS linux
ENV GOARCH amd64

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 local.yml .
COPY go.mod .
COPY *.go .
COPY vendor/ vendor/
COPY api/ api/

# Go runtime plugin using the --gcflags "all=-N -l" flag which effectively disables optimizations in the resulting plugin file.
RUN go build --trimpath --gcflags "all=-N -l" --mod=vendor --buildmode=plugin -o ./backend.so

# Using the nakama-dsym image rather than the standard nakama image.
# This is an image that provides us with a Nakama binary with optimizations disabled, suitable for running with dlv just like our plugin.
FROM registry.heroiclabs.com/heroiclabs/nakama-dsym:3.21.1

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

@BOFA1ex
Copy link
Owner

BOFA1ex commented Apr 3, 2024

Whether the packaged plug-in so file is consistent with your actual current code, this is currently the only possibility.

Please build dockerfile with latest code and try it again.

@BOFA1ex BOFA1ex added the help wanted Extra attention is needed label Apr 3, 2024
@baledreamcastau
Copy link
Author

Hi BOFA1ex

Thanks for the reply

I have tried using your docker file and compose file, and rebuilt the docker container. Still no luck, I guess i will just wait and hope this issue can go away in future updates

thanks for providing such a great plugin :)

@BOFA1ex
Copy link
Owner

BOFA1ex commented Apr 5, 2024

@baledreamcastau Would you mind sharing your nakama-plugin demo repo(slim)? For better reproduce your situation, i'll check it out step-by-step.

@baledreamcastau
Copy link
Author

demo-server-main.zip
Hi @BOFA1ex

Thanks for the reply

Here is my server git repo, appreciate in advance !

@BOFA1ex
Copy link
Owner

BOFA1ex commented Apr 6, 2024

@baledreamcastau i found the problem!
dlv3
dlv4

Because in goland(vgo.dlv) fetching the remote_file_path via the virtual_psi_file(which relatived src/player.go)

VirtualFileAbsolutePath

xxx/GolandProjects/sortify-server-main/src/player.go

VirtualFileRelativePath

src/player.go

DelveRemoteFilePath

dreamcastau.com/sortify/player.go

Solution:

  1. Changed the Dockerfile COPY src/*.go src/
    • COPY src/*.go src/
    • COPY src/* . (for build backend.so)
    • And change the(package main) as (package src)
  2. [RECOMMAND] Changed your go_project_structure, move the go files outside, not in src.

@BOFA1ex BOFA1ex added good first issue Good for newcomers and removed help wanted Extra attention is needed labels Apr 6, 2024
@BOFA1ex BOFA1ex pinned this issue Apr 6, 2024
@baledreamcastau
Copy link
Author

baledreamcastau commented Apr 7, 2024

Hi @BOFA1ex

Thank you for taking time investigating this issue :)

I have tried your second suggestion, i have moved all of my go files to outside of the src folder (their package is main still) and have my docker file updated (i noticed i have one less COPY yaml so added it int)

However, my breakpoint still seems not fixed :(
image

Did i do any step wrongly or missed any steps ?

@BOFA1ex
Copy link
Owner

BOFA1ex commented Apr 7, 2024

dlv5

Here is the modified Dockerfile:
Make sure the COPY *.go ., move the source code in WORKDIR.

FROM heroiclabs/nakama-pluginbuilder:3.21.1 AS go-builder

ENV GO111MODULE on
ENV CGO_ENABLED 1
ENV GOOS linux
ENV GOARCH amd64

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 *.go .
COPY vendor/ vendor/

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

FROM registry.heroiclabs.com/heroiclabs/nakama-dsym:3.21.1

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

@baledreamcastau
Copy link
Author

Still no luck, my suspicion is on the go build optimization or it has sth to do with my goland settings, or my go version. Because the breakpoint line does not match my actual file line.

so i guess sth interrupted the go build process to cause the final go file built not being exactly the same as my orignial go file.

But anyway the current debugging support should be enough for my project's current development phase, i will come back to investigate this issue again when im more freed up

Thank you for taking time helping me ! i really appreciated it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants