cmd/go: add check for unknown godebug setting

A //go:debug line mentioning an unknown or retired setting
should be diagnosed as making the program invalid. Do that.
We agreed on this in the proposal but I forgot to implement it.

Change-Id: Ie69072a1682d4eeb6866c02adbbb426f608567c4
Reviewed-on: https://go-review.googlesource.com/c/go/+/476280
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Russ Cox 2023-03-14 14:25:56 -04:00
parent 44e51e60ac
commit 14ab998f95
21 changed files with 208 additions and 164 deletions

View file

@ -4,6 +4,8 @@
package metrics
import "internal/godebugs"
// Description describes a runtime metric.
type Description struct {
// Name is the full name of the metric which includes the unit.
@ -49,7 +51,7 @@ type Description struct {
}
// The English language descriptions below must be kept in sync with the
// descriptions of each metric in doc.go.
// descriptions of each metric in doc.go by running 'go generate'.
var allDesc = []Description{
{
Name: "/cgo/go-to-c-calls:calls",
@ -277,104 +279,6 @@ var allDesc = []Description{
Kind: KindUint64,
Cumulative: false,
},
{
Name: "/godebug/non-default-behavior/execerrdot:events",
Description: "The number of non-default behaviors executed by the os/exec package " +
"due to a non-default GODEBUG=execerrdot=... setting.",
Kind: KindUint64,
Cumulative: true,
},
{
Name: "/godebug/non-default-behavior/http2client:events",
Description: "The number of non-default behaviors executed by the net/http package " +
"due to a non-default GODEBUG=http2client=... setting.",
Kind: KindUint64,
Cumulative: true,
},
{
Name: "/godebug/non-default-behavior/http2server:events",
Description: "The number of non-default behaviors executed by the net/http package " +
"due to a non-default GODEBUG=http2server=... setting.",
Kind: KindUint64,
Cumulative: true,
},
{
Name: "/godebug/non-default-behavior/installgoroot:events",
Description: "The number of non-default behaviors executed by the go/build package " +
"due to a non-default GODEBUG=installgoroot=... setting.",
Kind: KindUint64,
Cumulative: true,
},
{
Name: "/godebug/non-default-behavior/jstmpllitinterp:events",
Description: "The number of non-default behaviors executed by the html/template" +
"package due to a non-default GODEBUG=jstmpllitinterp=... setting.",
Kind: KindUint64,
Cumulative: true,
},
{
Name: "/godebug/non-default-behavior/multipartfiles:events",
Description: "The number of non-default behaviors executed by the mime/multipart package " +
"due to a non-default GODEBUG=multipartfiles=... setting.",
Kind: KindUint64,
Cumulative: true,
},
{
Name: "/godebug/non-default-behavior/multipartmaxheaders:events",
Description: "The number of non-default behaviors executed by the mime/multipart package " +
"due to a non-default GODEBUG=multipartmaxheaders=... setting.",
Kind: KindUint64,
Cumulative: true,
},
{
Name: "/godebug/non-default-behavior/multipartmaxparts:events",
Description: "The number of non-default behaviors executed by the mime/multipart package " +
"due to a non-default GODEBUG=multipartmaxparts=... setting.",
Kind: KindUint64,
Cumulative: true,
},
{
Name: "/godebug/non-default-behavior/panicnil:events",
Description: "The number of non-default behaviors executed by the runtime package " +
"due to a non-default GODEBUG=panicnil=... setting.",
Kind: KindUint64,
Cumulative: true,
},
{
Name: "/godebug/non-default-behavior/randautoseed:events",
Description: "The number of non-default behaviors executed by the math/rand package " +
"due to a non-default GODEBUG=randautoseed=... setting.",
Kind: KindUint64,
Cumulative: true,
},
{
Name: "/godebug/non-default-behavior/tarinsecurepath:events",
Description: "The number of non-default behaviors executed by the archive/tar package " +
"due to a non-default GODEBUG=tarinsecurepath=... setting.",
Kind: KindUint64,
Cumulative: true,
},
{
Name: "/godebug/non-default-behavior/x509sha1:events",
Description: "The number of non-default behaviors executed by the crypto/x509 package " +
"due to a non-default GODEBUG=x509sha1=... setting.",
Kind: KindUint64,
Cumulative: true,
},
{
Name: "/godebug/non-default-behavior/x509usefallbackroots:events",
Description: "The number of non-default behaviors executed by the crypto/x509 package " +
"due to a non-default GODEBUG=x509usefallbackroots=... setting.",
Kind: KindUint64,
Cumulative: true,
},
{
Name: "/godebug/non-default-behavior/zipinsecurepath:events",
Description: "The number of non-default behaviors executed by the archive/zip package " +
"due to a non-default GODEBUG=zipinsecurepath=... setting.",
Kind: KindUint64,
Cumulative: true,
},
{
Name: "/memory/classes/heap/free:bytes",
Description: "Memory that is completely free and eligible to be returned to the underlying system, " +
@ -472,6 +376,30 @@ var allDesc = []Description{
},
}
func init() {
// Insert all the the non-default-reporting GODEBUGs into the table,
// preserving the overall sort order.
i := 0
for i < len(allDesc) && allDesc[i].Name < "/godebug/" {
i++
}
more := make([]Description, i, len(allDesc)+len(godebugs.All))
copy(more, allDesc)
for _, info := range godebugs.All {
if !info.Opaque {
more = append(more, Description{
Name: "/godebug/non-default-behavior/" + info.Name + ":events",
Description: "The number of non-default behaviors executed by the " +
info.Package + " package " + "due to a non-default " +
"GODEBUG=" + info.Name + "=... setting.",
Kind: KindUint64,
Cumulative: true,
})
}
}
allDesc = append(more, allDesc[i:]...)
}
// All returns a slice of containing metric descriptions for all supported metrics.
func All() []Description {
return allDesc