README.md 5.4 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 pre 1.0. 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 or greater 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
#### Linux

You're done!

#### OS X

D
Derek Parker 已提交
25
If you are on OS X a few extra steps must be taken. You must create a self signed certificate and sign the binary with it:
D
Derek Parker 已提交
26 27 28 29 30 31 32 33

* 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.
D
Derek Parker 已提交
34
* Run the following: `CERT=$mycert make install`, which will install the binary and codesign it.
D
Derek Parker 已提交
35 36 37 38 39

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.
40

D
Dan Mace 已提交
41 42
See [Tips and troubleshooting](#tips-and-troubleshooting) for additional OS X setup information.

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

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

### Usage

51 52
The debugger can be launched in three ways:

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

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

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

	```
	$ dlv test
	```

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

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

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

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

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

K
Kirk 已提交
85 86
* `help` - Prints the help message.

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

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

D
Derek Parker 已提交
91
* `step` - Single step through program.
D
Derek Parker 已提交
92

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

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

97 98
* `thread $tid` - Switch to another thread.

D
Derek Parker 已提交
99 100
* `goroutines` - Print status of all goroutines.

101 102
* `breakpoints` - Print information on all active breakpoints.

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

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

M
Matt Self 已提交
112 113
* `exit` - Exit the debugger.

D
Dan Mace 已提交
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
### 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 已提交
136

D
Derek Parker 已提交
137 138 139
### Upcoming features

* In-scope variable setting
D
Derek Parker 已提交
140
* Editor integration
D
Derek Parker 已提交
141 142

### License
D
Derek Parker 已提交
143 144

MIT