vscode-go icon indicating copy to clipboard operation
vscode-go copied to clipboard

VSCode Breakpoint not hitting/stopping when run in debugger mode - Golang

Open riderrocks opened this issue 2 years ago • 20 comments

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal. go version go1.19 darwin/amd64

  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal. Unknown command: gopls

  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders. 1.70.2 e4503b30fc78200f846c62cf8091b76ff5547662 x64

  • Check your installed extensions to get the version of the VS Code Go extension Go v0.35.2

  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command. Checking configured tools.... GOBIN: undefined toolsGopath: gopath: /Users/ananthraghav/go GOROOT: /usr/local/go PATH: /Users/ananthraghav/google-cloud-sdk/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/mongodb/bin/:/usr/local/go/bin

    go: /usr/local/go/bin/go: go version go1.19 darwin/amd64

    gotests: /Users/ananthraghav/go/bin/gotests (version: v1.6.0 built with go: go1.19) gomodifytags: /Users/ananthraghav/go/bin/gomodifytags (version: v1.16.0 built with go: go1.19) impl: /Users/ananthraghav/go/bin/impl (version: v1.1.0 built with go: go1.19) goplay: /Users/ananthraghav/go/bin/goplay (version: v1.0.0 built with go: go1.19) dlv: /Users/ananthraghav/go/bin/dlv (version: v1.9.0 built with go: go1.19) staticcheck: /Users/ananthraghav/go/bin/staticcheck (version: v0.3.3 built with go: go1.19) gopls: /Users/ananthraghav/go/bin/gopls (version: v0.9.4 built with go: go1.19)

go env Workspace Folder (le-diy): /Users/ananthraghav/go/src/stash.bms.bz/bms/le-diy GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/Users/ananthraghav/Library/Caches/go-build" GOENV="/Users/ananthraghav/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="-trimpath" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/ananthraghav/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/ananthraghav/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" GOVCS="" GOVERSION="go1.19" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/Users/ananthraghav/go/src/stash.bms.bz/bms/le-diy/go.mod" GOWORK="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/ym/b8142c6d0hlc3byfnh5bggmr0000gq/T/go-build37387940=/tmp/go-build -gno-record-gcc-switches -fno-common"

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file. Share all the settings with the go. or ["go"] or gopls prefixes.

Describe the bug

When Start Debugging is fired, the program runs successfully. However the program doesn't stop at breakpoints. Breakpoint is enabled and placed alright. But it doesn't hit

Steps to reproduce the behavior:

  1. Go to Run -> Start debugging
  2. See in debug console - DAP server listening at: 127.0.0.1:50757
  3. Process 31415 has exited with status 0 dlv dap (31383) exited with code: 0

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.

Screenshot 2022-08-18 at 9 54 05 PM

defaultSettings.txt

riderrocks avatar Aug 18 '22 16:08 riderrocks

@riderrocks Could you share the launch configuration you are using? Thanks!

suzmue avatar Aug 18 '22 16:08 suzmue

