mirror of
https://github.com/golang/go
synced 2024-11-17 13:14:56 -07:00
cmd/compile/internal/ssagen,runtime: merge trace consts into internal/abi
For #59670
Change-Id: Iec85ee7312bb566b3f1224424f7d27bf4e408b13
GitHub-Last-Rev: c620abf967
GitHub-Pull-Request: golang/go#64905
Reviewed-on: https://go-review.googlesource.com/c/go/+/553295
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
99e12bee44
commit
7611d2e610
@ -7095,48 +7095,14 @@ func EmitArgInfo(f *ir.Func, abiInfo *abi.ABIParamResultInfo) *obj.LSym {
|
|||||||
return t.IsStruct() || t.IsArray() || t.IsComplex() || t.IsInterface() || t.IsString() || t.IsSlice()
|
return t.IsStruct() || t.IsArray() || t.IsComplex() || t.IsInterface() || t.IsString() || t.IsSlice()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate the data.
|
|
||||||
// The data is a stream of bytes, which contains the offsets and sizes of the
|
|
||||||
// non-aggregate arguments or non-aggregate fields/elements of aggregate-typed
|
|
||||||
// arguments, along with special "operators". Specifically,
|
|
||||||
// - for each non-aggrgate arg/field/element, its offset from FP (1 byte) and
|
|
||||||
// size (1 byte)
|
|
||||||
// - special operators:
|
|
||||||
// - 0xff - end of sequence
|
|
||||||
// - 0xfe - print { (at the start of an aggregate-typed argument)
|
|
||||||
// - 0xfd - print } (at the end of an aggregate-typed argument)
|
|
||||||
// - 0xfc - print ... (more args/fields/elements)
|
|
||||||
// - 0xfb - print _ (offset too large)
|
|
||||||
// These constants need to be in sync with runtime.traceback.go:printArgs.
|
|
||||||
const (
|
|
||||||
_endSeq = 0xff
|
|
||||||
_startAgg = 0xfe
|
|
||||||
_endAgg = 0xfd
|
|
||||||
_dotdotdot = 0xfc
|
|
||||||
_offsetTooLarge = 0xfb
|
|
||||||
_special = 0xf0 // above this are operators, below this are ordinary offsets
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
limit = 10 // print no more than 10 args/components
|
|
||||||
maxDepth = 5 // no more than 5 layers of nesting
|
|
||||||
|
|
||||||
// maxLen is a (conservative) upper bound of the byte stream length. For
|
|
||||||
// each arg/component, it has no more than 2 bytes of data (size, offset),
|
|
||||||
// and no more than one {, }, ... at each level (it cannot have both the
|
|
||||||
// data and ... unless it is the last one, just be conservative). Plus 1
|
|
||||||
// for _endSeq.
|
|
||||||
maxLen = (maxDepth*3+2)*limit + 1
|
|
||||||
)
|
|
||||||
|
|
||||||
wOff := 0
|
wOff := 0
|
||||||
n := 0
|
n := 0
|
||||||
writebyte := func(o uint8) { wOff = objw.Uint8(x, wOff, o) }
|
writebyte := func(o uint8) { wOff = objw.Uint8(x, wOff, o) }
|
||||||
|
|
||||||
// Write one non-aggregate arg/field/element.
|
// Write one non-aggregate arg/field/element.
|
||||||
write1 := func(sz, offset int64) {
|
write1 := func(sz, offset int64) {
|
||||||
if offset >= _special {
|
if offset >= rtabi.TraceArgsSpecial {
|
||||||
writebyte(_offsetTooLarge)
|
writebyte(rtabi.TraceArgsOffsetTooLarge)
|
||||||
} else {
|
} else {
|
||||||
writebyte(uint8(offset))
|
writebyte(uint8(offset))
|
||||||
writebyte(uint8(sz))
|
writebyte(uint8(sz))
|
||||||
@ -7148,19 +7114,19 @@ func EmitArgInfo(f *ir.Func, abiInfo *abi.ABIParamResultInfo) *obj.LSym {
|
|||||||
// Returns whether to continue visiting.
|
// Returns whether to continue visiting.
|
||||||
var visitType func(baseOffset int64, t *types.Type, depth int) bool
|
var visitType func(baseOffset int64, t *types.Type, depth int) bool
|
||||||
visitType = func(baseOffset int64, t *types.Type, depth int) bool {
|
visitType = func(baseOffset int64, t *types.Type, depth int) bool {
|
||||||
if n >= limit {
|
if n >= rtabi.TraceArgsLimit {
|
||||||
writebyte(_dotdotdot)
|
writebyte(rtabi.TraceArgsDotdotdot)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if !isAggregate(t) {
|
if !isAggregate(t) {
|
||||||
write1(t.Size(), baseOffset)
|
write1(t.Size(), baseOffset)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
writebyte(_startAgg)
|
writebyte(rtabi.TraceArgsStartAgg)
|
||||||
depth++
|
depth++
|
||||||
if depth >= maxDepth {
|
if depth >= rtabi.TraceArgsMaxDepth {
|
||||||
writebyte(_dotdotdot)
|
writebyte(rtabi.TraceArgsDotdotdot)
|
||||||
writebyte(_endAgg)
|
writebyte(rtabi.TraceArgsEndAgg)
|
||||||
n++
|
n++
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -7197,7 +7163,7 @@ func EmitArgInfo(f *ir.Func, abiInfo *abi.ABIParamResultInfo) *obj.LSym {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writebyte(_endAgg)
|
writebyte(rtabi.TraceArgsEndAgg)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7212,8 +7178,8 @@ func EmitArgInfo(f *ir.Func, abiInfo *abi.ABIParamResultInfo) *obj.LSym {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writebyte(_endSeq)
|
writebyte(rtabi.TraceArgsEndSeq)
|
||||||
if wOff > maxLen {
|
if wOff > rtabi.TraceArgsMaxLen {
|
||||||
base.Fatalf("ArgInfo too large")
|
base.Fatalf("ArgInfo too large")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -716,3 +716,36 @@ func NewName(n, tag string, exported, embedded bool) Name {
|
|||||||
|
|
||||||
return Name{Bytes: &b[0]}
|
return Name{Bytes: &b[0]}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
TraceArgsLimit = 10 // print no more than 10 args/components
|
||||||
|
TraceArgsMaxDepth = 5 // no more than 5 layers of nesting
|
||||||
|
|
||||||
|
// maxLen is a (conservative) upper bound of the byte stream length. For
|
||||||
|
// each arg/component, it has no more than 2 bytes of data (size, offset),
|
||||||
|
// and no more than one {, }, ... at each level (it cannot have both the
|
||||||
|
// data and ... unless it is the last one, just be conservative). Plus 1
|
||||||
|
// for _endSeq.
|
||||||
|
TraceArgsMaxLen = (TraceArgsMaxDepth*3+2)*TraceArgsLimit + 1
|
||||||
|
)
|
||||||
|
|
||||||
|
// Populate the data.
|
||||||
|
// The data is a stream of bytes, which contains the offsets and sizes of the
|
||||||
|
// non-aggregate arguments or non-aggregate fields/elements of aggregate-typed
|
||||||
|
// arguments, along with special "operators". Specifically,
|
||||||
|
// - for each non-aggrgate arg/field/element, its offset from FP (1 byte) and
|
||||||
|
// size (1 byte)
|
||||||
|
// - special operators:
|
||||||
|
// - 0xff - end of sequence
|
||||||
|
// - 0xfe - print { (at the start of an aggregate-typed argument)
|
||||||
|
// - 0xfd - print } (at the end of an aggregate-typed argument)
|
||||||
|
// - 0xfc - print ... (more args/fields/elements)
|
||||||
|
// - 0xfb - print _ (offset too large)
|
||||||
|
const (
|
||||||
|
TraceArgsEndSeq = 0xff
|
||||||
|
TraceArgsStartAgg = 0xfe
|
||||||
|
TraceArgsEndAgg = 0xfd
|
||||||
|
TraceArgsDotdotdot = 0xfc
|
||||||
|
TraceArgsOffsetTooLarge = 0xfb
|
||||||
|
TraceArgsSpecial = 0xf0 // above this are operators, below this are ordinary offsets
|
||||||
|
)
|
||||||
|
@ -650,25 +650,7 @@ func tracebackPCs(u *unwinder, skip int, pcBuf []uintptr) int {
|
|||||||
|
|
||||||
// printArgs prints function arguments in traceback.
|
// printArgs prints function arguments in traceback.
|
||||||
func printArgs(f funcInfo, argp unsafe.Pointer, pc uintptr) {
|
func printArgs(f funcInfo, argp unsafe.Pointer, pc uintptr) {
|
||||||
// The "instruction" of argument printing is encoded in _FUNCDATA_ArgInfo.
|
p := (*[abi.TraceArgsMaxLen]uint8)(funcdata(f, abi.FUNCDATA_ArgInfo))
|
||||||
// See cmd/compile/internal/ssagen.emitArgInfo for the description of the
|
|
||||||
// encoding.
|
|
||||||
// These constants need to be in sync with the compiler.
|
|
||||||
const (
|
|
||||||
_endSeq = 0xff
|
|
||||||
_startAgg = 0xfe
|
|
||||||
_endAgg = 0xfd
|
|
||||||
_dotdotdot = 0xfc
|
|
||||||
_offsetTooLarge = 0xfb
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
limit = 10 // print no more than 10 args/components
|
|
||||||
maxDepth = 5 // no more than 5 layers of nesting
|
|
||||||
maxLen = (maxDepth*3+2)*limit + 1 // max length of _FUNCDATA_ArgInfo (see the compiler side for reasoning)
|
|
||||||
)
|
|
||||||
|
|
||||||
p := (*[maxLen]uint8)(funcdata(f, abi.FUNCDATA_ArgInfo))
|
|
||||||
if p == nil {
|
if p == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -721,19 +703,19 @@ printloop:
|
|||||||
o := p[pi]
|
o := p[pi]
|
||||||
pi++
|
pi++
|
||||||
switch o {
|
switch o {
|
||||||
case _endSeq:
|
case abi.TraceArgsEndSeq:
|
||||||
break printloop
|
break printloop
|
||||||
case _startAgg:
|
case abi.TraceArgsStartAgg:
|
||||||
printcomma()
|
printcomma()
|
||||||
print("{")
|
print("{")
|
||||||
start = true
|
start = true
|
||||||
continue
|
continue
|
||||||
case _endAgg:
|
case abi.TraceArgsEndAgg:
|
||||||
print("}")
|
print("}")
|
||||||
case _dotdotdot:
|
case abi.TraceArgsDotdotdot:
|
||||||
printcomma()
|
printcomma()
|
||||||
print("...")
|
print("...")
|
||||||
case _offsetTooLarge:
|
case abi.TraceArgsOffsetTooLarge:
|
||||||
printcomma()
|
printcomma()
|
||||||
print("_")
|
print("_")
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user