mirror of
https://github.com/go-delve/delve.git
synced 2025-11-02 21:40:22 +08:00
Use subcommands instead of flags
This commit is contained in:
@ -50,7 +50,7 @@ The debugger can be launched in three ways:
|
|||||||
* Compile, run, and attach in one step:
|
* 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.
|
* 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.
|
* 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
|
### Breakpoints
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strings"
|
"strings"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
sys "golang.org/x/sys/unix"
|
sys "golang.org/x/sys/unix"
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ import (
|
|||||||
|
|
||||||
const historyFile string = ".dbg_history"
|
const historyFile string = ".dbg_history"
|
||||||
|
|
||||||
func Run(run bool, pid int, args []string) {
|
func Run(args []string) {
|
||||||
var (
|
var (
|
||||||
dbp *proctl.DebuggedProcess
|
dbp *proctl.DebuggedProcess
|
||||||
err error
|
err error
|
||||||
@ -26,8 +27,8 @@ func Run(run bool, pid int, args []string) {
|
|||||||
)
|
)
|
||||||
defer line.Close()
|
defer line.Close()
|
||||||
|
|
||||||
switch {
|
switch args[0] {
|
||||||
case run:
|
case "run":
|
||||||
const debugname = "debug"
|
const debugname = "debug"
|
||||||
cmd := exec.Command("go", "build", "-o", debugname, "-gcflags", "-N -l")
|
cmd := exec.Command("go", "build", "-o", debugname, "-gcflags", "-N -l")
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
@ -40,7 +41,11 @@ func Run(run bool, pid int, args []string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
die(1, "Could not launch program:", err)
|
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)
|
dbp, err = proctl.Attach(pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
die(1, "Could not attach to process:", err)
|
die(1, "Could not attach to process:", err)
|
||||||
|
|||||||
@ -11,6 +11,20 @@ import (
|
|||||||
|
|
||||||
const version string = "0.5.0.beta"
|
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() {
|
func init() {
|
||||||
// We must ensure here that we are running on the same thread during
|
// 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
|
// the execution of dbg. This is due to the fact that ptrace(2) expects
|
||||||
@ -19,19 +33,12 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var (
|
var printv bool
|
||||||
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.")
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if flag.NFlag() == 0 && len(flag.Args()) == 0 {
|
if flag.NFlag() == 0 && len(flag.Args()) == 0 {
|
||||||
flag.Usage()
|
fmt.Println(usage)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,5 +47,5 @@ func main() {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
cli.Run(run, pid, flag.Args())
|
cli.Run(os.Args[1:])
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user