blob: c6b16bed7668fa85c19d8aa1bf60672175ba2ac3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
package xerrors
import (
"fmt"
"github.com/ydb-platform/ydb/library/go/core/xerrors/internal/modes"
"github.com/ydb-platform/ydb/library/go/x/xruntime"
)
func DefaultStackTraceMode() {
modes.DefaultStackTraceMode()
}
func EnableFrames() {
modes.SetStackTraceMode(modes.StackTraceModeFrames)
}
func EnableStacks() {
modes.SetStackTraceMode(modes.StackTraceModeStacks)
}
func EnableStackThenFrames() {
modes.SetStackTraceMode(modes.StackTraceModeStackThenFrames)
}
func EnableStackThenNothing() {
modes.SetStackTraceMode(modes.StackTraceModeStackThenNothing)
}
func DisableStackTraces() {
modes.SetStackTraceMode(modes.StackTraceModeNothing)
}
// newStackTrace returns stacktrace based on current mode and frames count
func newStackTrace(skip int, err error) *xruntime.StackTrace {
skip++
m := modes.GetStackTraceMode()
switch m {
case modes.StackTraceModeFrames:
return xruntime.NewFrame(skip)
case modes.StackTraceModeStackThenFrames:
if err != nil && StackTraceOfEffect(err) != nil {
return xruntime.NewFrame(skip)
}
return _newStackTrace(skip)
case modes.StackTraceModeStackThenNothing:
if err != nil && StackTraceOfEffect(err) != nil {
return nil
}
return _newStackTrace(skip)
case modes.StackTraceModeStacks:
return _newStackTrace(skip)
case modes.StackTraceModeNothing:
return nil
}
panic(fmt.Sprintf("unknown stack trace mode %d", m))
}
func MaxStackFrames16() {
modes.SetStackFramesCountMax(modes.StackFramesCount16)
}
func MaxStackFrames32() {
modes.SetStackFramesCountMax(modes.StackFramesCount32)
}
func MaxStackFrames64() {
modes.SetStackFramesCountMax(modes.StackFramesCount64)
}
func MaxStackFrames128() {
modes.SetStackFramesCountMax(modes.StackFramesCount128)
}
func _newStackTrace(skip int) *xruntime.StackTrace {
skip++
count := modes.GetStackFramesCountMax()
switch count {
case 16:
return xruntime.NewStackTrace16(skip)
case 32:
return xruntime.NewStackTrace32(skip)
case 64:
return xruntime.NewStackTrace64(skip)
case 128:
return xruntime.NewStackTrace128(skip)
}
panic(fmt.Sprintf("unknown stack frames count %d", count))
}
|