launch.txt @suzmue Here is the launch.json { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Launch", "type": "go", "request": "launch", "mode": "auto", "program": "${fileDirname}", "env": {}, "args": [] } ] }

riderrocks avatar Aug 18 '22 18:08 riderrocks

@riderrocks Thanks! Could you also enable logging and send the output from the debug console? I would guess that the breakpoint is not being set for some reason, but not sure why without more information.

You can enable logging by updating your launch configuration to include "logOutput": "dap", "showLog": true:

 {
   "name": "Launch",
   "type": "go",
   "request": "launch",
   "mode": "auto",
   "program": "${fileDirname}",
   "logOutput": "dap",
   "showLog": true,
} 

suzmue avatar Aug 18 '22 18:08 suzmue

Hi @suzmue Thanks! Here is the output of debug console attacthed in txt file

` Starting: /Users/ananthraghav/go/bin/dlv dap --check-go-version=false --log=true --log-output=dap --listen=127.0.0.1:49787 --log-dest=3 from /Users/ananthraghav/Desktop/Test DAP server listening at: 127.0.0.1:49787 2022-08-19T00:38:13+05:30 debug layer=dap DAP server pid = 21237 2022-08-19T00:38:13+05:30 debug layer=dap DAP connection 1 started 2022-08-19T00:38:13+05:30 debug layer=dap [<- from client]{"seq":1,"type":"request","command":"initialize","arguments":{"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"go","locale":"en-gb","linesStartAt1":true,"columnsStartAt1":true,"pathFormat":"path","supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"supportsMemoryReferences":true,"supportsProgressReporting":true,"supportsInvalidatedEvent":true}} 2022-08-19T00:38:13+05:30 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":1,"success":true,"command":"initialize","body":{"supportsConfigurationDoneRequest":true,"supportsFunctionBreakpoints":true,"supportsConditionalBreakpoints":true,"supportsEvaluateForHovers":true,"supportsSetVariable":true,"supportsExceptionInfoRequest":true,"supportsDelayedStackTraceLoading":true,"supportsLogPoints":true,"supportsDisassembleRequest":true,"supportsClipboardContext":true,"supportsSteppingGranularity":true,"supportsInstructionBreakpoints":true}} 2022-08-19T00:38:14+05:30 debug layer=dap [<- from client]{"seq":2,"type":"request","command":"launch","arguments":{"name":"Launch","type":"go","request":"launch","mode":"debug","program":".","logOutput":"dap","showLog":true,"__configurationTarget":6,"noDebug":true,"packagePathToGoModPathMap":{"/Users/ananthraghav/Desktop/Test":"/Users/ananthraghav/Desktop/Test"},"debugAdapter":"dlv-dap","showRegisters":false,"showGlobalVariables":false,"substitutePath":[],"dlvFlags":[],"hideSystemGoroutines":false,"dlvToolPath":"/Users/ananthraghav/go/bin/dlv","env":{"GOPATH":"/Users/ananthraghav/go"},"__buildDir":"/Users/ananthraghav/Desktop/Test","__sessionId":"6640d3d6-bff4-4ce3-ab38-88b861909b72"}} 2022-08-19T00:38:14+05:30 debug layer=dap parsed launch config: { "mode": "debug", "program": ".", "noDebug": true, "env": { "GOPATH": "/Users/ananthraghav/go" }, "backend": "default", "stackTraceDepth": 50 } 2022-08-19T00:38:14+05:30 debug layer=dap building from "/Users/ananthraghav/Desktop/Test": [go build -o /Users/ananthraghav/Desktop/Test/__debug_bin -gcflags all=-N -l .] 2022-08-19T00:38:14+05:30 debug layer=dap launching binary '/Users/ananthraghav/Desktop/Test/__debug_bin' with config: { "mode": "debug", "program": "/Users/ananthraghav/Desktop/Test", "cwd": "/Users/ananthraghav/Desktop/Test", "output": "/Users/ananthraghav/Desktop/Test/__debug_bin", "noDebug": true, "dlvCwd": "/Users/ananthraghav/Desktop/Test", "env": { "GOPATH": "/Users/ananthraghav/go" }, "backend": "default", "stackTraceDepth": 50 } 2022-08-19T00:38:14+05:30 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":2,"success":true,"command":"launch"} Hello world

2022/08/19 00:38:14 helloWorld 2022-08-19T00:38:14+05:30 debug layer=dap [-> to client]{"seq":0,"type":"event","event":"output","body":{"category":"console","output":"Process 21260 has exited with status 0\n","source":{}}} 2022-08-19T00:38:14+05:30 debug layer=dap [-> to client]{"seq":0,"type":"event","event":"terminated","body":{}} Process 21260 has exited with status 0 2022-08-19T00:38:14+05:30 debug layer=dap [<- from client]{"seq":3,"type":"request","command":"disconnect","arguments":{}} 2022-08-19T00:38:14+05:30 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":3,"success":true,"command":"disconnect"} 2022-08-19T00:38:14+05:30 debug layer=dap [-> to client]{"seq":0,"type":"event","event":"terminated","body":{}} 2022-08-19T00:38:14+05:30 debug layer=dap DAP server stopping... 2022-08-19T00:38:14+05:30 debug layer=dap DAP server stopped dlv dap (21237) exited with code: 0 `

riderrocks avatar Aug 18 '22 19:08 riderrocks

Hmmm I'm not seeing any breakpoints requests.n Would you mind double checking that you have breakpoints set in the VS Code UI by going to the breakpoints view?

You can get there using the command prompt and running > Run and Debug: Focus on Breakpoints View:

Screen Shot 2022-08-18 at 3 20 42 PM i

suzmue avatar Aug 18 '22 19:08 suzmue

@suzmue Thanks! for the revert.

I have the set the breakpoints as can be seen in the image. It doesn't stop at the breakpoint instead prints the output and exits

Screenshot 2022-08-19 at 1 02 44 AM

riderrocks avatar Aug 18 '22 19:08 riderrocks

I see from your logs that noDebug is true, this means that it will not stop on the breakpoints.

Can you try running using the command > Debug: Start Debugging?

If you are using a keyboard short cut, make sure that the short cut you are using doesn't run the Debug: Start without Debugging command.

suzmue avatar Aug 19 '22 16:08 suzmue

@suzmue I tried Debug: Start Debugging

But still the result is same that the breakpoints are not hit. Here is the screenshot and output.

Screenshot 2022-08-19 at 10 45 17 PM [output1908.txt](https://github.com/golang/vscode-go/files/9384112/output1908.txt)

riderrocks avatar Aug 19 '22 17:08 riderrocks

I see that is now sending the setBreakpoints requests so that is progress!

The error that it is getting is "could not find file /Users/ananthraghav/Desktop/Test/main.go". Is this project by chance in a symlinked directory?

If not, can you try setting "stopOnEntry": true in your launch configuration. This should allow us to stop in the debug session without having to set a breakpoint. Once the debug session is running can you then type dlv sources in the debug console and look at the list of sources. You should be able to find the main.go file in that list somewhere.

suzmue avatar Aug 19 '22 17:08 suzmue

Hi @suzmue The file is not a symbolic link. -rw-r--r-- 1 ananthraghav staff 177 20 Aug 11:54 main.go

Tried the above suggestion. The main.go exists on the list. However the debugger doesn't allow the placement of breakpoint. Screenshot 2022-08-20 at 11 54 48 AM

riderrocks avatar Aug 20 '22 06:08 riderrocks

Was the path of main.go in the list of sources the same as /Users/ananthraghav/Desktop/Test/main.go?

If not, add this to your launch configuration with the directory from the list of sources:

"substitutePath": [{"from": "/Users/ananthraghav/Desktop/Test", "to": directoryFromSources}]

Otherwise lmk if the paths are identical (with a screenshot ideally :) )

suzmue avatar Aug 22 '22 17:08 suzmue

Hi @suzmue I put the substitutePath in launch.json and now breakpoints are hit :) Thanks much!

