示例#1
0
        public unsafe int GetReaderForFile(
            [MarshalAs(UnmanagedType.Interface)] object importer,
            [MarshalAs(UnmanagedType.LPWStr)] string fileName,
            [MarshalAs(UnmanagedType.LPWStr)] string searchPath,
            [MarshalAs(UnmanagedType.Interface)] out ISymUnmanagedReader reader)
        {
            if (importer == null || string.IsNullOrEmpty(fileName))
            {
                reader = null;
                return(HResult.E_INVALIDARG);
            }

            var metadataImport = importer as IMetadataImport;

            if (metadataImport == null)
            {
                reader = null;
                return(HResult.E_FAIL);
            }

            byte[] bytes;
            try
            {
                // TODO: use memory mapped files?
                bytes = PortableShim.File.ReadAllBytes(fileName);
            }
            catch
            {
                reader = null;
                return(HResult.E_INVALIDARG);
            }

            reader = new SymReader(new PortablePdbReader(bytes, bytes.Length, metadataImport));
            return(HResult.S_OK);
        }
示例#2
0
        public int GetReaderFromStream(
            [MarshalAs(UnmanagedType.Interface)] object importer,
            [MarshalAs(UnmanagedType.Interface)] object stream,
            [MarshalAs(UnmanagedType.Interface)] out ISymUnmanagedReader reader)
        {
            if (importer == null || stream == null)
            {
                reader = null;
                return(HResult.E_INVALIDARG);
            }

            var metadataImport = importer as IMetadataImport;

            if (metadataImport == null)
            {
                reader = null;
                return(HResult.E_FAIL);
            }

            byte[] bytes;
            int    size;

            ReadAllBytes((IStream)stream, out bytes, out size);

            // TODO: use IUnsafeComStream (ComMemoryStream in tests)?

            reader = new SymReader(new PortablePdbReader(bytes, size, metadataImport));
            return(HResult.S_OK);
        }
示例#3
0
        public unsafe int GetReaderForFile(
            [MarshalAs(UnmanagedType.Interface)]object importer, 
            [MarshalAs(UnmanagedType.LPWStr)]string fileName,
            [MarshalAs(UnmanagedType.LPWStr)]string searchPath,
            [MarshalAs(UnmanagedType.Interface)]out ISymUnmanagedReader reader)
        {
            if (importer == null || string.IsNullOrEmpty(fileName))
            {
                reader = null;
                return HResult.E_INVALIDARG;
            }

            var metadataImport = importer as IMetadataImport;
            if (metadataImport == null)
            {
                reader = null;
                return HResult.E_FAIL;
            }

            byte[] bytes;
            try
            {
                // TODO: use memory mapped files?
                bytes = PortableShim.File.ReadAllBytes(fileName);
            }
            catch
            {
                reader = null;
                return HResult.E_INVALIDARG;
            }

            reader = new SymReader(new PortablePdbReader(bytes, bytes.Length, metadataImport));
            return HResult.S_OK;
        }
示例#4
0
        private bool TryCreateReaderForMatchingPdb(
            string pdbFilePath,
            Guid guid,
            uint stamp,
            int age,
            LazyMetadataImport metadataImport,
            out ISymUnmanagedReader reader)
        {
            try
            {
                if (PortableShim.File.Exists(pdbFilePath))
                {
                    var symReader = SymReader.CreateFromFile(pdbFilePath, metadataImport);
                    reader = symReader;
                    return(symReader.PdbReader.MatchesModule(guid, stamp, age));
                }
            }
            catch
            {
                // nop
            }

            reader = null;
            return(false);
        }
