Delve: stub exited while waiting for connection: exit status 0

Created on 4 Oct 2019  路  12Comments  路  Source: go-delve/delve

Please answer the following before submitting your issue:

Note: Please include any substantial examples (debug session output,
stacktraces, etc) as linked gists.

  1. What version of Delve are you using (dlv version)?
Delve Debugger
Version: 1.3.0
Build: $Id: 2f59bfc686d60989dcef9de40b480d0a34aa2fa5 $
  1. What version of Go are you using? (go version)?
    go version go1.13.1 darwin/amd64```

  2. What operating system and processor architecture are you using?
    mac osX 10.14.6

  3. 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 and its giving the same error.

  4. What did you expect to see?

  5. 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

kinneeds more info

Most helpful comment

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):

  1. Create a code signing certificate with Keychain Access
  2. Create an 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>
  1. Notarize your executable (must be done after every build):
codesign -fs <certificate name> --timestamp --options=runtime --entitlements entitlements.plist $GOPATH/bin/<executable>
  1. Attach 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.

All 12 comments

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=pid

and 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):

  1. Create a code signing certificate with Keychain Access
  2. Create an 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>
  1. Notarize your executable (must be done after every build):
codesign -fs <certificate name> --timestamp --options=runtime --entitlements entitlements.plist $GOPATH/bin/<executable>
  1. Attach 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:

  1. Uninstall CommandLineTools: sudo rm -rf /Library/Developer/CommandLineTools
  2. Install Xcode from the App Store
  3. Run xcode-select --install
  4. Open Xcode and accept the prompts to install additional tools

And debugging in GoLand works again!

I just ran into this and fixed by running:

$ sudo /usr/sbin/DevToolsSecurity --enable
Was this page helpful?
0 / 5 - 0 ratings

Related issues

runningbar picture runningbar  路  4Comments

primalmotion picture primalmotion  路  3Comments

saleemjaffer picture saleemjaffer  路  4Comments

kdeenanauth picture kdeenanauth  路  5Comments

christianwoehrle picture christianwoehrle  路  5Comments