]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj, cmd/trace: restore bounds checks dropped in CL 56950
authorRuss Cox <rsc@golang.org>
Tue, 14 Nov 2017 03:32:19 +0000 (22:32 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 16 Nov 2017 16:29:08 +0000 (16:29 +0000)
CL 56950 correctly identified code with checks that were impossible.
But instead of correcting the checks it deleted them.
This CL corrects the code to check what was meant.

Change-Id: Ic89222184ee4fa5cacccae12d750601a9438ac8d
Reviewed-on: https://go-review.googlesource.com/78113
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/internal/obj/sym.go
src/cmd/trace/trace.go

index 2d32f5a436addbd692ed4b34dfc8ee229aadd37e..3fc17fa850711be0218cc24f845f22337f0819d8 100644 (file)
@@ -34,6 +34,7 @@ package obj
 import (
        "cmd/internal/objabi"
        "fmt"
+       "log"
        "math"
 )
 
@@ -44,7 +45,9 @@ func Linknew(arch *LinkArch) *Link {
        ctxt.Arch = arch
        ctxt.Pathname = objabi.WorkingDir()
 
-       ctxt.Headtype.Set(objabi.GOOS)
+       if err := ctxt.Headtype.Set(objabi.GOOS); err != nil {
+               log.Fatalf("unknown goos %s", objabi.GOOS)
+       }
 
        ctxt.Flag_optimize = true
        ctxt.Framepointer_enabled = objabi.Framepointer_enabled(objabi.GOOS, arch.Name)
index 71782877517ace263d3c52dc90463585c7b7c1cc..d69c5feebc2fcaa58162135c3d7bf5e7e90882a9 100644 (file)
@@ -278,7 +278,7 @@ type traceContext struct {
 
        heapStats, prevHeapStats     heapStats
        threadStats, prevThreadStats threadStats
-       gstates, prevGstates         [gStateCount]uint64
+       gstates, prevGstates         [gStateCount]int64
 }
 
 type heapStats struct {
@@ -449,6 +449,9 @@ func generateTrace(params *traceParams) (ViewerData, error) {
                if setGStateErr != nil {
                        return ctx.data, setGStateErr
                }
+               if ctx.gstates[gRunnable] < 0 || ctx.gstates[gRunning] < 0 || ctx.threadStats.insyscall < 0 {
+                       return ctx.data, fmt.Errorf("invalid state after processing %v: runnable=%d running=%d insyscall=%d", ev, ctx.gstates[gRunnable], ctx.gstates[gRunning], ctx.threadStats.insyscall)
+               }
 
                // Ignore events that are from uninteresting goroutines
                // or outside of the interesting timeframe.
@@ -644,7 +647,7 @@ func (ctx *traceContext) emitGoroutineCounters(ev *trace.Event) {
        if ctx.prevGstates == ctx.gstates {
                return
        }
-       ctx.emit(&ViewerEvent{Name: "Goroutines", Phase: "C", Time: ctx.time(ev), Pid: 1, Arg: &goroutineCountersArg{ctx.gstates[gRunning], ctx.gstates[gRunnable], ctx.gstates[gWaitingGC]}})
+       ctx.emit(&ViewerEvent{Name: "Goroutines", Phase: "C", Time: ctx.time(ev), Pid: 1, Arg: &goroutineCountersArg{uint64(ctx.gstates[gRunning]), uint64(ctx.gstates[gRunnable]), uint64(ctx.gstates[gWaitingGC])}})
        ctx.prevGstates = ctx.gstates
 }