
Fix signal handling during thread single stepping so that signals that are generated by executing the current instruction are immediately propagated to the inferior, while signals other signals sent to the thread are delayed until the full resume happens. Fixes a bug where a breakpoint set on an instruction that causes a SIGSEGV would make Delve hang and a bug where signals received during single step would make it look like an instruction is executed twice. Fixes #2801 Fixes #2792
36 lines
811 B
Go
36 lines
811 B
Go
package native
|
|
|
|
import (
|
|
"syscall"
|
|
|
|
sys "golang.org/x/sys/unix"
|
|
)
|
|
|
|
// ptraceAttach executes the sys.PtraceAttach call.
|
|
func ptraceAttach(pid int) error {
|
|
return sys.PtraceAttach(pid)
|
|
}
|
|
|
|
// ptraceDetach calls ptrace(PTRACE_DETACH).
|
|
func ptraceDetach(tid, sig int) error {
|
|
_, _, err := sys.Syscall6(sys.SYS_PTRACE, sys.PTRACE_DETACH, uintptr(tid), 1, uintptr(sig), 0, 0)
|
|
if err != syscall.Errno(0) {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ptraceCont executes ptrace PTRACE_CONT
|
|
func ptraceCont(tid, sig int) error {
|
|
return sys.PtraceCont(tid, sig)
|
|
}
|
|
|
|
// ptraceSingleStep executes ptrace PTRACE_SINGLESTEP
|
|
func ptraceSingleStep(pid, sig int) error {
|
|
_, _, e1 := sys.Syscall6(sys.SYS_PTRACE, uintptr(sys.PTRACE_SINGLESTEP), uintptr(pid), uintptr(0), uintptr(sig), 0, 0)
|
|
if e1 != 0 {
|
|
return e1
|
|
}
|
|
return nil
|
|
}
|