Please answer the following before submitting your issue:
Note: Please include any substantial examples (debug session output,
stacktraces, etc) as linked gists.
dlv version)?Delve Debugger
Version: 1.3.0
Build: $Id: 2f59bfc686d60989dcef9de40b480d0a34aa2fa5 $
What version of Go are you using? (go version)?
go version go1.13.1 darwin/amd64```
What operating system and processor architecture are you using?
mac osX 10.14.6
What did you do?
When I attached a process in GoLand the first time it worked fine and after some time its started failing with error below.
Then I used the command line dlv command dlv attach
What did you expect to see?
What did you see instead?
GOLAND error
```/Applications/GoLand.app/Contents/plugins/go/lib/dlv/mac/dlv --listen=localhost:50393 --headless=true --api-version=2 attach 28780 -- #gosetup
API server listening at: 127.0.0.1:50393
could not attach to pid 28780: stub exited while waiting for connection: exit status 0
Debugger finished with exit code 1```
CMD line error
could not attach to pid 28780: stub exited while waiting for connection: exit status 0
I have checked my hosts file and it looks fine. I am not sure what went wrong since its worked the first time and not it doesnt.
Please help
You need to try running debug server directly:
/Library/Developer/CommandLineTools/Library/PrivateFrameworks/LLDB.framework/Versions/A/Resources/debugserver --attach=pid
and see what happens.
You need to try running debug server directly:
/Library/Developer/CommandLineTools/Library/PrivateFrameworks/LLDB.framework/Versions/A/Resources/debugserver --attach=pidand see what happens.
I get the following
/Library/Developer/CommandLineTools/Library/PrivateFrameworks/LLDB.framework/Versions/A/Resources/debugserver --attach=98667
debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-1001.0.13.3
for x86_64.
Usage:
debugserver host:port [program-name program-arg1 program-arg2 ...]
debugserver /path/file [program-name program-arg1 program-arg2 ...]
debugserver host:port --attach=
debugserver /path/file --attach=
debugserver host:port --attach=
debugserver /path/file --attach=
Try: /Library/Developer/CommandLineTools/Library/PrivateFrameworks/LLDB.framework/Versions/A/Resources/debugserver 127.0.0.1:9000 --attach=<pid>
I get this
debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-1001.0.13.3
for x86_64.
Attaching to process 10608...
error: failed to attach process 10608: unable to start the exception thread
Exiting.
It's a problem with debugserver, you should report it to apple.
Thanks a lot. But When I initially tried attaching the process from GoLand it worked the first time and stopped running afterwards. Could there be anything else which might be stopping dlv cmd to run from GoLand and Terminal ?
What's stopping dlv from working is debugserver not working.
Gotcha! Not sure why I ran initially and what caused it to stop working. Thanks a lot for for explaining it!
Close, upstream issue.
For whomever stumbles upon this thread:
This is due to a MacOS restriction.
taskgated (Gatekeeper) checks for an entitlement com.apple.security.get-task-allow to attach the debugger. You can observe the relevant logs in Console.app for the processes (taskgated, debugserver, and kernel).
I was able to resolve this issue for me by running dlv attach... with sudo.
Or if you cannot run dlv as root (i.e. you really want to clicky attach in GoLand):
entitlements.plist file containing:<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.get-task-allow</key>
<true/>
</dict>
</plist>
codesign -fs <certificate name> --timestamp --options=runtime --entitlements entitlements.plist $GOPATH/bin/<executable>
dlv to the process.TL;DR: Run dlv attach with sudo.
P.S
Like the OP, I was also able to attach Delve on the initial attempt. It was probably allowed due to a bug. I was able to do it again one time after disabling SIP(csrutil disable).
P.P.S. There's probably another way to get this running easily in GoLand. Maybe renaming /Applications/GoLand.app/Contents/plugins/go/lib/dlv/mac/dlv and replacing it with a script named dlv that calls the former dlv with sudo and passes the args. OR, maybe I'll open an issue with JetBrains.
I ran into the exact issue described by @matthewhembree, but was perplexed that coworkers with a similar configuration had the same problem. I don't fully understand the root of the issue, but seems like the debugserver installed by Apple's standalone CommandLineTools package isn't properly signed in some way. There are more details that may be relevant in this issue. I found that all the people for whom debugserver had stopped working shared the following feature:
$ xcode-select -p
/Library/Developer/CommandLineTools
whereas those for whom it kept working had
$ xcode-select -p
/Applications/Xcode.app/Contents/Developer
So I did the following:
sudo rm -rf /Library/Developer/CommandLineToolsxcode-select --installAnd debugging in GoLand works again!
I just ran into this and fixed by running:
$ sudo /usr/sbin/DevToolsSecurity --enable
Most helpful comment
For whomever stumbles upon this thread:
This is due to a MacOS restriction.
taskgated(Gatekeeper) checks for an entitlementcom.apple.security.get-task-allowto attach the debugger. You can observe the relevant logs in Console.app for the processes (taskgated, debugserver, and kernel).I was able to resolve this issue for me by running
dlv attach...withsudo.Or if you cannot run
dlvas root (i.e. you really want to clicky attach in GoLand):entitlements.plistfile containing:dlvto the process.TL;DR: Run
dlv attachwithsudo.P.S
Like the OP, I was also able to attach Delve on the initial attempt. It was probably allowed due to a bug. I was able to do it again one time after disabling SIP(
csrutil disable).P.P.S. There's probably another way to get this running easily in GoLand. Maybe renaming
/Applications/GoLand.app/Contents/plugins/go/lib/dlv/mac/dlvand replacing it with a script nameddlvthat calls the formerdlvwithsudoand passes the args. OR, maybe I'll open an issue with JetBrains.