]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add debugging mode for import/export
authorKeith Randall <khr@golang.org>
Fri, 5 Mar 2021 17:49:28 +0000 (09:49 -0800)
committerKeith Randall <khr@golang.org>
Tue, 9 Mar 2021 17:51:10 +0000 (17:51 +0000)
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>
src/cmd/compile/internal/typecheck/iexport.go
src/cmd/compile/internal/typecheck/iimport.go

index 38ac75320145d8c57b8808dad45fa47acd31fcf7..6f33ca15972364b8834fedad20d8201d58cdd56e 100644 (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))
 }
 
index 8df75b2285f42618ace49bf4443e842f9f9e8d33..d7c118b631da3658f2b230d3965979d2e27d3081 100644 (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())
 }