Skip to content

cmd/compile: incorrect/confusing pkg prefix on unexported fields of anonymous struct #70963

Open
@ajwerner

Description

@ajwerner

Go version

go 1.23

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/ajwerner/.cache/go-build'
GOENV='/home/ajwerner/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/ajwerner/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/ajwerner/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/ajwerner/sdk/go1.23.2'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/ajwerner/sdk/go1.23.2/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.2'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/ajwerner/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/ajwerner/src/github.com/DataExMachina-dev/side-eye/play/go.mod'
GOWORK='off'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1402138110=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I observed that in DWARF, anonymous struct type names carry unexported field names with package path prefixes. See the below program:

https://go.dev/play/p/96lCdrfHAh3

The type is:

struct { baz int32; Qux int }

But in DWARF, the type is:

struct { play.ground/foo.baz int32; Qux int }

What did you see happen?

In dwarf, the fields in anonymous struct have a package path prefix.

What did you expect to see?

I expected in dwarf for the type to have the same name as it has in pclntab and upon runtime reflection. Maybe there's a good reason for this, but it's not obvious what that might be.

This has caused confusion for users of delve (go-delve/delve#1521).

Metadata

Metadata

Assignees

No one assigned

    Labels

    DebuggingNeedsInvestigationSomeone 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

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions