Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Build tags ignored when debugging #3185

Closed
cfiderer opened this issue Apr 16, 2020 · 4 comments
Closed

Build tags ignored when debugging #3185

cfiderer opened this issue Apr 16, 2020 · 4 comments
Labels
debug needs-decision Feedback is required from experts, contributors, and/or the community before a change can be made. needs-fix

Comments

@cfiderer
Copy link

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?

  • Run go version to get version of Go

    • go version go1.14.2 windows/amd64
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders

    • $ code -v
      1.44.1
      a9f8623ec050e5f0b44cc8ce8204a1455884749f
      x64
  • Check your installed extensions to get the version of the VS Code Go extension

    • 0.14.1 - 15th April, 2020
  • Run go env GOOS GOARCH to get the operating system and processor architecture details

    • $ go env GOOS GOARCH
      windows
      amd64

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.

  • User > settings.json: no go-relevant settings
  • Workspace (buildflags.code-workspace):
	"settings": {
		"go.buildTags": "myTag",
		"go.testTags": "myTag"
	},
	"go.useLanguageServer": false

buildflags.zip

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
Copy link
Contributor

hyangah commented Apr 20, 2020

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"
        }
    ]
}

@hyangah hyangah added the needs-decision Feedback is required from experts, contributors, and/or the community before a change can be made. label Apr 20, 2020
@cfiderer cfiderer changed the title Build flags ignored when debugging Build tags ignored when debugging Apr 24, 2020
@cfiderer
Copy link
Author

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

@ramya-rao-a
Copy link
Contributor

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:

  • The debug adapter and therefore everything around debugging runs in a different process than the rest of the extension
  • The debug adapter does not have access to any of the vscode apis that the rest of the extension does have access to. So, it cannot read settings
  • So to get around this, the buildFlags was introduced in the debug configuration you provide in the launch.json file
  • It was a few years later that the DebugConfigurationProvider interface was provided by VS Code for extensions to implement. See https://github.com/microsoft/vscode-go/blob/master/src/goDebugConfiguration.ts
  • With this we now have a chance to be the middleman between VS Code and the debug adapter, and be able to read settings and pass relevant information to the debug adapter

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

@ramya-rao-a
Copy link
Contributor

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 golang/vscode-go#128. Please subscribe to it for further updates

Thanks for all the support & Happy Coding!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debug needs-decision Feedback is required from experts, contributors, and/or the community before a change can be made. needs-fix
Projects
None yet
Development

No branches or pull requests

4 participants