Skip to content

Commit

Permalink
update docs/debug.md with more information on how to debug Go tests
Browse files Browse the repository at this point in the history
Signed-off-by: Shahriyar Jalayeri <[email protected]>
  • Loading branch information
shjala committed Aug 28, 2024
1 parent a499b32 commit a6afc29
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions docs/debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,51 @@ sleep 5
eden utils debug save flamegraph1.svg --perf-location="/persist/perf1.data"
eden utils debug save flamegraph2.svg --perf-location="/persist/perf2.data"
```

Check failure on line 53 in docs/debug.md

View workflow job for this annotation

GitHub Actions / yetus

markdownlint:MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]
## Debug Go tests in VS Code

Check failure on line 54 in docs/debug.md

View workflow job for this annotation

GitHub Actions / yetus

markdownlint:MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Above] [Context: "## Debug Go tests in VS Code"]

To debug Go tests, first ensure you have the debugger installed:

```bash

Check failure on line 58 in docs/debug.md

View workflow job for this annotation

GitHub Actions / yetus

blanks:end of line

Check failure on line 58 in docs/debug.md

View workflow job for this annotation

GitHub Actions / yetus

markdownlint:MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]
$ go install github.com/go-delve/delve/cmd/dlv@latest

Check failure on line 59 in docs/debug.md

View workflow job for this annotation

GitHub Actions / yetus

markdownlint:MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ go install github.com/go-del..."]
```

Next, make sure you have a debug target in your test Makefile, this target compiles the test with debug information into a final binary named `debug`:

```bash
debug:
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go test -c -gcflags "all=-N -l" -o $@ *.go

Check failure on line 66 in docs/debug.md

View workflow job for this annotation

GitHub Actions / yetus

markdownlint:MD010/no-hard-tabs Hard tabs [Column: 1]
dlv dap --listen=:12345

Check failure on line 67 in docs/debug.md

View workflow job for this annotation

GitHub Actions / yetus

markdownlint:MD010/no-hard-tabs Hard tabs [Column: 1]
```

Finally, ensure you have properly set up your `.vscode/launch.json`:

```json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Eden Test",
"type": "go",
"request": "launch",
"mode": "exec",
"program": "${fileDirname}/debug",
"args": [],
"showLog": true,
"port": 12345,
}
]
}
```

At this stage, simply open the test file in VS Code. Open a new terminal in VS Code, navigate to your test directory and run `make debug` :

Check failure on line 90 in docs/debug.md

View workflow job for this annotation

GitHub Actions / yetus

blanks:end of line

Check failure on line 90 in docs/debug.md

View workflow job for this annotation

GitHub Actions / yetus

markdownlint:MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]

```bash
$ cd tests/sec
$ make debug
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go test -c -gcflags "all=-N -l" -o debug *.go
dlv dap --listen=:12345
DAP server listening at: 0.0.0.0:12345
2024-08-28T14:59:52+03:00 warning layer=rpc Listening for remote connections (connections are not authenticated nor encrypted)
```

Finally, put a breakpoint in the part of the code you're interested in and press F5 or go to the menu "Run -> Start Debugging" to start debugging.

0 comments on commit a6afc29

Please sign in to comment.