delve/cmd/dlv/main.go

72 lines
1.3 KiB
Go
Raw Normal View History

2014-05-20 21:29:01 +00:00
package main
import (
"flag"
2014-05-20 21:29:01 +00:00
"fmt"
"os"
"runtime"
2014-05-20 21:29:01 +00:00
"github.com/derekparker/delve/client/cli"
2014-05-20 21:29:01 +00:00
)
const version string = "0.5.0.beta"
2014-11-10 12:53:33 +00:00
2015-04-25 14:49:12 +00:00
var usage string = `Delve version %s
2015-03-09 02:26:45 +00:00
flags:
2015-04-25 14:49:12 +00:00
%s
2015-03-09 02:26:45 +00:00
Invoke with the path to a binary:
2015-03-09 03:01:14 +00:00
dlv ./path/to/prog
2015-03-09 02:26:45 +00:00
or use the following commands:
run - Build, run, and attach to program
test - Build test binary, run and attach to it
2015-03-09 02:26:45 +00:00
attach - Attach to running process
2015-04-25 14:49:12 +00:00
`
2015-03-09 02:26:45 +00:00
2014-11-23 16:22:04 +00:00
func init() {
2015-04-25 14:49:12 +00:00
flag.Usage = help
// 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
2014-05-24 00:01:56 +00:00
// all commands after PTRACE_ATTACH to come from the same thread.
runtime.LockOSThread()
2014-11-23 16:22:04 +00:00
}
2014-11-23 16:22:04 +00:00
func main() {
2015-04-25 14:49:12 +00:00
var printv, printhelp bool
2015-03-09 02:26:45 +00:00
2015-03-09 14:03:54 +00:00
flag.BoolVar(&printv, "v", false, "Print version number and exit.")
2015-04-25 14:49:12 +00:00
flag.BoolVar(&printhelp, "h", false, "Print help text and exit.")
flag.Parse()
2014-05-20 23:11:00 +00:00
if flag.NFlag() == 0 && len(flag.Args()) == 0 {
2015-04-25 14:49:12 +00:00
help()
os.Exit(0)
2014-05-20 23:11:00 +00:00
}
2014-11-10 12:53:33 +00:00
if printv {
fmt.Printf("Delve version: %s\n", version)
os.Exit(0)
}
2015-04-25 14:49:12 +00:00
if printhelp {
help()
os.Exit(0)
}
2015-03-09 02:26:45 +00:00
cli.Run(os.Args[1:])
2014-05-20 21:29:01 +00:00
}
2015-04-25 14:49:12 +00:00
// help prints help text to os.Stderr.
func help() {
flags := ""
flag.VisitAll(func(f *flag.Flag) {
doc := fmt.Sprintf(" -%s=%s: %s\n", f.Name, f.DefValue, f.Usage)
flags += doc
})
fmt.Fprintf(os.Stderr, usage, version, flags)
}