| 1 |
// Copyright 2017 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package main |
| 6 |
|
| 7 |
import ( |
| 8 |
"fmt" |
| 9 |
"time" |
| 10 |
) |
| 11 |
|
| 12 |
func main() { |
| 13 |
growstack() // Use stack early to prevent growth during test, which confuses gdb |
| 14 |
test() |
| 15 |
} |
| 16 |
|
| 17 |
//go:noinline |
| 18 |
func id(x int) int { |
| 19 |
return x |
| 20 |
} |
| 21 |
|
| 22 |
func test() { |
| 23 |
x := id(0) |
| 24 |
y := id(0) |
| 25 |
fmt.Println(x) |
| 26 |
for i := x; i < 3; i++ { |
| 27 |
x := i * i |
| 28 |
y += id(x) //gdb-dbg=(x,y)//gdb-opt=(x,y) |
| 29 |
} |
| 30 |
y = x + y //gdb-dbg=(x,y)//gdb-opt=(x,y) |
| 31 |
fmt.Println(x, y) |
| 32 |
|
| 33 |
for x := 0; x <= 1; x++ { // From delve scopetest.go |
| 34 |
a := y |
| 35 |
f1(a) |
| 36 |
{ |
| 37 |
b := 0 |
| 38 |
f2(b) |
| 39 |
if gretbool() { |
| 40 |
c := 0 |
| 41 |
f3(c) |
| 42 |
} else { |
| 43 |
c := 1.1 |
| 44 |
f4(int(c)) |
| 45 |
} |
| 46 |
f5(b) |
| 47 |
} |
| 48 |
f6(a) |
| 49 |
} |
| 50 |
|
| 51 |
{ // From delve testnextprog.go |
| 52 |
var ( |
| 53 |
j = id(1) |
| 54 |
f = id(2) |
| 55 |
) |
| 56 |
for i := 0; i <= 5; i++ { |
| 57 |
j += j * (j ^ 3) / 100 |
| 58 |
if i == f { |
| 59 |
fmt.Println("foo") |
| 60 |
break |
| 61 |
} |
| 62 |
sleepytime() |
| 63 |
} |
| 64 |
helloworld() |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
func sleepytime() { |
| 69 |
time.Sleep(5 * time.Millisecond) |
| 70 |
} |
| 71 |
|
| 72 |
func helloworld() { |
| 73 |
fmt.Println("Hello, World!") |
| 74 |
} |
| 75 |
|
| 76 |
//go:noinline |
| 77 |
func f1(x int) {} |
| 78 |
|
| 79 |
//go:noinline |
| 80 |
func f2(x int) {} |
| 81 |
|
| 82 |
//go:noinline |
| 83 |
func f3(x int) {} |
| 84 |
|
| 85 |
//go:noinline |
| 86 |
func f4(x int) {} |
| 87 |
|
| 88 |
//go:noinline |
| 89 |
func f5(x int) {} |
| 90 |
|
| 91 |
//go:noinline |
| 92 |
func f6(x int) {} |
| 93 |
|
| 94 |
var boolvar = true |
| 95 |
|
| 96 |
func gretbool() bool { |
| 97 |
x := boolvar |
| 98 |
boolvar = !boolvar |
| 99 |
return x |
| 100 |
} |
| 101 |
|
| 102 |
var sink string |
| 103 |
|
| 104 |
//go:noinline |
| 105 |
func growstack() { |
| 106 |
sink = fmt.Sprintf("%#v,%#v,%#v", 1, true, "cat") |
| 107 |
} |