Commit 918b98ca authored by Russ Cox's avatar Russ Cox

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 <rsc@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent da21113b
...@@ -34,6 +34,7 @@ package obj ...@@ -34,6 +34,7 @@ package obj
import ( import (
"cmd/internal/objabi" "cmd/internal/objabi"
"fmt" "fmt"
"log"
"math" "math"
) )
...@@ -44,7 +45,9 @@ func Linknew(arch *LinkArch) *Link { ...@@ -44,7 +45,9 @@ func Linknew(arch *LinkArch) *Link {
ctxt.Arch = arch ctxt.Arch = arch
ctxt.Pathname = objabi.WorkingDir() 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.Flag_optimize = true
ctxt.Framepointer_enabled = objabi.Framepointer_enabled(objabi.GOOS, arch.Name) ctxt.Framepointer_enabled = objabi.Framepointer_enabled(objabi.GOOS, arch.Name)
......
...@@ -278,7 +278,7 @@ type traceContext struct { ...@@ -278,7 +278,7 @@ type traceContext struct {
heapStats, prevHeapStats heapStats heapStats, prevHeapStats heapStats
threadStats, prevThreadStats threadStats threadStats, prevThreadStats threadStats
gstates, prevGstates [gStateCount]uint64 gstates, prevGstates [gStateCount]int64
} }
type heapStats struct { type heapStats struct {
...@@ -449,6 +449,9 @@ func generateTrace(params *traceParams) (ViewerData, error) { ...@@ -449,6 +449,9 @@ func generateTrace(params *traceParams) (ViewerData, error) {
if setGStateErr != nil { if setGStateErr != nil {
return ctx.data, setGStateErr 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 // Ignore events that are from uninteresting goroutines
// or outside of the interesting timeframe. // or outside of the interesting timeframe.
...@@ -644,7 +647,7 @@ func (ctx *traceContext) emitGoroutineCounters(ev *trace.Event) { ...@@ -644,7 +647,7 @@ func (ctx *traceContext) emitGoroutineCounters(ev *trace.Event) {
if ctx.prevGstates == ctx.gstates { if ctx.prevGstates == ctx.gstates {
return 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 ctx.prevGstates = ctx.gstates
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment