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