Skip to content

2. Software

Saman edited this page Oct 8, 2025 · 5 revisions

Debugging

For Go language, the current debugging tool is Delve. To read more about the debugger and its commands, please visit their GitHub page: https://github.com/go-delve/delve.

Setting Up the Debugger

We need to add a new port so that our Docker setup connects to the required port. Follow these steps:

  1. Find the docker-compose.yml file under the docker directory.
  2. Add the following port to the ai section of this file:
    ports:
       - "2345:2345"

Using Delve with Terminal

  1. After running the start.sh script and choosing your module, install Delve by running:
    go install github.com/go-delve/delve/cmd/dlv@v1.25.0
  2. Navigate to the cmd directory:
    cd cmd/
  3. Launch Delve in debug mode:
    /go/bin/dlv debug main.go

You now have access to the terminal version of Delve where you can set breakpoints and inspect variables.

Connecting Delve to VS Code

  1. Ensure the port has been added as stated above
  2. After running the start.sh script and choosing your module, run the following commands:
    go install github.com/go-delve/delve/cmd/dlv@latest
    cd cmd/
    /go/bin/dlv debug main.go --headless --listen=0.0.0.0:2345 --api-version=2 --accept-multiclient --log
  3. Open VS Code, install the go package, set your breakpoints
  4. Press Ctrl + Shift + D
  5. A new page should appear asking to create a launch.json file. Click on it, and add the following content to your launch.json:
    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Attach",
                "type": "go",
                "request": "attach",
                "mode": "remote",
                "remotePath": "",
                "port": 2345,
                "host": "127.0.0.1",
                "showLog": true,
                "trace": "log",
                "logOutput": "rpc"
            }
        ]
    }
  6. Press Run and Debug. MAKE SURE YOUR VSCODE IS RUNNING FROM CONTROLLER DIRECTORY!!!

Clone this wiki locally