Debian Codegraph @

symbols/pdb/Microsoft.Cci.Pdb/PdbScope.cs

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