delve/pkg/proc
aarzilli f32ce1b21d proc/native: fix race condition between Halt and process death (linux)
If a breakpoint is hit close to process death on a thread that isn't
the group leader the process could die while we are trying to stop it.

This can be easily reproduced by having the goroutine that's executing
main.main (which will almost always run on the thread group leader)
wait for a second goroutine before exiting, then setting a breakpoint
on the second goroutine and stepping through it (see TestIssue1101 in
proc_test.go).

When stepping over the return instruction of main.f the deferred
wg.Done() call will be executed which will cause the main goroutine to
resume and proceed to exit. Both the temporary breakpoint on wg.Done
and the temporary breakpoint on the return address of main.f will be in
close proximity to main.main calling os.Exit() and causing the death of
the thread group leader.

Under these circumstances the call to native.(*Thread).waitFast in
native.(*Thread).halt can hang forever due to a bug similar to
https://sourceware.org/bugzilla/show_bug.cgi?id=12702 (see comment in
native.(*Thread).wait for an explanation).

Replacing waitFast with a normal wait work in most circumstances,
however, besides the performance hit, it looks like in this
circumstances trapWait sometimes receives a spurious SIGTRAP on the
dying group leader which would cause the subsequent call to wait in
halt to accidentally reap the process without noting that it did exit.

Instead this patch removes the call to wait from halt and instead calls
trapWait in a loop in setCurrentBreakpoints until all threads are set
to running=false. This is also a better fix than the workaround to
ESRCH error while setting current breakpoints implemented in 94b50d.

Fixes #1101
2018-03-06 09:06:19 -08:00
..
core dwarf/reader,proc: support DW_AT_abstract_origin (#1111) 2018-02-13 09:20:45 -08:00
gdbserial proc: rename ManualStopRequested to CheckAndClearManualStopRequest (#1119) 2018-02-09 11:42:45 -08:00
native proc/native: fix race condition between Halt and process death (linux) 2018-03-06 09:06:19 -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 dwarf/reader,proc: support DW_AT_abstract_origin (#1111) 2018-02-13 09:20:45 -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: rename ManualStopRequested to CheckAndClearManualStopRequest (#1119) 2018-02-09 11:42:45 -08:00
mem.go proc: disable caching for variables with an extended location 2018-01-31 06:39:44 -08:00
moduledata.go dwarf/reader,proc: support DW_AT_abstract_origin (#1111) 2018-02-13 09:20:45 -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/native: fix race condition between Halt and process death (linux) 2018-03-06 09:06:19 -08:00
proc_unix_test.go Fix various issues detected by megacheck (#880) 2017-06-29 11:15:59 -07:00
proc.go dwarf/reader,proc: support DW_AT_abstract_origin (#1111) 2018-02-13 09:20:45 -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 dwarf/reader,proc: support DW_AT_abstract_origin (#1111) 2018-02-13 09:20:45 -08:00
types.go proc: support interface type resolution for packages containing a dot 2018-03-05 10:07:11 -08:00
variable_test.go pkg/proc: Fix reporting of 'go' statement (#1136) 2018-03-05 10:40:42 +01:00
variables.go pkg/proc: Fix reporting of 'go' statement (#1136) 2018-03-05 10:40:42 +01:00