Delve: [OSX 10.10.3] Can't seem to be able to debug a program or attach to an existing one

Created on 30 Jun 2015  Â·  16Comments  Â·  Source: go-delve/delve

Running a process then attaching:

296 [13:56] roberto@roberto-aw> sudo dlv attach 59077
Password:
could not attach to pid 59077: could not get thread count
[Hope I was of service hunting your bug!]

The process to be attached is:

574 [13:55] roberto@roberto-aw:src/flightaware-go> ./bin/fa-export
2015/06/30 13:55:55 Connecting to foxtrot.hou.flightaware.com:1501 with TLS
2015/06/30 13:55:56 TLS negociation done.
2015/06/30 13:55:56 Flightaware init done.
2015/06/30 13:55:56 Waiting for data…
2015/06/30 13:55:56 Loop
[1]    59077 killed     ./bin/fa-export

trying to run the process through dlv:

572 [13:54] roberto@roberto-aw:src/flightaware-go> ll !$
ll bin/fa-export
-rwxr-xr-x  1 roberto  staff  5551876 Jun 30 12:06 bin/fa-export*
573 [13:54] roberto@roberto-aw:src/flightaware-go> dlv ./bin/fa-export
could not launch process: could not fork/exec
[Hope I was of service hunting your bug!]

Code is at https://github.com/keltia/flightaware-go/

kinbug

Most helpful comment

FWIF I had similar issue today:

"sudo dlv exec ./blah" worked fine, but "dlv exec ./blah" would print the dreaded "could not launch process: could not fork/exec".

I double checked that the certificate was configured properly and that dlv was properly signed. Restarting taskgated did not help in my case.

What helped was - surprisingly - starting XCode. Apparently the first time it starts, it installs some debugging support tools, which seems to allow dlv to run as regular user.

All 16 comments

What OS are you running?

I was able to build and run through Delve with the following commands:

derekparker at flightaware-go(master) make
go build -v -o bin/fa-export fa-export/fa-export.go fa-export/cli.go
gopkg.in/yaml.v2
_/Users/derekparker/go/src/github.com/keltia/flightaware-go/config
_/Users/derekparker/go/src/github.com/keltia/flightaware-go/flightaware
command-line-arguments
derekparker at flightaware-go(master+) dlv bin/fa-export
Type 'help' for list of commands.
(dlv) b main.main
Breakpoint 1 set at 0x2300 for main.main /Users/derekparker/go/src/github.com/keltia/flightaware-go/fa-export/fa-export.go:36
(dlv) c
current loc: main.main /Users/derekparker/go/src/github.com/keltia/flightaware-go/fa-export/fa-export.go:36
   31:                  log.Fatalf("Error writing %d bytes: %v", nb, err)
   32:          }
   33:  }
   34:
   35:  // Starts here.
=> 36:  func main() {
   37:          // Handle SIGINT
   38:          go func() {
   39:              sigint := make(chan os.Signal, 3)
   40:              signal.Notify(sigint, os.Interrupt)
   41:              <-sigint

(dlv) Would you like to kill the process? [Y/n]
[Hope I was of service hunting your bug!]

@keltia I imagine some flavor of FreeBSD?

Nope, unless you consider OS X to be one (which it is in a way ok). I'm running OS X 10.10.3 as indicated in the subject line :)

@keltia ah, sorry... I'm still waiting on coffee to kick in ;).

I'm running the same system and I was able to pass along the path to Delve. I can attempt attaching to a running process and see if that makes any difference.

could not launch process: could not fork/exec seems to indicate some kind of resource shortage but the rest of the system does work.

@keltia have you gone through the process of code signing the dlv binary?

Yes, created a fake self-signed root cert and signed. I could also have used my own certificate but didn't thought of that.

I am unable to reproduce this issue, I was able to attach to the binary by passing along the path.

Have you been able to use Delve successfully on your machine before? Could you try dlv run on an extremely simple test program and verify that it works?

If it does not work with a simple test program than I honestly suspect it is an issue with the cert.

Closing as related to #134.

Thanks for writing this great piece of software! Just compiled it on OSX 10.11 following all the required steps. I have the same issue when launching a debug session:

$ dlv debug main.go
could not launch process: could not fork/exec

The way I was able to resolve this is by running the command as sudo.

$ sudo dlv debug main.go
Password:
Type 'help' for list of commands.
(dlv)

@ObviousDesign thanks for checking it out! The debug subcommand actually does not take an argument, it expects to be run where you would run go build without any args. Secondly, since sudo worked for you, it seems there is an issue with how the dlv binary was codesigned. For sanity checks, did you make sure you killed the taskgated process? Also, the output of make install could be useful here.

Hi @derekparker, I was not able to kill the taskgated process before compiling first time. Now recompiled after a fresh restart and I am now able to run dlv without sudo. Thank you for your support. Jeroen

I had the same issue and it was related to taskgated. I just restarted and everything worked.

FWIF I had similar issue today:

"sudo dlv exec ./blah" worked fine, but "dlv exec ./blah" would print the dreaded "could not launch process: could not fork/exec".

I double checked that the certificate was configured properly and that dlv was properly signed. Restarting taskgated did not help in my case.

What helped was - surprisingly - starting XCode. Apparently the first time it starts, it installs some debugging support tools, which seems to allow dlv to run as regular user.

Make sure each time you try the code sign, run sudo pkill taskgated first.

I have same problem that I get error below except root user.
could not launch process: could not fork/exec
I killed taskgated just before make, but taskgated restarts after make process.

OS: OSX Yosemite 10.10.4
Darwin Kernel Version 14.4.0

In addition, after renamed these files, I am not able to run codesign.
/System/Library/LaunchDaemons/com.apple.taskgated-helper.plist
/System/Library/LaunchDaemons/com.apple.taskgated.plist

[root]$ codesign -s "dlv-cert" /Users/murotanimari/work/bin/dlv
error: One or more parameters passed to a function were not valid.

Was this page helpful?
0 / 5 - 0 ratings