提交 bb4356b7 编写于 作者: D Derek Parker

Add test sub command

Allows compiling a test binary and debugging it.
上级 0125e300
......@@ -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.
```
......
......@@ -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 {
......
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册