mirror of
https://github.com/go-delve/delve.git
synced 2025-11-03 22:08:33 +08:00
Add test sub command
Allows compiling a test binary and debugging it.
This commit is contained in:
@ -53,6 +53,12 @@ The debugger can be launched in three ways:
|
|||||||
$ dlv run
|
$ dlv run
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* Compile test binary, run and attach:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ dlv test
|
||||||
|
```
|
||||||
|
|
||||||
* Provide the name of the program you want to debug, and the debugger will launch it for you.
|
* Provide the name of the program you want to debug, and the debugger will launch it for you.
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
@ -6,8 +6,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strings"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
sys "golang.org/x/sys/unix"
|
sys "golang.org/x/sys/unix"
|
||||||
|
|
||||||
@ -41,6 +42,24 @@ func Run(args []string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
die(1, "Could not launch program:", err)
|
die(1, "Could not launch program:", err)
|
||||||
}
|
}
|
||||||
|
case "test":
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
die(1, err)
|
||||||
|
}
|
||||||
|
base := filepath.Base(wd)
|
||||||
|
cmd := exec.Command("go", "test", "-c", "-gcflags", "-N -l")
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
die(1, "Could not compile program:", err)
|
||||||
|
}
|
||||||
|
debugname := "./" + base + ".test"
|
||||||
|
defer os.Remove(debugname)
|
||||||
|
|
||||||
|
dbp, err = proctl.Launch(append([]string{debugname}, args...))
|
||||||
|
if err != nil {
|
||||||
|
die(1, "Could not launch program:", err)
|
||||||
|
}
|
||||||
case "attach":
|
case "attach":
|
||||||
pid, err := strconv.Atoi(args[1])
|
pid, err := strconv.Atoi(args[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -22,6 +22,7 @@ Invoke with the path to a binary:
|
|||||||
|
|
||||||
or use the following commands:
|
or use the following commands:
|
||||||
run - Build, run, and attach to program
|
run - Build, run, and attach to program
|
||||||
|
test - Build test binary, run and attach to it
|
||||||
attach - Attach to running process
|
attach - Attach to running process
|
||||||
`, version)
|
`, version)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user