提交 78c79927 编写于 作者: A aarzilli

proc: bugfix: [OS X] desync of mach message queue in Continue

上级 b21686e6
......@@ -388,13 +388,8 @@ func (dbp *Process) Continue() error {
return dbp.exitGuard(err)
}
dbp.SwitchThread(thread.Id)
for _, th := range dbp.Threads {
if th.CurrentBreakpoint == nil {
err := th.SetCurrentBreakpoint()
if err != nil {
return err
}
}
if err := dbp.setExtraBreakpoints(); err != nil {
return err
}
loc, err := thread.Location()
if err != nil {
......
......@@ -110,7 +110,7 @@ thread_count(task_t task) {
}
mach_port_t
mach_port_wait(mach_port_t port_set) {
mach_port_wait(mach_port_t port_set, int nonblocking) {
kern_return_t kret;
thread_act_t thread;
NDR_record_t *ndr;
......@@ -120,9 +120,13 @@ mach_port_wait(mach_port_t port_set) {
mach_msg_header_t hdr;
char data[256];
} msg;
mach_msg_option_t opts = MACH_RCV_MSG|MACH_RCV_INTERRUPT;
if (nonblocking) {
opts |= MACH_RCV_TIMEOUT;
}
// Wait for mach msg.
kret = mach_msg(&msg.hdr, MACH_RCV_MSG|MACH_RCV_INTERRUPT,
kret = mach_msg(&msg.hdr, opts,
0, sizeof(msg.data), port_set, 0, MACH_PORT_NULL);
if (kret == MACH_RCV_INTERRUPTED) return kret;
if (kret != MACH_MSG_SUCCESS) return 0;
......@@ -142,7 +146,7 @@ mach_port_wait(mach_port_t port_set) {
if (data[2] == EXC_SOFT_SIGNAL) {
if (data[3] != SIGTRAP) {
if (thread_resume(thread) != KERN_SUCCESS) return 0;
return mach_port_wait(port_set);
return mach_port_wait(port_set, nonblocking);
}
}
return thread;
......
......@@ -111,7 +111,7 @@ func (dbp *Process) Kill() (err error) {
}
}
for {
port := C.mach_port_wait(dbp.os.portSet)
port := C.mach_port_wait(dbp.os.portSet, C.int(0))
if port == dbp.os.notificationPort {
break
}
......@@ -268,7 +268,7 @@ func (dbp *Process) findExecutable(path string) (*macho.File, error) {
func (dbp *Process) trapWait(pid int) (*Thread, error) {
for {
port := C.mach_port_wait(dbp.os.portSet)
port := C.mach_port_wait(dbp.os.portSet, C.int(0))
switch port {
case dbp.os.notificationPort:
......@@ -318,6 +318,21 @@ func (dbp *Process) trapWait(pid int) (*Thread, error) {
}
}
func (dbp *Process) setExtraBreakpoints() error {
for {
port := C.mach_port_wait(dbp.os.portSet, C.int(1))
if port == 0 {
return nil
}
if th, ok := dbp.Threads[int(port)]; ok {
err := th.SetCurrentBreakpoint()
if err != nil {
return err
}
}
}
}
func (dbp *Process) loadProcessInformation(wg *sync.WaitGroup) {
wg.Done()
}
......
......@@ -36,7 +36,7 @@ int
thread_count(task_t task);
mach_port_t
mach_port_wait(mach_port_t);
mach_port_wait(mach_port_t, int);
kern_return_t
mach_send_reply(mach_msg_header_t);
......
......@@ -378,6 +378,18 @@ func (dbp *Process) wait(pid, options int) (int, *sys.WaitStatus, error) {
}
}
func (dbp *Process) setExtraBreakpoints() error {
for _, th := range dbp.Threads {
if th.CurrentBreakpoint == nil {
err := th.SetCurrentBreakpoint()
if err != nil {
return err
}
}
}
return nil
}
func (dbp *Process) exitGuard(err error) error {
if err != sys.ESRCH {
return err
......
......@@ -31,7 +31,7 @@ func (t *Thread) singleStep() error {
return fmt.Errorf("could not single step")
}
for {
port := C.mach_port_wait(t.dbp.os.portSet)
port := C.mach_port_wait(t.dbp.os.portSet, C.int(0))
if port == C.mach_port_t(t.Id) {
break
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册