delve/pkg/proc
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
..
core core_test: fix TestCoreFpRegisters on go1.9 (#1082) 2018-01-24 11:42:35 -08:00
gdbserial gdbserial: fix rr output parsing to support rr 5.1.0 2018-01-27 12:13:04 -08:00
native proc: Handle race between fork and task_for_pid (#1117) 2018-02-07 10:25:34 -08:00
test cmd, proc/test: disable optimizations on the C compiler 2017-11-28 11:00:53 -08:00
arch.go proc: support cgo stacktraces 2017-11-28 11:00:53 -08:00
bininfo.go pkg/terminal: print DWARF location expression with whatis 2017-12-20 16:34:47 -08:00
breakpoints.go proc: next should not skip lines with conditional bps 2017-11-20 11:25:35 -08:00
disasm_amd64.go pkg/proc: fix StepBreakpoint handling 2017-11-21 00:40:26 -08:00
disasm.go pkg/proc: fix StepBreakpoint handling 2017-11-21 00:40:26 -08:00
doc.go Move top-level packages into pkg 2017-02-08 12:17:19 -08:00
dwarf_expr_test.go proc: disable caching for variables with an extended location 2018-01-31 06:39:44 -08:00
eval.go pkg/proc: use constants to describe variable value 2017-12-13 12:18:18 -08:00
interface.go proc: breakpoints refactoring 2017-11-20 11:25:35 -08:00
mem.go proc: disable caching for variables with an extended location 2018-01-31 06:39:44 -08:00
moduledata.go pkg/proc: use constants to describe variable value 2017-12-13 12:18:18 -08:00
proc_general_test.go proc: refactoring: split backends to separate packages 2017-04-21 14:00:04 -07:00
proc_test.go proc: Remove unused code 2018-01-26 12:58:21 -08:00
proc_unix_test.go Fix various issues detected by megacheck (#880) 2017-06-29 11:15:59 -07:00
proc.go proc: Remove unused code 2018-01-26 12:58:21 -08:00
registers_amd64.go pkg/proc, pkg/dwarf/op: support DW_OP_piece, DW_OP_regX, DW_OP_fbreg 2017-11-21 11:51:02 -08:00
registers.go proc: refactor stack.go to use DWARF registers 2017-11-17 10:17:24 -08:00
scope_test.go proc_test: clean some repeated patterns in proc_test 2018-01-26 12:58:21 -08:00
stack.go proc: Remove unused code 2018-01-26 12:58:21 -08:00
threads.go proc: check error accessing g.m.curg in GetG 2018-01-03 10:03:05 -08:00
types.go proc, terminal: use DW_AT_producer to warn user about optimized code 2017-12-13 12:18:18 -08:00
variables.go proc: disable caching for variables with an extended location 2018-01-31 06:39:44 -08:00