Start Debugging Go on Windows(WSL)

Recently I started working with Go on windows, where everything was working fine, until I had to debug the application. For some reason It was not working or when started working, it was asking for firewall permission every(I guess that had to be with go binary being run from temp directory).

Finally I got the solution after some searching on google, stackoverflow and some medium blog post.

  1. Make sure to launch vscode from wsl shell(basically open your cmd/powershell terminal in your workspace directory, and type “wsl” to swicth to WSL shell and then type “code .” to open vscode in WSL).
    This Step is very important, otherwise you will get some weird error when you start debugging
  1. Create launch.json file under .vscode directory with following content
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch Package",
            "type": "go",
            "request": "launch",
            "mode": "exec",
            "program": "${workspaceFolder}/bin/server"
        }
    ]
}

3. After this build your binary with following command

go build -gcflags=all="-N -l" -o bin/server

4. Now you can start your debugging(Press F5 or Start Debug from debug window).

Update: I found issue regarding debugging on my machine. Actually It was not working because I was building my binary file in “wsl”(My default terminal was bash in vscode) and and running debugging inside window(which was causing issue with running binary build for linux, to be run windows)


Happy Debugging.

Thanks for reading…

Leave a Reply