コード例 #1
0
        public DbgEngDataReader(int pid, bool invasive, uint msecTimeout)
        {
            IntPtr client = CreateIDebugClient();
            CreateClient(client);

            DebugAttach attach = invasive ? DebugAttach.Default : DebugAttach.NonInvasive;
            _control.AddEngineOptions(DebugControl.INITIAL_BREAK);

            int hr = _client.AttachProcess((uint)pid, attach);

            if (hr == 0)
                hr = _control.WaitForEvent(msecTimeout) ? 0 : -1;

            if (hr == 1)
            {
                throw new TimeoutException("Break in did not occur within the allotted timeout.");
            }

            if (hr != 0)
            {
                if ((uint)hr == 0xd00000bb)
                    throw new InvalidOperationException("Mismatched architecture between this process and the target process.");

                throw new ClrDiagnosticsException($"Could not attach to process {pid:X}, HRESULT: 0x{hr:x8}", ClrDiagnosticsExceptionKind.DebuggerError, hr);
            }
        }
コード例 #2
0
ファイル: DbgEngDataReader.cs プロジェクト: tomasdeml/clrmd
        public DbgEngDataReader(int processId, bool invasive, uint msecTimeout)
        {
            DisplayName = $"{processId:x}";

            IntPtr client = CreateIDebugClient();

            CreateClient(client);

            DebugAttach attach = invasive ? DebugAttach.Default : DebugAttach.NonInvasive;

            _control.AddEngineOptions(DebugControl.INITIAL_BREAK);

            HResult hr = _client.AttachProcess((uint)processId, attach);

            if (hr)
            {
                hr = _control.WaitForEvent(msecTimeout);
            }

            if (hr == HResult.S_FALSE)
            {
                throw new TimeoutException("Break in did not occur within the allotted timeout.");
            }

            if (hr != 0)
            {
                if ((uint)hr.Value == 0xd00000bb)
                {
                    throw new InvalidOperationException("Mismatched architecture between this process and the target process.");
                }

                if (!WindowsFunctions.IsProcessRunning(processId))
                {
                    throw new ArgumentException($"Process {processId} is not running.");
                }

                throw new ArgumentException($"Could not attach to process {processId}, HRESULT: 0x{hr:x}");
            }
        }