| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | namespace System.Reflection.Metadata |
| | | 5 | | { |
| | | 6 | | /// <summary> |
| | | 7 | | /// Debug information associated with a method definition. Stored in debug metadata. |
| | | 8 | | /// </summary> |
| | | 9 | | /// <remarks> |
| | | 10 | | /// See https://github.com/dotnet/runtime/blob/main/src/libraries/System.Reflection.Metadata/specs/PortablePdb-Metad |
| | | 11 | | /// </remarks> |
| | | 12 | | public readonly struct MethodDebugInformation |
| | | 13 | | { |
| | | 14 | | private readonly MetadataReader _reader; |
| | | 15 | | |
| | | 16 | | // Workaround: JIT doesn't generate good code for nested structures, so use RowId. |
| | | 17 | | private readonly int _rowId; |
| | | 18 | | |
| | | 19 | | internal MethodDebugInformation(MetadataReader reader, MethodDebugInformationHandle handle) |
| | 0 | 20 | | { |
| | 0 | 21 | | _reader = reader; |
| | 0 | 22 | | _rowId = handle.RowId; |
| | 0 | 23 | | } |
| | | 24 | | |
| | 0 | 25 | | private MethodDebugInformationHandle Handle => MethodDebugInformationHandle.FromRowId(_rowId); |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Returns a blob encoding sequence points, or nil if the method doesn't have sequence points. |
| | | 29 | | /// Use <see cref="GetSequencePoints()"/> to decode the blob. |
| | | 30 | | /// </summary> |
| | 0 | 31 | | public BlobHandle SequencePointsBlob => _reader.MethodDebugInformationTable.GetSequencePoints(Handle); |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Handle of the single document containing all sequence points of the method, |
| | | 35 | | /// or nil if the method doesn't have sequence points or spans multiple documents. |
| | | 36 | | /// </summary> |
| | 0 | 37 | | public DocumentHandle Document => _reader.MethodDebugInformationTable.GetDocument(Handle); |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Returns local signature handle, or nil if the method doesn't define any local variables. |
| | | 41 | | /// </summary> |
| | | 42 | | public StandaloneSignatureHandle LocalSignature |
| | | 43 | | { |
| | | 44 | | get |
| | 0 | 45 | | { |
| | 0 | 46 | | if (SequencePointsBlob.IsNil) |
| | 0 | 47 | | { |
| | 0 | 48 | | return default(StandaloneSignatureHandle); |
| | | 49 | | } |
| | | 50 | | |
| | 0 | 51 | | return StandaloneSignatureHandle.FromRowId(_reader.GetBlobReader(SequencePointsBlob).ReadCompressedInteg |
| | 0 | 52 | | } |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// Returns a collection of sequence points decoded from <see cref="SequencePointsBlob"/>. |
| | | 57 | | /// </summary> |
| | | 58 | | public SequencePointCollection GetSequencePoints() |
| | 0 | 59 | | { |
| | 0 | 60 | | return new SequencePointCollection(_reader.BlobHeap.GetMemoryBlock(SequencePointsBlob), Document); |
| | 0 | 61 | | } |
| | | 62 | | |
| | | 63 | | /// <summary> |
| | | 64 | | /// If the method is a MoveNext method of a state machine returns the kickoff method of the state machine, other |
| | | 65 | | /// </summary> |
| | | 66 | | public MethodDefinitionHandle GetStateMachineKickoffMethod() |
| | 0 | 67 | | { |
| | 0 | 68 | | return _reader.StateMachineMethodTable.FindKickoffMethod(_rowId); |
| | 0 | 69 | | } |
| | | 70 | | } |
| | | 71 | | } |
| | | 72 | | |