delve/pkg/proc/native
Matt Bauer beb3e76f33 proc: Handle race between fork and task_for_pid (#1117)
* Handle race between fork and task_for_pid

On macOS a call to fork and a subsequent call to task_for_pid will race each other. This is because the macOS kernel assigns a new proc_t structure early but the new task, thread and uthread come much later. The function exec_mach_imgact in the XNU sources contains this logic.

In a system under load or one with delays in fork processing (i.e. various security software), task_for_pid as currently called by Delve often returns the parent task. This can be seen by printing out the task number around line 86. In a normal system we would see three calls:

-> ~/go/bin/dlv --listen=localhost:59115 --headless=true --api-version=2 --backend=native exec ./___main_go -- 
Task: 9731
Task: 9731
Task: 9731
API server listening at: 127.0.0.1:59115

This is the result on a system where the race is lost:

-> ~/go/bin/dlv --listen=localhost:59115 --headless=true --api-version=2 --backend=native exec ./___main_go -- 
Task: 8707
Task: 10499
Task: 10499
could not launch process: could not get thread count

In this latter case, task 8707 is the parent task. The child task of 10499 was desired and hence the error.

This code change checks to make sure the returned task is not that of the parent. If it is, it retries. It's possible other macOS reported Delve issues are the result of this failed race.

* proc: correct formatting
2018-02-07 10:25:34 -08:00
..
exc_user_darwin.c proc: refactoring: split backends to separate packages 2017-04-21 14:00:04 -07:00
exc.h proc: refactoring: split backends to separate packages 2017-04-21 14:00:04 -07:00
exec_darwin.c proc: refactoring: split backends to separate packages 2017-04-21 14:00:04 -07:00
exec_darwin.h proc: refactoring: split backends to separate packages 2017-04-21 14:00:04 -07:00
mach_exc_user_darwin.c proc: refactoring: split backends to separate packages 2017-04-21 14:00:04 -07:00
mach_exc.defs proc: refactoring: split backends to separate packages 2017-04-21 14:00:04 -07:00
mach_exc.h proc: refactoring: split backends to separate packages 2017-04-21 14:00:04 -07:00
proc_darwin.c proc: refactoring: split backends to separate packages 2017-04-21 14:00:04 -07:00
proc_darwin.go proc: Handle race between fork and task_for_pid (#1117) 2018-02-07 10:25:34 -08:00
proc_darwin.h proc: refactoring: split backends to separate packages 2017-04-21 14:00:04 -07:00
proc_linux.go proc: next should not skip lines with conditional bps 2017-11-20 11:25:35 -08:00
proc_windows.go proc: next should not skip lines with conditional bps 2017-11-20 11:25:35 -08:00
proc.go proc: next should not skip lines with conditional bps 2017-11-20 11:25:35 -08:00
ptrace_darwin.go proc: refactoring: split backends to separate packages 2017-04-21 14:00:04 -07:00
ptrace_linux.go proc/native/linux: ignore ENODEV when retrieving fp registers 2017-11-21 11:48:39 -08:00
registers_darwin_amd64.go proc: refactoring: merge target into proc 2017-04-21 14:00:04 -07:00
registers_linux_amd64.go proc/native/linux: ignore ENODEV when retrieving fp registers 2017-11-21 11:48:39 -08:00
registers_windows_amd64.go proc: refactoring: merge target into proc 2017-04-21 14:00:04 -07:00
syscall_windows_amd64.go proc: refactoring: split backends to separate packages 2017-04-21 14:00:04 -07:00
syscall_windows.go proc: refactoring: split backends to separate packages 2017-04-21 14:00:04 -07:00
threads_darwin.c proc: refactoring: split backends to separate packages 2017-04-21 14:00:04 -07:00
threads_darwin.go proc/native: error when reading/writing memory of exited process (#812) 2017-05-01 09:57:37 -07:00
threads_darwin.h proc: refactoring: split backends to separate packages 2017-04-21 14:00:04 -07:00
threads_linux.go proc/native/linux: call waitFast instead of wait in addThread and halt (#855) 2017-05-30 11:08:27 -07:00
threads_windows.go proc/native: error when reading/writing memory of exited process (#812) 2017-05-01 09:57:37 -07:00
threads.go proc: next should not skip lines with conditional bps 2017-11-20 11:25:35 -08:00
zsyscall_windows.go proc: refactoring: split backends to separate packages 2017-04-21 14:00:04 -07:00