提交 4e43b0f8 编写于 作者: D Derek Parker

Use subcommands instead of flags

上级 11405314
......@@ -50,7 +50,7 @@ The debugger can be launched in three ways:
* Compile, run, and attach in one step:
```
$ dlv -run
$ dlv run
```
* Provide the name of the program you want to debug, and the debugger will launch it for you.
......@@ -62,7 +62,7 @@ The debugger can be launched in three ways:
* Provide the pid of a currently running process, and the debugger will attach and begin the session.
```
$ sudo dlv -pid 44839
$ sudo dlv attach 44839
```
### Breakpoints
......
......@@ -7,6 +7,7 @@ import (
"os/exec"
"os/signal"
"strings"
"strconv"
sys "golang.org/x/sys/unix"
......@@ -18,7 +19,7 @@ import (
const historyFile string = ".dbg_history"
func Run(run bool, pid int, args []string) {
func Run(args []string) {
var (
dbp *proctl.DebuggedProcess
err error
......@@ -26,8 +27,8 @@ func Run(run bool, pid int, args []string) {
)
defer line.Close()
switch {
case run:
switch args[0] {
case "run":
const debugname = "debug"
cmd := exec.Command("go", "build", "-o", debugname, "-gcflags", "-N -l")
err := cmd.Run()
......@@ -40,7 +41,11 @@ func Run(run bool, pid int, args []string) {
if err != nil {
die(1, "Could not launch program:", err)
}
case pid != 0:
case "attach":
pid, err := strconv.Atoi(args[1])
if err != nil {
die(1, "Invalid pid", args[1])
}
dbp, err = proctl.Attach(pid)
if err != nil {
die(1, "Could not attach to process:", err)
......
......@@ -11,6 +11,20 @@ import (
const version string = "0.5.0.beta"
var usage string = fmt.Sprintf(`Delve version %s
flags:
-v - Print version
Invoke with the path to a binary:
dlv ./path/to/prog
or use the following commands:
run - Build, run, and attach to program
attach - Attach to running process
`, version)
func init() {
// We must ensure here that we are running on the same thread during
// the execution of dbg. This is due to the fact that ptrace(2) expects
......@@ -19,19 +33,12 @@ func init() {
}
func main() {
var (
pid int
run bool
printv bool
)
flag.IntVar(&pid, "pid", 0, "Pid of running process to attach to.")
flag.BoolVar(&run, "run", false, "Compile program and begin debug session.")
flag.BoolVar(&printv, "v", false, "Print version number and exit.")
var printv bool
flag.Parse()
if flag.NFlag() == 0 && len(flag.Args()) == 0 {
flag.Usage()
fmt.Println(usage)
os.Exit(0)
}
......@@ -40,5 +47,5 @@ func main() {
os.Exit(0)
}
cli.Run(run, pid, flag.Args())
cli.Run(os.Args[1:])
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册