VS Code go debug : could not launch process: not an executable file

Viewed 7882

i had the vscode running and debugging GO code just fine , after i did update from within VSCode now i can't debug and i keep getting this error :

could not launch process: not an executable file
Process exiting with code: 1

configuration :

go version
go version go1.15.5 windows/amd64

 dlv version
Delve Debugger
Version: 1.6.0


set GOPATH=C:\Users\foo\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\FOO~1\AppData\Local\Temp\go-build049073490=/tmp/go-build -gno-record-gcc-switches
PS C:\Dev\my\go\tests>

enter image description here I dont understand what went wrong in the update?

5 Answers

Addition to Jsperk answer. You also can configure launch.json so it always starts debugging main.go (file which have main() function). Because call stack begins from main(), you always will reach your breakpoint in another file.

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "main.go"
            
        }
    ]
}

In my case it was exactly what Jsperk said, I have to open the file that has the main() function in it, and only then I can press Run.

... main.go needs to remain open, if you have another file open, the test will show this error message. – Jsperk

You're getting this error because your package name isn't the same as your main function name.

package fibonacci //this needs to be called main. 

 func fibonacci(c, quit chan int) {

    x, y := 0, 1
    for {
        select {
        case c <- x:
            x, y = y, x+y
        case <-quit:
            fmt.Println("quit")
            return
        }
    }
}

func main() {
    c := make(chan int)
    quit := make(chan int)
    go func() {
        for i := 0; i < 10; i++ {
            fmt.Println(<-c)
        }
        quit <- 0
    }()
    fibonacci(c, quit)
}

I was having the same issue because of package naming. The solution was to use the standard declaration for a Go main file:

package main

func main () {
  // Your code + Breakpoint
}

... And then was able to debug, using the following launch.json file:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug Go",
      "type": "go",
      "request": "launch",
      "mode": "debug",
      "program": "${workspaceRoot}/main.go"
    }
  ]
}

I experience the same issue as user63898 on macos. I have tried everything I could find on StackOverflow and other forums.

I even made sure to keep my main.go file open while executing debug, but still get this issue:

API server listening at: 127.0.0.1:29559
could not launch process: not an executable file
Process exiting with code
Related