示例#1
0
        public SequencePoint(
            DebugSourceDocument document,
            int offset,
            int startLine,
            int startColumn,
            int endLine,
            int endColumn)
        {
            Debug.Assert(document != null);

            Offset = offset;
            StartLine = startLine;
            StartColumn = startColumn;
            EndLine = endLine;
            EndColumn = endColumn;
            Document = document;
        }
示例#2
0
        private ISymUnmanagedDocumentWriter GetDocumentWriter(DebugSourceDocument document)
        {
            ISymUnmanagedDocumentWriter writer;

            if (!_documentMap.TryGetValue(document, out writer))
            {
                Guid language = document.Language;
                Guid vendor   = document.LanguageVendor;
                Guid type     = document.DocumentType;

                try
                {
                    writer = _symWriter.DefineDocument(document.Location, ref language, ref vendor, ref type);
                }
                catch (Exception ex)
                {
                    throw new PdbWritingException(ex);
                }

                _documentMap.Add(document, writer);

                var checksumAndAlgorithm = document.ChecksumAndAlgorithm;
                if (!checksumAndAlgorithm.Item1.IsDefault)
                {
                    try
                    {
                        writer.SetCheckSum(checksumAndAlgorithm.Item2, (uint)checksumAndAlgorithm.Item1.Length, checksumAndAlgorithm.Item1.ToArray());
                    }
                    catch (Exception ex)
                    {
                        throw new PdbWritingException(ex);
                    }
                }
            }

            return(writer);
        }
示例#3
0
        internal ISymUnmanagedDocumentWriter GetDocumentWriter(DebugSourceDocument document)
        {
            ISymUnmanagedDocumentWriter writer;
            if (!this.documentMap.TryGetValue(document, out writer))
            {
                Guid language = document.Language;
                Guid vendor = document.LanguageVendor;
                Guid type = document.DocumentType;

                try
                {
                    writer = this.symWriter.DefineDocument(document.Location, ref language, ref vendor, ref type);
                }
                catch (Exception ex)
                {
                    throw new PdbWritingException(ex);
                }

                this.documentMap.Add(document, writer);

                var checkSum = document.SourceHash;
                if (!checkSum.IsDefault)
                {
                    Guid algoId = document.SourceHashKind;
                    try
                    {
                        writer.SetCheckSum(algoId, (uint)checkSum.Length, checkSum.ToArray());
                    }
                    catch (Exception ex)
                    {
                        throw new PdbWritingException(ex);
                    }
                }
            }

            return writer;
        }
