Search code examples
govisual-studio-codedelve

Remote Debugging Go REST Endpoints


I am new to Go and new to VSCode. I have also never used Delve before. I am trying to set up remote debugging but i can't seem to hit breakpoints.

My project hosts REST endpoints on localhost:8080. What should the launch.json file look like in order to have delve attach and listen so that I can put breakpoints on my REST endpoints? Currently, this is what i have:

"configurations": [
    {
        "name": "Launch",
        "type": "go",
        "request": "launch",
        "mode": "remote",
        "remotePath": "",
        "port": 8080,
        "host": "127.0.0.1",
        "program": "${workspaceRoot}",
        "env": {},
        "args": [],
        "showLog": true
    }

Thanks in advance!


Solution

  • This article mentioned:

    Unfortunately, you won’t be able to debug an application when running with buffalo dev. You’ll need to build an executable that skips compiler optimizations like function invocation inlining.
    If you skip these build flags Gogland won’t stop on your break points.

    More on that on "Debugging Go Code with GDB ".

    The code generated by the gc compiler includes inlining of function invocations and registerization of variables. These optimizations can sometimes make debugging with gdb harder.

    After that, you can follow "Remote Debugging"

    To remote debug using VS Code, you must first run a headless Delve server on the target machine. For example:

    $ dlv debug --headless --listen=:2345 --log
    

    Then your launcher can apply.