Example #1
0
        public IList <ModuleInfo> EnumerateModules()
        {
            if (_modules != null)
            {
                return(_modules);
            }

            List <ModuleInfo> modules = new List <ModuleInfo>();

            foreach (var mod in _dumpReader.EnumerateModules())
            {
                var raw = mod.Raw;

                ModuleInfo module = new ModuleInfo(this);
                module.FileName  = mod.FullName;
                module.ImageBase = raw.BaseOfImage;
                module.FileSize  = raw.SizeOfImage;
                module.TimeStamp = raw.TimeDateStamp;

                module.Version = GetVersionInfo(mod);
                modules.Add(module);
            }

            _modules = modules;
            return(modules);
        }
Example #2
0
        public IList <ModuleInfo> EnumerateModules()
        {
            if (_modules != null)
            {
                return(_modules);
            }

            List <ModuleInfo> modules = new List <ModuleInfo>();

            foreach (DumpModule mod in _dumpReader.EnumerateModules())
            {
                MINIDUMP_MODULE raw = mod.Raw;

                ModuleInfo module = new ModuleInfo(this)
                {
                    FileName  = mod.FullName,
                    ImageBase = raw.BaseOfImage,
                    FileSize  = raw.SizeOfImage,
                    TimeStamp = raw.TimeDateStamp,
                    Version   = GetVersionInfo(mod)
                };

                modules.Add(module);
            }

            _modules = modules;
            return(modules);
        }
Example #3
0
        public static ICorDebugProcess GetDebuggerHandleFromProcessDump(string processDumpFile, long clrInstanceId = 0)
        {
            LibraryProvider libraryProvider = new LibraryProvider();

            using (DumpReader reader = new DumpReader(processDumpFile))
            {
                if ((IntPtr.Size == 8) && (reader.ProcessorArchitecture == ProcessorArchitecture.PROCESSOR_ARCHITECTURE_INTEL))
                {
                    throw new InvalidOperationException("Opening a 32 bit dump in a 64 bit process.");
                }
                if ((IntPtr.Size == 4) && (reader.ProcessorArchitecture == ProcessorArchitecture.PROCESSOR_ARCHITECTURE_AMD64))
                {
                    throw new InvalidOperationException("Opening a 64 bit dump in a 32 bit process.");
                }
                using (DumpDataTarget target = new DumpDataTarget(reader))
                {
                    foreach (DumpModule module in reader.EnumerateModules())
                    {
                        if ((clrInstanceId == 0) || (clrInstanceId == (long)module.BaseAddress))
                        {
                            Version version;
                            ClrDebuggingProcessFlags flags;
                            ICorDebugProcess         process;
                            int errorCode = new CLRDebugging().TryOpenVirtualProcess(
                                module.BaseAddress, target, libraryProvider, new Version(4, 0, 0x7fff, 0x7fff), out version, out flags, out process);
                            if (errorCode < 0)
                            {
                                if (((errorCode != -2146231228) && (errorCode != -2146231226)) && (errorCode != -2146231225))
                                {
                                    Marshal.ThrowExceptionForHR(errorCode);
                                }
                            }
                            else
                            {
                                return(process);
                            }
                        }
                    }
                }
            }
            throw new InvalidOperationException("No V4.0 .NET Runtime found in dump file.");
        }
Example #4
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");
        }