Documentation ¶
Overview ¶
Hopwatch is a debugging tool for Go programs.
Hopwatch uses a HTML5 application to connect to your program (using a Websocket). Using Hopwatch requires adding function calls at points of interest that allow you to watch program state and suspend the program. On the Hopwatch page, you can view debug information (file:line,stack) and choose to resume the execution of your program.
You can provide more debug information using the Display function which takes an arbitrary number of variable,value pairs. The Display function itself does not suspend the program ; it is like having logging information in the browser.
Usage:
import ( "github.com/emicklei/hopwatch" ) func foo() { bar := "john" // suspends execution until hitting "Resume" in the browser hopwatch.Display("foo", bar).Break() }
Connect:
Open the Hopwatch debugger on http://localhost:23456/hopwatch.html after starting your program. Your browser must support WebSockets. It has been tested with Chrome and Safari on a Mac.
Other examples:
// zero or more conditions ; conditionally suspends program (or goroutine) hopwatch.Break(i > 10, j < 100) // zero or more name,value pairs ; no program suspend hopwatch.Display("i",i , "j",j")
The flags are:
-hopwatch if set to false then hopwatch is disabled.
Install:
go get -u github.com/emicklei/hopwatch
Resources:
https://github.com/emicklei/hopwatch http://ernestmicklei.com (blog)
(c) 2012, Ernest Micklei. MIT License
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Watchpoint ¶
type Watchpoint struct {
// contains filtered or unexported fields
}
watchpoint is a helper to provide a fluent style api. This allows for statements like hopwatch.Display("var",value).Break()
func CallerOffset ¶
func CallerOffset(offset int) *Watchpoint
CallerOffset (default=2) allows you to change the file indicator in hopwatch. Use this method when you wrap the .CallerOffset(..).Display(..).Break() in your own function.
func Display ¶
func Display(nameValuePairs ...interface{}) *Watchpoint
Display sends variable name,value pairs to the debugger. The parameter nameValuePairs must be even sized.
func (Watchpoint) Break ¶
func (self Watchpoint) Break(conditions ...bool)
Break halts the execution of the program and waits for an instruction from the debugger (e.g. Resume). Break is only effective if all (if any) conditions are true. The program will resume otherwise.
func (*Watchpoint) Display ¶
func (self *Watchpoint) Display(nameValuePairs ...interface{}) *Watchpoint
Display sends variable name,value pairs to the debugger. The parameter nameValuePairs must be even sized.