1
0
mirror of https://github.com/golang/go synced 2024-11-12 00:30:22 -07:00

cmd/compile: add debugging mode for import/export

Just add a simple magic number with each op, to detect when
the reader gets desynchronized from the writer.

Change-Id: Iac7dab7f465b0021b1d7ae31c8f8a353ac3663a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/299769
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
This commit is contained in:
Keith Randall 2021-03-05 09:49:28 -08:00
parent a70eb2c9f2
commit b60a3a8cfb
2 changed files with 11 additions and 0 deletions

View File

@ -246,6 +246,11 @@ const (
interfaceType
)
const (
debug = false
magic = 0x6742937dc293105
)
func WriteExports(out *bufio.Writer) {
p := iexporter{
allPkgs: map[*types.Pkg]bool{},
@ -1584,6 +1589,9 @@ func (w *exportWriter) expr(n ir.Node) {
}
func (w *exportWriter) op(op ir.Op) {
if debug {
w.uint64(magic)
}
w.uint64(uint64(op))
}

View File

@ -1228,6 +1228,9 @@ func (r *importReader) node() ir.Node {
}
func (r *importReader) op() ir.Op {
if debug && r.uint64() != magic {
base.Fatalf("import stream has desynchronized")
}
return ir.Op(r.uint64())
}