govscode-debuggerdelve

Debugging go in vscode doesn't stop at breakpoints, says "Could not find file ..." when debugger starts


Ubuntu. vscode 1.62.1. go1.17.3. vscode go extension v0.29.0. delve v1.7.1.

I'm new to vscode and Go. I have many years of experience debugging Java apps in Eclipse.

I've constructed a small multi-module Go app. I can set a breakpoint in main and other functions in other modules. Inside main.go, I select "Start Debugging".

It starts the application, and I can tell it's working from the console, and that the REST endpoint responds with my dummy response.

However, it will NOT stop at breakpoints. As soon as I start the session, the red breakpoint markers suddenly become hollow, and hovering on one of them shows a message "Could not find file ...", which prints the full path to the source file in question.

When I start it, it shows the following in the console:

Starting: /home/.../go/bin/dlv-dap dap --check-go-version=false --listen=127.0.0.1:43347 --log-dest=3 from /home/.../... DAP server listening at: 127.0.0.1:43347

I haven't modified the launch.json (I hope someday a friendlier interface to editing launch configurations is provided).

What else could I be doing wrong?

Update:

This is a screenshot showing main.go just before I press F5 (Start Debugging):

Before pressing F5

Notice that I have a breakpoint on the print statement, on the first line of main.

This is what I see after I press F5:

After pressing F5

Notice that it printed "At start of main" in the console. It didn't stop at the breakpoint. Also notice message in tooltip when hovering over the breakpoint.

Update:

This is a view of my directory structure:

project directory structure


Solution

  • First, just make sure you have initiated your project with go mod init voltagems: that would explain the import "voltagems/xxx", but also helps delve to find your main.go file at debug time.
    You should have go.mod and go.sum files beside main.go.

    Second, check your go env output, making sure GOPATH and GOROOT are set to default paths.

    The OP David M. Karr adds in the comments:

    I did run "go mod init" when I first created the project, but I realized that I didn't like the root module name, so I changed it to "voltagems"

    I believe you can edit directly go.mod first line, and make sure it says:

    module voltagems
    

    Then go mod verify + go mod tidy

    Finally, go build .. Restart your VSCode (or the command Reload Window), and see if the issue persists.


    The OP David M. Karr points out to a root cause:

    There are symbolic links in my project path.

    There is a "substitutePath" configuration in VSCode-Go that is used to map to absolute paths.

    You can see this parameter mentioned in Debugging with Legacy Debug Adapter

    substitutePath

    Path mappings to apply to get from a path in the editor to a path in the compiled program (default: []).

    That comes from issue 622 "debug: breakpoints don't work when working with symlink".
    And commit 93f32bb

    src/debugAdapter: add substitutePath config for debugging

    This change adds a new configuration option to both launch and attach requests.
    substituePath takes an array that maps from string to string that is used to translate paths passed to the debugger and then back to the client.

    This allows users to translate their symlinked directories to the files that were actually used to build the binary.
    In addition this can also be used for remote debugging, and when the location of the files has moved since the program was built.

    Example: you need a from and to key:

        "substitutePath": [
            {
                "from": "/symlink/path/dir/on/local/machine",
                "to": "/absolute/path/dir/on/local/machine",
            },