diff options
| author | Than McIntosh <thanm@google.com> | 2022-03-07 10:32:51 -0500 |
|---|---|---|
| committer | Than McIntosh <thanm@google.com> | 2022-09-27 10:30:53 +0000 |
| commit | e6d9057e2f3442b133afe7e37bec72bb9b780b04 (patch) | |
| tree | 15ac9b503567f7d7151238f8f9a62235c8d00794 /src/internal/coverage | |
| parent | 072c7d4969862c84430cc2daef20a8f7f3ba78a2 (diff) | |
| download | go-e6d9057e2f3442b133afe7e37bec72bb9b780b04.tar.xz | |
cmd/compile: add coverage fixup mode
Adds a -coveragecfg=<configfile> command line option to the compiler
to help support a cooperative "tool and compiler" mode for coverage
instrumentation. In this mode the cmd/cover tool generates most of the
counter instrumentation via source-to-source rewriting, but the
compiler fixes up the result if passed the "-coveragecfg" option. The
fixups include:
- reclassifying counter variables (special storage class)
- marking meta-data variables are read-only
- adding in an init call to do registation
Updates #51430.
Change-Id: Iead72b85209725ee044542374465f118a3ee72e0
Reviewed-on: https://go-review.googlesource.com/c/go/+/395895
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/internal/coverage')
| -rw-r--r-- | src/internal/coverage/cmddefs.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/internal/coverage/cmddefs.go b/src/internal/coverage/cmddefs.go new file mode 100644 index 0000000000..a146ca53e4 --- /dev/null +++ b/src/internal/coverage/cmddefs.go @@ -0,0 +1,66 @@ +// Copyright 2022 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 coverage + +// CoverPkgConfig is a bundle of information passed from the Go +// command to the cover command during "go build -cover" runs. The +// Go command creates and fills in a struct as below, then passes +// file containing the encoded JSON for the struct to the "cover" +// tool when instrumenting the source files in a Go package. +type CoverPkgConfig struct { + // File into which cmd/cover should emit summary info + // when instrumentation is complete. + OutConfig string + + // Import path for the package being instrumented. + PkgPath string + + // Package name. + PkgName string + + // Instrumentation granularity: one of "perfunc" or "perblock" (default) + Granularity string + + // Module path for this package (empty if no go.mod in use) + ModulePath string +} + +// CoverFixupConfig contains annotations/notes generated by the +// cmd/cover tool (during instrumentation) to be passed on to the +// compiler when the instrumented code is compiled. The cmd/cover tool +// creates a struct of this type, JSON-encodes it, and emits the +// result to a file, which the Go command then passes to the compiler +// when the instrumented package is built. +type CoverFixupConfig struct { + // Name of the variable (created by cmd/cover) containing the + // encoded meta-data for the package. + MetaVar string + + // Length of the meta-data. + MetaLen int + + // Hash computed by cmd/cover of the meta-data. + MetaHash string + + // Instrumentation strategy. For now this is always set to + // "normal", but in the future we may add new values (for example, + // if panic paths are instrumented, or if the instrumenter + // eliminates redundant counters). + Strategy string + + // Prefix assigned to the names of counter variables generated + // during instrumentation by cmd/cover. + CounterPrefix string + + // Name chosen for the package ID variable generated during + // instrumentation. + PkgIdVar string + + // Counter mode (e.g. set/count/atomic) + CounterMode string + + // Counter granularity (perblock or perfunc). + CounterGranularity string +} |
