mirror of
https://github.com/golang/go.git
synced 2025-05-29 19:35:42 +00:00
cmd/compile: accept string debug flags
The compiler's -d flag accepts string-valued flags, but currently only for SSA debug flags. Extend it to support string values for other flags. This also makes the syntax somewhat more sane so flag=value and flag:value now both accept integers and strings. Change-Id: Idd144d8479a430970cc1688f824bffe0a56ed2df Reviewed-on: https://go-review.googlesource.com/37345 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
parent
5bfd1ef036
commit
8eb14e9de5
@ -41,11 +41,12 @@ var (
|
|||||||
|
|
||||||
// Debug arguments.
|
// Debug arguments.
|
||||||
// These can be specified with the -d flag, as in "-d nil"
|
// These can be specified with the -d flag, as in "-d nil"
|
||||||
// to set the debug_checknil variable. In general the list passed
|
// to set the debug_checknil variable.
|
||||||
// to -d can be comma-separated.
|
// Multiple options can be comma-separated.
|
||||||
|
// Each option accepts an optional argument, as in "gcprog=2"
|
||||||
var debugtab = []struct {
|
var debugtab = []struct {
|
||||||
name string
|
name string
|
||||||
val *int
|
val interface{} // must be *int or *string
|
||||||
}{
|
}{
|
||||||
{"append", &Debug_append}, // print information about append compilation
|
{"append", &Debug_append}, // print information about append compilation
|
||||||
{"closure", &Debug_closure}, // print information about closure compilation
|
{"closure", &Debug_closure}, // print information about closure compilation
|
||||||
@ -269,26 +270,33 @@ func Main() {
|
|||||||
if name == "" {
|
if name == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
val := 1
|
val, valstring, haveInt := 1, "", true
|
||||||
valstring := ""
|
if i := strings.IndexAny(name, "=:"); i >= 0 {
|
||||||
if i := strings.Index(name, "="); i >= 0 {
|
|
||||||
var err error
|
var err error
|
||||||
val, err = strconv.Atoi(name[i+1:])
|
name, valstring = name[:i], name[i+1:]
|
||||||
|
val, err = strconv.Atoi(valstring)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("invalid debug value %v", name)
|
val, haveInt = 1, false
|
||||||
}
|
}
|
||||||
name = name[:i]
|
|
||||||
} else if i := strings.Index(name, ":"); i >= 0 {
|
|
||||||
valstring = name[i+1:]
|
|
||||||
name = name[:i]
|
|
||||||
}
|
}
|
||||||
for _, t := range debugtab {
|
for _, t := range debugtab {
|
||||||
if t.name == name {
|
if t.name != name {
|
||||||
if t.val != nil {
|
continue
|
||||||
*t.val = val
|
|
||||||
continue Split
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
switch vp := t.val.(type) {
|
||||||
|
case nil:
|
||||||
|
// Ignore
|
||||||
|
case *string:
|
||||||
|
*vp = valstring
|
||||||
|
case *int:
|
||||||
|
if !haveInt {
|
||||||
|
log.Fatalf("invalid debug value %v", name)
|
||||||
|
}
|
||||||
|
*vp = val
|
||||||
|
default:
|
||||||
|
panic("bad debugtab type")
|
||||||
|
}
|
||||||
|
continue Split
|
||||||
}
|
}
|
||||||
// special case for ssa for now
|
// special case for ssa for now
|
||||||
if strings.HasPrefix(name, "ssa/") {
|
if strings.HasPrefix(name, "ssa/") {
|
||||||
|
@ -204,7 +204,7 @@ func PhaseOption(phase, flag string, val int, valString string) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "" +
|
return "" +
|
||||||
`GcFlag -d=ssa/<phase>/<flag>[=<value>]|[:<function_name>]
|
`GcFlag -d=ssa/<phase>/<flag>[=<value>|<function_name>]
|
||||||
<phase> is one of:
|
<phase> is one of:
|
||||||
` + phasenames + `
|
` + phasenames + `
|
||||||
<flag> is one of on, off, debug, mem, time, test, stats, dump
|
<flag> is one of on, off, debug, mem, time, test, stats, dump
|
||||||
|
Loading…
x
Reference in New Issue
Block a user