示例#4
0
        private ISymUnmanagedDocumentWriter GetDocumentWriter(DebugSourceDocument document)
        {
            ISymUnmanagedDocumentWriter writer;
            if (!_documentMap.TryGetValue(document, out writer))
            {
                Guid language = document.Language;
                Guid vendor = document.LanguageVendor;
                Guid type = document.DocumentType;

                try
                {
                    writer = _symWriter.DefineDocument(document.Location, ref language, ref vendor, ref type);
                    if (_callLogger.LogOperation(OP.DefineDocument))
                    {
                        _callLogger.LogArgument(document.Location);
                        _callLogger.LogArgument(language.ToByteArray());
                        _callLogger.LogArgument(vendor.ToByteArray());
                        _callLogger.LogArgument(type.ToByteArray());
                    }
                }
                catch (Exception ex)
                {
                    throw new PdbWritingException(ex);
                }

                _documentMap.Add(document, writer);

                var checksumAndAlgorithm = document.ChecksumAndAlgorithm;
                if (!checksumAndAlgorithm.Item1.IsDefault)
                {
                    try
                    {
                        var algorithmId = checksumAndAlgorithm.Item2;
                        var checksum = checksumAndAlgorithm.Item1.ToArray();
                        var checksumSize = (uint)checksum.Length;
                        writer.SetCheckSum(algorithmId, checksumSize, checksum);
                        if (_callLogger.LogOperation(OP.SetCheckSum))
                        {
                            _callLogger.LogArgument(algorithmId.ToByteArray());
                            _callLogger.LogArgument(checksumSize);
                            _callLogger.LogArgument(checksum);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new PdbWritingException(ex);
                    }
                }
            }

            return writer;
        }
示例#5
0
        private ISymUnmanagedDocumentWriter GetDocumentWriter(DebugSourceDocument document)
        {
            ISymUnmanagedDocumentWriter writer;
            if (!_documentMap.TryGetValue(document, out writer))
            {
                Guid language = document.Language;
                Guid vendor = document.LanguageVendor;
                Guid type = document.DocumentType;

                try
                {
                    writer = _symWriter.DefineDocument(document.Location, ref language, ref vendor, ref type);
                    if (_callLogger.LogOperation(OP.DefineDocument))
                    {
                        _callLogger.LogArgument(document.Location);
                        _callLogger.LogArgument(language.ToByteArray());
                        _callLogger.LogArgument(vendor.ToByteArray());
                        _callLogger.LogArgument(type.ToByteArray());
                    }
                }
                catch (Exception ex)
                {
                    throw new PdbWritingException(ex);
                }

                _documentMap.Add(document, writer);

                DebugSourceInfo info = document.GetSourceInfo();
                if (!info.Checksum.IsDefault)
                {
                    try
                    {
                        var algorithmId = info.ChecksumAlgorithmId;
                        var checksum = info.Checksum.ToArray();
                        var checksumSize = (uint)checksum.Length;
                        writer.SetCheckSum(algorithmId, checksumSize, checksum);
                        if (_callLogger.LogOperation(OP.SetCheckSum))
                        {
                            _callLogger.LogArgument(algorithmId.ToByteArray());
                            _callLogger.LogArgument(checksumSize);
                            _callLogger.LogArgument(checksum);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new PdbWritingException(ex);
                    }
                }

                // embedded text not currently supported for native PDB and we should have validated that
                Debug.Assert(info.EmbeddedTextBlob.IsDefault);
            }

            return writer;
        }
 internal int GetOrAddDocument(DebugSourceDocument document)
 {
     return GetOrAddDocument(document, _documentIndex);
 }
        private int GetOrAddDocument(DebugSourceDocument document, Dictionary<DebugSourceDocument, int> index)
        {
            int documentRowId;
            if (!index.TryGetValue(document, out documentRowId))
            {
                documentRowId = _documentTable.Count + 1;
                index.Add(document, documentRowId);

                var checksumAndAlgorithm = document.ChecksumAndAlgorithm;
                _documentTable.Add(new DocumentRow
                {
                    Name = SerializeDocumentName(document.Location),
                    HashAlgorithm = (checksumAndAlgorithm.Item1.IsDefault ? default(GuidHandle) : GetOrAddGuid(checksumAndAlgorithm.Item2)),
                    Hash = (checksumAndAlgorithm.Item1.IsDefault) ? default(BlobHandle) : GetOrAddBlob(checksumAndAlgorithm.Item1)
                });
            }

            return documentRowId;
        }
示例#8
0
        /// <summary>
        /// Get all the sequence points, possibly mapping them using #line/ExternalSource directives, and mapping
        /// file names to debug documents with the given mapping function.
        /// </summary>
        /// <param name="documentProvider">Function that maps file paths to CCI debug documents</param>
        public ImmutableArray <Cci.SequencePoint> GetSequencePoints(DebugDocumentProvider documentProvider)
        {
            bool   lastPathIsMapped = false;
            string lastPath         = null;

            Cci.DebugSourceDocument lastDebugDocument = null;

            // First, count the number of sequence points.
            int count = 0;
            SequencePointList current = this;

            while (current != null)
            {
                count  += current._points.Length;
                current = current._next;
            }

            ArrayBuilder <Cci.SequencePoint> result = ArrayBuilder <Cci.SequencePoint> .GetInstance(count);

            current = this;
            while (current != null)
            {
                SyntaxTree currentTree = current._tree;

                foreach (var offsetAndSpan in current._points)
                {
                    TextSpan span = offsetAndSpan.Span;

                    // if it's a hidden sequence point, or a sequence point with syntax that points to a position that is inside
                    // of a hidden region (can be defined with #line hidden (C#) or implicitly by #ExternalSource (VB), make it
                    // a hidden sequence point.

                    bool isHidden = span == RawSequencePoint.HiddenSequencePointSpan;
                    FileLinePositionSpan fileLinePositionSpan = default(FileLinePositionSpan);
                    if (!isHidden)
                    {
                        fileLinePositionSpan = currentTree.GetMappedLineSpanAndVisibility(span, out isHidden);
                    }

                    if (isHidden)
                    {
                        if (lastPath == null)
                        {
                            lastPath          = currentTree.FilePath;
                            lastDebugDocument = documentProvider(lastPath, basePath: null);
                        }

                        if (lastDebugDocument != null)
                        {
                            result.Add(new Cci.SequencePoint(
                                           lastDebugDocument,
                                           offset: offsetAndSpan.Offset,
                                           startLine: HiddenSequencePointLine,
                                           startColumn: 0,
                                           endLine: HiddenSequencePointLine,
                                           endColumn: 0));
                        }
                    }
                    else
                    {
                        if (lastPath != fileLinePositionSpan.Path || lastPathIsMapped != fileLinePositionSpan.HasMappedPath)
                        {
                            lastPath          = fileLinePositionSpan.Path;
                            lastPathIsMapped  = fileLinePositionSpan.HasMappedPath;
                            lastDebugDocument = documentProvider(lastPath, basePath: lastPathIsMapped ? currentTree.FilePath : null);
                        }

                        if (lastDebugDocument != null)
                        {
                            result.Add(new Cci.SequencePoint(
                                           lastDebugDocument,
                                           offset: offsetAndSpan.Offset,
                                           startLine: (fileLinePositionSpan.StartLinePosition.Line == -1) ? 0 : fileLinePositionSpan.StartLinePosition.Line + 1,
                                           startColumn: fileLinePositionSpan.StartLinePosition.Character + 1,
                                           endLine: (fileLinePositionSpan.EndLinePosition.Line == -1) ? 0 : fileLinePositionSpan.EndLinePosition.Line + 1,
                                           endColumn: fileLinePositionSpan.EndLinePosition.Character + 1
                                           ));
                        }
                    }
                }

                current = current._next;
            }

            return(result.ToImmutableAndFree());
        }
        private BlobHandle SerializeSequencePoints(
            StandaloneSignatureHandle localSignatureHandleOpt,
            ImmutableArray <SequencePoint> sequencePoints,
            Dictionary <DebugSourceDocument, DocumentHandle> documentIndex,
            out DocumentHandle singleDocumentHandle)
        {
            if (sequencePoints.Length == 0)
            {
                singleDocumentHandle = default(DocumentHandle);
                return(default(BlobHandle));
            }

            BlobBuilder writer = new BlobBuilder();

            int previousNonHiddenStartLine   = -1;
            int previousNonHiddenStartColumn = -1;

            // header:
            writer.WriteCompressedInteger(MetadataTokens.GetRowNumber(localSignatureHandleOpt));

            DebugSourceDocument previousDocument = TryGetSingleDocument(sequencePoints);

            singleDocumentHandle = (previousDocument != null) ? GetOrAddDocument(previousDocument, documentIndex) : default(DocumentHandle);

            for (int i = 0; i < sequencePoints.Length; i++)
            {
                DebugSourceDocument currentDocument = sequencePoints[i].Document;
                if (previousDocument != currentDocument)
                {
                    DocumentHandle documentHandle = GetOrAddDocument(currentDocument, documentIndex);

                    // optional document in header or document record:
                    if (previousDocument != null)
                    {
                        writer.WriteCompressedInteger(0);
                    }

                    writer.WriteCompressedInteger(MetadataTokens.GetRowNumber(documentHandle));
                    previousDocument = currentDocument;
                }

                // delta IL offset:
                if (i > 0)
                {
                    writer.WriteCompressedInteger(sequencePoints[i].Offset - sequencePoints[i - 1].Offset);
                }
                else
                {
                    writer.WriteCompressedInteger(sequencePoints[i].Offset);
                }

                if (sequencePoints[i].IsHidden)
                {
                    writer.WriteInt16(0);
                    continue;
                }

                // Delta Lines & Columns:
                SerializeDeltaLinesAndColumns(writer, sequencePoints[i]);

                // delta Start Lines & Columns:
                if (previousNonHiddenStartLine < 0)
                {
                    Debug.Assert(previousNonHiddenStartColumn < 0);
                    writer.WriteCompressedInteger(sequencePoints[i].StartLine);
                    writer.WriteCompressedInteger(sequencePoints[i].StartColumn);
                }
                else
                {
                    writer.WriteCompressedSignedInteger(sequencePoints[i].StartLine - previousNonHiddenStartLine);
                    writer.WriteCompressedSignedInteger(sequencePoints[i].StartColumn - previousNonHiddenStartColumn);
                }

                previousNonHiddenStartLine   = sequencePoints[i].StartLine;
                previousNonHiddenStartColumn = sequencePoints[i].StartColumn;
            }

            return(_debugMetadataOpt.GetOrAddBlob(writer));
        }
 internal int GetOrAddDocument(DebugSourceDocument document)
 {
     return(GetOrAddDocument(document, _documentIndex));
 }
示例#11
0
        /// <summary>
        /// Get all the sequence points, possibly mapping them using #line/ExternalSource directives, and mapping
        /// file names to debug documents with the given mapping function.
        /// </summary>
        /// <param name="documentProvider">Function that maps file paths to CCI debug documents</param>
        /// <param name="builder">where sequence points should be deposited</param>
        public void GetSequencePoints(
            DebugDocumentProvider documentProvider,
            ArrayBuilder <Cci.SequencePoint> builder)
        {
            bool   lastPathIsMapped = false;
            string lastPath         = null;

            Cci.DebugSourceDocument lastDebugDocument = null;

            FileLinePositionSpan?firstReal = FindFirstRealSequencePoint();

            if (!firstReal.HasValue)
            {
                return;
            }
            lastPath          = firstReal.Value.Path;
            lastPathIsMapped  = firstReal.Value.HasMappedPath;
            lastDebugDocument = documentProvider(lastPath, basePath: lastPathIsMapped ? this._tree.FilePath : null);

            SequencePointList current = this;

            while (current != null)
            {
                SyntaxTree currentTree = current._tree;

                foreach (OffsetAndSpan offsetAndSpan in current._points)
                {
                    TextSpan span = offsetAndSpan.Span;

                    // if it's a hidden sequence point, or a sequence point with syntax that points to a position that is inside
                    // of a hidden region (can be defined with #line hidden (C#) or implicitly by #ExternalSource (VB), make it
                    // a hidden sequence point.

                    bool isHidden = span == RawSequencePoint.HiddenSequencePointSpan;
                    FileLinePositionSpan fileLinePositionSpan = default(FileLinePositionSpan);
                    if (!isHidden)
                    {
                        fileLinePositionSpan = currentTree.GetMappedLineSpanAndVisibility(span, out isHidden);
                    }

                    if (isHidden)
                    {
                        if (lastPath == null)
                        {
                            lastPath          = currentTree.FilePath;
                            lastDebugDocument = documentProvider(lastPath, basePath: null);
                        }

                        if (lastDebugDocument != null)
                        {
                            builder.Add(new Cci.SequencePoint(
                                            lastDebugDocument,
                                            offset: offsetAndSpan.Offset,
                                            startLine: HiddenSequencePointLine,
                                            startColumn: 0,
                                            endLine: HiddenSequencePointLine,
                                            endColumn: 0));
                        }
                    }
                    else
                    {
                        if (lastPath != fileLinePositionSpan.Path || lastPathIsMapped != fileLinePositionSpan.HasMappedPath)
                        {
                            lastPath          = fileLinePositionSpan.Path;
                            lastPathIsMapped  = fileLinePositionSpan.HasMappedPath;
                            lastDebugDocument = documentProvider(lastPath, basePath: lastPathIsMapped ? currentTree.FilePath : null);
                        }

                        if (lastDebugDocument != null)
                        {
                            builder.Add(new Cci.SequencePoint(
                                            lastDebugDocument,
                                            offset: offsetAndSpan.Offset,
                                            startLine: (fileLinePositionSpan.StartLinePosition.Line == -1) ? 0 : fileLinePositionSpan.StartLinePosition.Line + 1,
                                            startColumn: fileLinePositionSpan.StartLinePosition.Character + 1,
                                            endLine: (fileLinePositionSpan.EndLinePosition.Line == -1) ? 0 : fileLinePositionSpan.EndLinePosition.Line + 1,
                                            endColumn: fileLinePositionSpan.EndLinePosition.Character + 1
                                            ));
                        }
                    }
                }

                current = current._next;
            }
        }
示例#12
0
        private ISymUnmanagedDocumentWriter GetDocumentWriter(DebugSourceDocument document)
        {
            ISymUnmanagedDocumentWriter writer;
            if (!_documentMap.TryGetValue(document, out writer))
            {
                Guid language = document.Language;
                Guid vendor = document.LanguageVendor;
                Guid type = document.DocumentType;

                try
                {
                    writer = _symWriter.DefineDocument(document.Location, ref language, ref vendor, ref type);
                }
                catch (Exception ex)
                {
                    throw new PdbWritingException(ex);
                }

                _documentMap.Add(document, writer);

                var checksumAndAlgorithm = document.ChecksumAndAlgorithm;
                if (!checksumAndAlgorithm.Item1.IsDefault)
                {
                    try
                    {
                        writer.SetCheckSum(checksumAndAlgorithm.Item2, (uint)checksumAndAlgorithm.Item1.Length, checksumAndAlgorithm.Item1.ToArray());
                    }
                    catch (Exception ex)
                    {
                        throw new PdbWritingException(ex);
                    }
                }
            }

            return writer;
        }