Пример #1
0
        public static ICorDebugProcess CreateICorDebugProcess(ulong baseAddress, ICorDebugDataTarget dataTarget, ICLRDebuggingLibraryProvider libraryProvider)
        {
            Debug.Assert(baseAddress != 0);

            Version version;
            ClrDebuggingProcessFlags flags;
            ICorDebugProcess         process;
            int errorCode = new CLRDebugging().TryOpenVirtualProcess(
                baseAddress,
                dataTarget,
                libraryProvider,
                new Version(4, 6, 0x7fff, 0x7fff),
                out version,
                out flags,
                out process);

            if (errorCode < 0)
            {
                if (errorCode != -2146231228 && errorCode != -2146231226 && errorCode != -2146231225)
                {
                    Marshal.ThrowExceptionForHR(errorCode);
                }

                process = null;
            }

            return(process);
        }
Пример #2
0
        /// <summary>
        /// Detects if a native module represents a CLR and if so provides the debugging interface
        /// and versioning information
        /// </summary>
        /// <param name="moduleBaseAddress">The native base address of a module which might be a CLR</param>
        /// <param name="dataTarget">The process abstraction which can be used for inspection</param>
        /// <param name="libraryProvider">A callback interface for locating version specific debug libraries
        /// such as mscordbi.dll and mscordacwks.dll</param>
        /// <param name="maxDebuggerSupportedVersion">The highest version of the CLR/debugging libraries which
        /// the caller can support</param>
        /// <param name="version">The version of the CLR detected or null if no CLR was detected</param>
        /// <param name="flags">Flags which have additional information about the CLR.
        /// See ClrDebuggingProcessFlags for more details</param>
        /// <returns>The CLR's debugging interface</returns>
        public ICorDebugProcess OpenVirtualProcess(ulong moduleBaseAddress,
                                                   ICorDebugDataTarget dataTarget,
                                                   ICLRDebuggingLibraryProvider libraryProvider,
                                                   Version maxDebuggerSupportedVersion,
                                                   out Version version,
                                                   out ClrDebuggingProcessFlags flags)
        {
            ICorDebugProcess process;
            int hr = TryOpenVirtualProcess(moduleBaseAddress, dataTarget, libraryProvider, maxDebuggerSupportedVersion, out version, out flags, out process);

            if (hr < 0)
            {
                throw new COMException("Failed to OpenVirtualProcess for module at " + moduleBaseAddress + ".", hr);
            }
            return(process);
        }
Пример #3
0
        /// <summary>
        /// Version of the above that doesn't throw exceptions on failure
        /// </summary>
        public int TryOpenVirtualProcess(
            ulong moduleBaseAddress,
            ICorDebugDataTarget dataTarget,
            ICLRDebuggingLibraryProvider libraryProvider,
            Version maxDebuggerSupportedVersion,
            out Version version,
            out ClrDebuggingProcessFlags flags,
            out ICorDebugProcess process)
        {
            ClrDebuggingVersion maxSupport = new ClrDebuggingVersion();
            ClrDebuggingVersion clrVersion = new ClrDebuggingVersion();

            maxSupport.StructVersion = 0;
            maxSupport.Major         = (short)maxDebuggerSupportedVersion.Major;
            maxSupport.Minor         = (short)maxDebuggerSupportedVersion.Minor;
            maxSupport.Build         = (short)maxDebuggerSupportedVersion.Build;
            maxSupport.Revision      = (short)maxDebuggerSupportedVersion.Revision;
            object processIface = null;

            clrVersion.StructVersion = 0;
            Guid iid = typeof(ICorDebugProcess).GetGuid();

            int result = _clrDebugging.OpenVirtualProcess(
                moduleBaseAddress,
                dataTarget,
                libraryProvider,
                ref maxSupport,
                ref iid,
                out processIface,
                ref clrVersion,
                out flags);

            // This may be set regardless of success/failure
            version = new Version(clrVersion.Major, clrVersion.Minor, clrVersion.Build, clrVersion.Revision);

            if (result < 0)
            {
                // OpenVirtualProcess failed
                process = null;
                return(result);
            }

            // Success
            process = (ICorDebugProcess)processIface;
            return(0);
        }
Пример #4
0
        public static ICorDebugProcess CreateICorDebugProcess(ulong baseAddress, ICorDebugDataTarget dataTarget, ICLRDebuggingLibraryProvider libraryProvider)
        {
            Debug.Assert(baseAddress != 0);
            
            Version version;
            ClrDebuggingProcessFlags flags;
            ICorDebugProcess process;
            int errorCode = new CLRDebugging().TryOpenVirtualProcess(baseAddress, dataTarget, libraryProvider, new Version(4, 6, 0x7fff, 0x7fff), out version, out flags, out process);
            if (errorCode < 0)
            {
                if (((errorCode != -2146231228) && (errorCode != -2146231226)) && (errorCode != -2146231225))
                {
                    Marshal.ThrowExceptionForHR(errorCode);
                }

                process = null;
            }
            
            return process;
        }
