Пример #1
0
        private void CreateClient(IDebugClient client)
        {
            DebuggerInterface = client;

            _spaces    = (IDebugDataSpaces)DebuggerInterface;
            _spacesPtr = (IDebugDataSpacesPtr)DebuggerInterface;
            _symbols   = (IDebugSymbols)DebuggerInterface;
            _control   = (IDebugControl2)DebuggerInterface;

            // These interfaces may not be present in older DbgEng dlls.
            _spaces2        = DebuggerInterface as IDebugDataSpaces2;
            _symbols3       = DebuggerInterface as IDebugSymbols3;
            _advanced       = DebuggerInterface as IDebugAdvanced;
            _systemObjects  = DebuggerInterface as IDebugSystemObjects;
            _systemObjects3 = DebuggerInterface as IDebugSystemObjects3;

            Interlocked.Increment(ref s_totalInstanceCount);

            if (_systemObjects3 == null && s_totalInstanceCount > 1)
            {
                throw new ClrDiagnosticsException("This version of DbgEng is too old to create multiple instances of DataTarget.", ClrDiagnosticsExceptionKind.DebuggerError);
            }

            if (_systemObjects3 != null)
            {
                _systemObjects3.GetCurrentSystemId(out _instance);
            }
        }
        protected uint SetCurrentThreadId(uint engineThreadId, IDebugAdvanced debugClient)
        {
            IDebugSystemObjects sytemObject = ((IDebugSystemObjects)debugClient);
            uint set_h_result = (uint)sytemObject.SetCurrentThreadId(engineThreadId);

            if (set_h_result == DbgEng.E_NOINTERFACE)
            {
                throw new InvalidOperationException("No thread with the specified ID was found.");
            }
            return set_h_result;
        }
        public override bool SetThreadContext(ThreadInfo threadInfo, IDebugAdvanced debugClient, IDataReader dataReader)
        {
            bool result = false;
            var plat = dataReader.GetArchitecture();

            if (plat == Architecture.Amd64)
            {
                throw new InvalidOperationException("Unexpected architecture.");
            }

            byte[] contextBytes = new byte[GetThreadContextSize(dataReader)];

            if (SetCurrentThreadId(threadInfo.EngineThreadId, debugClient) == DbgEng.S_OK)
            {
                var gch = GCHandle.Alloc(contextBytes, GCHandleType.Pinned);

                var h_result = ((IDebugAdvanced)debugClient).GetThreadContext(gch.AddrOfPinnedObject(), (uint)contextBytes.Length);

                if (h_result == DbgEng.S_OK)
                {
                    try
                    {
                        var structure = Marshal.PtrToStructure<CONTEXT_X86>(gch.AddrOfPinnedObject());
                        threadInfo.ContextStruct = new Model.UnifiedThreadContext(structure, threadInfo);
                        result = true;
                    }
                    finally
                    {
                        gch.Free();
                    }
                }

            }

            return result;
        }
 public abstract bool SetThreadContext(ThreadInfo threadInfo, IDebugAdvanced debugClient, IDataReader dataReader);
Пример #5
0
        private void CreateClient(IDebugClient client)
        {
            _client = client;

            _spaces = (IDebugDataSpaces)_client;
            _spacesPtr = (IDebugDataSpacesPtr)_client;
            _symbols = (IDebugSymbols)_client;
            _control = (IDebugControl2)_client;

            // These interfaces may not be present in older DbgEng dlls.
            _spaces2 = _client as IDebugDataSpaces2;
            _symbols3 = _client as IDebugSymbols3;
            _advanced = _client as IDebugAdvanced;
            _systemObjects = _client as IDebugSystemObjects;
            _systemObjects3 = _client as IDebugSystemObjects3;

            Interlocked.Increment(ref s_totalInstanceCount);

            if (_systemObjects3 == null && s_totalInstanceCount > 1)
                throw new ClrDiagnosticsException("This version of DbgEng is too old to create multiple instances of DataTarget.", ClrDiagnosticsException.HR.DebuggerError);

            if (_systemObjects3 != null)
                _systemObjects3.GetCurrentSystemId(out _instance);
        }