godebug

command module
v0.0.0-...-bfb01ae Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2017 License: Apache-2.0 Imports: 17 Imported by: 0

README

DEPRECATED! There will be no further development. Please use https://github.com/derekparker/delve. But if you want to keep the project going and ready to become its maintaner please contact us and we can make you one.

godebug


Linux Build Status Windows Build Status

A cross-platform debugger for Go.

How?

godebug uses source code generation to instrument your program with debugging calls. go tool cover takes a similar approach to code coverage. When you run godebug, it parses your program, instruments function calls, variable declarations, and statement lines, outputs the resulting code somewhere, and runs/compiles it. When this modified code runs, it stops at breakpoints and lets you step through the program and inspect variables.

For more detail, see the end of this README.

Status

godebug is still very new. File an issue or send me an email if you find any rough edges:

contact

Installation:

$ go get github.com/mailgun/godebug

Getting started:

Insert a breakpoint anywhere in a source file you want to debug:

_ = "breakpoint"

If the breakpoint is in package main and you don't want to examine any imported packages, you can just run:

$ godebug run gofiles... [arguments...]

If you want to trace the program outside of the main package, list the packages to trace in the -instrument flag:

$ godebug run -instrument=pkg1,pkg2,pkg3 gofiles... [arguments...]

If you are debugging a test, use 'godebug test' like you would use 'go test':

$ godebug test [-instrument pkgs...] [packages]

Finally, you can [cross-]compile a debugging binary using 'godebug build':

$ godebug build [-instrument pkgs...] [-o output] [package]

The compiled binary has no dependencies, so you can build it locally and then debug on i.e. a staging server.

That's it. See 'godebug help' for the full usage.

Debugger commands:

The current commands are:

command result
h(elp) show help message
n(ext) run the next line
s(tep) run for one step
c(ontinue) run until the next breakpoint
l(ist) show the current line in context of the code around it
p(rint) [expression] print a variable or any other Go expression
q(uit) exit the program

Caveats

It is not currently possible to step into standard library packages. (Issue #12)

How it works (more detail)

Consider this program:

package main

import "fmt"

func main() {
    fmt.Println("Hello, world!")
}

Now let's modify it a bit:

package main

import (
    "bufio"
    "fmt"
    "os"
)

func main() {
    fmt.Println(`-> fmt.Println("Hello, world!")`)
    bufio.NewScanner(os.Stdin).Scan()
    fmt.Println("Hello, world!")
}

When we run this modified version, we see:

-> fmt.Println("Hello, world!")

And then the program waits for input before proceeding.

We have just implemented a debugger for the first program! It may not seem like much, but this program implements two fundamental debugger behaviors: (1) display the current state of the program, and (2) do not proceed until instructed by the user. Furthermore, the changes we made were straightforward and easy to automate:

  • insert import statements for bufio and os, if not already present.
  • in main(), insert the statement fmt.Println(<quote next line>)
  • in main(), insert the statement bufio.NewScanner(os.Stdin).Scan().

We could do exactly the same thing for any other program with a single-line main function. And it's not hard to see how to generalize this to multiple lines. This, in essence, is what godebug does. Parse source code, insert extra code that implements the behavior of a debugger for that program, output and run the result. godebug handles many more cases than this simple example and implements more interesting debugging behavior, but the principle is exactly the same.

Documentation

Overview

Command godebug provides debugging for Go packages.

Example Usage

Generate debugging code for the package in the current directory:

$ godebug -w .

Directories

Path Synopsis
Godeps
_workspace/src/bitbucket.org/JeremySchlatter/go-atexit
Package atexit implements a simple atexit library.
Package atexit implements a simple atexit library.
_workspace/src/github.com/0xfaded/eval/demo
Example repl is a simple REPL (read-eval-print loop) for GO using http://github.com/0xfaded/eval to the heavy lifting to implement the eval() part.
Example repl is a simple REPL (read-eval-print loop) for GO using http://github.com/0xfaded/eval to the heavy lifting to implement the eval() part.
_workspace/src/github.com/jtolds/gls
Package gls implements goroutine-local storage.
Package gls implements goroutine-local storage.
_workspace/src/github.com/kisielk/gotool
Package gotool is a library of utility functions used to implement the standard "Go" tool provided as a convenience to developers who want to write tools with similar semantics.
Package gotool is a library of utility functions used to implement the standard "Go" tool provided as a convenience to developers who want to write tools with similar semantics.
_workspace/src/github.com/kylelemons/godebug/diff
Package diff implements a linewise diff algorithm.
Package diff implements a linewise diff algorithm.
_workspace/src/github.com/peterh/liner
Package liner implements a simple command line editor, inspired by linenoise (https://github.com/antirez/linenoise/).
Package liner implements a simple command line editor, inspired by linenoise (https://github.com/antirez/linenoise/).
_workspace/src/golang.org/x/tools/go/ast/astutil
Package astutil contains common utilities for working with the Go AST.
Package astutil contains common utilities for working with the Go AST.
_workspace/src/golang.org/x/tools/go/exact
Package exact implements Values representing untyped Go constants and the corresponding operations.
Package exact implements Values representing untyped Go constants and the corresponding operations.
_workspace/src/golang.org/x/tools/go/gccgoimporter
Package gccgoimporter implements Import for gccgo-generated object files.
Package gccgoimporter implements Import for gccgo-generated object files.
_workspace/src/golang.org/x/tools/go/gcimporter
Package gcimporter implements Import for gc-generated object files.
Package gcimporter implements Import for gc-generated object files.
_workspace/src/golang.org/x/tools/go/importer
package importer implements an exporter and importer for Go export data.
package importer implements an exporter and importer for Go export data.
_workspace/src/golang.org/x/tools/go/loader
Package loader loads, parses and type-checks packages of Go code plus their transitive closure, and retains both the ASTs and the derived facts.
Package loader loads, parses and type-checks packages of Go code plus their transitive closure, and retains both the ASTs and the derived facts.
_workspace/src/golang.org/x/tools/go/types
Package types declares the data types and implements the algorithms for type-checking of Go packages.
Package types declares the data types and implements the algorithms for type-checking of Go packages.
_workspace/src/golang.org/x/tools/go/types/typeutil
Package typeutil defines various utilities for types, such as Map, a mapping from types.Type to interface{} values.
Package typeutil defines various utilities for types, such as Map, a mapping from types.Type to interface{} values.
_workspace/src/gopkg.in/yaml.v2
Package yaml implements YAML support for the Go language.
Package yaml implements YAML support for the Go language.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL