Add test sub command

Allows compiling a test binary and debugging it.
This commit is contained in:
Derek Parker
2015-03-08 22:59:37 -05:00
parent 0125e300cd
commit bb4356b713
3 changed files with 27 additions and 1 deletions

View File

@ -53,6 +53,12 @@ The debugger can be launched in three ways:
$ 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.
```

View File

@ -6,8 +6,9 @@ import (
"os"
"os/exec"
"os/signal"
"strings"
"path/filepath"
"strconv"
"strings"
sys "golang.org/x/sys/unix"
@ -41,6 +42,24 @@ func Run(args []string) {
if err != nil {
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":
pid, err := strconv.Atoi(args[1])
if err != nil {

View File

@ -22,6 +22,7 @@ Invoke with the path to a binary:
or use the following commands:
run - Build, run, and attach to program
test - Build test binary, run and attach to it
attach - Attach to running process
`, version)