mirror of
https://github.com/golang/go
synced 2024-11-05 16:16:11 -07:00
cmd/compile: provide a way to auto-discover -d debug keys
Currently one needs to refer to the sources to have a list of accepted debug keys. We can copy what 'ssa/help' does and introspect the list of debug keys to print a more detailed help: $ go tool compile -d help usage: -d arg[,arg]* and arg is <key>[=<value>] <key> is one of: append print information about append compilation closure print information about closure compilation disablenil disable nil checks dclstack run internal dclstack check gcprog print dump of GC programs nil print information about nil checks panic do not hide any compiler panic slice print information about slice compilation typeassert print information about type assertion inlining wb print information about write barriers export print export data pctab print named pc-value table ssa/help print help about SSA debugging <value> is key-specific. Key "pctab" supports values: "pctospadj", "pctofile", "pctoline", "pctoinline", "pctopcdata" For '-d help' to be discoverable, a hint is given in the -d flag description. A last thing, today at least one go file needs to be provided to get to the code printing ssa/help. $ go tool compile -d ssa/help foo.go Add a check so one can just do '-d help' or '-d ssa/help' Caught by trybot: I needed to update fmt_test.go as I'm introducing the usage of %-*s in a format string. Fixes #20041 Change-Id: Ib2858b038c1bcbe644aa3b1a371009710c6d957d Reviewed-on: https://go-review.googlesource.com/41091 Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
parent
1e72bf6218
commit
f9be63b9ba
@ -687,6 +687,7 @@ var knownFormats = map[string]string{
|
||||
"reflect.Type %s": "",
|
||||
"rune %#U": "",
|
||||
"rune %c": "",
|
||||
"string %-*s": "",
|
||||
"string %-16s": "",
|
||||
"string %.*s": "",
|
||||
"string %q": "",
|
||||
|
@ -51,22 +51,36 @@ var (
|
||||
// Each option accepts an optional argument, as in "gcprog=2"
|
||||
var debugtab = []struct {
|
||||
name string
|
||||
help string
|
||||
val interface{} // must be *int or *string
|
||||
}{
|
||||
{"append", &Debug_append}, // print information about append compilation
|
||||
{"closure", &Debug_closure}, // print information about closure compilation
|
||||
{"disablenil", &disable_checknil}, // disable nil checks
|
||||
{"dclstack", &debug_dclstack}, // run internal dclstack checks
|
||||
{"gcprog", &Debug_gcprog}, // print dump of GC programs
|
||||
{"nil", &Debug_checknil}, // print information about nil checks
|
||||
{"panic", &Debug_panic}, // do not hide any compiler panic
|
||||
{"slice", &Debug_slice}, // print information about slice compilation
|
||||
{"typeassert", &Debug_typeassert}, // print information about type assertion inlining
|
||||
{"wb", &Debug_wb}, // print information about write barriers
|
||||
{"export", &Debug_export}, // print export data
|
||||
{"pctab", &Debug_pctab}, // print named pc-value table
|
||||
{"append", "print information about append compilation", &Debug_append},
|
||||
{"closure", "print information about closure compilation", &Debug_closure},
|
||||
{"disablenil", "disable nil checks", &disable_checknil},
|
||||
{"dclstack", "run internal dclstack check", &debug_dclstack},
|
||||
{"gcprog", "print dump of GC programs", &Debug_gcprog},
|
||||
{"nil", "print information about nil checks", &Debug_checknil},
|
||||
{"panic", "do not hide any compiler panic", &Debug_panic},
|
||||
{"slice", "print information about slice compilation", &Debug_slice},
|
||||
{"typeassert", "print information about type assertion inlining", &Debug_typeassert},
|
||||
{"wb", "print information about write barriers", &Debug_wb},
|
||||
{"export", "print export data", &Debug_export},
|
||||
{"pctab", "print named pc-value table", &Debug_pctab},
|
||||
}
|
||||
|
||||
const debugHelpHeader = `usage: -d arg[,arg]* and arg is <key>[=<value>]
|
||||
|
||||
<key> is one of:
|
||||
|
||||
`
|
||||
|
||||
const debugHelpFooter = `
|
||||
<value> is key-specific.
|
||||
|
||||
Key "pctab" supports values:
|
||||
"pctospadj", "pctofile", "pctoline", "pctoinline", "pctopcdata"
|
||||
`
|
||||
|
||||
func usage() {
|
||||
fmt.Printf("usage: compile [options] file.go...\n")
|
||||
objabi.Flagprint(1)
|
||||
@ -171,7 +185,7 @@ func Main(archInit func(*Arch)) {
|
||||
flag.StringVar(&asmhdr, "asmhdr", "", "write assembly header to `file`")
|
||||
flag.StringVar(&buildid, "buildid", "", "record `id` as the build id in the export metadata")
|
||||
flag.BoolVar(&pure_go, "complete", false, "compiling complete package (no C or assembly)")
|
||||
flag.StringVar(&debugstr, "d", "", "print debug information about items in `list`")
|
||||
flag.StringVar(&debugstr, "d", "", "print debug information about items in `list`; try -d help")
|
||||
flag.BoolVar(&flagDWARF, "dwarf", true, "generate DWARF symbols")
|
||||
objabi.Flagcount("e", "no limit on number of errors reported", &Debug['e'])
|
||||
objabi.Flagcount("f", "debug stack frames", &Debug['f'])
|
||||
@ -223,7 +237,7 @@ func Main(archInit func(*Arch)) {
|
||||
Ctxt.DebugInfo = debuginfo
|
||||
}
|
||||
|
||||
if flag.NArg() < 1 {
|
||||
if flag.NArg() < 1 && debugstr != "help" && debugstr != "ssa/help" {
|
||||
usage()
|
||||
}
|
||||
|
||||
@ -273,6 +287,23 @@ func Main(archInit func(*Arch)) {
|
||||
if name == "" {
|
||||
continue
|
||||
}
|
||||
// display help about the -d option itself and quit
|
||||
if name == "help" {
|
||||
fmt.Printf(debugHelpHeader)
|
||||
maxLen := len("ssa/help")
|
||||
for _, t := range debugtab {
|
||||
if len(t.name) > maxLen {
|
||||
maxLen = len(t.name)
|
||||
}
|
||||
}
|
||||
for _, t := range debugtab {
|
||||
fmt.Printf("\t%-*s\t%s\n", maxLen, t.name, t.help)
|
||||
}
|
||||
// ssa options have their own help
|
||||
fmt.Printf("\t%-*s\t%s\n", maxLen, "ssa/help", "print help about SSA debugging")
|
||||
fmt.Printf(debugHelpFooter)
|
||||
os.Exit(0)
|
||||
}
|
||||
val, valstring, haveInt := 1, "", true
|
||||
if i := strings.IndexAny(name, "=:"); i >= 0 {
|
||||
var err error
|
||||
|
Loading…
Reference in New Issue
Block a user