Skip to content

Commit 7611d2e

Browse files
qiulaidongfengrandall77
authored andcommitted
cmd/compile/internal/ssagen,runtime: merge trace consts into internal/abi
For #59670 Change-Id: Iec85ee7312bb566b3f1224424f7d27bf4e408b13 GitHub-Last-Rev: c620abf GitHub-Pull-Request: #64905 Reviewed-on: https://go-review.googlesource.com/c/go/+/553295 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 99e12be commit 7611d2e

File tree

3 files changed

+50
-69
lines changed

3 files changed

+50
-69
lines changed

src/cmd/compile/internal/ssagen/ssa.go

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7095,48 +7095,14 @@ func EmitArgInfo(f *ir.Func, abiInfo *abi.ABIParamResultInfo) *obj.LSym {
70957095
return t.IsStruct() || t.IsArray() || t.IsComplex() || t.IsInterface() || t.IsString() || t.IsSlice()
70967096
}
70977097

7098-
// Populate the data.
7099-
// The data is a stream of bytes, which contains the offsets and sizes of the
7100-
// non-aggregate arguments or non-aggregate fields/elements of aggregate-typed
7101-
// arguments, along with special "operators". Specifically,
7102-
// - for each non-aggrgate arg/field/element, its offset from FP (1 byte) and
7103-
// size (1 byte)
7104-
// - special operators:
7105-
// - 0xff - end of sequence
7106-
// - 0xfe - print { (at the start of an aggregate-typed argument)
7107-
// - 0xfd - print } (at the end of an aggregate-typed argument)
7108-
// - 0xfc - print ... (more args/fields/elements)
7109-
// - 0xfb - print _ (offset too large)
7110-
// These constants need to be in sync with runtime.traceback.go:printArgs.
7111-
const (
7112-
_endSeq = 0xff
7113-
_startAgg = 0xfe
7114-
_endAgg = 0xfd
7115-
_dotdotdot = 0xfc
7116-
_offsetTooLarge = 0xfb
7117-
_special = 0xf0 // above this are operators, below this are ordinary offsets
7118-
)
7119-
7120-
const (
7121-
limit = 10 // print no more than 10 args/components
7122-
maxDepth = 5 // no more than 5 layers of nesting
7123-
7124-
// maxLen is a (conservative) upper bound of the byte stream length. For
7125-
// each arg/component, it has no more than 2 bytes of data (size, offset),
7126-
// and no more than one {, }, ... at each level (it cannot have both the
7127-
// data and ... unless it is the last one, just be conservative). Plus 1
7128-
// for _endSeq.
7129-
maxLen = (maxDepth*3+2)*limit + 1
7130-
)
7131-
71327098
wOff := 0
71337099
n := 0
71347100
writebyte := func(o uint8) { wOff = objw.Uint8(x, wOff, o) }
71357101