示例#5
0
        public int GetReaderFromStream(
            [MarshalAs(UnmanagedType.Interface)]object importer,
            [MarshalAs(UnmanagedType.Interface)]object stream,
            [MarshalAs(UnmanagedType.Interface)]out ISymUnmanagedReader reader)
        {
            if (importer == null || stream == null)
            {
                reader = null;
                return HResult.E_INVALIDARG;
            }

            var metadataImport = importer as IMetadataImport;
            if (metadataImport == null)
            {
                reader = null;
                return HResult.E_FAIL;
            }

            byte[] bytes;
            int size;
            ReadAllBytes((IStream)stream, out bytes, out size);

            // TODO: use IUnsafeComStream (ComMemoryStream in tests)?

            reader = new SymReader(new PortablePdbReader(bytes, size, metadataImport));
            return HResult.S_OK;
        }
示例#6
0
        public int GetReaderForFile(
            [MarshalAs(UnmanagedType.Interface)] object importer,
            [MarshalAs(UnmanagedType.LPWStr)] string fileName,
            [MarshalAs(UnmanagedType.LPWStr)] string searchPath,
            [MarshalAs(UnmanagedType.Interface)] out ISymUnmanagedReader reader)
        {
            var pdbReader = new PortablePdbReader(File.OpenRead(fileName), importer);

            reader = new SymReader(pdbReader);
            return(HResult.S_OK);
        }
示例#7
0
        public int GetReaderFromPdbFile(
            [MarshalAs(UnmanagedType.Interface)] IMetadataImportProvider metadataImportProvider,
            [MarshalAs(UnmanagedType.LPWStr)] string pdbFilePath,
            [MarshalAs(UnmanagedType.Interface)] out ISymUnmanagedReader reader)
        {
            if (metadataImportProvider == null || string.IsNullOrEmpty(pdbFilePath))
            {
                reader = null;
                return(HResult.E_INVALIDARG);
            }

            reader = SymReader.CreateFromFile(pdbFilePath, new LazyMetadataImport(metadataImportProvider));
            return(HResult.S_OK);
        }
示例#8
0
        internal void Update(SymReader symReader, MetadataReader reader, int version, out ImmutableArray <MethodId> handleToIdMap)
        {
            if (_lazyInfos == null)
            {
                _lazyInfos = new List <MethodInfo>();

                foreach (var handle in symReader.GetReader(version: 1).MetadataReader.MethodDebugInformation)
                {
                    _lazyInfos.Add(new MethodInfo(handle, version: 1));
                }
            }

            handleToIdMap = CreateHandleToIdMap(reader, _lazyInfos, version);
        }
示例#9
0
        /// <summary>
        /// Get the line information associated with <paramref name="offset"/>.
        /// </summary>
        /// <remarks>
        /// If <paramref name="offset"/> is not a sequence point it is associated with the previous one.
        /// <paramref name="sequencePointOffset"/> provides the associated sequence point.
        /// </remarks>
        public int GetLineFromOffset(
            int offset,
            out int startLine,
            out int startColumn,
            out int endLine,
            out int endColumn,
            out int sequencePointOffset)
        {
            if (offset < 0)
            {
                offset = int.MaxValue;
            }

            var candidate      = default(SequencePoint);
            int candidateIndex = -1;

            int sequencePointIndex = 0;

            foreach (var sp in GetSequencePoints())
            {
                if (sp.Offset <= offset)
                {
                    candidate      = sp;
                    candidateIndex = sequencePointIndex;
                }
                else if (sp.Offset > offset)
                {
                    break;
                }

                sequencePointIndex++;
            }

            if (candidateIndex < 0)
            {
                startLine = startColumn = endLine = endColumn = sequencePointOffset = 0;
                return(HResult.E_FAIL);
            }

            int delta = !candidate.IsHidden && SymReader.TryGetLineDeltas(GetId(), out var deltas) ?
                        deltas.GetDeltaForSequencePoint(candidateIndex) : 0;

            startLine           = candidate.StartLine + delta;
            startColumn         = candidate.StartColumn;
            endLine             = candidate.EndLine + delta;
            endColumn           = candidate.EndColumn;
            sequencePointOffset = candidate.Offset;
            return(HResult.S_OK);
        }
