Exemple #1
0
        public int GetDocuments(
            int bufferLength,
            out int count,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] ISymUnmanagedDocument[] documents)
        {
            count = MetadataReader.Documents.Count;

            if (bufferLength == 0)
            {
                return(HResult.S_OK);
            }

            int i = 0;

            foreach (var documentHandle in MetadataReader.Documents)
            {
                if (i >= bufferLength)
                {
                    break;
                }

                documents[i++] = new SymDocument(this, documentHandle);
            }

            return(HResult.S_OK);
        }
Exemple #2
0
        public int GetDocument(
            [MarshalAs(UnmanagedType.LPWStr)] string url,
            Guid language,
            Guid languageVendor,
            Guid documentType,
            [MarshalAs(UnmanagedType.Interface)] out ISymUnmanagedDocument document)
        {
            DocumentHandle documentHandle;

            // SymReader: language, vendor and type parameters are ignored.

            if (_pdbReader.IsDisposed)
            {
                throw new ObjectDisposedException(nameof(SymReader));
            }

            if (_lazyDocumentMap.Value.TryGetDocument(url, out documentHandle))
            {
                document = new SymDocument(this, documentHandle);
                return(HResult.S_OK);
            }

            document = null;
            return(HResult.S_FALSE);
        }
Exemple #3
0
        /// <summary>
        /// Get a list of all documents, including those added via EnC.
        /// </summary>
        public int GetDocuments(
            int bufferLength,
            out int count,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] ISymUnmanagedDocument[] documents)
        {
            DocumentMap       documentMapOpt = null;
            PortablePdbReader pdbReaderOpt   = null;

            if (Version > 1)
            {
                documentMapOpt = GetDocumentMap();
                count          = documentMapOpt.DocumentCount;
            }
            else
            {
                pdbReaderOpt = GetReader(version: 1);
                count        = pdbReaderOpt.MetadataReader.Documents.Count;
            }

            if (bufferLength == 0)
            {
                return(HResult.S_OK);
            }

            if (documents == null)
            {
                count = 0;
                return(HResult.E_INVALIDARG);
            }

            int i = 0;

            if (documentMapOpt != null)
            {
                foreach (var info in documentMapOpt.Infos)
                {
                    if (i >= bufferLength)
                    {
                        break;
                    }

                    documents[i++] = new SymDocument(GetReader(info.Version), info.Handle);
                }
            }
            else
            {
                foreach (var documentHandle in pdbReaderOpt.MetadataReader.Documents)
                {
                    if (i >= bufferLength)
                    {
                        break;
                    }

                    documents[i++] = new SymDocument(pdbReaderOpt, documentHandle);
                }
            }

            return(HResult.S_OK);
        }
Exemple #4
0
        /// <summary>
        /// Get the documents this method has lines in.
        /// </summary>
        public int GetDocumentsForMethod(
            int bufferLength,
            out int count,
            [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] ISymUnmanagedDocument[] documents)
        {
            if (documents == null)
            {
                count = 0;
                return(HResult.E_INVALIDARG);
            }

            var(single, multiple) = MethodExtents.GetMethodBodyDocuments(MetadataReader, DebugHandle);
            if (!single.IsNil)
            {
                count = 1;

                if (documents.Length < 1)
                {
                    return(HResult.E_INVALIDARG);
                }

                documents[0] = new SymDocument(PdbReader, single);
                return(HResult.S_OK);
            }

            // SymMethod w/o debug info wouldn't be created:
            Debug.Assert(multiple != null);

            // Methods don't usually span too many documents, so it's ok to use linear search.
            var uniqueHandles = new List <DocumentHandle>();

            foreach (var documentHandle in multiple)
            {
                if (!uniqueHandles.Contains(documentHandle))
                {
                    uniqueHandles.Add(documentHandle);
                }
            }

            count = uniqueHandles.Count;

            if (documents.Length < uniqueHandles.Count)
            {
                return(HResult.E_INVALIDARG);
            }

            for (int i = 0; i < uniqueHandles.Count; i++)
            {
                documents[i] = new SymDocument(PdbReader, uniqueHandles[i]);
            }

            return(HResult.S_OK);
        }
Exemple #5
0
        /// <summary>
        /// Finds document of a specified name.
        /// </summary>
        /// <param name="url">Document name.</param>
        /// <param name="language">Ignored.</param>
        /// <param name="languageVendor">Ignored.</param>
        /// <param name="documentType">Ignored.</param>
        /// <param name="document">Document or null.</param>
        /// <returns>
        /// S_OK if found, S_FALSE if not found.
        /// </returns>
        /// <remarks>
        /// EnC: Returns document in the first generation that defines one with matching name,
        /// even if the document is not referred to by any sequence point anymore
        /// (e.g. the statement was removed by a subsequent edit).
        /// </remarks>
        public int GetDocument(
            [MarshalAs(UnmanagedType.LPWStr)] string url,
            Guid language,
            Guid languageVendor,
            Guid documentType,
            [MarshalAs(UnmanagedType.Interface)] out ISymUnmanagedDocument document)
        {
            var map = GetDocumentMap();

            if (map.TryGetDocument(url, out var documentId))
            {
                var info = map.GetInfo(documentId);
                document = new SymDocument(GetReader(info.Version), info.Handle);
                return(HResult.S_OK);
            }

            document = null;
            return(HResult.S_FALSE);
        }
