未验证 提交 0ae77bd6 编写于 作者: N nd 提交者: GitHub

Don't call suspend on DbgUiRemoteBreakin threads (#2281)

Sometimes it makes debuggee to hang.

Should fix #2244
上级 7dcd7b4d
......@@ -85,9 +85,11 @@ func initialize(dbp *nativeProcess) error {
// Suspend all threads so that the call to _ContinueDebugEvent will
// not resume the target.
for _, thread := range dbp.threads {
_, err := _SuspendThread(thread.os.hThread)
if err != nil {
return err
if !thread.os.dbgUiRemoteBreakIn {
_, err := _SuspendThread(thread.os.hThread)
if err != nil {
return err
}
}
}
......@@ -195,7 +197,7 @@ func (dbp *nativeProcess) updateThreadList() error {
return nil
}
func (dbp *nativeProcess) addThread(hThread syscall.Handle, threadID int, attach, suspendNewThreads bool) (*nativeThread, error) {
func (dbp *nativeProcess) addThread(hThread syscall.Handle, threadID int, attach, suspendNewThreads bool, dbgUiRemoteBreakIn bool) (*nativeThread, error) {
if thread, ok := dbp.threads[threadID]; ok {
return thread, nil
}
......@@ -204,12 +206,13 @@ func (dbp *nativeProcess) addThread(hThread syscall.Handle, threadID int, attach
dbp: dbp,
os: new(osSpecificDetails),
}
thread.os.dbgUiRemoteBreakIn = dbgUiRemoteBreakIn
thread.os.hThread = hThread
dbp.threads[threadID] = thread
if dbp.memthread == nil {
dbp.memthread = dbp.threads[threadID]
}
if suspendNewThreads {
if suspendNewThreads && !dbgUiRemoteBreakIn {
_, err := _SuspendThread(thread.os.hThread)
if err != nil {
return nil, err
......@@ -261,14 +264,16 @@ func (dbp *nativeProcess) waitForDebugEvent(flags waitForDebugEventFlags) (threa
}
dbp.os.entryPoint = uint64(debugInfo.BaseOfImage)
dbp.os.hProcess = debugInfo.Process
_, err = dbp.addThread(debugInfo.Thread, int(debugEvent.ThreadId), false, flags&waitSuspendNewThreads != 0)
_, err = dbp.addThread(debugInfo.Thread, int(debugEvent.ThreadId), false,
flags&waitSuspendNewThreads != 0, debugInfo.StartAddress == dbgUiRemoteBreakin.Addr())
if err != nil {
return 0, 0, err
}
break
case _CREATE_THREAD_DEBUG_EVENT:
debugInfo := (*_CREATE_THREAD_DEBUG_INFO)(unionPtr)
_, err = dbp.addThread(debugInfo.Thread, int(debugEvent.ThreadId), false, flags&waitSuspendNewThreads != 0)
_, err = dbp.addThread(debugInfo.Thread, int(debugEvent.ThreadId), false,
flags&waitSuspendNewThreads != 0, debugInfo.StartAddress == dbgUiRemoteBreakin.Addr())
if err != nil {
return 0, 0, err
}
......@@ -430,9 +435,11 @@ func (dbp *nativeProcess) stop(trapthread *nativeThread) (*nativeThread, error)
}
for _, thread := range dbp.threads {
_, err := _SuspendThread(thread.os.hThread)
if err != nil {
return nil, err
if !thread.os.dbgUiRemoteBreakIn {
_, err := _SuspendThread(thread.os.hThread)
if err != nil {
return nil, err
}
}
}
......
......@@ -16,7 +16,8 @@ type waitStatus sys.WaitStatus
// osSpecificDetails holds information specific to the Windows
// operating system / kernel.
type osSpecificDetails struct {
hThread syscall.Handle
hThread syscall.Handle
dbgUiRemoteBreakIn bool // whether thread is an auxiliary DbgUiRemoteBreakIn thread created by Windows
}
func (t *nativeThread) singleStep() error {
......@@ -77,9 +78,11 @@ func (t *nativeThread) singleStep() error {
}
for i := 0; i < suspendcnt; i++ {
_, err = _SuspendThread(t.os.hThread)
if err != nil {
return err
if !t.os.dbgUiRemoteBreakIn {
_, err = _SuspendThread(t.os.hThread)
if err != nil {
return err
}
}
}
......
......@@ -14,6 +14,7 @@ var (
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
procNtQueryInformationThread = modntdll.NewProc("NtQueryInformationThread")
dbgUiRemoteBreakin = modntdll.NewProc("DbgUiRemoteBreakin")
procGetThreadContext = modkernel32.NewProc("GetThreadContext")
procSetThreadContext = modkernel32.NewProc("SetThreadContext")
procSuspendThread = modkernel32.NewProc("SuspendThread")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册