Skip to content

x/tools/gopls: invalid memory address or nil pointer dereference in IdentifierInfo.Hover #44326

@pohly

Description

@pohly

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

$ go version
go version go1.15.7 linux/amd64
$ gopls version
golang.org/x/tools/gopls v0.6.5
    golang.org/x/tools/gopls@v0.6.5 h1:kLt9rD/dWtVdvc8LmdcxagDFih6zxYXREpKSYYZu5KE=

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="/home/pohly/.cache/go-build"
GOENV="/home/pohly/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/nvme/gopath/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/nvme/gopath"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/nvme/gopath/go-1.15.7"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/nvme/gopath/go-1.15.7/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build348293716=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I configured emacs to use gopls in lsp-mode, with gopls running remote through tramp. I opened one Go source file and started moving the cursor through it.

More specifically, the source code location where it crashed was one of these lines:
https://github.com/intel/pmem-csi/blob/a4218ed04b213c5604a0a65f796438b45db39992/pkg/pmem-csi-driver/main.go#L32-L59

Stepping through it line-by-line triggers it reliably.

What did you expect to see?

No errors.

What did you see instead?

Emacs reports: Server gopls-remote:19535 exited with status exit(check corresponding stderr buffer for details). Do you want to restart it? (y or n)

From /tmp/gopls-remote-5-stderr (stderr of gopls when invoked through emacs/tramp):

...
[Trace - 10:50:45 AM] Sending request 'textDocument/hover - (63)'.
Params: {"textDocument":{"uri":"file:///nvme/gopath/src/github.com/intel/pmem-csi/pkg/pmem-csi-driver/main.go"},"position":{"line":40,"character":0}}

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x6bfee6]

goroutine 18 [running]:
golang.org/x/tools/internal/lsp/source.(*IdentifierInfo).Hover(0x0, 0x0, 0x85d800, 0xc0001fe090, 0x85e700, 0xc0001be0a0)
        golang.org/x/tools/internal/lsp/source/definition.go:50 +0x76
golang.org/x/tools/internal/lsp.(*server).Hover(0xc00012a600, 0x85e380, 0xc023396600, 0xc023398c20, 0xc023398c20, 0x0, 0x0)
        golang.org/x/tools/internal/lsp/server.go:225 +0x182
golang.org/x/tools/internal/lsp/protocol.serverHandler.func1(0x85e380, 0xc023396600, 0xc0001babd0, 0xc023398be0)
        golang.org/x/tools/internal/lsp/protocol/server.go:211 +0xd62
golang.org/x/tools/internal/jsonrpc2.(*Conn).run(0xc0001babd0, 0x85e3c0, 0xc0000180b8, 0xc00007a7c8, 0x605b13)
        golang.org/x/tools/internal/jsonrpc2/jsonrpc2.go:327 +0x5c8
golang.org/x/tools/internal/jsonrpc2.NewConn.func4(0xc0001babd0, 0x85e3c0, 0xc0000180b8)
        golang.org/x/tools/internal/jsonrpc2/jsonrpc2.go:107 +0x3f
created by golang.org/x/tools/internal/jsonrpc2.NewConn
        golang.org/x/tools/internal/jsonrpc2/jsonrpc2.go:106 +0x187

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions