github.com/nikandfor/loc@v0.5.1/print_stack_test.go (about) 1 package loc 2 3 import ( 4 "runtime" 5 "testing" 6 ) 7 8 func TestPrintStack(t *testing.T) { 9 inline3var = inline3 10 11 func() { 12 inline2(t) 13 }() 14 } 15 16 var inline3var func(*testing.T) 17 18 func inline2(t *testing.T) { 19 inline3var(t) 20 } 21 22 func inline3(t *testing.T) { 23 defer func() { //nolint:gocritic 24 var pcsbuf [6]PC 25 26 pcs := CallersFill(0, pcsbuf[:]) 27 28 for _, pc := range pcs { 29 n, f, l := pc.NameFileLine() 30 31 t.Logf("location %x %v %v %v", uintptr(pc), n, f, l) 32 } 33 34 var fpcs [6]uintptr 35 n := runtime.Callers(1, fpcs[:]) 36 37 fr := runtime.CallersFrames(fpcs[:n]) 38 39 for { 40 f, more := fr.Next() 41 42 t.Logf("runtime %x %v %v %v", f.PC, f.Function, f.File, f.Line) 43 44 if !more { 45 break 46 } 47 } 48 }() 49 }