I wanted to know without mentioning the substitute path how can the same result be achieved.

Screenshot 2022-08-27 at 12 15 05 PM Screenshot 2022-08-27 at 12 14 26 PM

riderrocks avatar Aug 27 '22 06:08 riderrocks

I appear same issue,I try the up method,not stop running,still not resolved this is log:

Starting: /home/cwh/Go/bin/dlv dap --only-same-user=false --log=true --log-output=dap --listen=127.0.0.1:3174 --log-dest=3 from /home/cwh/Go/src/numb
DAP server listening at: 127.0.0.1:3174
2023-03-24T17:14:58+08:00 debug layer=dap DAP server pid = 14472
2023-03-24T17:14:58+08:00 debug layer=dap DAP connection 1 started
2023-03-24T17:14:58+08:00 debug layer=dap [<- from client]{"seq":1,"type":"request","command":"initialize","arguments":{"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"go","locale":"zh-cn","linesStartAt1":true,"columnsStartAt1":true,"pathFormat":"path","supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"supportsMemoryReferences":true,"supportsProgressReporting":true,"supportsInvalidatedEvent":true,"supportsMemoryEvent":true}}
2023-03-24T17:14:58+08:00 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":1,"success":true,"command":"initialize","body":{"supportsConfigurationDoneRequest":true,"supportsFunctionBreakpoints":true,"supportsConditionalBreakpoints":true,"supportsEvaluateForHovers":true,"supportsSetVariable":true,"supportsExceptionInfoRequest":true,"supportsDelayedStackTraceLoading":true,"supportsLogPoints":true,"supportsDisassembleRequest":true,"supportsClipboardContext":true,"supportsSteppingGranularity":true,"supportsInstructionBreakpoints":true}}
2023-03-24T17:14:58+08:00 debug layer=dap [<- from client]{"seq":2,"type":"request","command":"launch","arguments":{"name":"Launch Package","type":"go","request":"launch","mode":"debug","program":"./numb.go","dlvFlags":["--only-same-user=false"],"stopOnEntry":true,"logOutput":"dap","showLog":true,"substitutePath":[{"from":"/home/cwh/Go/src/numb/","to":"./test"}],"__configurationTarget":6,"packagePathToGoModPathMap":{"/home/cwh/Go/src/numb":"/home/cwh/Go/src/numb"},"debugAdapter":"dlv-dap","showRegisters":false,"showGlobalVariables":false,"hideSystemGoroutines":false,"dlvToolPath":"/home/cwh/Go/bin/dlv","env":{"GO111MODULE":"on","GOPATH":"/home/cwh/Go"},"__buildDir":"/home/cwh/Go/src/numb","__sessionId":"b5ee25aa-fb8e-4044-a2ac-9546a33749bd"}}
2023-03-24T17:14:58+08:00 debug layer=dap parsed launch config: {
	"mode": "debug",
	"program": "./numb.go",
	"env": {
		"GO111MODULE": "on",
		"GOPATH": "/home/cwh/Go"
	},
	"stopOnEntry": true,
	"backend": "default",
	"stackTraceDepth": 50,
	"substitutePath": [
		{
			"from": "/home/cwh/Go/src/numb/",
			"to": "./test"
		}
	]
}
2023-03-24T17:14:59+08:00 debug layer=dap building from "/home/cwh/Go/src/numb": [go build -o /home/cwh/Go/src/numb/__debug_bin -gcflags all=-N -l ./numb.go]
2023-03-24T17:14:59+08:00 debug layer=dap launching binary '/home/cwh/Go/src/numb/__debug_bin' with config: {
	"mode": "debug",
	"program": "/home/cwh/Go/src/numb/numb.go",
	"cwd": "/home/cwh/Go/src/numb",
	"output": "/home/cwh/Go/src/numb/__debug_bin",
	"dlvCwd": "/home/cwh/Go/src/numb",
	"env": {
		"GO111MODULE": "on",
		"GOPATH": "/home/cwh/Go"
	},
	"stopOnEntry": true,
	"backend": "default",
	"stackTraceDepth": 50,
	"substitutePath": [
		{
			"from": "/home/cwh/Go/src/numb/",
			"to": "./test"
		}
	]
}

