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 ). 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.
-
Remove entry point in dockerfile that you use to make debug image.
-
In your docker-compose apply all suggestions from the article except removing entrypoint.
-
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
- In docker-compose again, add debug port number
ports:
- "7349:7349"
- "7350:7350"
- "7351:7351"
- "4000:4000"
- Inside of your VSCode workspace
.vscode
folder, addlaunch.json
file.
SetsubstitutePath
:from
property to yourgo.mod
file location, mine lives in src folder.
ReplacesubstitutePath
: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>
},
]
}
]
}
- 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.
-
Run your docker image in terminal or however you like to start yours.
docker compose up --build nakama
-
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
-
Enjoy civilization ^^
Pretty neat imho ^^
Thanks all