modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/issue7690.go (about) 1 // run 2 3 // Copyright 2014 The Go Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file. 6 7 // issue 7690 - Stack and other routines did not back up initial PC 8 // into CALL instruction, instead reporting line number of next instruction, 9 // which might be on a different line. 10 11 package main 12 13 import ( 14 "bytes" 15 "regexp" 16 "runtime" 17 "strconv" 18 ) 19 20 func main() { 21 buf1 := make([]byte, 1000) 22 buf2 := make([]byte, 1000) 23 24 runtime.Stack(buf1, false) // CALL is last instruction on this line 25 n := runtime.Stack(buf2, false) // CALL is followed by load of result from stack 26 27 buf1 = buf1[:bytes.IndexByte(buf1, 0)] 28 buf2 = buf2[:n] 29 30 re := regexp.MustCompile(`(?m)^main\.main\(\)\n.*/issue7690.go:([0-9]+)`) 31 m1 := re.FindStringSubmatch(string(buf1)) 32 if m1 == nil { 33 println("BUG: cannot find main.main in first trace") 34 return 35 } 36 m2 := re.FindStringSubmatch(string(buf2)) 37 if m2 == nil { 38 println("BUG: cannot find main.main in second trace") 39 return 40 } 41 42 n1, _ := strconv.Atoi(m1[1]) 43 n2, _ := strconv.Atoi(m2[1]) 44 if n1+1 != n2 { 45 println("BUG: expect runtime.Stack on back to back lines, have", n1, n2) 46 println(string(buf1)) 47 println(string(buf2)) 48 } 49 }