Vim-go: "could not connect to debugger" when running :GoDebugStart

Created on 28 Apr 2020  Â·  21Comments  Â·  Source: fatih/vim-go

What did you do? (required: The issue will be closed when not provided)


I installed vim-go from the master branch like so:

git clone https://github.com/fatih/vim-go.git ~/.vim/pack/plugins/start/vim-go

Then I ran :GoInstallBinaries, which exited successfully.

Then I ran :GoDebugStart or :GoDebugStart . to try and debug my go program.

What did you expect to happen?

I would be able to debug my go program.

What happened instead?

I get these messages:

vim-go: [debug] dispatched
vim-go: could not connect to debugger
vim-go: [debug] FAIL

All the other go commands (:GoDef, :GoDefPop, etc) appear to be working fine.
I can also debug my go program on the command line just fine with dlv debug.
But with vim-go it just won't connect and I'm not sure what the issue is.

Configuration (MUST fill this out):

vim-go version:

From master branch. I tried switching to the latest stable release (v1.22) but it didn't affect anything.
I also tried installing via Pathogen instead of the vim 8 packages (rm -rfed the old one), but that didn't change anything either.

vimrc you used to reproduce:



vimrc

set backspace=indent,eol,start
set expandtab
syntax on
set incsearch
filetype indent plugin on
"this was just from my second installation attempt
execute pathogen#infect()

Vim version (first three lines from :version):


VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Mar 4 2020 22:41:50)
macOS version
Included patches: 1-350

Go version (go version):


go version go1.14 darwin/amd64

Go environment

go env Output:


GO111MODULE=""
GOARCH="amd64"
GOBIN="$HOME/go/bin"
GOCACHE="$HOME/Library/Caches/go-build"
GOENV="$HOME/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="$HOME/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/cy/3qlwtf011g32xnt94zthm72w0000gq/T/go-build209266189=/tmp/go-build -gno-record-gcc-switches -fno-common"

gopls version

gopls version Output:


golang.org/x/tools/gopls 0.4.0
golang.org/x/tools/[email protected] h1:G4+YP9kaV4dJb79J5MobyApxX493Qa6VoiTceUmxqik=

vim-go configuration:

vim-go configuration

g:go_loaded_install = 1
g:go_jump_to_error = 1
g:go_loaded_gosnippets = 1

filetype detection configuration:

filetype detection

filetype detection:ON plugin:ON indent:ON

All 21 comments

Do you have something else listening on port 8181? If so, g:go_debug_address can be used to change the port that delve listens on.

I did check and try that, but unfortunately that's not the issue.
When I run :GoDebugStart, I can see that the process is running, but it won't connect for some reason.

Does the binary you're trying to debug build with :GoBuild?

Yep. :GoRun works as well

Edit: Actually, I don't think :GoBuild works. It says it does, but it's not producing the binary.
I'll take another look at it

Ok. Can you change https://github.com/fatih/vim-go/blob/master/autoload/go/debug.vim#L531 to read call go#util#EchoError("could not connect to debugger" . ch_status(l:ch)), try again, and let me know what the modified message is?

Apparently ch_status(l:ch) is "fail":

vim-go: could not connect to debugger fail

Okay, the :GoBuild command is running:

go build -tags  . errors

Which does nothing.
I just found this in the output of go help build:

When compiling multiple packages or a single non-main package,
build compiles the packages but discards the resulting object,
serving only as a check that the packages can be built.

So if I remove the errors part, or specify the output directory with :GoBuild -o ./, it works fine.

Still not sure how this is related to :GoDebugStart not working.

