Source file
src/runtime/symtabinl_test.go
1
2
3
4
5 package runtime
6
7 import (
8 "internal/abi"
9 "internal/stringslite"
10 "runtime/internal/sys"
11 )
12
13 func XTestInlineUnwinder(t TestingT) {
14 if TestenvOptimizationOff() {
15 t.Skip("skipping test with inlining optimizations disabled")
16 }
17
18 pc1 := abi.FuncPCABIInternal(tiuTest)
19 f := findfunc(pc1)
20 if !f.valid() {
21 t.Fatalf("failed to resolve tiuTest at PC %#x", pc1)
22 }
23
24 want := map[string]int{
25 "tiuInlined1:3 tiuTest:10": 0,
26 "tiuInlined1:3 tiuInlined2:6 tiuTest:11": 0,
27 "tiuInlined2:7 tiuTest:11": 0,
28 "tiuTest:12": 0,
29 }
30 wantStart := map[string]int{
31 "tiuInlined1": 2,
32 "tiuInlined2": 5,
33 "tiuTest": 9,
34 }
35
36
37 prevStack := "x"
38 for pc := pc1; pc < pc1+1024 && findfunc(pc) == f; pc += sys.PCQuantum {
39 stack := ""
40 u, uf := newInlineUnwinder(f, pc)
41 if file, _ := u.fileLine(uf); file == "?" {
42
43
44
45
46
47
48
49 continue
50 }
51 for ; uf.valid(); uf = u.next(uf) {
52 file, line := u.fileLine(uf)
53 const wantFile = "symtabinl_test.go"
54 if !stringslite.HasSuffix(file, wantFile) {
55 t.Errorf("tiuTest+%#x: want file ...%s, got %s", pc-pc1, wantFile, file)
56 }
57
58 sf := u.srcFunc(uf)
59
60 name := sf.name()
61 const namePrefix = "runtime."
62 if stringslite.HasPrefix(name, namePrefix) {
63 name = name[len(namePrefix):]
64 }
65 if !stringslite.HasPrefix(name, "tiu") {
66 t.Errorf("tiuTest+%#x: unexpected function %s", pc-pc1, name)
67 }
68
69 start := int(sf.startLine) - tiuStart
70 if start != wantStart[name] {
71 t.Errorf("tiuTest+%#x: want startLine %d, got %d", pc-pc1, wantStart[name], start)
72 }
73 if sf.funcID != abi.FuncIDNormal {
74 t.Errorf("tiuTest+%#x: bad funcID %v", pc-pc1, sf.funcID)
75 }
76
77 if len(stack) > 0 {
78 stack += " "
79 }
80 stack += FmtSprintf("%s:%d", name, line-tiuStart)
81 }
82
83 if stack != prevStack {
84 prevStack = stack
85
86 t.Logf("tiuTest+%#x: %s", pc-pc1, stack)
87
88 if _, ok := want[stack]; ok {
89 want[stack]++
90 }
91 }
92 }
93
94
95 for stack, count := range want {
96 if count == 0 {
97 t.Errorf("missing stack %s", stack)
98 }
99 }
100 }
101
102 func lineNumber() int {
103 _, _, line, _ := Caller(1)
104 return line
105 }
106
107
108
109 var tiuStart = lineNumber()
110 var tiu1, tiu2, tiu3 int
111 func tiuInlined1() {
112 tiu1++
113 }
114 func tiuInlined2() {
115 tiuInlined1()
116 tiu2++
117 }
118 func tiuTest() {
119 tiuInlined1()
120 tiuInlined2()
121 tiu3++
122 }
123
View as plain text