11

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?

rioV8
  • 24,506
  • 3
  • 32
  • 49
user63898
  • 29,839
  • 85
  • 272
  • 514

5 Answers5

6

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"
            
        }
    ]
}
Amaimersion
  • 787
  • 15
  • 28
3

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

wellsantos
  • 466
  • 4
  • 5
3

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"
    }
  ]
}

Axel Prieto
  • 535
  • 10
  • 20
  • 1
    Got recently the same issue main.go with package testapp wasn't working. After switching the package name to main its working! – user743414 Feb 19 '23 at 09:56
2

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)
}
void
  • 21
  • 1
  • The question doesn't provide the package name, but the author mentioned the errors occured after a VScode update (worked previously). This indicates the package is probably "main". – mpx Apr 16 '22 at 04:46
  • Based on this specific error the package name indicates it is not "main". – void Apr 16 '22 at 20:59
  • @mpx Debugging in Go is pretty straightforward, you must first start debugging in main.go. If you do it in any other file other than the executable file (i.e. main.go) you will get the message `could not launch process: not an executable file`. Furthermore once debugging has commenced in main.go then and only then can you proceed to debug other files. – void Apr 16 '22 at 21:14
  • Yes, you're correct that this error is also generated when trying to debug a non-main package - but there are other more likely reasons. The author mentioned that debugging previously worked but broke after a toolchain update. While the toolchain update is unlikely to cause the breakage, it does indicate they probably didn't rename the package to something incorrect. The author has now indicated it was an issue with their launch.json/open files based on Jsperk's comment. – mpx Apr 17 '22 at 01:59
  • It worked for me, thanks! – Alex Medveshchek Jul 12 '23 at 19:44
-1

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
Francois Harmse
  • 197
  • 1
  • 5
  • 1
    This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/30238172) – eglease Nov 02 '21 at 13:31