< Summary

Information
Line coverage
0%
Covered lines: 0
Uncovered lines: 27
Coverable lines: 27
Total lines: 514
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)0%440%
FindKickoffMethod(...)0%220%
GetKickoffMethod(...)100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/PortablePdb/Tables.Debug.cs

#LineLine coverage
 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
 4using System.Reflection.Internal;
 5
 6namespace System.Reflection.Metadata.Ecma335
 7{
 8    internal readonly struct DocumentTableReader
 9    {
 10        internal readonly int NumberOfRows;
 11
 12        private readonly bool _isGuidHeapRefSizeSmall;
 13        private readonly bool _isBlobHeapRefSizeSmall;
 14
 15        private const int NameOffset = 0;
 16        private readonly int _hashAlgorithmOffset;
 17        private readonly int _hashOffset;
 18        private readonly int _languageOffset;
 19
 20        internal readonly int RowSize;
 21        internal readonly MemoryBlock Block;
 22
 23        internal DocumentTableReader(
 24            int numberOfRows,
 25            int guidHeapRefSize,
 26            int blobHeapRefSize,
 27            MemoryBlock containingBlock,
 28            int containingBlockOffset)
 29        {
 30            NumberOfRows = numberOfRows;
 31            _isGuidHeapRefSizeSmall = guidHeapRefSize == 2;
 32            _isBlobHeapRefSizeSmall = blobHeapRefSize == 2;
 33
 34            _hashAlgorithmOffset = NameOffset + blobHeapRefSize;
 35            _hashOffset = _hashAlgorithmOffset + guidHeapRefSize;
 36            _languageOffset = _hashOffset + blobHeapRefSize;
 37            RowSize = _languageOffset + guidHeapRefSize;
 38
 39            Block = containingBlock.GetMemoryBlockAt(containingBlockOffset, RowSize * numberOfRows);
 40        }
 41
 42        internal DocumentNameBlobHandle GetName(DocumentHandle handle)
 43        {
 44            int rowOffset = (handle.RowId - 1) * RowSize;
 45            return DocumentNameBlobHandle.FromOffset(Block.PeekHeapReference(rowOffset + NameOffset, _isBlobHeapRefSizeS
 46        }
 47
 48        internal GuidHandle GetHashAlgorithm(DocumentHandle handle)
 49        {
 50            int rowOffset = (handle.RowId - 1) * RowSize;
 51            return GuidHandle.FromIndex(Block.PeekHeapReference(rowOffset + _hashAlgorithmOffset, _isGuidHeapRefSizeSmal
 52        }
 53
 54        internal BlobHandle GetHash(DocumentHandle handle)
 55        {
 56            int rowOffset = (handle.RowId - 1) * RowSize;
 57            return BlobHandle.FromOffset(Block.PeekHeapReference(rowOffset + _hashOffset, _isBlobHeapRefSizeSmall));
 58        }
 59
 60        internal GuidHandle GetLanguage(DocumentHandle handle)
 61        {
 62            int rowOffset = (handle.RowId - 1) * RowSize;
 63            return GuidHandle.FromIndex(Block.PeekHeapReference(rowOffset + _languageOffset, _isGuidHeapRefSizeSmall));
 64        }
 65    }
 66
 67    internal readonly struct MethodDebugInformationTableReader
 68    {
 69        internal readonly int NumberOfRows;
 70
 71        private readonly bool _isDocumentRefSmall;
 72        private readonly bool _isBlobHeapRefSizeSmall;
 73
 74        private const int DocumentOffset = 0;
 75        private readonly int _sequencePointsOffset;
 76
 77        internal readonly int RowSize;
 78        internal readonly MemoryBlock Block;
 79
 80        internal MethodDebugInformationTableReader(
 81            int numberOfRows,
 82            int documentRefSize,
 83            int blobHeapRefSize,
 84            MemoryBlock containingBlock,
 85            int containingBlockOffset)
 86        {
 87            NumberOfRows = numberOfRows;
 88            _isDocumentRefSmall = documentRefSize == 2;
 89            _isBlobHeapRefSizeSmall = blobHeapRefSize == 2;
 90
 91            _sequencePointsOffset = DocumentOffset + documentRefSize;
 92            RowSize = _sequencePointsOffset + blobHeapRefSize;
 93
 94            Block = containingBlock.GetMemoryBlockAt(containingBlockOffset, RowSize * numberOfRows);
 95        }
 96
 97        internal DocumentHandle GetDocument(MethodDebugInformationHandle handle)
 98        {
 99            int rowOffset = (handle.RowId - 1) * RowSize;
 100            return DocumentHandle.FromRowId(Block.PeekReference(rowOffset + DocumentOffset, _isDocumentRefSmall));
 101        }
 102
 103        internal BlobHandle GetSequencePoints(MethodDebugInformationHandle handle)
 104        {
 105            int rowOffset = (handle.RowId - 1) * RowSize;
 106            return BlobHandle.FromOffset(Block.PeekHeapReference(rowOffset + _sequencePointsOffset, _isBlobHeapRefSizeSm
 107        }
 108    }
 109
 110    internal readonly struct LocalScopeTableReader
 111    {
 112        internal readonly int NumberOfRows;
 113
 114        private readonly bool _isMethodRefSmall;
 115        private readonly bool _isImportScopeRefSmall;
 116        private readonly bool _isLocalConstantRefSmall;
 117        private readonly bool _isLocalVariableRefSmall;
 118
 119        private const int MethodOffset = 0;
 120        private readonly int _importScopeOffset;
 121        private readonly int _variableListOffset;
 122        private readonly int _constantListOffset;
 123        private readonly int _startOffsetOffset;
 124        private readonly int _lengthOffset;
 125
 126        internal readonly int RowSize;
 127        internal readonly MemoryBlock Block;
 128
 129        internal LocalScopeTableReader(
 130            int numberOfRows,
 131            bool declaredSorted,
 132            int methodRefSize,
 133            int importScopeRefSize,
 134            int localVariableRefSize,
 135            int localConstantRefSize,
 136            MemoryBlock containingBlock,
 137            int containingBlockOffset)
 138        {
 139            NumberOfRows = numberOfRows;
 140            _isMethodRefSmall = methodRefSize == 2;
 141            _isImportScopeRefSmall = importScopeRefSize == 2;
 142            _isLocalVariableRefSmall = localVariableRefSize == 2;
 143            _isLocalConstantRefSmall = localConstantRefSize == 2;
 144
 145            _importScopeOffset = MethodOffset + methodRefSize;
 146            _variableListOffset = _importScopeOffset + importScopeRefSize;
 147            _constantListOffset = _variableListOffset + localVariableRefSize;
 148            _startOffsetOffset = _constantListOffset + localConstantRefSize;
 149            _lengthOffset = _startOffsetOffset + sizeof(uint);
 150            RowSize = _lengthOffset + sizeof(uint);
 151
 152            Block = containingBlock.GetMemoryBlockAt(containingBlockOffset, RowSize * numberOfRows);
 153
 154            if (numberOfRows > 0 && !declaredSorted)
 155            {
 156                Throw.TableNotSorted(TableIndex.LocalScope);
 157            }
 158        }
 159
 160        internal MethodDefinitionHandle GetMethod(int rowId)
 161        {
 162            int rowOffset = (rowId - 1) * RowSize;
 163            return MethodDefinitionHandle.FromRowId(Block.PeekReference(rowOffset + MethodOffset, _isMethodRefSmall));
 164        }
 165
 166        internal ImportScopeHandle GetImportScope(LocalScopeHandle handle)
 167        {
 168            int rowOffset = (handle.RowId - 1) * RowSize;
 169            return ImportScopeHandle.FromRowId(Block.PeekReference(rowOffset + _importScopeOffset, _isImportScopeRefSmal
 170        }
 171
 172        internal int GetVariableStart(int rowId)
 173        {
 174            int rowOffset = (rowId - 1) * RowSize;
 175            return Block.PeekReference(rowOffset + _variableListOffset, _isLocalVariableRefSmall);
 176        }
 177
 178        internal int GetConstantStart(int rowId)
 179        {
 180            int rowOffset = (rowId - 1) * RowSize;
 181            return Block.PeekReference(rowOffset + _constantListOffset, _isLocalConstantRefSmall);
 182        }
 183
 184        internal int GetStartOffset(int rowId)
 185        {
 186            int rowOffset = (rowId - 1) * RowSize;
 187            return Block.PeekInt32(rowOffset + _startOffsetOffset);
 188        }
 189
 190        internal int GetLength(int rowId)
 191        {
 192            int rowOffset = (rowId - 1) * RowSize;
 193            return Block.PeekInt32(rowOffset + _lengthOffset);
 194        }
 195
 196        internal int GetEndOffset(int rowId)
 197        {
 198            int rowOffset = (rowId - 1) * RowSize;
 199
 200            long result =
 201                Block.PeekUInt32(rowOffset + _startOffsetOffset) +
 202                Block.PeekUInt32(rowOffset + _lengthOffset);
 203
 204            if (unchecked((int)result) != result)
 205            {
 206                Throw.ValueOverflow();
 207            }
 208
 209            return (int)result;
 210        }
 211
 212        internal void GetLocalScopeRange(int methodDefRid, out int firstScopeRowId, out int lastScopeRowId)
 213        {
 214            int startRowNumber, endRowNumber;
 215            Block.BinarySearchReferenceRange(
 216                NumberOfRows,
 217                RowSize,
 218                MethodOffset,
 219                (uint)methodDefRid,
 220                _isMethodRefSmall,
 221                out startRowNumber,
 222                out endRowNumber
 223            );
 224
 225            if (startRowNumber == -1)
 226            {
 227                firstScopeRowId = 1;
 228                lastScopeRowId = 0;
 229            }
 230            else
 231            {
 232                firstScopeRowId = startRowNumber + 1;
 233                lastScopeRowId = endRowNumber + 1;
 234            }
 235        }
 236    }
 237
 238    internal readonly struct LocalVariableTableReader
 239    {
 240        internal readonly int NumberOfRows;
 241        private readonly bool _isStringHeapRefSizeSmall;
 242        private readonly int _attributesOffset;
 243        private readonly int _indexOffset;
 244        private readonly int _nameOffset;
 245        internal readonly int RowSize;
 246        internal readonly MemoryBlock Block;
 247
 248        internal LocalVariableTableReader(
 249            int numberOfRows,
 250            int stringHeapRefSize,
 251            MemoryBlock containingBlock,
 252            int containingBlockOffset
 253        )
 254        {
 255            NumberOfRows = numberOfRows;
 256            _isStringHeapRefSizeSmall = stringHeapRefSize == 2;
 257
 258            _attributesOffset = 0;
 259            _indexOffset = _attributesOffset + sizeof(ushort);
 260            _nameOffset = _indexOffset + sizeof(ushort);
 261            RowSize = _nameOffset + stringHeapRefSize;
 262
 263            Block = containingBlock.GetMemoryBlockAt(containingBlockOffset, RowSize * numberOfRows);
 264        }
 265
 266        internal LocalVariableAttributes GetAttributes(LocalVariableHandle handle)
 267        {
 268            int rowOffset = (handle.RowId - 1) * RowSize;
 269            return (LocalVariableAttributes)Block.PeekUInt16(rowOffset + _attributesOffset);
 270        }
 271
 272        internal ushort GetIndex(LocalVariableHandle handle)
 273        {
 274            int rowOffset = (handle.RowId - 1) * RowSize;
 275            return Block.PeekUInt16(rowOffset + _indexOffset);
 276        }
 277
 278        internal StringHandle GetName(LocalVariableHandle handle)
 279        {
 280            int rowOffset = (handle.RowId - 1) * RowSize;
 281            return StringHandle.FromOffset(Block.PeekHeapReference(rowOffset + _nameOffset, _isStringHeapRefSizeSmall));
 282        }
 283    }
 284
 285    internal readonly struct LocalConstantTableReader
 286    {
 287        internal readonly int NumberOfRows;
 288        private readonly bool _isStringHeapRefSizeSmall;
 289        private readonly bool _isBlobHeapRefSizeSmall;
 290
 291        private const int NameOffset = 0;
 292        private readonly int _signatureOffset;
 293
 294        internal readonly int RowSize;
 295        internal readonly MemoryBlock Block;
 296
 297        internal LocalConstantTableReader(
 298            int numberOfRows,
 299            int stringHeapRefSize,
 300            int blobHeapRefSize,
 301            MemoryBlock containingBlock,
 302            int containingBlockOffset)
 303        {
 304            NumberOfRows = numberOfRows;
 305            _isStringHeapRefSizeSmall = stringHeapRefSize == 2;
 306            _isBlobHeapRefSizeSmall = blobHeapRefSize == 2;
 307
 308            _signatureOffset = NameOffset + stringHeapRefSize;
 309            RowSize = _signatureOffset + blobHeapRefSize;
 310
 311            Block = containingBlock.GetMemoryBlockAt(containingBlockOffset, RowSize * numberOfRows);
 312        }
 313
 314        internal StringHandle GetName(LocalConstantHandle handle)
 315        {
 316            int rowOffset = (handle.RowId - 1) * RowSize;
 317            return StringHandle.FromOffset(Block.PeekHeapReference(rowOffset + NameOffset, _isStringHeapRefSizeSmall));
 318        }
 319
 320        internal BlobHandle GetSignature(LocalConstantHandle handle)
 321        {
 322            int rowOffset = (handle.RowId - 1) * RowSize;
 323            return BlobHandle.FromOffset(Block.PeekHeapReference(rowOffset + _signatureOffset, _isBlobHeapRefSizeSmall))
 324        }
 325    }
 326
 327    internal readonly struct StateMachineMethodTableReader
 328    {
 329        internal readonly int NumberOfRows;
 330
 331        private readonly bool _isMethodRefSizeSmall;
 332
 333        private const int MoveNextMethodOffset = 0;
 334        private readonly int _kickoffMethodOffset;
 335
 336        internal readonly int RowSize;
 337        internal readonly MemoryBlock Block;
 338
 339        internal StateMachineMethodTableReader(
 340            int numberOfRows,
 341            bool declaredSorted,
 342            int methodRefSize,
 343            MemoryBlock containingBlock,
 344            int containingBlockOffset)
 0345        {
 0346            NumberOfRows = numberOfRows;
 0347            _isMethodRefSizeSmall = methodRefSize == 2;
 348
 0349            _kickoffMethodOffset = methodRefSize;
 0350            RowSize = _kickoffMethodOffset + methodRefSize;
 351
 0352            Block = containingBlock.GetMemoryBlockAt(containingBlockOffset, RowSize * numberOfRows);
 353
 0354            if (numberOfRows > 0 && !declaredSorted)
 0355            {
 0356                Throw.TableNotSorted(TableIndex.StateMachineMethod);
 357            }
 0358        }
 359
 360        internal MethodDefinitionHandle FindKickoffMethod(int moveNextMethodRowId)
 0361        {
 0362            int foundRowNumber =
 0363              this.Block.BinarySearchReference(
 0364                this.NumberOfRows,
 0365                this.RowSize,
 0366                MoveNextMethodOffset,
 0367                (uint)moveNextMethodRowId,
 0368                _isMethodRefSizeSmall);
 369
 0370            if (foundRowNumber < 0)
 0371            {
 0372                return default(MethodDefinitionHandle);
 373            }
 374
 0375            return GetKickoffMethod(foundRowNumber + 1);
 0376        }
 377
 378        private MethodDefinitionHandle GetKickoffMethod(int rowId)
 0379        {
 0380            int rowOffset = (rowId - 1) * RowSize;
 0381            return MethodDefinitionHandle.FromRowId(Block.PeekReference(rowOffset + _kickoffMethodOffset, _isMethodRefSi
 0382        }
 383    }
 384
 385    internal readonly struct ImportScopeTableReader
 386    {
 387        internal readonly int NumberOfRows;
 388
 389        private readonly bool _isImportScopeRefSizeSmall;
 390        private readonly bool _isBlobHeapRefSizeSmall;
 391
 392        private const int ParentOffset = 0;
 393        private readonly int _importsOffset;
 394
 395        internal readonly int RowSize;
 396        internal readonly MemoryBlock Block;
 397
 398        internal ImportScopeTableReader(
 399            int numberOfRows,
 400            int importScopeRefSize,
 401            int blobHeapRefSize,
 402            MemoryBlock containingBlock,
 403            int containingBlockOffset)
 404        {
 405            NumberOfRows = numberOfRows;
 406            _isImportScopeRefSizeSmall = importScopeRefSize == 2;
 407            _isBlobHeapRefSizeSmall = blobHeapRefSize == 2;
 408
 409            _importsOffset = ParentOffset + importScopeRefSize;
 410            RowSize = _importsOffset + blobHeapRefSize;
 411
 412            Block = containingBlock.GetMemoryBlockAt(containingBlockOffset, RowSize * numberOfRows);
 413        }
 414
 415        internal ImportScopeHandle GetParent(ImportScopeHandle handle)
 416        {
 417            int rowOffset = (handle.RowId - 1) * RowSize;
 418            return ImportScopeHandle.FromRowId(Block.PeekReference(rowOffset + ParentOffset, _isImportScopeRefSizeSmall)
 419        }
 420
 421        internal BlobHandle GetImports(ImportScopeHandle handle)
 422        {
 423            int rowOffset = (handle.RowId - 1) * RowSize;
 424            return BlobHandle.FromOffset(Block.PeekHeapReference(rowOffset + _importsOffset, _isBlobHeapRefSizeSmall));
 425        }
 426    }
 427
 428    internal readonly struct CustomDebugInformationTableReader
 429    {
 430        internal readonly int NumberOfRows;
 431
 432        private readonly bool _isHasCustomDebugInformationRefSizeSmall;
 433        private readonly bool _isGuidHeapRefSizeSmall;
 434        private readonly bool _isBlobHeapRefSizeSmall;
 435
 436        private const int ParentOffset = 0;
 437        private readonly int _kindOffset;
 438        private readonly int _valueOffset;
 439
 440        internal readonly int RowSize;
 441        internal readonly MemoryBlock Block;
 442
 443        internal CustomDebugInformationTableReader(
 444            int numberOfRows,
 445            bool declaredSorted,
 446            int hasCustomDebugInformationRefSize,
 447            int guidHeapRefSize,
 448            int blobHeapRefSize,
 449            MemoryBlock containingBlock,
 450            int containingBlockOffset)
 451        {
 452            NumberOfRows = numberOfRows;
 453            _isHasCustomDebugInformationRefSizeSmall = hasCustomDebugInformationRefSize == 2;
 454            _isGuidHeapRefSizeSmall = guidHeapRefSize == 2;
 455            _isBlobHeapRefSizeSmall = blobHeapRefSize == 2;
 456
 457            _kindOffset = ParentOffset + hasCustomDebugInformationRefSize;
 458            _valueOffset = _kindOffset + guidHeapRefSize;
 459            RowSize = _valueOffset + blobHeapRefSize;
 460
 461            Block = containingBlock.GetMemoryBlockAt(containingBlockOffset, RowSize * numberOfRows);
 462
 463            if (numberOfRows > 0 && !declaredSorted)
 464            {
 465                Throw.TableNotSorted(TableIndex.CustomDebugInformation);
 466            }
 467        }
 468
 469        internal EntityHandle GetParent(CustomDebugInformationHandle handle)
 470        {
 471            int rowOffset = (handle.RowId - 1) * RowSize;
 472            return HasCustomDebugInformationTag.ConvertToHandle(Block.PeekTaggedReference(rowOffset + ParentOffset, _isH
 473        }
 474
 475        internal GuidHandle GetKind(CustomDebugInformationHandle handle)
 476        {
 477            int rowOffset = (handle.RowId - 1) * RowSize;
 478            return GuidHandle.FromIndex(Block.PeekHeapReference(rowOffset + _kindOffset, _isGuidHeapRefSizeSmall));
 479        }
 480
 481        internal BlobHandle GetValue(CustomDebugInformationHandle handle)
 482        {
 483            int rowOffset = (handle.RowId - 1) * RowSize;
 484            return BlobHandle.FromOffset(Block.PeekHeapReference(rowOffset + _valueOffset, _isBlobHeapRefSizeSmall));
 485        }
 486
 487        internal void GetRange(EntityHandle parentHandle, out int firstImplRowId, out int lastImplRowId)
 488        {
 489            int startRowNumber, endRowNumber;
 490
 491            Block.BinarySearchReferenceRange(
 492                NumberOfRows,
 493                RowSize,
 494                ParentOffset,
 495                HasCustomDebugInformationTag.ConvertToTag(parentHandle),
 496                _isHasCustomDebugInformationRefSizeSmall,
 497                out startRowNumber,
 498                out endRowNumber
 499            );
 500
 501            if (startRowNumber == -1)
 502            {
 503                firstImplRowId = 1;
 504                lastImplRowId = 0;
 505            }
 506            else
 507            {
 508                firstImplRowId = startRowNumber + 1;
 509                lastImplRowId = endRowNumber + 1;
 510            }
 511        }
 512    }
 513}
 514