PdbScope.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Copyright (c) Microsoft. All rights reserved.
  2. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
  3. using System;
  4. namespace Microsoft.Cci.Pdb {
  5. internal class PdbScope {
  6. internal PdbConstant[] constants;
  7. internal PdbSlot[] slots;
  8. internal PdbScope[] scopes;
  9. internal string[] usedNamespaces;
  10. //internal uint segment;
  11. internal uint address;
  12. internal uint offset;
  13. internal uint length;
  14. internal PdbScope(uint address, uint offset, uint length, PdbSlot[] slots, PdbConstant[] constants, string[] usedNamespaces) {
  15. this.constants = constants;
  16. this.slots = slots;
  17. this.scopes = new PdbScope[0];
  18. this.usedNamespaces = usedNamespaces;
  19. this.address = address;
  20. this.offset = offset;
  21. this.length = length;
  22. }
  23. internal PdbScope(uint address, uint length, PdbSlot[] slots, PdbConstant[] constants, string[] usedNamespaces)
  24. : this(address, 0, length, slots, constants, usedNamespaces)
  25. {
  26. }
  27. internal PdbScope(uint funcOffset, BlockSym32 block, BitAccess bits, out uint typind) {
  28. //this.segment = block.seg;
  29. this.address = block.off;
  30. this.offset = block.off - funcOffset;
  31. this.length = block.len;
  32. typind = 0;
  33. int constantCount;
  34. int scopeCount;
  35. int slotCount;
  36. int namespaceCount;
  37. PdbFunction.CountScopesAndSlots(bits, block.end, out constantCount, out scopeCount, out slotCount, out namespaceCount);
  38. constants = new PdbConstant[constantCount];
  39. scopes = new PdbScope[scopeCount];
  40. slots = new PdbSlot[slotCount];
  41. usedNamespaces = new string[namespaceCount];
  42. int constant = 0;
  43. int scope = 0;
  44. int slot = 0;
  45. int usedNs = 0;
  46. while (bits.Position < block.end) {
  47. ushort siz;
  48. ushort rec;
  49. bits.ReadUInt16(out siz);
  50. int star = bits.Position;
  51. int stop = bits.Position + siz;
  52. bits.Position = star;
  53. bits.ReadUInt16(out rec);
  54. switch ((SYM)rec) {
  55. case SYM.S_BLOCK32: {
  56. BlockSym32 sub = new BlockSym32();
  57. bits.ReadUInt32(out sub.parent);
  58. bits.ReadUInt32(out sub.end);
  59. bits.ReadUInt32(out sub.len);
  60. bits.ReadUInt32(out sub.off);
  61. bits.ReadUInt16(out sub.seg);
  62. bits.SkipCString(out sub.name);
  63. bits.Position = stop;
  64. scopes[scope++] = new PdbScope(funcOffset, sub, bits, out typind);
  65. break;
  66. }
  67. case SYM.S_MANSLOT:
  68. slots[slot++] = new PdbSlot(bits);
  69. bits.Position = stop;
  70. break;
  71. case SYM.S_UNAMESPACE:
  72. bits.ReadCString(out usedNamespaces[usedNs++]);
  73. bits.Position = stop;
  74. break;
  75. case SYM.S_END:
  76. bits.Position = stop;
  77. break;
  78. case SYM.S_MANCONSTANT:
  79. constants[constant++] = new PdbConstant(bits);
  80. bits.Position = stop;
  81. break;
  82. default:
  83. //throw new PdbException("Unknown SYM in scope {0}", (SYM)rec);
  84. bits.Position = stop;
  85. break;
  86. }
  87. }
  88. if (bits.Position != block.end) {
  89. throw new Exception("Not at S_END");
  90. }
  91. ushort esiz;
  92. ushort erec;
  93. bits.ReadUInt16(out esiz);
  94. bits.ReadUInt16(out erec);
  95. if (erec != (ushort)SYM.S_END) {
  96. throw new Exception("Missing S_END");
  97. }
  98. }
  99. }
  100. }