Beispiel #1
0
 public void Clone(out IStream ppstm) => ppstm = new DataReaderIStream(dataReaderFactory, reader, name);
Beispiel #2
0
        public static SymbolReader Create(PdbReaderContext pdbContext, MD.Metadata metadata, DataReaderFactory pdbStream)
        {
            ISymUnmanagedReader  unmanagedReader = null;
            SymbolReaderImpl     symReader       = null;
            ReaderMetaDataImport mdImporter      = null;
            DataReaderIStream    comPdbStream    = null;
            bool error = true;

            try {
                if (pdbStream is null)
                {
                    return(null);
                }
                var debugDir = pdbContext.CodeViewDebugDirectory;
                if (debugDir is null)
                {
                    return(null);
                }
                if (!pdbContext.TryGetCodeViewData(out var pdbGuid, out uint age))
                {
                    return(null);
                }

                unmanagedReader = CreateSymUnmanagedReader(pdbContext.Options);
                if (unmanagedReader is null)
                {
                    return(null);
                }

                mdImporter   = new ReaderMetaDataImport(metadata);
                comPdbStream = new DataReaderIStream(pdbStream);
                int hr = unmanagedReader.Initialize(mdImporter, null, null, comPdbStream);
                if (hr < 0)
                {
                    return(null);
                }

                symReader = new SymbolReaderImpl(unmanagedReader, new object[] { pdbStream, mdImporter, comPdbStream });
                if (!symReader.MatchesModule(pdbGuid, debugDir.TimeDateStamp, age))
                {
                    return(null);
                }

                error = false;
                return(symReader);
            }
            catch (IOException) {
            }
            catch (InvalidCastException) {
            }
            catch (COMException) {
            }
            finally {
                if (error)
                {
                    pdbStream?.Dispose();
                    symReader?.Dispose();
                    mdImporter?.Dispose();
                    comPdbStream?.Dispose();
                    (unmanagedReader as ISymUnmanagedDispose)?.Destroy();
                }
            }
            return(null);
        }