Skip to content

runtime: FuncForPC FileLine returns autogenerated instead of actual path #51774

@vearutop

Description

@vearutop

What version of Go are you using (go version)?

$ go version
go version go1.18 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/vearutop/Library/Caches/go-build"
GOENV="/Users/vearutop/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/vearutop/go/pkg/mod"
GONOPROXY="github.com/adjust,github.com/vearutop,github.com/Unbotify"
GONOSUMDB="github.com/adjust,github.com/vearutop,github.com/Unbotify"
GOOS="darwin"
GOPATH="/Users/vearutop/go"
GOPRIVATE="github.com/adjust,github.com/vearutop,github.com/Unbotify"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/vearutop/sdk/go1.18"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/vearutop/sdk/go1.18/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/vearutop/gohack/github.com/cucumber/godog/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/n7/jv2b0zv57jzc8y6zhmfzbn7c0000gn/T/go-build1890007164=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I was getting file and line of struct method.

https://go.dev/play/p/VFs8FKAkTLf

package main

import (
	"reflect"
	"runtime"
)

type s struct{}

func (tc *s) f() {}

func main() {
	tc := &s{}

	v := reflect.ValueOf(tc.f)
	ptr := v.Pointer()
	f := runtime.FuncForPC(ptr)
	file, line := f.FileLine(f.Entry())
	name := f.Name()

	println(file, line, name)
}

What did you expect to see?

.../main.go 10 main.(*s).f-fm

What did you see instead?

<autogenerated> 1 main.(*s).f-fm

The issue is reproducible with go1.18 and gotip, however go1.18rc1 and below (go1.17) works as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    Triage Backlog

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions