Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

4
external/cecil/symbols/pdb/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
bin
obj
*.xml
*.user

View File

@@ -0,0 +1,255 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
using System.IO;
using System.Text;
namespace Microsoft.Cci.Pdb {
internal class BitAccess {
internal BitAccess(int capacity) {
this.buffer = new byte[capacity];
}
internal byte[] Buffer {
get { return buffer; }
}
private byte[] buffer;
internal void FillBuffer(Stream stream, int capacity) {
MinCapacity(capacity);
stream.Read(buffer, 0, capacity);
offset = 0;
}
internal void Append(Stream stream, int count) {
int newCapacity = offset + count;
if (buffer.Length < newCapacity) {
byte[] newBuffer = new byte[newCapacity];
Array.Copy(buffer, newBuffer, buffer.Length);
buffer = newBuffer;
}
stream.Read(buffer, offset, count);
offset += count;
}
internal int Position {
get { return offset; }
set { offset = value; }
}
private int offset;
//internal void WriteBuffer(Stream stream, int count) {
// stream.Write(buffer, 0, count);
//}
internal void MinCapacity(int capacity) {
if (buffer.Length < capacity) {
buffer = new byte[capacity];
}
offset = 0;
}
internal void Align(int alignment) {
while ((offset % alignment) != 0) {
offset++;
}
}
//internal void WriteInt32(int value) {
// buffer[offset + 0] = (byte)value;
// buffer[offset + 1] = (byte)(value >> 8);
// buffer[offset + 2] = (byte)(value >> 16);
// buffer[offset + 3] = (byte)(value >> 24);
// offset += 4;
//}
//internal void WriteInt32(int[] values) {
// for (int i = 0; i < values.Length; i++) {
// WriteInt32(values[i]);
// }
//}
//internal void WriteBytes(byte[] bytes) {
// for (int i = 0; i < bytes.Length; i++) {
// buffer[offset++] = bytes[i];
// }
//}
internal void ReadInt16(out short value) {
value = (short)((buffer[offset + 0] & 0xFF) |
(buffer[offset + 1] << 8));
offset += 2;
}
internal void ReadInt8(out sbyte value) {
value = (sbyte)buffer[offset];
offset += 1;
}
internal void ReadInt32(out int value) {
value = (int)((buffer[offset + 0] & 0xFF) |
(buffer[offset + 1] << 8) |
(buffer[offset + 2] << 16) |
(buffer[offset + 3] << 24));
offset += 4;
}
internal void ReadInt64(out long value) {
value = (long)(((ulong)buffer[offset + 0] & 0xFF) |
((ulong)buffer[offset + 1] << 8) |
((ulong)buffer[offset + 2] << 16) |
((ulong)buffer[offset + 3] << 24) |
((ulong)buffer[offset + 4] << 32) |
((ulong)buffer[offset + 5] << 40) |
((ulong)buffer[offset + 6] << 48) |
((ulong)buffer[offset + 7] << 56));
offset += 8;
}
internal void ReadUInt16(out ushort value) {
value = (ushort)((buffer[offset + 0] & 0xFF) |
(buffer[offset + 1] << 8));
offset += 2;
}
internal void ReadUInt8(out byte value) {
value = (byte)((buffer[offset + 0] & 0xFF));
offset += 1;
}
internal void ReadUInt32(out uint value) {
value = (uint)((buffer[offset + 0] & 0xFF) |
(buffer[offset + 1] << 8) |
(buffer[offset + 2] << 16) |
(buffer[offset + 3] << 24));
offset += 4;
}
internal void ReadUInt64(out ulong value) {
value = (ulong)(((ulong)buffer[offset + 0] & 0xFF) |
((ulong)buffer[offset + 1] << 8) |
((ulong)buffer[offset + 2] << 16) |
((ulong)buffer[offset + 3] << 24) |
((ulong)buffer[offset + 4] << 32) |
((ulong)buffer[offset + 5] << 40) |
((ulong)buffer[offset + 6] << 48) |
((ulong)buffer[offset + 7] << 56));
offset += 8;
}
internal void ReadInt32(int[] values) {
for (int i = 0; i < values.Length; i++) {
ReadInt32(out values[i]);
}
}
internal void ReadUInt32(uint[] values) {
for (int i = 0; i < values.Length; i++) {
ReadUInt32(out values[i]);
}
}
internal void ReadBytes(byte[] bytes) {
for (int i = 0; i < bytes.Length; i++) {
bytes[i] = buffer[offset++];
}
}
internal float ReadFloat() {
float result = BitConverter.ToSingle(buffer, offset);
offset += 4;
return result;
}
internal double ReadDouble() {
double result = BitConverter.ToDouble(buffer, offset);
offset += 8;
return result;
}
internal decimal ReadDecimal() {
int[] bits = new int[4];
this.ReadInt32(bits);
return new decimal(bits[2], bits[3], bits[1], bits[0] < 0, (byte)((bits[0] & 0x00FF0000) >> 16));
}
internal void ReadBString(out string value) {
ushort len;
this.ReadUInt16(out len);
value = Encoding.UTF8.GetString(buffer, offset, len);
offset += len;
}
internal string ReadBString(int len) {
var result = Encoding.UTF8.GetString(buffer, offset, len);
offset += len;
return result;
}
internal void ReadCString(out string value) {
int len = 0;
while (offset + len < buffer.Length && buffer[offset + len] != 0) {
len++;
}
value = Encoding.UTF8.GetString(buffer, offset, len);
offset += len + 1;
}
internal void SkipCString(out string value) {
int len = 0;
while (offset + len < buffer.Length && buffer[offset + len] != 0) {
len++;
}
offset += len + 1;
value= null;
}
internal void ReadGuid(out Guid guid) {
uint a;
ushort b;
ushort c;
byte d;
byte e;
byte f;
byte g;
byte h;
byte i;
byte j;
byte k;
ReadUInt32(out a);
ReadUInt16(out b);
ReadUInt16(out c);
ReadUInt8(out d);
ReadUInt8(out e);
ReadUInt8(out f);
ReadUInt8(out g);
ReadUInt8(out h);
ReadUInt8(out i);
ReadUInt8(out j);
ReadUInt8(out k);
guid = new Guid(a, b, c, d, e, f, g, h, i, j, k);
}
internal string ReadString() {
int len = 0;
while (offset + len < buffer.Length && buffer[offset + len] != 0) {
len+=2;
}
string result = Encoding.Unicode.GetString(buffer, offset, len);
offset += len + 2;
return result;
}
}
}

View File

@@ -0,0 +1,74 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
namespace Microsoft.Cci.Pdb {
internal struct BitSet {
internal BitSet(BitAccess bits) {
bits.ReadInt32(out size); // 0..3 : Number of words
words = new uint[size];
bits.ReadUInt32(words);
}
//internal BitSet(int size) {
// this.size = size;
// words = new uint[size];
//}
internal bool IsSet(int index) {
int word = index / 32;
if (word >= this.size) return false;
return ((words[word] & GetBit(index)) != 0);
}
//internal void Set(int index) {
// int word = index / 32;
// if (word >= this.size) return;
// words[word] |= GetBit(index);
//}
//internal void Clear(int index) {
// int word = index / 32;
// if (word >= this.size) return;
// words[word] &= ~GetBit(index);
//}
private static uint GetBit(int index) {
return ((uint)1 << (index % 32));
}
//private static uint ReverseBits(uint value) {
// uint o = 0;
// for (int i = 0; i < 32; i++) {
// o = (o << 1) | (value & 1);
// value >>= 1;
// }
// return o;
//}
internal bool IsEmpty {
get { return size == 0; }
}
//internal bool GetWord(int index, out uint word) {
// if (index < size) {
// word = ReverseBits(words[index]);
// return true;
// }
// word = 0;
// return false;
//}
private int size;
private uint[] words;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,111 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
using System.IO;
namespace Microsoft.Cci.Pdb {
internal class DataStream {
internal DataStream() {
}
internal DataStream(int contentSize, BitAccess bits, int count) {
this.contentSize = contentSize;
if (count > 0) {
this.pages = new int[count];
bits.ReadInt32(this.pages);
}
}
internal void Read(PdbReader reader, BitAccess bits) {
bits.MinCapacity(contentSize);
Read(reader, 0, bits.Buffer, 0, contentSize);
}
internal void Read(PdbReader reader, int position,
byte[] bytes, int offset, int data) {
if (position + data > contentSize) {
throw new PdbException("DataStream can't read off end of stream. " +
"(pos={0},siz={1})",
position, data);
}
if (position == contentSize) {
return;
}
int left = data;
int page = position / reader.pageSize;
int rema = position % reader.pageSize;
// First get remained of first page.
if (rema != 0) {
int todo = reader.pageSize - rema;
if (todo > left) {
todo = left;
}
reader.Seek(pages[page], rema);
reader.Read(bytes, offset, todo);
offset += todo;
left -= todo;
page++;
}
// Now get the remaining pages.
while (left > 0) {
int todo = reader.pageSize;
if (todo > left) {
todo = left;
}
reader.Seek(pages[page], 0);
reader.Read(bytes, offset, todo);
offset += todo;
left -= todo;
page++;
}
}
//private void AddPages(int page0, int count) {
// if (pages == null) {
// pages = new int[count];
// for (int i = 0; i < count; i++) {
// pages[i] = page0 + i;
// }
// } else {
// int[] old = pages;
// int used = old.Length;
// pages = new int[used + count];
// Array.Copy(old, pages, used);
// for (int i = 0; i < count; i++) {
// pages[used + i] = page0 + i;
// }
// }
//}
//internal int Pages {
// get { return pages == null ? 0 : pages.Length; }
//}
internal int Length {
get { return contentSize; }
}
//internal int GetPage(int index) {
// return pages[index];
//}
internal int contentSize;
internal int[] pages;
}
}

View File

@@ -0,0 +1,41 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
namespace Microsoft.Cci.Pdb {
internal struct DbiDbgHdr {
internal DbiDbgHdr(BitAccess bits) {
bits.ReadUInt16(out snFPO);
bits.ReadUInt16(out snException);
bits.ReadUInt16(out snFixup);
bits.ReadUInt16(out snOmapToSrc);
bits.ReadUInt16(out snOmapFromSrc);
bits.ReadUInt16(out snSectionHdr);
bits.ReadUInt16(out snTokenRidMap);
bits.ReadUInt16(out snXdata);
bits.ReadUInt16(out snPdata);
bits.ReadUInt16(out snNewFPO);
bits.ReadUInt16(out snSectionHdrOrig);
}
internal ushort snFPO; // 0..1
internal ushort snException; // 2..3 (deprecated)
internal ushort snFixup; // 4..5
internal ushort snOmapToSrc; // 6..7
internal ushort snOmapFromSrc; // 8..9
internal ushort snSectionHdr; // 10..11
internal ushort snTokenRidMap; // 12..13
internal ushort snXdata; // 14..15
internal ushort snPdata; // 16..17
internal ushort snNewFPO; // 18..19
internal ushort snSectionHdrOrig; // 20..21
}
}

View File

@@ -0,0 +1,59 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
namespace Microsoft.Cci.Pdb {
internal struct DbiHeader {
internal DbiHeader(BitAccess bits) {
bits.ReadInt32(out sig);
bits.ReadInt32(out ver);
bits.ReadInt32(out age);
bits.ReadInt16(out gssymStream);
bits.ReadUInt16(out vers);
bits.ReadInt16(out pssymStream);
bits.ReadUInt16(out pdbver);
bits.ReadInt16(out symrecStream);
bits.ReadUInt16(out pdbver2);
bits.ReadInt32(out gpmodiSize);
bits.ReadInt32(out secconSize);
bits.ReadInt32(out secmapSize);
bits.ReadInt32(out filinfSize);
bits.ReadInt32(out tsmapSize);
bits.ReadInt32(out mfcIndex);
bits.ReadInt32(out dbghdrSize);
bits.ReadInt32(out ecinfoSize);
bits.ReadUInt16(out flags);
bits.ReadUInt16(out machine);
bits.ReadInt32(out reserved);
}
internal int sig; // 0..3
internal int ver; // 4..7
internal int age; // 8..11
internal short gssymStream; // 12..13
internal ushort vers; // 14..15
internal short pssymStream; // 16..17
internal ushort pdbver; // 18..19
internal short symrecStream; // 20..21
internal ushort pdbver2; // 22..23
internal int gpmodiSize; // 24..27
internal int secconSize; // 28..31
internal int secmapSize; // 32..35
internal int filinfSize; // 36..39
internal int tsmapSize; // 40..43
internal int mfcIndex; // 44..47
internal int dbghdrSize; // 48..51
internal int ecinfoSize; // 52..55
internal ushort flags; // 56..57
internal ushort machine; // 58..59
internal int reserved; // 60..63
}
}

View File

@@ -0,0 +1,57 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
namespace Microsoft.Cci.Pdb {
internal class DbiModuleInfo {
internal DbiModuleInfo(BitAccess bits, bool readStrings) {
bits.ReadInt32(out opened);
new DbiSecCon(bits);
bits.ReadUInt16(out flags);
bits.ReadInt16(out stream);
bits.ReadInt32(out cbSyms);
bits.ReadInt32(out cbOldLines);
bits.ReadInt32(out cbLines);
bits.ReadInt16(out files);
bits.ReadInt16(out pad1);
bits.ReadUInt32(out offsets);
bits.ReadInt32(out niSource);
bits.ReadInt32(out niCompiler);
if (readStrings) {
bits.ReadCString(out moduleName);
bits.ReadCString(out objectName);
} else {
bits.SkipCString(out moduleName);
bits.SkipCString(out objectName);
}
bits.Align(4);
//if (opened != 0 || pad1 != 0) {
// throw new PdbException("Invalid DBI module. "+
// "(opened={0}, pad={1})", opened, pad1);
//}
}
internal int opened; // 0..3
//internal DbiSecCon section; // 4..31
internal ushort flags; // 32..33
internal short stream; // 34..35
internal int cbSyms; // 36..39
internal int cbOldLines; // 40..43
internal int cbLines; // 44..57
internal short files; // 48..49
internal short pad1; // 50..51
internal uint offsets;
internal int niSource;
internal int niCompiler;
internal string moduleName;
internal string objectName;
}
}

View File

@@ -0,0 +1,42 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
namespace Microsoft.Cci.Pdb {
internal struct DbiSecCon {
internal DbiSecCon(BitAccess bits) {
bits.ReadInt16(out section);
bits.ReadInt16(out pad1);
bits.ReadInt32(out offset);
bits.ReadInt32(out size);
bits.ReadUInt32(out flags);
bits.ReadInt16(out module);
bits.ReadInt16(out pad2);
bits.ReadUInt32(out dataCrc);
bits.ReadUInt32(out relocCrc);
//if (pad1 != 0 || pad2 != 0) {
// throw new PdbException("Invalid DBI section. "+
// "(pad1={0}, pad2={1})",
// pad1, pad2);
//}
}
internal short section; // 0..1
internal short pad1; // 2..3
internal int offset; // 4..7
internal int size; // 8..11
internal uint flags; // 12..15
internal short module; // 16..17
internal short pad2; // 18..19
internal uint dataCrc; // 20..23
internal uint relocCrc; // 24..27
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
namespace Microsoft.Cci {
/// <summary>
/// A range of CLR IL operations that comprise a lexical scope, specified as an IL offset and a length.
/// </summary>
public interface ILocalScope {
/// <summary>
/// The offset of the first operation in the scope.
/// </summary>
uint Offset { get; }
/// <summary>
/// The length of the scope. Offset+Length equals the offset of the first operation outside the scope, or equals the method body length.
/// </summary>
uint Length { get; }
}
/// <summary>
/// A description of the lexical scope in which a namespace type has been nested. This scope is tied to a particular
/// method body, so that partial types can be accommodated.
/// </summary>
public interface INamespaceScope {
/// <summary>
/// Zero or more used namespaces. These correspond to using clauses in C#.
/// </summary>
IEnumerable<IUsedNamespace> UsedNamespaces { get; }
}
/// <summary>
/// A namespace that is used (imported) inside a namespace scope.
/// </summary>
public interface IUsedNamespace {
/// <summary>
/// An alias for a namespace. For example the "x" of "using x = y.z;" in C#. Empty if no alias is present.
/// </summary>
IName Alias { get; }
/// <summary>
/// The name of a namepace that has been aliased. For example the "y.z" of "using x = y.z;" or "using y.z" in C#.
/// </summary>
IName NamespaceName { get; }
}
/// <summary>
/// The name of an entity. Typically name instances come from a common pool. Within the pool no two distinct instances will have the same Value or UniqueKey.
/// </summary>
public interface IName {
/// <summary>
/// An integer that is unique within the pool from which the name instance has been allocated. Useful as a hashtable key.
/// </summary>
int UniqueKey {
get;
//^ ensures result > 0;
}
/// <summary>
/// An integer that is unique within the pool from which the name instance has been allocated. Useful as a hashtable key.
/// All name instances in the pool that have the same string value when ignoring the case of the characters in the string
/// will have the same key value.
/// </summary>
int UniqueKeyIgnoringCase {
get;
//^ ensures result > 0;
}
/// <summary>
/// The string value corresponding to this name.
/// </summary>
string Value { get; }
}
}

View File

@@ -0,0 +1,22 @@
Microsoft Public License (Ms-PL)
This license governs use of the accompanying software. If you use the software, you
accept this license. If you do not accept the license, do not use the software.
1. Definitions
The terms "reproduce," "reproduction," "derivative works," and "distribution" have the
same meaning here as under U.S. copyright law.
A "contribution" is the original software, or any additions or changes to the software.
A "contributor" is any person that distributes its contribution under this license.
"Licensed patents" are a contributor's patent claims that read directly on its contribution.
2. Grant of Rights
(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
3. Conditions and Limitations
(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.

View File

@@ -0,0 +1,58 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
namespace Microsoft.Cci.Pdb {
internal class MsfDirectory {
internal MsfDirectory(PdbReader reader, PdbFileHeader head, BitAccess bits) {
int pages = reader.PagesFromSize(head.directorySize);
// 0..n in page of directory pages.
bits.MinCapacity(head.directorySize);
int directoryRootPages = head.directoryRoot.Length;
int pagesPerPage = head.pageSize / 4;
int pagesToGo = pages;
for (int i = 0; i < directoryRootPages; i++) {
int pagesInThisPage = pagesToGo <= pagesPerPage ? pagesToGo : pagesPerPage;
reader.Seek(head.directoryRoot[i], 0);
bits.Append(reader.reader, pagesInThisPage * 4);
pagesToGo -= pagesInThisPage;
}
bits.Position = 0;
DataStream stream = new DataStream(head.directorySize, bits, pages);
bits.MinCapacity(head.directorySize);
stream.Read(reader, bits);
// 0..3 in directory pages
int count;
bits.ReadInt32(out count);
// 4..n
int[] sizes = new int[count];
bits.ReadInt32(sizes);
// n..m
streams = new DataStream[count];
for (int i = 0; i < count; i++) {
if (sizes[i] <= 0) {
streams[i] = new DataStream();
} else {
streams[i] = new DataStream(sizes[i], bits,
reader.PagesFromSize(sizes[i]));
}
}
}
internal DataStream[] streams;
}
}

View File

@@ -0,0 +1,89 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
using System.Runtime.InteropServices;
namespace Microsoft.Cci.Pdb {
internal class PdbConstant {
internal string name;
internal uint token;
internal object value;
internal PdbConstant(BitAccess bits) {
bits.ReadUInt32(out this.token);
byte tag1;
bits.ReadUInt8(out tag1);
byte tag2;
bits.ReadUInt8(out tag2);
if (tag2 == 0) {
this.value = tag1;
} else if (tag2 == 0x80) {
switch (tag1) {
case 0x00: //sbyte
sbyte sb;
bits.ReadInt8(out sb);
this.value = sb;
break;
case 0x01: //short
short s;
bits.ReadInt16(out s);
this.value = s;
break;
case 0x02: //ushort
ushort us;
bits.ReadUInt16(out us);
this.value = us;
break;
case 0x03: //int
int i;
bits.ReadInt32(out i);
this.value = i;
break;
case 0x04: //uint
uint ui;
bits.ReadUInt32(out ui);
this.value = ui;
break;
case 0x05: //float
this.value = bits.ReadFloat();
break;
case 0x06: //double
this.value = bits.ReadDouble();
break;
case 0x09: //long
long sl;
bits.ReadInt64(out sl);
this.value = sl;
break;
case 0x0a: //ulong
ulong ul;
bits.ReadUInt64(out ul);
this.value = ul;
break;
case 0x10: //string
string str;
bits.ReadBString(out str);
this.value = str;
break;
case 0x19: //decimal
this.value = bits.ReadDecimal();
break;
default:
//TODO: error
break;
}
} else {
//TODO: error
}
bits.ReadCString(out name);
}
}
}

View File

@@ -0,0 +1,20 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
using System.IO;
namespace Microsoft.Cci.Pdb {
internal class PdbDebugException : IOException {
internal PdbDebugException(String format, params object[] args)
: base(String.Format(format, args)) {
}
}
}

View File

@@ -0,0 +1,20 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
using System.IO;
namespace Microsoft.Cci.Pdb {
internal class PdbException : IOException {
internal PdbException(String format, params object[] args)
: base(String.Format(format, args)) {
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,90 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
using System.IO;
using System.Text;
namespace Microsoft.Cci.Pdb {
internal class PdbFileHeader {
//internal PdbFileHeader(int pageSize) {
// this.magic = new byte[32] {
// 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, // "Microsof"
// 0x74, 0x20, 0x43, 0x2F, 0x43, 0x2B, 0x2B, 0x20, // "t C/C++ "
// 0x4D, 0x53, 0x46, 0x20, 0x37, 0x2E, 0x30, 0x30, // "MSF 7.00"
// 0x0D, 0x0A, 0x1A, 0x44, 0x53, 0x00, 0x00, 0x00 // "^^^DS^^^"
// };
// this.pageSize = pageSize;
//}
internal PdbFileHeader(Stream reader, BitAccess bits) {
bits.MinCapacity(56);
reader.Seek(0, SeekOrigin.Begin);
bits.FillBuffer(reader, 52);
this.magic = new byte[32];
bits.ReadBytes(this.magic); // 0..31
bits.ReadInt32(out this.pageSize); // 32..35
bits.ReadInt32(out this.freePageMap); // 36..39
bits.ReadInt32(out this.pagesUsed); // 40..43
bits.ReadInt32(out this.directorySize); // 44..47
bits.ReadInt32(out this.zero); // 48..51
int directoryPages = ((((directorySize + pageSize - 1) / pageSize) * 4) + pageSize - 1) / pageSize;
this.directoryRoot = new int[directoryPages];
bits.FillBuffer(reader, directoryPages * 4);
bits.ReadInt32(this.directoryRoot);
}
//internal string Magic {
// get { return StringFromBytesUTF8(magic); }
//}
//internal void Write(Stream writer, BitAccess bits) {
// bits.MinCapacity(pageSize);
// bits.WriteBytes(magic); // 0..31
// bits.WriteInt32(pageSize); // 32..35
// bits.WriteInt32(freePageMap); // 36..39
// bits.WriteInt32(pagesUsed); // 40..43
// bits.WriteInt32(directorySize); // 44..47
// bits.WriteInt32(zero); // 48..51
// bits.WriteInt32(directoryRoot); // 52..55
// writer.Seek(0, SeekOrigin.Begin);
// bits.WriteBuffer(writer, pageSize);
//}
//////////////////////////////////////////////////// Helper Functions.
//
//internal static string StringFromBytesUTF8(byte[] bytes) {
// return StringFromBytesUTF8(bytes, 0, bytes.Length);
//}
//internal static string StringFromBytesUTF8(byte[] bytes, int offset, int length) {
// for (int i = 0; i < length; i++) {
// if (bytes[offset + i] < ' ') {
// length = i;
// }
// }
// return Encoding.UTF8.GetString(bytes, offset, length);
//}
////////////////////////////////////////////////////////////// Fields.
//
internal readonly byte[] magic;
internal readonly int pageSize;
internal int freePageMap;
internal int pagesUsed;
internal int directorySize;
internal readonly int zero;
internal int[] directoryRoot;
}
}

View File

@@ -0,0 +1,498 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
namespace Microsoft.Cci.Pdb {
internal class PdbFunction {
static internal readonly Guid msilMetaData = new Guid(0xc6ea3fc9, 0x59b3, 0x49d6, 0xbc, 0x25,
0x09, 0x02, 0xbb, 0xab, 0xb4, 0x60);
static internal readonly IComparer byAddress = new PdbFunctionsByAddress();
static internal readonly IComparer byAddressAndToken = new PdbFunctionsByAddressAndToken();
//static internal readonly IComparer byToken = new PdbFunctionsByToken();
internal uint token;
internal uint slotToken;
internal uint tokenOfMethodWhoseUsingInfoAppliesToThisMethod;
//internal string name;
//internal string module;
//internal ushort flags;
internal uint segment;
internal uint address;
//internal uint length;
//internal byte[] metadata;
internal PdbScope[] scopes;
internal PdbSlot[] slots;
internal PdbConstant[] constants;
internal string[] usedNamespaces;
internal PdbLines[] lines;
internal ushort[]/*?*/ usingCounts;
internal IEnumerable<INamespaceScope>/*?*/ namespaceScopes;
internal string/*?*/ iteratorClass;
internal List<ILocalScope>/*?*/ iteratorScopes;
internal PdbSynchronizationInformation/*?*/ synchronizationInformation;
private static string StripNamespace(string module) {
int li = module.LastIndexOf('.');
if (li > 0) {
return module.Substring(li + 1);
}
return module;
}
internal static PdbFunction[] LoadManagedFunctions(/*string module,*/
BitAccess bits, uint limit,
bool readStrings) {
//string mod = StripNamespace(module);
int begin = bits.Position;
int count = 0;
while (bits.Position < limit) {
ushort siz;
ushort rec;
bits.ReadUInt16(out siz);
int star = bits.Position;
int stop = bits.Position + siz;
bits.Position = star;
bits.ReadUInt16(out rec);
switch ((SYM)rec) {
case SYM.S_GMANPROC:
case SYM.S_LMANPROC:
ManProcSym proc;
bits.ReadUInt32(out proc.parent);
bits.ReadUInt32(out proc.end);
bits.Position = (int)proc.end;
count++;
break;
case SYM.S_END:
bits.Position = stop;
break;
default:
//Console.WriteLine("{0,6}: {1:x2} {2}",
// bits.Position, rec, (SYM)rec);
bits.Position = stop;
break;
}
}
if (count == 0) {
return null;
}
bits.Position = begin;
PdbFunction[] funcs = new PdbFunction[count];
int func = 0;
while (bits.Position < limit) {
ushort siz;
ushort rec;
bits.ReadUInt16(out siz);
int star = bits.Position;
int stop = bits.Position + siz;
bits.ReadUInt16(out rec);
switch ((SYM)rec) {
case SYM.S_GMANPROC:
case SYM.S_LMANPROC:
ManProcSym proc;
//int offset = bits.Position;
bits.ReadUInt32(out proc.parent);
bits.ReadUInt32(out proc.end);
bits.ReadUInt32(out proc.next);
bits.ReadUInt32(out proc.len);
bits.ReadUInt32(out proc.dbgStart);
bits.ReadUInt32(out proc.dbgEnd);
bits.ReadUInt32(out proc.token);
bits.ReadUInt32(out proc.off);
bits.ReadUInt16(out proc.seg);
bits.ReadUInt8(out proc.flags);
bits.ReadUInt16(out proc.retReg);
if (readStrings) {
bits.ReadCString(out proc.name);
} else {
bits.SkipCString(out proc.name);
}
//Console.WriteLine("token={0:X8} [{1}::{2}]", proc.token, module, proc.name);
bits.Position = stop;
funcs[func++] = new PdbFunction(/*module,*/ proc, bits);
break;
default: {
//throw new PdbDebugException("Unknown SYMREC {0}", (SYM)rec);
bits.Position = stop;
break;
}
}
}
return funcs;
}
internal static void CountScopesAndSlots(BitAccess bits, uint limit,
out int constants, out int scopes, out int slots, out int usedNamespaces) {
int pos = bits.Position;
BlockSym32 block;
constants = 0;
slots = 0;
scopes = 0;
usedNamespaces = 0;
while (bits.Position < limit) {
ushort siz;
ushort rec;
bits.ReadUInt16(out siz);
int star = bits.Position;
int stop = bits.Position + siz;
bits.Position = star;
bits.ReadUInt16(out rec);
switch ((SYM)rec) {
case SYM.S_BLOCK32: {
bits.ReadUInt32(out block.parent);
bits.ReadUInt32(out block.end);
scopes++;
bits.Position = (int)block.end;
break;
}
case SYM.S_MANSLOT:
slots++;
bits.Position = stop;
break;
case SYM.S_UNAMESPACE:
usedNamespaces++;
bits.Position = stop;
break;
case SYM.S_MANCONSTANT:
constants++;
bits.Position = stop;
break;
default:
bits.Position = stop;
break;
}
}
bits.Position = pos;
}
internal PdbFunction() {
}
internal PdbFunction(/*string module, */ManProcSym proc, BitAccess bits) {
this.token = proc.token;
//this.module = module;
//this.name = proc.name;
//this.flags = proc.flags;
this.segment = proc.seg;
this.address = proc.off;
//this.length = proc.len;
if (proc.seg != 1) {
throw new PdbDebugException("Segment is {0}, not 1.", proc.seg);
}
if (proc.parent != 0 || proc.next != 0) {
throw new PdbDebugException("Warning parent={0}, next={1}",
proc.parent, proc.next);
}
//if (proc.dbgStart != 0 || proc.dbgEnd != 0) {
// throw new PdbDebugException("Warning DBG start={0}, end={1}",
// proc.dbgStart, proc.dbgEnd);
//}
int constantCount;
int scopeCount;
int slotCount;
int usedNamespacesCount;
CountScopesAndSlots(bits, proc.end, out constantCount, out scopeCount, out slotCount, out usedNamespacesCount);
int scope = constantCount > 0 || slotCount > 0 || usedNamespacesCount > 0 ? 1 : 0;
int slot = 0;
int constant = 0;
int usedNs = 0;
scopes = new PdbScope[scopeCount+scope];
slots = new PdbSlot[slotCount];
constants = new PdbConstant[constantCount];
usedNamespaces = new string[usedNamespacesCount];
if (scope > 0)
scopes[0] = new PdbScope(this.address, proc.len, slots, constants, usedNamespaces);
while (bits.Position < proc.end) {
ushort siz;
ushort rec;
bits.ReadUInt16(out siz);
int star = bits.Position;
int stop = bits.Position + siz;
bits.Position = star;
bits.ReadUInt16(out rec);
switch ((SYM)rec) {
case SYM.S_OEM: { // 0x0404
OemSymbol oem;
bits.ReadGuid(out oem.idOem);
bits.ReadUInt32(out oem.typind);
// internal byte[] rgl; // user data, force 4-byte alignment
if (oem.idOem == msilMetaData) {
string name = bits.ReadString();
if (name == "MD2") {
byte version;
bits.ReadUInt8(out version);
if (version == 4) {
byte count;
bits.ReadUInt8(out count);
bits.Align(4);
while (count-- > 0)
this.ReadCustomMetadata(bits);
}
} else if (name == "asyncMethodInfo") {
this.synchronizationInformation = new PdbSynchronizationInformation(bits);
}
bits.Position = stop;
break;
} else {
throw new PdbDebugException("OEM section: guid={0} ti={1}",
oem.idOem, oem.typind);
// bits.Position = stop;
}
}
case SYM.S_BLOCK32: {
BlockSym32 block = new BlockSym32();
bits.ReadUInt32(out block.parent);
bits.ReadUInt32(out block.end);
bits.ReadUInt32(out block.len);
bits.ReadUInt32(out block.off);
bits.ReadUInt16(out block.seg);
bits.SkipCString(out block.name);
bits.Position = stop;
scopes[scope++] = new PdbScope(this.address, block, bits, out slotToken);
bits.Position = (int)block.end;
break;
}
case SYM.S_MANSLOT:
slots[slot++] = new PdbSlot(bits);
bits.Position = stop;
break;
case SYM.S_MANCONSTANT:
constants[constant++] = new PdbConstant(bits);
bits.Position = stop;
break;
case SYM.S_UNAMESPACE:
bits.ReadCString(out usedNamespaces[usedNs++]);
bits.Position = stop;
break;
case SYM.S_END:
bits.Position = stop;
break;
default: {
//throw new PdbDebugException("Unknown SYM: {0}", (SYM)rec);
bits.Position = stop;
break;
}
}
}
if (bits.Position != proc.end) {
throw new PdbDebugException("Not at S_END");
}
ushort esiz;
ushort erec;
bits.ReadUInt16(out esiz);
bits.ReadUInt16(out erec);
if (erec != (ushort)SYM.S_END) {
throw new PdbDebugException("Missing S_END");
}
}
private void ReadCustomMetadata(BitAccess bits) {
int savedPosition = bits.Position;
byte version;
bits.ReadUInt8(out version);
if (version != 4) {
throw new PdbDebugException("Unknown custom metadata item version: {0}", version);
}
byte kind;
bits.ReadUInt8(out kind);
bits.Align(4);
uint numberOfBytesInItem;
bits.ReadUInt32(out numberOfBytesInItem);
switch (kind) {
case 0: this.ReadUsingInfo(bits); break;
case 1: this.ReadForwardInfo(bits); break;
case 2: break; // this.ReadForwardedToModuleInfo(bits); break;
case 3: this.ReadIteratorLocals(bits); break;
case 4: this.ReadForwardIterator(bits); break;
default: throw new PdbDebugException("Unknown custom metadata item kind: {0}", kind);
}
bits.Position = savedPosition+(int)numberOfBytesInItem;
}
private void ReadForwardIterator(BitAccess bits) {
this.iteratorClass = bits.ReadString();
}
private void ReadIteratorLocals(BitAccess bits) {
uint numberOfLocals;
bits.ReadUInt32(out numberOfLocals);
this.iteratorScopes = new List<ILocalScope>((int)numberOfLocals);
while (numberOfLocals-- > 0) {
uint ilStartOffset;
uint ilEndOffset;
bits.ReadUInt32(out ilStartOffset);
bits.ReadUInt32(out ilEndOffset);
this.iteratorScopes.Add(new PdbIteratorScope(ilStartOffset, ilEndOffset-ilStartOffset));
}
}
//private void ReadForwardedToModuleInfo(BitAccess bits) {
//}
private void ReadForwardInfo(BitAccess bits) {
bits.ReadUInt32(out this.tokenOfMethodWhoseUsingInfoAppliesToThisMethod);
}
private void ReadUsingInfo(BitAccess bits) {
ushort numberOfNamespaces;
bits.ReadUInt16(out numberOfNamespaces);
this.usingCounts = new ushort[numberOfNamespaces];
for (ushort i = 0; i < numberOfNamespaces; i++) {
bits.ReadUInt16(out this.usingCounts[i]);
}
}
internal class PdbFunctionsByAddress : IComparer {
public int Compare(Object x, Object y) {
PdbFunction fx = (PdbFunction)x;
PdbFunction fy = (PdbFunction)y;
if (fx.segment < fy.segment) {
return -1;
} else if (fx.segment > fy.segment) {
return 1;
} else if (fx.address < fy.address) {
return -1;
} else if (fx.address > fy.address) {
return 1;
} else {
return 0;
}
}
}
internal class PdbFunctionsByAddressAndToken : IComparer {
public int Compare(Object x, Object y) {
PdbFunction fx = (PdbFunction)x;
PdbFunction fy = (PdbFunction)y;
if (fx.segment < fy.segment) {
return -1;
} else if (fx.segment > fy.segment) {
return 1;
} else if (fx.address < fy.address) {
return -1;
} else if (fx.address > fy.address) {
return 1;
} else {
if (fx.token < fy.token)
return -1;
else if (fx.token > fy.token)
return 1;
else
return 0;
}
}
}
//internal class PdbFunctionsByToken : IComparer {
// public int Compare(Object x, Object y) {
// PdbFunction fx = (PdbFunction)x;
// PdbFunction fy = (PdbFunction)y;
// if (fx.token < fy.token) {
// return -1;
// } else if (fx.token > fy.token) {
// return 1;
// } else {
// return 0;
// }
// }
//}
}
internal class PdbSynchronizationInformation {
internal uint kickoffMethodToken;
internal uint generatedCatchHandlerIlOffset;
internal PdbSynchronizationPoint[] synchronizationPoints;
internal PdbSynchronizationInformation(BitAccess bits) {
uint asyncStepInfoCount;
bits.ReadUInt32(out this.kickoffMethodToken);
bits.ReadUInt32(out this.generatedCatchHandlerIlOffset);
bits.ReadUInt32(out asyncStepInfoCount);
this.synchronizationPoints = new PdbSynchronizationPoint[asyncStepInfoCount];
for (uint i = 0; i < asyncStepInfoCount; i += 1) {
this.synchronizationPoints[i] = new PdbSynchronizationPoint(bits);
}
}
public uint GeneratedCatchHandlerOffset {
get { return this.generatedCatchHandlerIlOffset; }
}
}
internal class PdbSynchronizationPoint {
internal uint synchronizeOffset;
internal uint continuationMethodToken;
internal uint continuationOffset;
internal PdbSynchronizationPoint(BitAccess bits) {
bits.ReadUInt32(out this.synchronizeOffset);
bits.ReadUInt32(out this.continuationMethodToken);
bits.ReadUInt32(out this.continuationOffset);
}
public uint SynchronizeOffset {
get { return this.synchronizeOffset; }
}
public uint ContinuationOffset {
get { return this.continuationOffset; }
}
}
}

View File

@@ -0,0 +1,29 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
namespace Microsoft.Cci.Pdb {
internal struct PdbLine {
internal uint offset;
internal uint lineBegin;
internal uint lineEnd;
internal ushort colBegin;
internal ushort colEnd;
internal PdbLine(uint offset, uint lineBegin, ushort colBegin, uint lineEnd, ushort colEnd) {
this.offset = offset;
this.lineBegin = lineBegin;
this.colBegin = colBegin;
this.lineEnd = lineEnd;
this.colEnd = colEnd;
}
}
}

Some files were not shown because too many files have changed in this diff Show More