microsoft / vscode-go

An extension for VS Code which provides support for the Go language. We have moved to https://github.com/golang/vscode-go
Other
5.93k stars 648 forks source link

Build tags ignored when debugging #3185

Closed cfiderer closed 4 years ago

cfiderer commented 4 years ago

Please direct general questions to:

Please review the Wiki before filing an issue. Helpful pages include:

Please answer these questions before submitting your issue. Thanks!

What version of Go, VS Code & VS Code Go extension are you using?

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file. Share all the settings with the go. or ["go"] prefixes.

Describe the bug

A clear and concise description of what the bug. When I debug the main program, I end up in the doSomething() function from the withoutTag.go file (without "myTag").

A clear and concise description of what you expected to happen. I expect the configured build tag to be passed to dlv, so that the generated code uses the doSomething() function from withTag.go.

Debugging with buildflags used to work well in the past. Running the code with go run -tags myTag . in the Terminal window works fine.

Steps to reproduce the behavior:

Use VS Code with the Go extension and the dlv debugger installed.

  1. Open the workspace from the attached buildflags.zip archive
  2. Open the main.go file
  3. Hit the F5 key to start dlv

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.

hyangah commented 4 years ago

I briefly looked into how buildTags and testTags, and buildFlags are being used in different context currently - which is not pretty but complex. I don't know why this extension treats -tags specially unlike other go build flags (see go help build for the list of build flags).

Anyway - @ramya-rao-a we can compute and plumb the buildFlags, buildTags, and testTags (only if the debugged/launched file is "_test.go" file) unless launch.json already specifies the buildFlags. Let me know if it breaks existing users' usages.

@cfiderer you can specify the tags (and other go build flags) using the buildFlags field in the launch.json.

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${fileDirname}",
            "env": {},
            "args": [],
            "buildFlags": "-tags=myTag"
        }
    ]
}
cfiderer commented 4 years ago

@hyangah thank you for the tip: not nice, but a workaround.

ramya-rao-a commented 4 years ago

Note on passing build tags via the debug configuration: https://github.com/microsoft/vscode-go/wiki/Debugging-Go-code-using-VS-Code#using-build-tags

Some history here:

So, yes. We can compute the right flags and tags in the resolveDebugConfiguration() method

ramya-rao-a commented 4 years ago

Hey @cfiderer,

We are in the midst of a repo move, see We are moving section in our readme for more details.

Closing this issue in favor of https://github.com/golang/vscode-go/issues/128. Please subscribe to it for further updates

Thanks for all the support & Happy Coding!