From: Russ Cox Date: Tue, 14 Nov 2017 03:32:19 +0000 (-0500) Subject: cmd/internal/obj, cmd/trace: restore bounds checks dropped in CL 56950 X-Git-Tag: go1.10beta1~234 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=918b98ca707e36ec84c0494b884ff0a02c9121c2;p=gostls13.git cmd/internal/obj, cmd/trace: restore bounds checks dropped in CL 56950 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 Reviewed-by: Ian Lance Taylor --- diff --git a/src/cmd/internal/obj/sym.go b/src/cmd/internal/obj/sym.go index 2d32f5a436..3fc17fa850 100644 --- a/src/cmd/internal/obj/sym.go +++ b/src/cmd/internal/obj/sym.go @@ -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) diff --git a/src/cmd/trace/trace.go b/src/cmd/trace/trace.go index 7178287751..d69c5feebc 100644 --- a/src/cmd/trace/trace.go +++ b/src/cmd/trace/trace.go @@ -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 }