-
Notifications
You must be signed in to change notification settings - Fork 1k
Go Development Portal
This page is for notes, tips, and suggestions for Go development
The Golang corpus does not include a native debugger. It is possible to attach GDB to a go program, but the results are often disappointing on account of a lack of insight into the Go runtime (such as goroutines, etc). The obvious and perhaps idiomatic way to debug a Go application is with the tried and true printf+iterate model. However, there are several options above and beyond that may make certain problems easier to find.
derekparker/delve is a third party project that offers a comprehensive gdb-like, yet go-aware debugger. We won't reiterate the description or documentation here, but if you are looking for a way to debug a nasty problem, Delve does a pretty decent job.
You can run your go program with arguments (similar to gdb's "set arg") using the "--" parameter, as per here
kill -ABRT
is a useful way to generate a stack trace of all goroutines, helpful if your program appears hung.
The following steps show how to setup and use Eclipse with GOLang for debugging and other IDE use
- Eclipse Mars is the minimum Pre-req
- Java 8 is required to run GOClipse
http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/mars2
- go get github.com/nsf/gocode
- go get golang.org/x/tools/cmd/oracle
- Start Eclipse and accept default workspace, by clicking on Eclipse executable in the root of Eclipse directory
- From File Menu→ Help→ Install New Software → and click the add button
- Set the location to http://goclipse.github.io/releases and name it goclipse
- Click on OK
- Wait for the list to get populated
- Choose GoClipse from the list as follows:
- Click on Next and accept all later on
- Restart Eclipse after install
- From File Menu → Eclipse → Preferences → Go
- Set GOROOT to /usr/local/go
- Accept the Gopath and projects
- Switch to Go→ Tools
- Browse to gocode, oracle and godef which has been already installed in $GOPATH/bin
- Accept all other defaults
- Click on OK
- File Menu → New → Go Project
- Name the project
- Uncheck Use Default location
- Type in the GOPath location in the Directory field
- Click on Finish
Any source code in GOPath/src is accesssible to debug and run in Eclipse