Ejemplo n.º 1
0
        /// <summary>
        /// Waits for a debug event from any of the processes in the wait set.
        /// </summary>
        /// <param name="timeout">timeout in milliseconds to wait. If 0, checks for a debug event and returns immediately</param>
        /// <returns>Null if no event is available</returns>
        /// <remarks>Debug events should be continued by calling ContinueEvent. The debuggee is completely stopped when a
        /// debug event is dispatched and until it is continued.</remarks>
        public NativeEvent WaitForDebugEvent(int timeout)
        {
            EnsureIsOnWin32EventThread();
            bool fHasEvent;

            if (IntPtr.Size == sizeof(Int32))
            {
                DebugEvent32 event32 = new DebugEvent32();
                fHasEvent = NativeMethods.WaitForDebugEvent32(ref event32, timeout);
                if (fHasEvent)
                {
                    return(NativeEvent.Build(this, ref event32.header, ref event32.union));
                }
            }
            else
            {
                DebugEvent64 event64 = new DebugEvent64();
                fHasEvent = NativeMethods.WaitForDebugEvent64(ref event64, timeout);
                if (fHasEvent)
                {
                    return(NativeEvent.Build(this, ref event64.header, ref event64.union));
                }
            }

            // Not having an event could be a timeout, or it could be a real failure.
            // Empirically, timeout produces GetLastError()=121 (ERROR_SEM_TIMEOUT), but MSDN doesn't spec that, so
            // we don't want to rely on it. So if we don't have an event, just return NULL and
            // don't try to probe any further.
            return(null);
        }
Ejemplo n.º 2
0
            private static bool WaitForDebugEvent(ref dynamic debugEvent32Or64, int dwMilliseconds)
            {
                bool is64BitProcess = (IntPtr.Size == 8);

                if (is64BitProcess)
                {
                    var debugEvent64 = new DebugEvent64();
                    if (!NativeDebuggingMethods.WaitForDebugEvent64(ref debugEvent64, dwMilliseconds))
                    {
                        return(false);
                    }
                    debugEvent32Or64 = debugEvent64;
                }
                else
                {
                    var debugEvent32 = new DebugEvent32();
                    if (!NativeDebuggingMethods.WaitForDebugEvent32(ref debugEvent32, dwMilliseconds))
                    {
                        return(false);
                    }
                    debugEvent32Or64 = debugEvent32;
                }
                return(true);
            }