README.md 5.3 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
Delve is a Go debugger, written in Go.
D
Derek Parker 已提交
8

D
Derek Parker 已提交
9
**This project is currently in beta. Most of the functionality is there, however there are various improvements to be made. Delve is not (yet) ready for daily use.**
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
Dan Mace 已提交
40 41
See [Tips and troubleshooting](#tips-and-troubleshooting) for additional OS X setup information.

D
Derek Parker 已提交
42 43
### Features

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

### Usage

50 51
The debugger can be launched in three ways:

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

	```
D
Derek Parker 已提交
55
	$ dlv run
56
	```
D
Derek Parker 已提交
57

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

	```
	$ dlv test
	```

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

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

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

D
Derek Parker 已提交
72
	```
D
Derek Parker 已提交
73
	$ sudo dlv attach 44839
D
Derek Parker 已提交
74
	```
D
Derek Parker 已提交
75

D
Derek Parker 已提交
76 77 78 79 80 81
### 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 已提交
82 83
Once inside a debugging session, the following commands may be used:

D
Derek Parker 已提交
84
* `break` - Set a breakpoint. Example: `break foo.go:13` or `break main.main`.
D
Derek Parker 已提交
85

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

D
Derek Parker 已提交
88
* `step` - Single step through program.
D
Derek Parker 已提交
89

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

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

94 95
* `thread $tid` - Switch to another thread.

D
Derek Parker 已提交
96 97
* `goroutines` - Print status of all goroutines.

98 99
* `breakpoints` - Print information on all active breakpoints.

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

D
Derek Parker 已提交
102
* `info $type [regex]` - Outputs information about the symbol table. An optional regex filters the list. Example `info funcs unicode`. Valid types are:
103
  * `args` - Prints the name and value of all arguments to the current function
D
Derek Parker 已提交
104
  * `funcs` - Prings the name of all defined functions
E
epipho 已提交
105
  * `locals` - Prints the name and value of all local variables in the current context
106 107
  * `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 已提交
108

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

D
Dan Mace 已提交
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
### Tips and troubleshooting

#### OS X

##### Eliminating codesign authorization prompt during builds

If you're prompted for authorization when running `make` using your self-signed certificate, try the following:

* Open application “Keychain Access” (/Applications/Utilities/Keychain Access.app)
* Double-click on the private key corresponding to your self-signed certificate (dlv-cert in the example)
* Choose the "Access Control" tab
* Click the [+] under "Always allow access by these applications", and choose `/usr/bin/codesign` from the Finder dialog
* Click the "Save changes" button

##### Eliminating "Developer tools access" prompt running delve

If you are prompted with this when running `dlv`:

    "Developer tools access needs to take control of another process for debugging to continue. Type your password to allow this"

Try running `DevToolsSecurity -enable` to eliminate the prompt. See `man DevToolsSecurity` for more information.

M
Matt Self 已提交
133

D
Derek Parker 已提交
134 135 136
### Upcoming features

* In-scope variable setting
D
Derek Parker 已提交
137
* Editor integration
D
Derek Parker 已提交
138 139

### License
D
Derek Parker 已提交
140 141

MIT