/// <summary> /// Dispose method. /// </summary> public void Dispose() { // Clear any cached objects. _disposing = true; AcquireWriteLock(); _info = null; _memoryChunks = null; _mappedFileMemory = null; // All resources are backed by safe-handles, so we don't need a finalizer. if (_fileMapping != null) { _fileMapping.Close(); } if (_view != null) { _view.Close(); } if (_file != null) { _file.Dispose(); } }
/// <summary> /// Constructor /// </summary> /// <param name="path">filename to open dump file</param> public DumpReader(string path) { _file = File.OpenRead(path); long length = _file.Length; // The dump file may be many megabytes large, so we don't want to // read it all at once. Instead, doing a mapping. _fileMapping = CreateFileMapping(_file.SafeFileHandle, IntPtr.Zero, PageProtection.Readonly, 0, 0, null); if (_fileMapping.IsInvalid) { int error = Marshal.GetHRForLastWin32Error(); Marshal.ThrowExceptionForHR(error, new IntPtr(-1)); } _view = MapViewOfFile(_fileMapping, WindowsFunctions.NativeMethods.FILE_MAP_READ, 0, 0, IntPtr.Zero); if (_view.IsInvalid) { int error = Marshal.GetHRForLastWin32Error(); Marshal.ThrowExceptionForHR(error, new IntPtr(-1)); } _base = DumpPointer.DangerousMakeDumpPointer(_view.BaseAddress, (uint)length); // // Cache stuff // DumpPointer pStream; // System info. pStream = GetStream(MINIDUMP_STREAM_TYPE.SystemInfoStream); _info = pStream.PtrToStructure <MINIDUMP_SYSTEM_INFO>(); // Memory64ListStream is present in MinidumpWithFullMemory. if (TryGetStream(MINIDUMP_STREAM_TYPE.Memory64ListStream, out pStream)) { _memoryChunks = new MinidumpMemoryChunks(pStream, MINIDUMP_STREAM_TYPE.Memory64ListStream); } else { // MiniDumpNormal doesn't have a Memory64ListStream, it has a MemoryListStream. pStream = GetStream(MINIDUMP_STREAM_TYPE.MemoryListStream); _memoryChunks = new MinidumpMemoryChunks(pStream, MINIDUMP_STREAM_TYPE.MemoryListStream); } _mappedFileMemory = new LoadedFileMemoryLookups(); IsMinidump = DumpNative.IsMiniDump(_view.BaseAddress); }