Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        private Dictionary <DocumentId, List <(MethodId, int)> > GroupLineDeltasByDocument(SymUnmanagedLineDelta[] lineDeltas, int lineDeltaCount)
        {
            var methodMap        = GetMethodMap();
            var deltasByDocument = new Dictionary <DocumentId, List <(MethodId, int)> >();

            for (int i = 0; i < lineDeltaCount; i++)
            {
                int methodToken = lineDeltas[i].MethodToken;
                if (!TryGetDebuggableMethod(methodToken, out var pdbReader, out var handle))
                {
                    continue;
                }

                var methodId = MethodId.FromToken(methodToken);
                var(single, multiple) = MethodExtents.GetMethodBodyDocuments(pdbReader.MetadataReader, handle);
                if (!single.IsNil)
                {
                    AddExtentForDocument(single);
                }
                else
                {
                    // method has debug info:
                    Debug.Assert(multiple != null);

                    foreach (var documentHandle in multiple)
                    {
                        AddExtentForDocument(documentHandle);
                    }
                }

                void AddExtentForDocument(DocumentHandle documentHandle)
                {
                    var documentId = pdbReader.GetDocumentId(documentHandle);

                    if (!deltasByDocument.TryGetValue(documentId, out var extents))
                    {
                        deltasByDocument.Add(documentId, extents = new List <(MethodId, int)>());
                    }

                    extents.Add((methodId, lineDeltas[i].Delta));
                }
            }