go/src/cmd/compile/internal/gc/debug.go

168 lines
4.8 KiB
Go
Raw Normal View History

[dev.regabi] cmd/compile: clean up debug flag (-d) handling [generated] The debug table is not as haphazard as flags, but there are still a few mismatches between command-line names and variable names. This CL moves them all into a consistent home (var Debug, like var Flag). Code updated automatically using the rf command below. A followup CL will make a few manual cleanups, leaving this CL completely automated and easier to regenerate during merge conflicts. [git-generate] cd src/cmd/compile/internal/gc rf ' add main.go var Debug struct{} mv Debug_append Debug.Append mv Debug_checkptr Debug.Checkptr mv Debug_closure Debug.Closure mv Debug_compilelater Debug.CompileLater mv disable_checknil Debug.DisableNil mv debug_dclstack Debug.DclStack mv Debug_gcprog Debug.GCProg mv Debug_libfuzzer Debug.Libfuzzer mv Debug_checknil Debug.Nil mv Debug_panic Debug.Panic mv Debug_slice Debug.Slice mv Debug_typeassert Debug.TypeAssert mv Debug_wb Debug.WB mv Debug_export Debug.Export mv Debug_pctab Debug.PCTab mv Debug_locationlist Debug.LocationLists mv Debug_typecheckinl Debug.TypecheckInl mv Debug_gendwarfinl Debug.DwarfInl mv Debug_softfloat Debug.SoftFloat mv Debug_defer Debug.Defer mv Debug_dumpptrs Debug.DumpPtrs mv flag.go:/parse.-d/-1,/unknown.debug/+2 parseDebug mv debugtab Debug parseDebug \ debugHelpHeader debugHelpFooter \ debug.go # Remove //go:generate line copied from main.go rm debug.go:/go:generate/-+ ' Change-Id: I625761ca5659be4052f7161a83baa00df75cca91 Reviewed-on: https://go-review.googlesource.com/c/go/+/272246 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-11-16 01:17:25 -05:00
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gc
import (
"fmt"
"log"
"os"
"strconv"
"strings"
"cmd/compile/internal/ssa"
"cmd/internal/objabi"
)
// Debug arguments.
// These can be specified with the -d flag, as in "-d nil"
// to set the debug_checknil variable.
// Multiple options can be comma-separated.
// 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", "print information about append compilation", &Debug.Append},
{"checkptr", "instrument unsafe pointer conversions", &Debug.Checkptr},
{"closure", "print information about closure compilation", &Debug.Closure},
{"compilelater", "compile functions as late as possible", &Debug.CompileLater},
{"disablenil", "disable nil checks", &Debug.DisableNil},
{"dclstack", "run internal dclstack check", &Debug.DclStack},
{"dumpptrs", "show Node pointer values in Dump/dumplist output", &Debug.DumpPtrs},
{"gcprog", "print dump of GC programs", &Debug.GCProg},
{"libfuzzer", "coverage instrumentation for libfuzzer", &Debug.Libfuzzer},
{"nil", "print information about nil checks", &Debug.Nil},
{"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},
{"locationlists", "print information about DWARF location list creation", &Debug.LocationLists},
{"typecheckinl", "eager typechecking of inline function bodies", &Debug.TypecheckInl},
{"dwarfinl", "print information about DWARF inlined function creation", &Debug.DwarfInl},
{"softfloat", "force compiler to emit soft-float code", &Debug.SoftFloat},
{"defer", "print information about defer compilation", &Debug.Defer},
{"fieldtrack", "enable fieldtracking", &objabi.Fieldtrack_enabled},
}
var Debug struct {
Append int
Checkptr int
Closure int
CompileLater int
DisableNil int
DclStack int
GCProg int
Libfuzzer int
Nil int
Panic int
Slice int
TypeAssert int
WB int
Export int
PCTab string
LocationLists int
TypecheckInl int
DwarfInl int
SoftFloat int
Defer int
DumpPtrs int
}
func parseDebug() {
// parse -d argument
if Flag.LowerD != "" {
Split:
for _, name := range strings.Split(Flag.LowerD, ",") {
if name == "" {
continue
}
// display help about the -d option itself and quit
if name == "help" {
fmt.Print(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.Print(debugHelpFooter)
os.Exit(0)
}
val, valstring, haveInt := 1, "", true
if i := strings.IndexAny(name, "=:"); i >= 0 {
var err error
name, valstring = name[:i], name[i+1:]
val, err = strconv.Atoi(valstring)
if err != nil {
val, haveInt = 1, false
}
}
for _, t := range debugtab {
if t.name != name {
continue
}
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
if strings.HasPrefix(name, "ssa/") {
// expect form ssa/phase/flag
// e.g. -d=ssa/generic_cse/time
// _ in phase name also matches space
phase := name[4:]
flag := "debug" // default flag is debug
if i := strings.Index(phase, "/"); i >= 0 {
flag = phase[i+1:]
phase = phase[:i]
}
err := ssa.PhaseOption(phase, flag, val, valstring)
if err != "" {
log.Fatalf(err)
}
continue Split
}
log.Fatalf("unknown debug key -d %s\n", name)
}
}
}
const debugHelpHeader = `usage: -d arg[,arg]* and arg is <key>[=<value>]
<key> is one of:
`
const debugHelpFooter = `
<value> is key-specific.
Key "checkptr" supports values:
"0": instrumentation disabled
"1": conversions involving unsafe.Pointer are instrumented
"2": conversions to unsafe.Pointer force heap allocation
Key "pctab" supports values:
"pctospadj", "pctofile", "pctoline", "pctoinline", "pctopcdata"
`