Пример #5
0
 public CorProcess OpenVirtualProcess(ulong moduleBaseAddress,
     ICorDebugDataTarget dataTarget,
     ICLRDebuggingLibraryProvider libraryProvider,
     Version maxDebuggerSupportedVersion,
     out Version version,
     out ClrDebuggingProcessFlags flags)
 {
     CorProcess process;
     int hr = TryOpenVirtualProcess(moduleBaseAddress, dataTarget, libraryProvider, maxDebuggerSupportedVersion, out version, out flags, out process);
     if (hr < 0)
         throw new COMException("Failed to OpenVirtualProcess for module at " + moduleBaseAddress + ".", hr);
     return process;
 }
Пример #6
0
        public int TryOpenVirtualProcess(ulong moduleBaseAddress,
            ICorDebugDataTarget dataTarget,
            ICLRDebuggingLibraryProvider libraryProvider,
            Version maxDebuggerSupportedVersion,
            out Version version,
            out ClrDebuggingProcessFlags flags,
            out CorProcess process)
        {
            ClrDebuggingVersion maxSupport = new ClrDebuggingVersion();
            ClrDebuggingVersion clrVersion = new ClrDebuggingVersion();
            maxSupport.StructVersion = 0;
            maxSupport.Major = (short)maxDebuggerSupportedVersion.Major;
            maxSupport.Minor = (short)maxDebuggerSupportedVersion.Minor;
            maxSupport.Build = (short)maxDebuggerSupportedVersion.Build;
            maxSupport.Revision = (short)maxDebuggerSupportedVersion.Revision;
            object processIface = null;
            clrVersion.StructVersion = 0;
            Guid iid = typeof(ICorDebugProcess).GUID;

            int result = m_CLRDebugging.OpenVirtualProcess(moduleBaseAddress, dataTarget, libraryProvider,
                ref maxSupport, ref iid, out processIface, ref clrVersion, out flags);

            // This may be set regardless of success/failure
            version = new Version(clrVersion.Major, clrVersion.Minor, clrVersion.Build, clrVersion.Revision);

            if (result < 0)
            {
                // OpenVirtualProcess failed
                process = null;
                return result;
            }

            // Success
            process = CorProcess.GetCorProcess((ICorDebugProcess)processIface);
            return 0;
        }
Пример #7
0
        /// <summary>
        /// Attaches the process to a dump using the specified DumpDataTarget
        /// </summary>
        /// <param name="dumpReader">A reader for the dump</param>
        /// <param name="clrInstanceId">The moduleBaseAddress of the CLR to debug or null
        /// to debug the first CLR encountered</param>
        public void AttachToDump(DumpReader dumpReader, long? clrInstanceId, ICorDebugDataTarget dataTarget)
        {
            Debug.Assert(!IsAlive);

            if (IsAlive)
                throw new InvalidOperationException("cannot call Attach on active process");

            // set up the stopGo controller
            NoninvasiveStopGoController stopGo = new NoninvasiveStopGoController();
            stopGo.Init(this);
            m_stopGo = stopGo;
            NativeProcessCreated();

            foreach (DumpModule module in dumpReader.EnumerateModules())
            {
                // use the selected runtime if there was one, otherwise just attach to the first
                // runtime we find
                if (clrInstanceId.HasValue && (clrInstanceId.Value != (long)module.BaseAddress))
                    continue;

                CLRDebugging clrDebugging = new CLRDebugging();
                Version actualVersion;
                ClrDebuggingProcessFlags flags;
                CorProcess proc;
                int hr = clrDebugging.TryOpenVirtualProcess(module.BaseAddress, dataTarget, LibraryProvider,
                    new Version(4, 0, short.MaxValue, short.MaxValue), out actualVersion, out flags, out proc);

                if (hr < 0)
                {
                    if ((hr == (int)HResult.CORDBG_E_NOT_CLR) ||
                       (hr == (int)HResult.CORDBG_E_UNSUPPORTED_DEBUGGING_MODEL) ||
                       (hr == (int)HResult.CORDBG_E_UNSUPPORTED_FORWARD_COMPAT))
                    {
                        // these errors are all potentially benign, just ignore this module.
                    }
                    else
                    {
                        Marshal.ThrowExceptionForHR(hr); // the rest are bad
                    }
                }
                else
                {
                    // We must have succeeded
                    Debug.Assert(proc != null);
                    BindToExistingClrInTarget(proc);
                    m_dumpReader = dumpReader;
                    return; // SUCCESS - done
                }
            }

            // If we've got here, it means there were no supported CLRs in the dump
            Debug.Assert(m_corProcess == null); // Should not yet be bound
            throw new MDbgException("Failed to open the dump - no supported CLRs found in the module list");
        }