Beispiel #1
0
        private bool TryGetDebuggableMethod(int methodToken, out PortablePdbReader pdbReader, out MethodDebugInformationHandle handle)
        {
            if (!MetadataUtilities.IsMethodToken(methodToken))
            {
                pdbReader = null;
                handle    = default(MethodDebugInformationHandle);
                return(false);
            }

            var methodId = MethodId.FromToken(methodToken);

            if (Version == 1)
            {
                pdbReader = GetReader(version: 1);
                if (pdbReader.TryGetMethodHandle(methodId, out handle))
                {
                    return(pdbReader.HasDebugInfo(handle));
                }
            }
            else
            {
                var methodMap = GetMethodMap();
                if (methodMap.IsValidMethodRowId(methodId.Value))
                {
                    var info = methodMap.GetInfo(methodId);
                    pdbReader = GetReader(info.Version);
                    handle    = info.Handle;
                    return(pdbReader.HasDebugInfo(handle));
                }
            }

            pdbReader = null;
            handle    = default(MethodDebugInformationHandle);
            return(false);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        internal void Update(PortablePdbReader pdbReader, MethodDebugInformationHandle methodHandle, ImmutableArray <int> deltas, int expectedSequencePointCount)
        {
            var newExtentsByDocument = GroupExtentsByDocument(GetMethodExtents(pdbReader, methodHandle, deltas, expectedSequencePointCount));

            foreach (var(documentId, newExtents) in newExtentsByDocument)
            {
                // we only created extents for a single methods and all extents of a single method within document were merged into one:
                _extentsByDocument[documentId] = UpdateExtent(_extentsByDocument[documentId], newExtents.Single());
            }
        }
Beispiel #4
0
        // Takes ownership of <paramref name="pdbReader"/>.
        internal SymReader(PortablePdbReader pdbReader)
        {
            Debug.Assert(pdbReader != null);

            _pdbReader = pdbReader;
            _version   = 1;

            _lazyDocumentMap = new Lazy <DocumentMap>(() => new DocumentMap(MetadataReader));
            _lazyVbSemantics = new Lazy <bool>(() => IsVisualBasicAssembly());
        }
Beispiel #5
0
        /// <summary>
        /// Creates <see cref="SymReader"/>.
        /// </summary>
        /// <param name="pdbReader"></param>
        /// <remarks>
        /// Takes ownership of <paramref name="pdbReader"/>.
        /// </remarks>
        public SymReader(PortablePdbReader pdbReader)
        {
            Debug.Assert(pdbReader != null);

            _pdbReader = pdbReader;
            _version = 1;

            _lazyDocumentMap = new Lazy<DocumentMap>(() => new DocumentMap(MetadataReader));
            _lazyVbSemantics = new Lazy<bool>(() => IsVisualBasicAssembly());
        }
Beispiel #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);
        }
Beispiel #7
0
        /// Takes ownership of <paramref name="pdbReader"/> and <paramref name="metadataImport"/>.
        internal SymReader(PortablePdbReader pdbReader, LazyMetadataImport metadataImport)
        {
            Debug.Assert(pdbReader != null);
            Debug.Assert(metadataImport != null);

            pdbReader.SymReader = this;
            _pdbReaders         = new List <PortablePdbReader>()
            {
                pdbReader
            };

            _metadataImport    = metadataImport;
            _lazyDocumentMap   = new Lazy <DocumentMap>(() => new DocumentMap(_pdbReaders[0].MetadataReader));
            _methodMap         = new Lazy <MethodMap>(() => new MethodMap(_pdbReaders[0]));
            _lazyMethodExtents = new Lazy <MethodExtents>(() => new MethodExtents(_pdbReaders[0]));
            _lazyVbSemantics   = new Lazy <bool>(() => IsVisualBasicAssembly());
        }
Beispiel #8
0
        private int UpdateSymbolStoreImpl(
            IStream stream,
            string fileName,
            SymUnmanagedLineDelta[] lineDeltas,
            int lineDeltaCount)
        {
            Debug.Assert(stream != null ^ fileName != null);
            Debug.Assert(lineDeltas != null);
            Debug.Assert(lineDeltaCount >= 0);

            lineDeltaCount = Math.Min(lineDeltas.Length, lineDeltaCount);
            var methodMap     = GetMethodMap();
            var documentMap   = GetDocumentMap();
            var methodExtents = GetMethodExtents();

            var lineDeltasByDocument = GroupLineDeltasByDocument(lineDeltas, lineDeltaCount);

            int newVersion = Version + 1;

            var provider = (stream != null) ? CreateProviderFromStream(stream) : CreateProviderFromFile(fileName);

            var pdbReader = new PortablePdbReader(provider, newVersion, documentMap.DocumentCount);

            documentMap.Update(this, pdbReader.MetadataReader, newVersion, out var documentHandleToIdMap);
            methodMap.Update(this, pdbReader.MetadataReader, newVersion, out var methodHandleToIdMap);
            pdbReader.InitializeHandleToIdMaps(documentHandleToIdMap, methodHandleToIdMap);
            methodExtents.Update(pdbReader, lineDeltasByDocument);

            // remove line deltas of methods updated in this generation:
            for (int i = 0; i < methodHandleToIdMap.Length; i++)
            {
                RemoveLineDeltas(methodHandleToIdMap[i]);
            }

            // apply line deltas of methods moved around in this generation:
            for (int i = 0; i < lineDeltaCount; i++)
            {
                UpdateLineDeltas(MethodId.FromToken(lineDeltas[i].MethodToken), new MethodLineDeltas(lineDeltas[i].Delta, ImmutableArray <int> .Empty));
            }

            _pdbReaders.Add(pdbReader);
            pdbReader.SymReader = this;

            return(HResult.S_OK);
        }
        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);
        }
Beispiel #10
0
 internal void Update(PortablePdbReader pdbReader, Dictionary <DocumentId, List <(MethodId, int)> > lineDeltasByDocument)
Beispiel #11
0
 public MethodExtents(PortablePdbReader pdbReader)
 {
     _extentsByDocument = GroupExtentsByDocument(GetMethodExtents(pdbReader));
 }
Beispiel #12
0
 internal SymMethod(PortablePdbReader pdbReader, MethodDebugInformationHandle handle)
 {
     Debug.Assert(pdbReader != null);
     PdbReader   = pdbReader;
     DebugHandle = handle;
 }
Beispiel #13
0
 internal SymConstant(PortablePdbReader pdbReader, LocalConstantHandle handle)
 {
     Debug.Assert(pdbReader != null);
     _pdbReader = pdbReader;
     _handle    = handle;
 }
Beispiel #14
0
 internal SymDocument(PortablePdbReader pdbReader, DocumentHandle documentHandle)
 {
     Debug.Assert(pdbReader != null);
     PdbReader = pdbReader;
     Handle    = documentHandle;
 }
Beispiel #15
0
 public MethodMap(PortablePdbReader pdbReader)
 {
     _baselineMethodCount = pdbReader.MetadataReader.MethodDebugInformation.Count;
 }