示例#10
0
        public int GetReaderFromPdbStream(
            [MarshalAs(UnmanagedType.Interface)] IMetadataImportProvider metadataImportProvider,
            [MarshalAs(UnmanagedType.Interface)] object stream,
            [MarshalAs(UnmanagedType.Interface)] out ISymUnmanagedReader reader)
        {
            IStream comStream = stream as IStream;

            if (metadataImportProvider == null || comStream == null)
            {
                reader = null;
                return(HResult.E_INVALIDARG);
            }

            reader = SymReader.CreateFromStream(comStream, new LazyMetadataImport(metadataImportProvider));
            return(HResult.S_OK);
        }
示例#11
0
        public int GetReaderFromPdbStream(
            [MarshalAs(UnmanagedType.Interface)] IMetadataImportProvider metadataImportProvider,
            [MarshalAs(UnmanagedType.Interface)] object stream,
            [MarshalAs(UnmanagedType.Interface)] out ISymUnmanagedReader reader)
        {
            var comStream = stream as IStream ??
                            throw new ArgumentException(null, nameof(stream));

            if (metadataImportProvider == null)
            {
                throw new ArgumentException(null, nameof(metadataImportProvider));
            }

            reader = SymReader.CreateFromStream(comStream, new LazyMetadataImport(metadataImportProvider));
            return(HResult.S_OK);
        }
示例#12
0
        public int GetReaderFromPdbFile(
            [MarshalAs(UnmanagedType.Interface)] IMetadataImportProvider metadataImportProvider,
            [MarshalAs(UnmanagedType.LPWStr)] string pdbFilePath,
            [MarshalAs(UnmanagedType.Interface)] out ISymUnmanagedReader reader)
        {
            if (metadataImportProvider == null)
            {
                throw new ArgumentException(null, nameof(metadataImportProvider));
            }

            if (string.IsNullOrEmpty(pdbFilePath))
            {
                throw new ArgumentException(null, nameof(pdbFilePath));
            }

            reader = SymReader.CreateFromFile(pdbFilePath, new LazyMetadataImport(metadataImportProvider));
            return(HResult.S_OK);
        }
示例#13
0
        public int GetReaderFromStream(
            [MarshalAs(UnmanagedType.Interface)] object metadataImport,
            [MarshalAs(UnmanagedType.Interface)] object stream,
            [MarshalAs(UnmanagedType.Interface)] out ISymUnmanagedReader reader)
        {
            reader = null;

            try
            {
                var comStream = stream as IStream ?? throw new ArgumentNullException(null, nameof(stream));
                var mdImport  = MetadataImport.FromObject(metadataImport) ?? throw new ArgumentException(null, nameof(metadataImport));

                reader = SymReader.CreateFromStream(comStream, new LazyMetadataImport(mdImport));
                return(HResult.S_OK);
            }
            finally
            {
                InteropUtilities.TransferOwnershipOrRelease(ref metadataImport, reader);
            }
        }
示例#14
0
        internal int GetMethodSourceExtentInDocument(ISymUnmanagedDocument document, SymMethod method, out int startLine, out int endLine)
        {
            var symDocument = SymReader.AsSymDocument(document);

            if (symDocument == null)
            {
                startLine = endLine = 0;
                return(HResult.E_INVALIDARG);
            }

            var methodExtents = SymReader.GetMethodExtents();

            if (!methodExtents.TryGetMethodSourceExtent(symDocument.GetId(), method.GetId(), out startLine, out endLine))
            {
                startLine = endLine = 0;
                return(HResult.E_FAIL);
            }

            return(HResult.S_OK);
        }
