README.md 4.2 KB
Newer Older
D
Derek Parker 已提交
1
# Delve
D
Derek Parker 已提交
2

F
Florin Patan 已提交
3 4
[![GoDoc](https://godoc.org/github.com/derekparker/delve?status.svg)](https://godoc.org/github.com/derekparker/delve)

D
Derek Parker 已提交
5
### What is Delve?
D
Derek Parker 已提交
6

D
Derek Parker 已提交
7 8 9
Delve is a (Beta) Go debugger, written in Go.

This project is currently in beta. Most of the functionality is there, but there are various improvements to be made.
D
Derek Parker 已提交
10

D
Derek Parker 已提交
11 12
### Building

D
Derek Parker 已提交
13
Delve requires Go 1.4 to build.
D
Derek Parker 已提交
14

15
```
D
Derek Parker 已提交
16
go get -u github.com/derekparker/delve/cmd/dlv
17 18
```

D
Derek Parker 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#### Linux

You're done!

#### OS X

If you are on OS X a few extra steps must be taken. You must create a self signed certificate:

* Open application “Keychain Access” (/Applications/Utilities/Keychain Access.app)
* Open menu /Keychain Access/Certificate Assistant/Create a Certificate...
* Choose a name (dlv-cert in the example), set “Identity Type” to “Self Signed Root”, set “Certificate Type” to “Code Signing” and select the “Let me override defaults”. Click “Continue”. You might want to extend the predefined 365 days period to 3650 days.
* Click several times on “Continue” until you get to the “Specify a Location For The Certificate” screen, then set “Keychain to System”.
* If you can't store the certificate in the “System” keychain, create it in the “login” keychain, then export it. You can then import it into the “System” keychain.
* In keychains select “System”, and you should find your new certificate. Use the context menu for the certificate, select “Get Info”, open the “Trust” item, and set “Code Signing” to “Always Trust”.
* You must quit “Keychain Access” application in order to use the certificate and restart “taskgated” service by killing the current running “taskgated” process. Alternatively you can restart your computer.

All `make` commands assume a CERT environment variables that contains the name of the cert you created above.
Following that you can `CERT=mycert make install` which should install the binary and codesign it. For running tests, simply run `CERT=mycert make test`.

The makefile is only necessary to help facilitate the process of building and codesigning.
39

D
Derek Parker 已提交
40 41
### Features

D
Derek Parker 已提交
42 43
* Attach to an already running process
* Launch a process and begin debug session
D
Derek Parker 已提交
44
* Set breakpoints, single step, step over functions, print variable contents, print thread and goroutine information
D
Derek Parker 已提交
45 46 47

### Usage

48 49
The debugger can be launched in three ways:

D
Derek Parker 已提交
50
* Compile, run, and attach in one step:
51 52

	```
D
Derek Parker 已提交
53
	$ dlv run
54
	```
D
Derek Parker 已提交
55

D
Derek Parker 已提交
56 57 58 59 60 61
* Compile test binary, run and attach:

	```
	$ dlv test
	```

D
Derek Parker 已提交
62
* Provide the name of the program you want to debug, and the debugger will launch it for you.
D
Derek Parker 已提交
63

D
Derek Parker 已提交
64
	```
65
	$ dlv path/to/program
D
Derek Parker 已提交
66
	```
D
Derek Parker 已提交
67 68 69

* Provide the pid of a currently running process, and the debugger will attach and begin the session.

D
Derek Parker 已提交
70
	```
D
Derek Parker 已提交
71
	$ sudo dlv attach 44839
D
Derek Parker 已提交
72
	```
D
Derek Parker 已提交
73

D
Derek Parker 已提交
74 75 76 77 78 79
### Breakpoints

Delve can insert breakpoints via the `breakpoint` command once inside a debug session, however for ease of debugging, you can also call `runtime.Breakpoint()` and Delve will handle the breakpoint and stop the program at the next source line.

### Commands

D
Derek Parker 已提交
80 81
Once inside a debugging session, the following commands may be used:

D
Derek Parker 已提交
82
* `break` - Set break point at the entry point of a function, or at a specific file/line. Example: `break foo.go:13`.
D
Derek Parker 已提交
83

J
Jack Christensen 已提交
84 85
* `continue` - Run until breakpoint or program termination.

D
Derek Parker 已提交
86
* `step` - Single step through program.
D
Derek Parker 已提交
87

D
Derek Parker 已提交
88
* `next` - Step over to next source line.
D
Derek Parker 已提交
89

D
Derek Parker 已提交
90
* `threads` - Print status of all traced threads.
D
Derek Parker 已提交
91

92 93
* `thread $tid` - Switch to another thread.

D
Derek Parker 已提交
94 95
* `goroutines` - Print status of all goroutines.

96 97
* `breakpoints` - Print information on all active breakpoints.

D
Derek Parker 已提交
98 99
* `print $var` - Evaluate a variable.

D
Derek Parker 已提交
100
* `info $type [regex]` - Outputs information about the symbol table. An optional regex filters the list. Example `info funcs unicode`. Valid types are:
101
  * `args` - Prints the name and value of all arguments to the current function
D
Derek Parker 已提交
102
  * `funcs` - Prings the name of all defined functions
E
epipho 已提交
103
  * `locals` - Prints the name and value of all local variables in the current context
104 105
  * `sources` - Prings the path of all source files
  * `vars` - Prints the name and value of all package variables in the app. Any variable that is not local or arg is considered a package variables
E
epipho 已提交
106

M
Matt Self 已提交
107 108 109
* `exit` - Exit the debugger.


D
Derek Parker 已提交
110 111 112
### Upcoming features

* In-scope variable setting
D
Derek Parker 已提交
113
* Editor integration
D
Derek Parker 已提交
114 115

### License
D
Derek Parker 已提交
116 117

MIT