Exemple #6
0
        public int GetDocument(
            [MarshalAs(UnmanagedType.LPWStr)]string url,
            Guid language,          
            Guid languageVendor,    
            Guid documentType,      
            [MarshalAs(UnmanagedType.Interface)]out ISymUnmanagedDocument document)
        {
            DocumentHandle documentHandle;

            // SymReader: language, vendor and type parameters are ignored.

            if (_lazyDocumentMap.Value.TryGetDocument(url, out documentHandle))
            {
                document = new SymDocument(this, documentHandle);
                return HResult.S_OK;
            }

            document = null;
            return HResult.S_FALSE;
        }
Exemple #7
0
        public int GetSequencePoints(
            int bufferLength,
            out int count,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] int[] offsets,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] ISymUnmanagedDocument[] documents,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] int[] startLines,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] int[] startColumns,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] int[] endLines,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] int[] endColumns)
        {
            SymDocument currentDocument = null;

            if ((startLines == null && endLines == null) || !SymReader.TryGetLineDeltas(GetId(), out var deltas))
            {
                deltas = default(MethodLineDeltas);
            }

            int i = 0;

            foreach (var sp in GetSequencePoints())
            {
                if (bufferLength != 0 && i >= bufferLength)
                {
                    break;
                }

                int delta = sp.IsHidden ? 0 : deltas.GetDeltaForSequencePoint(i);

                if (offsets != null)
                {
                    offsets[i] = sp.Offset;
                }

                if (startLines != null)
                {
                    startLines[i] = sp.StartLine + delta;
                }

                if (startColumns != null)
                {
                    startColumns[i] = sp.StartColumn;
                }

                if (endLines != null)
                {
                    endLines[i] = sp.EndLine + delta;
                }

                if (endColumns != null)
                {
                    endColumns[i] = sp.EndColumn;
                }

                if (documents != null)
                {
                    if (currentDocument == null || currentDocument.Handle != sp.Document)
                    {
                        currentDocument = new SymDocument(PdbReader, sp.Document);
                    }

                    documents[i] = currentDocument;
                }

                i++;
            }

            count = i;
            return(HResult.S_OK);
        }
Exemple #8
0
        public int GetSequencePoints(
            int bufferLength,
            out int count,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] int[] offsets,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] ISymUnmanagedDocument[] documents,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] int[] startLines,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] int[] startColumns,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] int[] endLines,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] int[] endColumns)
        {
            SymDocument currentDocument = null;
            var         spReader        = GetSequencePointEnumerator();

            int i = 0;

            while (spReader.MoveNext())
            {
                if (bufferLength != 0 && i >= bufferLength)
                {
                    break;
                }

                var sp = spReader.Current;

                if (offsets != null)
                {
                    offsets[i] = sp.Offset;
                }

                if (startLines != null)
                {
                    startLines[i] = sp.StartLine;
                }

                if (startColumns != null)
                {
                    startColumns[i] = sp.StartColumn;
                }

                if (endLines != null)
                {
                    endLines[i] = sp.EndLine;
                }

                if (endColumns != null)
                {
                    endColumns[i] = sp.EndColumn;
                }

                if (documents != null)
                {
                    if (currentDocument == null || currentDocument.Handle != sp.Document)
                    {
                        currentDocument = new SymDocument(SymReader, sp.Document);
                    }

                    documents[i] = currentDocument;
                }

                i++;
            }

            count = i;
            return(HResult.S_OK);
        }
Exemple #9
0
        public int GetDocuments(
            int bufferLength, 
            out int count, 
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out]ISymUnmanagedDocument[] documents)
        {
            count = MetadataReader.Documents.Count;

            if (bufferLength == 0)
            {
                return HResult.S_OK;
            }

            int i = 0;
            foreach (var documentHandle in MetadataReader.Documents)
            {
                if (i >= bufferLength)
                {
                    break;
                }

                documents[i++] = new SymDocument(this, documentHandle);
            }

            return HResult.S_OK;
        }
Exemple #10
0
        public int GetSequencePoints(
            int bufferLength,
            out int count,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] int[] offsets,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] ISymUnmanagedDocument[] documents,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] int[] startLines,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] int[] startColumns,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] int[] endLines,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] int[] endColumns)
        {
            // TODO: cache

            var mdReader = _symReader.MetadataReader;

            var body     = mdReader.GetMethodBody(_handle);
            var spReader = mdReader.GetSequencePointsReader(body.SequencePoints);

            SymDocument currentDocument = null;

            int i = 0;

            while (spReader.MoveNext())
            {
                if (bufferLength != 0 && i >= bufferLength)
                {
                    break;
                }

                var sp = spReader.Current;

                if (offsets != null)
                {
                    offsets[i] = sp.Offset;
                }

                if (startLines != null)
                {
                    startLines[i] = sp.StartLine;
                }

                if (startColumns != null)
                {
                    startColumns[i] = sp.StartColumn;
                }

                if (endLines != null)
                {
                    endLines[i] = sp.EndLine;
                }

                if (endColumns != null)
                {
                    endColumns[i] = sp.EndColumn;
                }

                if (documents != null)
                {
                    if (currentDocument == null || currentDocument.Handle != sp.Document)
                    {
                        currentDocument = new SymDocument(_symReader, sp.Document);
                    }

                    documents[i] = currentDocument;
                }

                i++;
            }

            count = i;
            return(HResult.S_OK);
        }