You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What steps will reproduce the problem?
package gospec
import (
"testing"
"runtime"
"fmt"
)
func TestLineNumbersOfFuncFileLine(t *testing.T) {
defer func() {
if cause := recover(); cause != nil {
callers := make([]uintptr, 100)
count := runtime.Callers(0, callers)
callers = callers[0:count]
for _, pc := range callers {
f := runtime.FuncForPC(pc)
name := f.Name()
file, line := f.FileLine(pc)
fmt.Printf("%v %v:%v\n", name, file, line)
}
}
}()
var x *Foo = nil
x.Fail()
}
func TestLineNumbersOfPanic(t *testing.T) {
var x *Foo = nil
x.Fail()
}
type Foo struct {
x string
}
func (this *Foo) Fail() string {
return this.x
}
What is the expected output?
The line number of sigpanic in file runtime/linux/thread.c should be 286 in both stack
traces.
What do you see instead?
panicstring /home/orfjackal/go/src/pkg/runtime/runtime.c:83
sigpanic /home/orfjackal/go/src/pkg/runtime/linux/thread.c:287
gospec.*Foo·Fail /home/orfjackal/devel/gospec/src/gospec/bug_test.go:42
...
panicstring+0x69 /home/orfjackal/go/src/pkg/runtime/runtime.c:83
panicstring(0x48ded8, 0x2b207ce90850)
sigpanic+0x148 /home/orfjackal/go/src/pkg/runtime/linux/thread.c:286
sigpanic()
gospec.*Foo·Fail+0x18 /home/orfjackal/devel/gospec/src/gospec/bug_test.go:42
gospec.*Foo·Fail(0x4166e1, 0x0, 0x2b207ce8bcf0, 0x2b207ce8bcf0)
What is your $GOOS? $GOARCH?
linux amd64
(BTW, is there a simple way to get $GOOS and $GOARCH now that they are optional since
release.2010-08-25?)
Which revision are you using? (hg identify)
97ccc7fb2173 tip
Please provide any additional information below.
This might be related to https://golang.org/issue/754
The text was updated successfully, but these errors were encountered:
> (BTW, is there a simple way to get $GOOS and $GOARCH now that they are optional since
release.2010-08-25?)
Thanks. I changed the questions to ask for the compiler name and operating system.
Thanks for these reports. It would help if you could send programs
that use package main and define a main function, so they are easier to run.
This is actually working as intended. It's a subtle thing,
but runtime.Callers returns the return PCs going up the
stack. The return PCs are the PCs of the instruction that
the call returns to, not the call itself. The code that formats
the traceback for a crash subtracts 1 from each PC before
translating it to a line number. The equivalent change
in your code would be to call f.FileLine(pc - 1).
runtime.Callers could lie and do the subtraction, but
this is pretty subtle already and I think it's clearer for
all involved to hand out the raw data and let clients
adjust. Otherwise the clients who want the return PCs
have to add 1, and then if that changes they're all broken,
and so on and so on.
by esko.luontola:
The text was updated successfully, but these errors were encountered: