Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ewohltman/delve-example
Example usage of the Delve Go debugger
https://github.com/ewohltman/delve-example
debugger debugging delve go golang
Last synced: about 1 month ago
JSON representation
Example usage of the Delve Go debugger
- Host: GitHub
- URL: https://github.com/ewohltman/delve-example
- Owner: ewohltman
- License: mit
- Created: 2019-10-01T12:59:08.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-02T04:03:13.000Z (over 5 years ago)
- Last Synced: 2024-06-20T13:29:42.108Z (7 months ago)
- Topics: debugger, debugging, delve, go, golang
- Language: Go
- Size: 3.91 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `delve-example`
Delve: [https://github.com/go-delve/delve](https://github.com/go-delve/delve)
---
## Debugging main application
### Start Delve
```
dlv debug delve-example.go
```### Set breakpoints
```
(dlv) break delve-example.go:30
Breakpoint 1 set at 0x4ac131 for main.main() ./delve-example.go:30
``````
(dlv) break delve-example.go:21
Breakpoint 2 set at 0x4abeaf for main.output() ./delve-example.go:21
```### Run until first breakpoint
```
(dlv) continue
> main.main() ./delve-example.go:30 (hits goroutine(1):1 total:1) (PC: 0x4ac131)
25: examples := makeExampleSlice()
26:
27: exampleSlice1 := append(examples, example{exampleValue: &exampleValue{value: 1}})
28: exampleSlice2 := append(examples, example{exampleValue: &exampleValue{value: 2}})
29:
=> 30: output("example1", exampleSlice1)
31: output("example2", exampleSlice2)
32: }
```#### List function local variables
```
(dlv) locals
examples = []main.example len: 2, cap: 2, [...]
exampleSlice2 = []main.example len: 3, cap: 4, [...]
exampleSlice1 = []main.example len: 3, cap: 4, [...]
```#### Print value of local variable
```
(dlv) print exampleSlice1[2]
main.example {
exampleValue: *main.exampleValue {value: 1},}
```### Run until second breakpoint
```
(dlv) continue
> main.output() ./delve-example.go:21 (hits goroutine(1):1 total:1) (PC: 0x4abeaf)
16: {exampleValue: &exampleValue{value: 0}},
17: }
18: }
19:
20: func output(name string, exampleSlice []example) {
=> 21: fmt.Printf("%s: %+v\n", name, exampleSlice)
22: }
23:
24: func main() {
25: examples := makeExampleSlice()
26:
```#### List function arguments
```
(dlv) args
name = "example1"
exampleSlice = []main.example len: 3, cap: 4, [...]
```#### Print value of function argument
```
(dlv) print exampleSlice[2]
main.example {
exampleValue: *main.exampleValue {value: 1},}
```---
## Debugging tests
### Start Delve
```
dlv test ./internal/pkg/example/
```### Set breakpoints
```
(dlv) break example_test.go:9
Breakpoint 1 set at 0x547e5f for github.com/ewohltman/delve-example/internal/pkg/example.TestNew() ./internal/pkg/example/example_test.go:9
``````
(dlv) break example_test.go:29
Breakpoint 2 set at 0x5480a0 for github.com/ewohltman/delve-example/internal/pkg/example.TestNewSlice() ./internal/pkg/example/example_test.go:29
```### See remaining examples under `Debugging main application`
---
## Exit Delve
```
(dlv) exit
```