-1

Attempting to use Delve to debug Go, I get the following error:

could not launch process: fork/exec C:\code\go_stuff\debugtest\__debug_bin: Access is denied.
could not remove C:\code\go_stuff\debugtest\__debug_bin: remove C:\code\go_stuff\debugtest\__debug_bin: Access is denied.

This is on a very simple Go project I created using go mod init and I wrote the main.go using Vim, so no VSCode or anything else is involved.

I tried to run dlv debug from the terminal and I get the above output. I also get the above output when I try and debug using Delve in VSCode as well.

I have tried this on another PC and it works perfectly so it may well be something environmental but I cannot fathom what is causing this.

None of the projects I am trying to debug are in git or indeed any other source control.

Before I incur any downvotes due to lack of code, here is my entire project:

package main

import "fmt"

func main() {
    fmt.Println("So we begin")
    fmt.Println("Here we end")
}
Matt Hogan-Jones
  • 2,981
  • 1
  • 29
  • 35
  • If you run `~/go/bin/dlv --help` (or whatever the installed delve path is in windows), does the command run? – Christian Apr 23 '21 at 08:40
  • @Christian yes, the command runs and outputs the dlv help content in the terminal, so it looks like dlv is installed and working from that respect. – Matt Hogan-Jones Apr 23 '21 at 08:51
  • Now it's even more odd - on the same Go project, I can debug in VSCode using Delve but running `dlv debug` from the terminal gives the same error. On another project, I am able to debug in both the terminal and VSCode... – Matt Hogan-Jones Apr 23 '21 at 09:28
  • As soon as I edited and saved `main.go` in the project where I could debug in both terminal and VSCode, I can no no longer debug in either. – Matt Hogan-Jones Apr 23 '21 at 09:43
  • @MattHogan-Jones did you ever resolve this? – jordan Apr 01 '22 at 16:23
  • @jordan I think now that this issue was caused by over-zealous anti-virus deleting the executable as soon as it was run. I've moved to using WSL2 for Go development, but since I wrote this post I've no longer been doing Go development so forgot about it. However, I've just built and debugged a Go application via VSCode from WSL2 and it works fine, so it would seem to indeed be the fault of the AV. – Matt Hogan-Jones Apr 04 '22 at 08:56
  • @MattHogan-Jones Thanks, ya that is also my issue I discovered. Curious why no more Go development, just not needed for your current work, or decided to abandon the language altogether? – jordan Apr 04 '22 at 13:38
  • @Jordan Not required for current work, where we needed stuff that was better represented in other languages. – Matt Hogan-Jones Apr 04 '22 at 14:40

2 Answers2

1

It seems to be have been an issue caused by anti-virus deleting the executable when I tried to run it or even debug it. I moved to developing Go in WSL2 using VSCode and I can debug the code without issue, so this would appear to be environmental and not an issue with either Delve or Go.

Matt Hogan-Jones
  • 2,981
  • 1
  • 29
  • 35
0

Actually I've met similar problem. I modify the "settings.json" file of VScode as following:

{
        "workbench.colorTheme": "Default Dark+",
        "workbench.editorAssociations": {
            "*.ipynb": "jupyter.notebook.ipynb"
        },
        "gopls": {
            "experimentalWorkspaceModule": true
        },
        "go.alternateTools": {
        
        },
        "go.delveConfig": {      
            "dlvLoadConfig": {
                "followPointers": true,
                "maxVariableRecurse": 1,
                "maxStringLen": 64,
                "maxArrayValues": 64,
                "maxStructFields": -1
            },
            "apiVersion": 2,
            "showGlobalVariables": false,
            "debugAdapter": "legacy",
            "substitutePath": []
        }
}

Then try to debug or either run without debug. It works and the "__debug_bin.exe" will not generate anymore. However I don't know the reason, it seems some problem of dlv configuration. Does anyone know the root cause? Hope this help you!

Binkesi
  • 1
  • 1