Delve into Nakama plugin from VSCode

Hi,

Just wanted to share my experience, maybe someone will find it useful too. It’s about how to setup VSCode debugging UI to delve into Nakama plugin.

Reading the article Nakama: Debugging with Delve | Heroic Labs Documentation was quite useful. It let me setup my already running Docker image and use basic delve commands (article is quite straight forward thanks for that :slight_smile: ). Right away the next question in my mind was how to get vscode debugger to work with it.

It turns out all support is already there and the changes that needed are minimal.

  1. Remove entry point in dockerfile that you use to make debug image.

  2. In your docker-compose apply all suggestions from the article except removing entrypoint.

  3. Change docker-compose entrypoint to run container using dlv command.
    Note I am using cockroach db here so modify these to your needs
    You can read more about dlv flags used here → delve/dlv_attach.md at master · go-delve/delve · GitHub

    entrypoint:
      - "/bin/sh"
      - "-ecx"
      - >
          /nakama/nakama migrate up --database.address root@cockroachdb:26257 &&
          /nakama/dlv --log --log-output=debugger --listen=:4000 --headless=true --api-version=2 exec /nakama/nakama -- --config /nakama/data/local.yml --database.address root@cockroachdb:26257
  1. In docker-compose again, add debug port number
    ports:
      - "7349:7349"
      - "7350:7350"
      - "7351:7351"
      - "4000:4000"
  1. Inside of your VSCode workspace .vscode folder, add launch.json file.
    Set substitutePath:from property to your go.mod file location, mine lives in src folder.
    Replace substitutePath:to property according to your module go module name.
{
    "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",
            "substitutePath": [
                { 
                    "from": "${workspaceFolder}/src",
                    "to": <YOUR GO MODULE NAME FROM go.mod FILE i.e. example.com/mygameserver>
                },
            ]
        }
    ]
}
  1. Because of Nakama goes into a state of waiting for a termination signal after startup *. Set functional breakpoint in VSCode like it is suggested in the article.

  1. Run your docker image in terminal or however you like to start yours.
    docker compose up --build nakama

  2. Once main.go:181 is hit you will be able to set other functional breakpoints, in my case its a function that registers a Lobby match handler.
    Note - I was not able to set breakpoints directly on line numbers in vscode, but it is still possible to set a functioal breakpoint and access to dlv command via VSCode UI

  3. Enjoy civilization ^^

dlvdebug

Pretty neat imho ^^

Thanks all

3 Likes