71367102
// Write one non-aggregate arg/field/element.
71377103
write1 := func(sz, offset int64) {
7138-
if offset >= _special {
7139-
writebyte(_offsetTooLarge)
7104+
if offset >= rtabi.TraceArgsSpecial {
7105+
writebyte(rtabi.TraceArgsOffsetTooLarge)
71407106
} else {
71417107
writebyte(uint8(offset))
71427108
writebyte(uint8(sz))
@@ -7148,19 +7114,19 @@ func EmitArgInfo(f *ir.Func, abiInfo *abi.ABIParamResultInfo) *obj.LSym {
71487114
// Returns whether to continue visiting.
71497115
var visitType func(baseOffset int64, t *types.Type, depth int) bool
71507116
visitType = func(baseOffset int64, t *types.Type, depth int) bool {
7151-
if n >= limit {
7152-
writebyte(_dotdotdot)
7117+
if n >= rtabi.TraceArgsLimit {
7118+
writebyte(rtabi.TraceArgsDotdotdot)
71537119
return false
71547120
}
71557121
if !isAggregate(t) {
71567122
write1(t.Size(), baseOffset)
71577123
return true
71587124
}
7159-
writebyte(_startAgg)
7125+
writebyte(rtabi.TraceArgsStartAgg)
71607126
depth++
7161-
if depth >= maxDepth {
7162-
writebyte(_dotdotdot)
7163-
writebyte(_endAgg)
7127+
if depth >= rtabi.TraceArgsMaxDepth {
7128+
writebyte(rtabi.TraceArgsDotdotdot)
7129+
writebyte(rtabi.TraceArgsEndAgg)
71647130
n++
71657131
return true
71667132
}
@@ -7197,7 +7163,7 @@ func EmitArgInfo(f *ir.Func, abiInfo *abi.ABIParamResultInfo) *obj.LSym {
71977163
}
71987164
}
71997165
}
7200-
writebyte(_endAgg)
7166+
writebyte(rtabi.TraceArgsEndAgg)
72017167
return true
72027168
}
72037169

@@ -7212,8 +7178,8 @@ func EmitArgInfo(f *ir.Func, abiInfo *abi.ABIParamResultInfo) *obj.LSym {
72127178
break
72137179
}
72147180
}
7215-
writebyte(_endSeq)
7216-
if wOff > maxLen {
7181+
writebyte(rtabi.TraceArgsEndSeq)
7182+
if wOff > rtabi.TraceArgsMaxLen {
72177183
base.Fatalf("ArgInfo too large")
72187184
}
72197185

src/internal/abi/type.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,3 +716,36 @@ func NewName(n, tag string, exported, embedded bool) Name {
716716

717717
return Name{Bytes: &b[0]}
718718
}
719+
720+
const (
721+
TraceArgsLimit = 10 // print no more than 10 args/components
722+
TraceArgsMaxDepth = 5 // no more than 5 layers of nesting
723+
724+
// maxLen is a (conservative) upper bound of the byte stream length. For
725+
// each arg/component, it has no more than 2 bytes of data (size, offset),
726+
// and no more than one {, }, ... at each level (it cannot have both the
727+
// data and ... unless it is the last one, just be conservative). Plus 1
728+
// for _endSeq.
729+
TraceArgsMaxLen = (TraceArgsMaxDepth*3+2)*TraceArgsLimit + 1
730+
)
731+
732+
// Populate the data.
733+
// The data is a stream of bytes, which contains the offsets and sizes of the
734+
// non-aggregate arguments or non-aggregate fields/elements of aggregate-typed
735+
// arguments, along with special "operators". Specifically,
736+
// - for each non-aggrgate arg/field/element, its offset from FP (1 byte) and
737+
// size (1 byte)
738+
// - special operators:
739+
// - 0xff - end of sequence
740+
// - 0xfe - print { (at the start of an aggregate-typed argument)
741+
// - 0xfd - print } (at the end of an aggregate-typed argument)
742+
// - 0xfc - print ... (more args/fields/elements)
743+
// - 0xfb - print _ (offset too large)
744+
const (
745+
TraceArgsEndSeq = 0xff
746+
TraceArgsStartAgg = 0xfe
747+
TraceArgsEndAgg = 0xfd
748+
TraceArgsDotdotdot = 0xfc
749+
TraceArgsOffsetTooLarge = 0xfb
750+
TraceArgsSpecial = 0xf0 // above this are operators, below this are ordinary offsets
751+
)

src/runtime/traceback.go

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -650,25 +650,7 @@ func tracebackPCs(u *unwinder, skip int, pcBuf []uintptr) int {
650650

651651
// printArgs prints function arguments in traceback.
652652
func printArgs(f funcInfo, argp unsafe.Pointer, pc uintptr) {
653-
// The "instruction" of argument printing is encoded in _FUNCDATA_ArgInfo.
654-
// See cmd/compile/internal/ssagen.emitArgInfo for the description of the
655-
// encoding.
656-
// These constants need to be in sync with the compiler.
657-
const (
658-
_endSeq = 0xff
659-
_startAgg = 0xfe
660-
_endAgg = 0xfd
661-
_dotdotdot = 0xfc
662-
_offsetTooLarge = 0xfb
663-
)
664-
665-
const (
666-
limit = 10 // print no more than 10 args/components
667-
maxDepth = 5 // no more than 5 layers of nesting
668-
maxLen = (maxDepth*3+2)*limit + 1 // max length of _FUNCDATA_ArgInfo (see the compiler side for reasoning)
669-
)
670-
671-
p := (*[maxLen]uint8)(funcdata(f, abi.FUNCDATA_ArgInfo))
653+
p := (*[abi.TraceArgsMaxLen]uint8)(funcdata(f, abi.FUNCDATA_ArgInfo))
672654
if p == nil {
673655
return
674656
}
@@ -721,19 +703,19 @@ printloop:
721703
o := p[pi]
722704
pi++
723705
switch o {
724-
case _endSeq:
706+
case abi.TraceArgsEndSeq:
725707
break printloop
726-
case _startAgg:
708+
case abi.TraceArgsStartAgg:
727709
printcomma()
728710
print("{")
729711
start = true
730712
continue
731-
case _endAgg:
713+
case abi.TraceArgsEndAgg:
732714
print("}")
733-
case _dotdotdot:
715+
case abi.TraceArgsDotdotdot:
734716
printcomma()
735717
print("...")
736-
case _offsetTooLarge:
718+
case abi.TraceArgsOffsetTooLarge:
737719
printcomma()
738720
print("_")
739721
default:

0 commit comments

Comments
 (0)