示例#15
0
        private bool TryCreateReaderForMatchingPdb(
            string pdbFilePath,
            Guid guid,
            uint stamp,
            int age,
            LazyMetadataImport metadataImport,
            out ISymUnmanagedReader reader)
        {
            if (PortableShim.File.Exists(pdbFilePath))
            {
                SymReader symReader;
                try
                {
                    symReader = SymReader.CreateFromFile(pdbFilePath, metadataImport);
                }
                catch
                {
                    reader = null;
                    return(false);
                }

                try
                {
                    if (symReader.PdbReader.MatchesModule(guid, stamp, age))
                    {
                        reader    = symReader;
                        symReader = null;
                        return(true);
                    }
                }
                finally
                {
                    symReader?.Destroy();
                }
            }

            reader = null;
            return(false);
        }
示例#16
0
        private bool TryCreateReaderForMatchingPdb(
            string pdbFilePath,
            Guid guid,
            uint stamp,
            int age,
            LazyMetadataImport metadataImport,
            out ISymUnmanagedReader reader)
        {
            if (PortableShim.File.Exists(pdbFilePath))
            {
                PortablePdbReader pdbReader;
                try
                {
                    pdbReader = new PortablePdbReader(SymReader.CreateProviderFromFile(pdbFilePath), version: 1, previousDocumentCount: 0);
                }
                catch
                {
                    reader = null;
                    return(false);
                }

                try
                {
                    if (pdbReader.MatchesModule(guid, stamp, age))
                    {
                        reader    = new SymReader(pdbReader, metadataImport);
                        pdbReader = null;
                        return(true);
                    }
                }
                finally
                {
                    pdbReader?.Dispose();
                }
            }

            reader = null;
            return(false);
        }
示例#17
0
        public int GetReaderFromStream(
            [MarshalAs(UnmanagedType.Interface)] object metadataImport,
            [MarshalAs(UnmanagedType.Interface)] object stream,
            [MarshalAs(UnmanagedType.Interface)] out ISymUnmanagedReader reader)
        {
            reader = null;

            try
            {
                IStream comStream = stream as IStream;
                var     mdImport  = metadataImport as IMetadataImport;
                if (mdImport == null || comStream == null)
                {
                    return(HResult.E_INVALIDARG);
                }

                reader = SymReader.CreateFromStream(comStream, new LazyMetadataImport(mdImport));
                return(HResult.S_OK);
            }
            finally
            {
                InteropUtilities.TransferOwnershipOrRelease(ref metadataImport, reader);
            }
        }
示例#18
0
 internal SymMethod(SymReader symReader, MethodDebugInformationHandle handle)
 {
     Debug.Assert(symReader != null);
     SymReader   = symReader;
     DebugHandle = handle;
 }
示例#19
0
 internal SymConstant(SymReader symReader, LocalConstantHandle handle)
 {
     Debug.Assert(symReader != null);
     _symReader = symReader;
     _handle    = handle;
 }
示例#20
0
 internal SymConstant(SymReader symReader, LocalConstantHandle handle)
 {
     Debug.Assert(symReader != null);
     _symReader = symReader;
     _handle = handle;
 }
示例#21
0
 /// <summary>
 /// Get the smallest start line and largest end line, for the method, in a specific document.
 /// </summary>
 public int GetSourceExtentInDocument(ISymUnmanagedDocument document, out int startLine, out int endLine)
 {
     return(SymReader.GetMethodSourceExtentInDocument(document, this, out startLine, out endLine));
 }
示例#22
0
 internal SymMethod(SymReader symReader, MethodDefinitionHandle handle)
 {
     Debug.Assert(symReader != null);
     _symReader = symReader;
     _handle    = handle;
 }
示例#23
0
 internal SymDocument(SymReader symReader, DocumentHandle documentHandle)
 {
     Debug.Assert(symReader != null);
     _symReader = symReader;
     _handle = documentHandle;
 }
示例#24
0
 internal SymDocument(SymReader symReader, DocumentHandle documentHandle)
 {
     Debug.Assert(symReader != null);
     SymReader = symReader;
     Handle    = documentHandle;
 }
示例#25
0
 internal SymMethod(SymReader symReader, MethodBodyHandle handle)
 {
     Debug.Assert(symReader != null);
     SymReader  = symReader;
     BodyHandle = handle;
 }