@suzmue

cwh12355 avatar Mar 24 '23 09:03 cwh12355

"substitutePath": [{"from": "/Users/ananthraghav/Desktop/Test", "to": directoryFromSources}]

Thanks. I forgot that my root directory was a symlink which was causing this issue. I think this substitution will solve some of the other issues I've been facing too.

wisefool01 avatar Jul 26 '23 22:07 wisefool01

@cwh12355 please open a new issue rather than tacking onto this one - easier for the people providing support.

@suzmue These are the most kick-ass troubleshooting steps. A model for how it should be done! Thanks.

bitwombat avatar Oct 22 '23 00:10 bitwombat

Stops on breakpoint with such config:

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

In the root of a project lies entry main.go file.

maximLyakhov avatar Nov 06 '23 10:11 maximLyakhov

"substitutePath": [{"from": "/Users/ananthraghav/Desktop/Test", "to": directoryFromSources}]

Thanks. I forgot that my root directory was a symlink which was causing this issue. I think this substitution will solve some of the other issues I've been facing too.

This fixed the issue for me as well. Note that you only need to substitute up to the common path:

// launch.json
// Scenario:
//     Project: /workspaces/nisimpson/myproject
//     Symlink: /home/nisimpson/w/myproject
{
  "configurations": [
    {
       "substitutePath": [{
          "from": "/home/nisimpson/w",
          "to": "/workspaces/nisimpson"
        }],
        ...
    }
  ]
}

nisimpson avatar Dec 18 '23 23:12 nisimpson

I fixed my issue by ensuring breakpoints were on a line that had code. They seem to be skipped if they are on a line that is just whitespace.

klm127 avatar Feb 16 '24 23:02 klm127

This solved the issue for me as well.

TLDR: if folder you are using with VSCode has a symlink in its path, you need to tell VSCode to replace the symlink with real ones, else it would not find the files (doesn't work with symlinks).

Not clear why it doesn't work with symlinks.

in your launch.json add:

{
  "configurations": [
    {
      "substitutePath": [{
        // location of project folder in VSCode: 
        //   "/path/to/symlink-parent/myproject"
        // location of symlink parent:
        //   "/path/to/symlink-parent"
        // location of real parent:            
        //   "/path/to/real-parent"
        // location of real project folder:
        //   "/path/to/real-parent/myproject"
        //
        // map the symlink parent to real parent.
        //
          "from": "/path/to/symlink-parent",
          "to":   "/path/to/real-parent"
        }],
    }
  ]
}

ghasemloo avatar Apr 18 '24 03:04 ghasemloo