Is there a reason why errors is appended to the go build command (https://github.com/fatih/vim-go/blob/master/autoload/go/cmd.vim#L33)?

You answered my question about :GoBuild; no need to focus on it now. The important thing to resolve your issues is https://github.com/fatih/vim-go/issues/2866#issuecomment-621439425.

Can you try updating dlv with :GoUpdateBinaries dlv and try to debug your application again?

But to answer your questions:
I asked about :GoBuild, because I wanted to make sure your issue wasn't somehow related to a binary that dlv may have had a problem building.
errors is added so that the binary is not actually written to disk. Also, :GoBuild actually runs the equivalent of go build -tags '' . errors at the shell (notice the empty arguments to -tags.

After running :GoUpdateBinaries dlv I get the same output as before.

If it helps, this is the command it's running:

/Users/kimbo/go/bin/dlv debug path/to/my/go/project --output /var/folders/cy/3qlwtf011g32xnt94zthm72w0000gq/T/v8gIL2T/7 --headless --api-version 2 --listen 127.0.0.1:42131 --log --log-output debugger,rpc

As you can see, the listen address/port is different because I modified g:go_debug_address

Can you try debugging with dlv at the command line? Does that work?

Do you have a firewall or something that could be interferring with the socket connection?

Yeah, I can debug it from the command line. It also works with vscode.
I'm running MacOS, idk if there are known issues with that. Yesterday night after work I hopped on Ubuntu 18.04 and it worked like a charm. Maybe I'll just boot up a vm lol.

I'm not aware of any issues that would prevent it from working on macOS: I debug in vim-go on macOS regularly

Idk if this helps, but :GoDebugTest doesn't work either.

vim-go: could not remove /var/folders/cy/3qlwtf011g32xnt94zthm72w0000gq/T/vs3MRkd/6: remove /var/folders/cy/3qlwtf011g32xnt94zthm72w0000gq/T/vs3MRkd/6: no such file or directory

I'm wondering where you have some permissions issues on your machine 🤔

I think you are correct. It works when I run it as root...

Now it works like a charm, even as a normal user! I just ran it once as root, and now it works great. How strange indeed.

I appreciate your help @jblebrun@

Now it works like a charm, even as a normal user! I just ran it once as root, and now it works great. How strange indeed.

Hi Kimbo
How did you launch GoDebugStart as root? i am facing the same problem GoBuild & GoRun work fine.

I just ran sudo vi <file.go>

On Mon, Jul 27, 2020, 4:39 PM LuisPe notifications@github.com wrote:

Now it works like a charm, even as a normal user! I just ran it once as
root, and now it works great. How strange indeed.

Hi Kimbo
How did you launch GoDebugStart as root? i am facing the same problem
GoBuild & GoRun work fine.

—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
https://github.com/fatih/vim-go/issues/2866#issuecomment-664674247, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AI25UPSRYNJ4CWFQGLJEDATR5X63TANCNFSM4MS6LPWQ
.

I just ran sudo vi <file.go>
…
On Mon, Jul 27, 2020, 4:39 PM LuisPe @.*> wrote: Now it works like a charm, even as a normal user! I just ran it once as root, and now it works great. How strange indeed. Hi Kimbo How did you launch GoDebugStart as root? i am facing the same problem GoBuild & GoRun work fine. — You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub <#2866 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI25UPSRYNJ4CWFQGLJEDATR5X63TANCNFSM4MS6LPWQ .

Thanks Kimbo, it worsk GoDebugStart with your suggestion

I just ran sudo vi <file.go>
…
On Mon, Jul 27, 2020, 4:39 PM LuisPe @.*> wrote: Now it works like a charm, even as a normal user! I just ran it once as root, and now it works great. How strange indeed. Hi Kimbo How did you launch GoDebugStart as root? i am facing the same problem GoBuild & GoRun work fine. — You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub <#2866 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI25UPSRYNJ4CWFQGLJEDATR5X63TANCNFSM4MS6LPWQ .

I'm facing a similar issue. Not able to debug. What's weirder is that when I ran :GoDebugStart sometimes it would open a debug.go file that was a main package that just had a

func main() {
    fmt.Println("vim-go")
}

code in it.

I'm on a Mac too. I ran vim <file.go> (not as root) in the terminal, then started the debugger, and now it works in MacVim.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

orlangure picture orlangure  Â·  3Comments

danielmanesku picture danielmanesku  Â·  4Comments

derekchiang picture derekchiang  Â·  3Comments

joeblubaugh picture joeblubaugh  Â·  3Comments

cassiobotaro picture cassiobotaro  Â·  3Comments