README.md 5.3 KB
Newer Older
D
Derek Parker 已提交
1
![Delve](https://raw.githubusercontent.com/derekparker/delve/master/assets/delve_horizontal.png)
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
### Usage

45 46
The debugger can be launched in three ways:

D
Derek Parker 已提交
47
* Compile, run, and attach in one step:
48 49

	```
D
Derek Parker 已提交
50
	$ dlv run
51
	```
D
Derek Parker 已提交
52

D
Derek Parker 已提交
53 54 55 56 57 58
* Compile test binary, run and attach:

	```
	$ dlv test
	```

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

D
Derek Parker 已提交
61
	```
62
	$ dlv path/to/program
D
Derek Parker 已提交
63
	```
D
Derek Parker 已提交
64 65 66

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

D
Derek Parker 已提交
67
	```
D
Derek Parker 已提交
68
	$ sudo dlv attach 44839
D
Derek Parker 已提交
69
	```
D
Derek Parker 已提交
70

D
Derek Parker 已提交
71 72
### Breakpoints

D
Derek Parker 已提交
73
Delve can insert breakpoints via the `breakpoint` command once inside a debug session, however for ease of debugging, you can also use the `runtime.Breakpoint()` function in your source code and Delve will handle the breakpoint and stop the program at the next source line.
D
Derek Parker 已提交
74 75 76

### Commands

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

K
Kirk 已提交
79 80
* `help` - Prints the help message.

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

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

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

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

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

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

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

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

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

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

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

D
Dan Mace 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
### 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 已提交
130

D
Derek Parker 已提交
131 132 133
### Upcoming features

* In-scope variable setting
D
Derek Parker 已提交
134
* Editor integration
D
Derek Parker 已提交
135 136

### License
D
Derek Parker 已提交
137 138

MIT