diff --git a/README.md b/README.md index 8b2952f1677a16677d5a3b11ceba268110d51fdc..658e8dd25c06e64f74bd8012ae79d84877e92619 100644 --- a/README.md +++ b/README.md @@ -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. ``` diff --git a/client/cli/cli.go b/client/cli/cli.go index 530c64f0e557780a5b6d72776217cf7f64fc250e..ea373ab15c6be1dcea31f68aec2a7e3d53bbc51b 100644 --- a/client/cli/cli.go +++ b/client/cli/cli.go @@ -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 { diff --git a/cmd/dlv/main.go b/cmd/dlv/main.go index 5ad35d0f00140566bb318dc4e43c75e151907685..203752d04dd8ec20e7ac2d5d4f7f6adcac7d73c6 100644 --- a/cmd/dlv/main.go +++ b/cmd/dlv/main.go @@ -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)