3

Can anyone tell me how can I run and use debugger in Visual Studio for a simple go program in Windows step by step?

I took a reference from this page:

https://marketplace.visualstudio.com/items?itemName=lukehoban.Go

But I was not able to run the code. My current GOPATH is C:\dev\go. Please let me know if any other details are required.

4
  • 2
    What does the compiler(debugger) complain about? Commented Jun 28, 2016 at 15:43
  • We need to know what step in that guide failed and how, or any steps you couldn't do. Right now you're asking us to write another tutorial, and if we did that it still might not work for you. Commented Jun 28, 2016 at 18:11
  • this is what i get when i start debugger : can't load package: package .: no buildable Go source files in c:\dev\go exit status 1 Commented Jun 30, 2016 at 14:14
  • Very similar to this. ethereum.stackexchange.com/a/41135/7044 Commented Mar 2, 2018 at 9:57

3 Answers 3

9

First of all, debuggers are not part of Go. C#, F# and other managed languages under the Microsoft stack have debuggers as that's part of the .NET stack.

Second, Visual Studio Code != Visual Studio. VS Code is a light(er) weight IDE that is geared towards extensibility to support a wide range of languages by creating runners. But that's the thing: someone else needs to write the runners and hopefully they created a seamless experience with a Debugger (if available). This is why you have multiple versions of language runners.

In other words: if you want a VSCode-compatible Debugger+Runner for X language, read up on X language about how to debug it.

Go is no exception. You must read the language spec, and specifically I recommend Effective Go as it explains why you don't need a Debugger.

--

Now with all of that said, the community has come together and created somewhat of a debugger for GoLang. It is called Delve.

Learning how to install it for VS Code is beyond this post. I recommend finding a VSCode package that supports Go coding with Delve (there is at least one out there, as I have used it).

Opinion: it's an Ok experience in VSCode to debug Go. I've experimented with it. While visually pleasing, I went back to Atom for it's large package support of many other Go utilities and Linters - most of which is missing in VSCode (and some packages didn't allow me to modify the config to exclude certain Go workflows).

EDIT 2018: After a few years, VSCode has matured nicely! I've since switched 100% to VSCode as my primary editor.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks mate. My bad , i forgot to write "CODE" with Visual Studio. I have installed Delve. but i get this error in when i start to debug. can't load package: package .: no buildable Go source files in c:\dev\go exit status 1
Again, look for packages within VS Code that are built specifically to do the debugging. They may install their other version of delve, or have instructions on how to do it that is compatible with that package.
6

One possible option to install Debugger for Go language on Windows is:

go get github.com/derekparker/delve/cmd/dlv

After that the Visual Studio Code (vscode) will be able to run (debug) launch configuration.

By default, file launch.json points to the root of the project:

"program": "${workspaceRoot}"

If you want configure it to the another location (eg. your/package/foo/dir) then edit it as the following:

"program": "${workspaceRoot}/foo/dir"

2 Comments

You mean the location where my go code is. My code is at C:\dev\go\src\github.com\golang\game\game.go. Error i am getting is : can't load package: package .: no buildable Go source files in c:\dev\go exit status 1
@A-kay Please, try read this information: golang.org/doc/code.html and this talks.golang.org/2014/organizeio.slide#1. In vscode the workspaceRoot in "program": "${workspaceRoot}" means a your current project workspace.
1

In case you want to debug a Go module running inside an application server you can have a look at debugging golang appengine module with visual studio code.

Explanations are for Appengine server, but you can easily understand how to do remote debugging from vscode using Delve.

1 Comment

Please consider pointing the relevant parts of the link you provided as part of the answer. A link-only answer might be not that useful at the end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.