From 84af4ab09269cd225c8d19fd9e561d86ead1f43a Mon Sep 17 00:00:00 2001 From: Jb Evain Date: Fri, 28 Oct 2011 10:07:38 +0200 Subject: Update Microsoft.Cci; Make sure we properly read basic documents; Fix #81 --- symbols/pdb/Microsoft.Cci.Pdb/BitAccess.cs | 98 +++++--- symbols/pdb/Microsoft.Cci.Pdb/BitSet.cs | 69 +++--- symbols/pdb/Microsoft.Cci.Pdb/CvInfo.cs | 109 +++++---- symbols/pdb/Microsoft.Cci.Pdb/DataStream.cs | 95 +++----- symbols/pdb/Microsoft.Cci.Pdb/DbiDbgHdr.cs | 7 +- symbols/pdb/Microsoft.Cci.Pdb/DbiHeader.cs | 7 +- symbols/pdb/Microsoft.Cci.Pdb/DbiModuleInfo.cs | 11 +- symbols/pdb/Microsoft.Cci.Pdb/DbiSecCon.cs | 7 +- symbols/pdb/Microsoft.Cci.Pdb/IntHashTable.cs | 262 +++++++++++---------- symbols/pdb/Microsoft.Cci.Pdb/MsfDirectory.cs | 21 +- symbols/pdb/Microsoft.Cci.Pdb/PdbConstant.cs | 12 +- symbols/pdb/Microsoft.Cci.Pdb/PdbDebugException.cs | 7 +- symbols/pdb/Microsoft.Cci.Pdb/PdbException.cs | 7 +- symbols/pdb/Microsoft.Cci.Pdb/PdbFile.cs | 72 +++--- symbols/pdb/Microsoft.Cci.Pdb/PdbFileHeader.cs | 88 +++---- symbols/pdb/Microsoft.Cci.Pdb/PdbFunction.cs | 123 +++++++--- symbols/pdb/Microsoft.Cci.Pdb/PdbLine.cs | 7 +- symbols/pdb/Microsoft.Cci.Pdb/PdbLines.cs | 7 +- symbols/pdb/Microsoft.Cci.Pdb/PdbReader.cs | 13 +- symbols/pdb/Microsoft.Cci.Pdb/PdbScope.cs | 32 ++- symbols/pdb/Microsoft.Cci.Pdb/PdbSlot.cs | 15 +- symbols/pdb/Microsoft.Cci.Pdb/PdbSource.cs | 13 +- symbols/pdb/Microsoft.Cci.Pdb/PdbWriter.cs | 129 ---------- .../Microsoft.Cci.Pdb/SourceLocationProvider.cs | 33 --- symbols/pdb/Mono.Cecil.Pdb.csproj | 1 - symbols/pdb/Test/Mono.Cecil.Tests/PdbTests.cs | 18 ++ .../pdb/Test/Resources/assemblies/VBConsApp.exe | Bin 0 -> 15360 bytes .../pdb/Test/Resources/assemblies/VBConsApp.pdb | Bin 0 -> 36352 bytes 28 files changed, 646 insertions(+), 617 deletions(-) delete mode 100644 symbols/pdb/Microsoft.Cci.Pdb/PdbWriter.cs create mode 100755 symbols/pdb/Test/Resources/assemblies/VBConsApp.exe create mode 100755 symbols/pdb/Test/Resources/assemblies/VBConsApp.pdb (limited to 'symbols') diff --git a/symbols/pdb/Microsoft.Cci.Pdb/BitAccess.cs b/symbols/pdb/Microsoft.Cci.Pdb/BitAccess.cs index 852f797..e8e77b0 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/BitAccess.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/BitAccess.cs @@ -1,6 +1,11 @@ //----------------------------------------------------------------------------- // -// Copyright (C) Microsoft Corporation. All Rights Reserved. +// 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; @@ -12,7 +17,6 @@ namespace Microsoft.Cci.Pdb { internal BitAccess(int capacity) { this.buffer = new byte[capacity]; - this.offset = 0; } internal byte[] Buffer { @@ -26,15 +30,26 @@ namespace Microsoft.Cci.Pdb { 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 WriteBuffer(Stream stream, int count) { + // stream.Write(buffer, 0, count); + //} internal void MinCapacity(int capacity) { if (buffer.Length < capacity) { @@ -49,25 +64,25 @@ namespace Microsoft.Cci.Pdb { } } - 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 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 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 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) | @@ -75,6 +90,11 @@ namespace Microsoft.Cci.Pdb { 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) | @@ -84,14 +104,14 @@ namespace Microsoft.Cci.Pdb { } internal void ReadInt64(out long value) { - value = (long)((buffer[offset + 0] & 0xFF) | - (buffer[offset + 1] << 8) | - (buffer[offset + 2] << 16) | - (buffer[offset + 3] << 24) | - (buffer[offset + 4] << 32) | - (buffer[offset + 5] << 40) | - (buffer[offset + 6] << 48) | - (buffer[offset + 7] << 56)); + 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; } @@ -115,14 +135,14 @@ namespace Microsoft.Cci.Pdb { } internal void ReadUInt64(out ulong value) { - value = (ulong)((buffer[offset + 0] & 0xFF) | - (buffer[offset + 1] << 8) | - (buffer[offset + 2] << 16) | - (buffer[offset + 3] << 24) | - (buffer[offset + 4] << 32) | - (buffer[offset + 5] << 40) | - (buffer[offset + 6] << 48) | - (buffer[offset + 7] << 56)); + 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; } @@ -159,7 +179,7 @@ namespace Microsoft.Cci.Pdb { internal decimal ReadDecimal() { int[] bits = new int[4]; this.ReadInt32(bits); - return new decimal(bits); + return new decimal(bits[2], bits[3], bits[1], bits[0] < 0, (byte)((bits[0] & 0x00FF0000) >> 16)); } internal void ReadBString(out string value) { diff --git a/symbols/pdb/Microsoft.Cci.Pdb/BitSet.cs b/symbols/pdb/Microsoft.Cci.Pdb/BitSet.cs index a9ed7f7..6719131 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/BitSet.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/BitSet.cs @@ -1,6 +1,11 @@ //----------------------------------------------------------------------------- // -// Copyright (C) Microsoft Corporation. All Rights Reserved. +// 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; @@ -13,10 +18,10 @@ namespace Microsoft.Cci.Pdb { bits.ReadUInt32(words); } - internal BitSet(int size) { - this.size = size; - words = new uint[size]; - } + //internal BitSet(int size) { + // this.size = size; + // words = new uint[size]; + //} internal bool IsSet(int index) { int word = index / 32; @@ -24,43 +29,43 @@ namespace Microsoft.Cci.Pdb { 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 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); - } + //internal void Clear(int index) { + // int word = index / 32; + // if (word >= this.size) return; + // words[word] &= ~GetBit(index); + //} - private uint GetBit(int index) { + private static uint GetBit(int index) { return ((uint)1 << (index % 32)); } - private uint ReverseBits(uint value) { - uint o = 0; - for (int i = 0; i < 32; i++) { - o = (o << 1) | (value & 1); - value >>= 1; - } - return o; - } + //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; - } + //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; diff --git a/symbols/pdb/Microsoft.Cci.Pdb/CvInfo.cs b/symbols/pdb/Microsoft.Cci.Pdb/CvInfo.cs index bef3086..49c51ce 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/CvInfo.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/CvInfo.cs @@ -1,6 +1,11 @@ //----------------------------------------------------------------------------- // -// Copyright (C) Microsoft Corporation. All Rights Reserved. +// 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. // //----------------------------------------------------------------------------- // @@ -163,67 +168,67 @@ namespace Microsoft.Cci.Pdb { // function to extract primitive mode, type and size - internal static CV_prmode CV_MODE(TYPE_ENUM typ) { - return (CV_prmode)((((uint)typ) & CV_MMASK) >> CV_MSHIFT); - } + //internal static CV_prmode CV_MODE(TYPE_ENUM typ) { + // return (CV_prmode)((((uint)typ) & CV_MMASK) >> CV_MSHIFT); + //} - internal static CV_type CV_TYPE(TYPE_ENUM typ) { - return (CV_type)((((uint)typ) & CV_TMASK) >> CV_TSHIFT); - } + //internal static CV_type CV_TYPE(TYPE_ENUM typ) { + // return (CV_type)((((uint)typ) & CV_TMASK) >> CV_TSHIFT); + //} - internal static uint CV_SUBT(TYPE_ENUM typ) { - return ((((uint)typ) & CV_SMASK) >> CV_SSHIFT); - } + //internal static uint CV_SUBT(TYPE_ENUM typ) { + // return ((((uint)typ) & CV_SMASK) >> CV_SSHIFT); + //} // functions to check the type of a primitive - internal static bool CV_TYP_IS_DIRECT(TYPE_ENUM typ) { - return (CV_MODE(typ) == CV_prmode.CV_TM_DIRECT); - } - - internal static bool CV_TYP_IS_PTR(TYPE_ENUM typ) { - return (CV_MODE(typ) != CV_prmode.CV_TM_DIRECT); - } - - internal static bool CV_TYP_IS_SIGNED(TYPE_ENUM typ) { - return - (((CV_TYPE(typ) == CV_type.CV_SIGNED) && CV_TYP_IS_DIRECT(typ)) || - (typ == TYPE_ENUM.T_INT1) || - (typ == TYPE_ENUM.T_INT2) || - (typ == TYPE_ENUM.T_INT4) || - (typ == TYPE_ENUM.T_INT8) || - (typ == TYPE_ENUM.T_INT16) || - (typ == TYPE_ENUM.T_RCHAR)); - } - - internal static bool CV_TYP_IS_UNSIGNED(TYPE_ENUM typ) { - return (((CV_TYPE(typ) == CV_type.CV_UNSIGNED) && CV_TYP_IS_DIRECT(typ)) || - (typ == TYPE_ENUM.T_UINT1) || - (typ == TYPE_ENUM.T_UINT2) || - (typ == TYPE_ENUM.T_UINT4) || - (typ == TYPE_ENUM.T_UINT8) || - (typ == TYPE_ENUM.T_UINT16)); - } - - internal static bool CV_TYP_IS_REAL(TYPE_ENUM typ) { - return ((CV_TYPE(typ) == CV_type.CV_REAL) && CV_TYP_IS_DIRECT(typ)); - } + //internal static bool CV_TYP_IS_DIRECT(TYPE_ENUM typ) { + // return (CV_MODE(typ) == CV_prmode.CV_TM_DIRECT); + //} + + //internal static bool CV_TYP_IS_PTR(TYPE_ENUM typ) { + // return (CV_MODE(typ) != CV_prmode.CV_TM_DIRECT); + //} + + //internal static bool CV_TYP_IS_SIGNED(TYPE_ENUM typ) { + // return + // (((CV_TYPE(typ) == CV_type.CV_SIGNED) && CV_TYP_IS_DIRECT(typ)) || + // (typ == TYPE_ENUM.T_INT1) || + // (typ == TYPE_ENUM.T_INT2) || + // (typ == TYPE_ENUM.T_INT4) || + // (typ == TYPE_ENUM.T_INT8) || + // (typ == TYPE_ENUM.T_INT16) || + // (typ == TYPE_ENUM.T_RCHAR)); + //} + + //internal static bool CV_TYP_IS_UNSIGNED(TYPE_ENUM typ) { + // return (((CV_TYPE(typ) == CV_type.CV_UNSIGNED) && CV_TYP_IS_DIRECT(typ)) || + // (typ == TYPE_ENUM.T_UINT1) || + // (typ == TYPE_ENUM.T_UINT2) || + // (typ == TYPE_ENUM.T_UINT4) || + // (typ == TYPE_ENUM.T_UINT8) || + // (typ == TYPE_ENUM.T_UINT16)); + //} + + //internal static bool CV_TYP_IS_REAL(TYPE_ENUM typ) { + // return ((CV_TYPE(typ) == CV_type.CV_REAL) && CV_TYP_IS_DIRECT(typ)); + //} const uint CV_FIRST_NONPRIM = 0x1000; - internal static bool CV_IS_PRIMITIVE(TYPE_ENUM typ) { - return ((uint)(typ) < CV_FIRST_NONPRIM); - } + //internal static bool CV_IS_PRIMITIVE(TYPE_ENUM typ) { + // return ((uint)(typ) < CV_FIRST_NONPRIM); + //} - internal static bool CV_TYP_IS_COMPLEX(TYPE_ENUM typ) { - return ((CV_TYPE(typ) == CV_type.CV_COMPLEX) && CV_TYP_IS_DIRECT(typ)); - } + //internal static bool CV_TYP_IS_COMPLEX(TYPE_ENUM typ) { + // return ((CV_TYPE(typ) == CV_type.CV_COMPLEX) && CV_TYP_IS_DIRECT(typ)); + //} - internal static bool CV_IS_INTERNAL_PTR(TYPE_ENUM typ) { - return (CV_IS_PRIMITIVE(typ) && - CV_TYPE(typ) == CV_type.CV_CVRESERVED && - CV_TYP_IS_PTR(typ)); - } + //internal static bool CV_IS_INTERNAL_PTR(TYPE_ENUM typ) { + // return (CV_IS_PRIMITIVE(typ) && + // CV_TYPE(typ) == CV_type.CV_CVRESERVED && + // CV_TYP_IS_PTR(typ)); + //} } // selected values for type_index - for a more complete definition, see diff --git a/symbols/pdb/Microsoft.Cci.Pdb/DataStream.cs b/symbols/pdb/Microsoft.Cci.Pdb/DataStream.cs index 99929d9..48a1851 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/DataStream.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/DataStream.cs @@ -1,6 +1,11 @@ //----------------------------------------------------------------------------- // -// Copyright (C) Microsoft Corporation. All Rights Reserved. +// 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; @@ -9,8 +14,6 @@ using System.IO; namespace Microsoft.Cci.Pdb { internal class DataStream { internal DataStream() { - this.contentSize = 0; - this.pages = null; } internal DataStream(int contentSize, BitAccess bits, int count) { @@ -72,73 +75,35 @@ namespace Microsoft.Cci.Pdb { } } - internal void Write(PdbWriter writer, byte[] bytes) { - Write(writer, bytes, bytes.Length); - } - - internal void Write(PdbWriter writer, byte[] bytes, int data) { - if (bytes == null || data == 0) { - return; - } - - int left = data; - int used = 0; - int rema = contentSize % writer.pageSize; - if (rema != 0) { - int todo = writer.pageSize - rema; - if (todo > left) { - todo = left; - } - - int lastPage = pages[pages.Length - 1]; - writer.Seek(lastPage, rema); - writer.Write(bytes, used, todo); - used += todo; - left -= todo; - } - - if (left > 0) { - int count = (left + writer.pageSize - 1) / writer.pageSize; - int page0 = writer.AllocatePages(count); - - writer.Seek(page0, 0); - writer.Write(bytes, used, left); - - AddPages(page0, count); - } - - contentSize += data; - } - - 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; } - } + //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 GetPage(int index) { + // return pages[index]; + //} internal int contentSize; internal int[] pages; diff --git a/symbols/pdb/Microsoft.Cci.Pdb/DbiDbgHdr.cs b/symbols/pdb/Microsoft.Cci.Pdb/DbiDbgHdr.cs index b6159ab..588f3c1 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/DbiDbgHdr.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/DbiDbgHdr.cs @@ -1,6 +1,11 @@ //----------------------------------------------------------------------------- // -// Copyright (C) Microsoft Corporation. All Rights Reserved. +// 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; diff --git a/symbols/pdb/Microsoft.Cci.Pdb/DbiHeader.cs b/symbols/pdb/Microsoft.Cci.Pdb/DbiHeader.cs index 29fb9fd..0ca7915 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/DbiHeader.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/DbiHeader.cs @@ -1,6 +1,11 @@ //----------------------------------------------------------------------------- // -// Copyright (C) Microsoft Corporation. All Rights Reserved. +// 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; diff --git a/symbols/pdb/Microsoft.Cci.Pdb/DbiModuleInfo.cs b/symbols/pdb/Microsoft.Cci.Pdb/DbiModuleInfo.cs index a9a5b2a..8ab3717 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/DbiModuleInfo.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/DbiModuleInfo.cs @@ -1,6 +1,11 @@ //----------------------------------------------------------------------------- // -// Copyright (C) Microsoft Corporation. All Rights Reserved. +// 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; @@ -9,7 +14,7 @@ namespace Microsoft.Cci.Pdb { internal class DbiModuleInfo { internal DbiModuleInfo(BitAccess bits, bool readStrings) { bits.ReadInt32(out opened); - section = new DbiSecCon(bits); + new DbiSecCon(bits); bits.ReadUInt16(out flags); bits.ReadInt16(out stream); bits.ReadInt32(out cbSyms); @@ -35,7 +40,7 @@ namespace Microsoft.Cci.Pdb { } internal int opened; // 0..3 - internal DbiSecCon section; // 4..31 + //internal DbiSecCon section; // 4..31 internal ushort flags; // 32..33 internal short stream; // 34..35 internal int cbSyms; // 36..39 diff --git a/symbols/pdb/Microsoft.Cci.Pdb/DbiSecCon.cs b/symbols/pdb/Microsoft.Cci.Pdb/DbiSecCon.cs index 1e2b60d..de9fde9 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/DbiSecCon.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/DbiSecCon.cs @@ -1,6 +1,11 @@ //----------------------------------------------------------------------------- // -// Copyright (C) Microsoft Corporation. All Rights Reserved. +// 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; diff --git a/symbols/pdb/Microsoft.Cci.Pdb/IntHashTable.cs b/symbols/pdb/Microsoft.Cci.Pdb/IntHashTable.cs index a092b1c..db0e41b 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/IntHashTable.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/IntHashTable.cs @@ -1,6 +1,11 @@ //----------------------------------------------------------------------------- // -// Copyright (C) Microsoft Corporation. All Rights Reserved. +// 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; @@ -54,7 +59,7 @@ namespace Microsoft.Cci.Pdb { // By Brian Grunkemeyer, algorithm by Patrick Dussud. // Version 1.30 2/20/2000 //| - internal class IntHashTable : IEnumerable { + internal class IntHashTable {//: IEnumerable { /* Implementation Notes: @@ -125,7 +130,7 @@ namespace Microsoft.Cci.Pdb { 187751, 225307, 270371, 324449, 389357, 467237, 560689, 672827, 807403, 968897, 1162687, 1395263, 1674319, 2009191, 2411033, 2893249, 3471899, 4166287, 4999559, 5999471, 7199369}; - private int GetPrime(int minSize) { + private static int GetPrime(int minSize) { if (minSize < 0) { throw new ArgumentException("Arg_HTCapacityOverflow"); } @@ -168,17 +173,17 @@ namespace Microsoft.Cci.Pdb { : this(0, 100) { } - // Constructs a new hashtable with the given initial capacity and a load - // factor of 1.0. The capacity argument serves as an indication of - // the number of entries the hashtable will contain. When this number (or - // an approximation) is known, specifying it in the constructor can - // eliminate a number of resizing operations that would otherwise be - // performed when elements are added to the hashtable. - // - //| - internal IntHashTable(int capacity) - : this(capacity, 100) { - } + //// Constructs a new hashtable with the given initial capacity and a load + //// factor of 1.0. The capacity argument serves as an indication of + //// the number of entries the hashtable will contain. When this number (or + //// an approximation) is known, specifying it in the constructor can + //// eliminate a number of resizing operations that would otherwise be + //// performed when elements are added to the hashtable. + //// + ////| + //internal IntHashTable(int capacity) + // : this(capacity, 100) { + //} // Constructs a new hashtable with the given initial capacity and load // factor. The capacity argument serves as an indication of the @@ -213,7 +218,7 @@ namespace Microsoft.Cci.Pdb { // The out parameter seed is h1(key), while the out parameter // incr is h2(key, hashSize). Callers of this function should // add incr each time through a loop. - private uint InitHash(int key, int hashsize, out uint seed, out uint incr) { + private static uint InitHash(int key, int hashsize, out uint seed, out uint incr) { // Hashcode must be positive. Also, we must not use the sign bit, since // that is used for the collision bit. uint hashcode = (uint)key & 0x7FFFFFFF; @@ -236,52 +241,52 @@ namespace Microsoft.Cci.Pdb { Insert(key, value, true); } - // Removes all entries from this hashtable. - //| - internal void Clear() { - if (count == 0) - return; + //// Removes all entries from this hashtable. + ////| + //internal void Clear() { + // if (count == 0) + // return; - for (int i = 0; i < buckets.Length; i++) { - buckets[i].hash_coll = 0; - buckets[i].key = -1; - buckets[i].val = null; - } + // for (int i = 0; i < buckets.Length; i++) { + // buckets[i].hash_coll = 0; + // buckets[i].key = -1; + // buckets[i].val = null; + // } - count = 0; - occupancy = 0; - } + // count = 0; + // occupancy = 0; + //} // Checks if this hashtable contains an entry with the given key. This is // an O(1) operation. // //| - internal bool Contains(int key) { - if (key < 0) { - throw new ArgumentException("Argument_KeyLessThanZero"); - } - - uint seed; - uint incr; - // Take a snapshot of buckets, in case another thread resizes table - bucket[] lbuckets = buckets; - uint hashcode = InitHash(key, lbuckets.Length, out seed, out incr); - int ntry = 0; - - bucket b; - do { - int bucketNumber = (int)(seed % (uint)lbuckets.Length); - b = lbuckets[bucketNumber]; - if (b.val == null) { - return false; - } - if (((b.hash_coll & 0x7FFFFFFF) == hashcode) && b.key == key) { - return true; - } - seed += incr; - } while (b.hash_coll < 0 && ++ntry < lbuckets.Length); - return false; - } + //internal bool Contains(int key) { + // if (key < 0) { + // throw new ArgumentException("Argument_KeyLessThanZero"); + // } + + // uint seed; + // uint incr; + // // Take a snapshot of buckets, in case another thread resizes table + // bucket[] lbuckets = buckets; + // uint hashcode = InitHash(key, lbuckets.Length, out seed, out incr); + // int ntry = 0; + + // bucket b; + // do { + // int bucketNumber = (int)(seed % (uint)lbuckets.Length); + // b = lbuckets[bucketNumber]; + // if (b.val == null) { + // return false; + // } + // if (((b.hash_coll & 0x7FFFFFFF) == hashcode) && b.key == key) { + // return true; + // } + // seed += incr; + // } while (b.hash_coll < 0 && ++ntry < lbuckets.Length); + // return false; + //} // Returns the value associated with the given key. If an entry with the // given key is not found, the returned value is null. @@ -313,9 +318,9 @@ namespace Microsoft.Cci.Pdb { } while (b.hash_coll < 0 && ++ntry < lbuckets.Length); return null; } - set { - Insert(key, value, false); - } + //set { + // Insert(key, value, false); + //} } // Increases the bucket count of this hashtable. This method is called from @@ -374,9 +379,9 @@ namespace Microsoft.Cci.Pdb { // enumerator will throw an exception. // //| - IEnumerator IEnumerable.GetEnumerator() { - return new IntHashTableEnumerator(this); - } + //IEnumerator IEnumerable.GetEnumerator() { + // return new IntHashTableEnumerator(this); + //} // Internal method to compare two keys. // @@ -502,78 +507,77 @@ namespace Microsoft.Cci.Pdb { // Returns the number of associations in this hashtable. // //| - internal int Count { - get { return count; } - } + //internal int Count { + // get { return count; } + //} // Implements an enumerator for a hashtable. The enumerator uses the // internal version number of the hashtabke to ensure that no modifications // are made to the hashtable while an enumeration is in progress. - private class IntHashTableEnumerator : IEnumerator { - private IntHashTable hashtable; - private int bucket; - private int version; - private bool current; - private int currentKey; - private Object currentValue; - - internal IntHashTableEnumerator(IntHashTable hashtable) { - this.hashtable = hashtable; - bucket = hashtable.buckets.Length; - version = hashtable.version; - current = false; - } - - public bool MoveNext() { - if (version != hashtable.version) - throw new InvalidOperationException("InvalidOperation_EnumFailedVersion"); - while (bucket > 0) { - bucket--; - Object val = hashtable.buckets[bucket].val; - if (val != null) { - currentKey = hashtable.buckets[bucket].key; - currentValue = val; - current = true; - return true; - } - } - current = false; - return false; - } - - internal int Key { - get { - if (current == false) - throw new InvalidOperationException("InvalidOperation_EnumOpCantHappen"); - return currentKey; - } - } - - public Object Current { - get { - if (current == false) - throw new InvalidOperationException("InvalidOperation_EnumOpCantHappen"); - return currentValue; - } - } - - public Object Value { - get { - if (version != hashtable.version) - throw new InvalidOperationException("InvalidOperation_EnumFailedVersion"); - if (current == false) - throw new InvalidOperationException("InvalidOperation_EnumOpCantHappen"); - return currentValue; - } - } - - public void Reset() { - if (version != hashtable.version) throw new InvalidOperationException("InvalidOperation_EnumFailedVersion"); - current = false; - bucket = hashtable.buckets.Length; - currentKey = -1; - currentValue = null; - } - } + //private class IntHashTableEnumerator : IEnumerator { + // private IntHashTable hashtable; + // private int bucket; + // private int version; + // private bool current; + // //private int currentKey; + // private Object currentValue; + + // internal IntHashTableEnumerator(IntHashTable hashtable) { + // this.hashtable = hashtable; + // bucket = hashtable.buckets.Length; + // version = hashtable.version; + // } + + // public bool MoveNext() { + // if (version != hashtable.version) + // throw new InvalidOperationException("InvalidOperation_EnumFailedVersion"); + // while (bucket > 0) { + // bucket--; + // Object val = hashtable.buckets[bucket].val; + // if (val != null) { + // //currentKey = hashtable.buckets[bucket].key; + // currentValue = val; + // current = true; + // return true; + // } + // } + // current = false; + // return false; + // } + + // //internal int Key { + // // get { + // // if (current == false) + // // throw new InvalidOperationException("InvalidOperation_EnumOpCantHappen"); + // // return currentKey; + // // } + // //} + + // public Object Current { + // get { + // if (current == false) + // throw new InvalidOperationException("InvalidOperation_EnumOpCantHappen"); + // return currentValue; + // } + // } + + // //public Object Value { + // // get { + // // if (version != hashtable.version) + // // throw new InvalidOperationException("InvalidOperation_EnumFailedVersion"); + // // if (current == false) + // // throw new InvalidOperationException("InvalidOperation_EnumOpCantHappen"); + // // return currentValue; + // // } + // //} + + // public void Reset() { + // if (version != hashtable.version) throw new InvalidOperationException("InvalidOperation_EnumFailedVersion"); + // current = false; + // bucket = hashtable.buckets.Length; + // //currentKey = -1; + // currentValue = null; + // } + //} } } diff --git a/symbols/pdb/Microsoft.Cci.Pdb/MsfDirectory.cs b/symbols/pdb/Microsoft.Cci.Pdb/MsfDirectory.cs index 3a7910d..a6669b5 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/MsfDirectory.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/MsfDirectory.cs @@ -1,6 +1,11 @@ //----------------------------------------------------------------------------- // -// Copyright (C) Microsoft Corporation. All Rights Reserved. +// 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; @@ -8,12 +13,20 @@ using System; namespace Microsoft.Cci.Pdb { internal class MsfDirectory { internal MsfDirectory(PdbReader reader, PdbFileHeader head, BitAccess bits) { - bits.MinCapacity(head.directorySize); int pages = reader.PagesFromSize(head.directorySize); // 0..n in page of directory pages. - reader.Seek(head.directoryRoot, 0); - bits.FillBuffer(reader.reader, pages * 4); + 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); diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbConstant.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbConstant.cs index 1f1aec1..434841b 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/PdbConstant.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbConstant.cs @@ -1,6 +1,11 @@ //----------------------------------------------------------------------------- // -// Copyright (C) Microsoft Corporation. All Rights Reserved. +// 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; @@ -22,6 +27,11 @@ namespace Microsoft.Cci.Pdb { 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); diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbDebugException.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbDebugException.cs index 515dc37..d7f8f0f 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/PdbDebugException.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbDebugException.cs @@ -1,6 +1,11 @@ //----------------------------------------------------------------------------- // -// Copyright (C) Microsoft Corporation. All Rights Reserved. +// 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; diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbException.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbException.cs index 0dd7f93..38d1d56 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/PdbException.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbException.cs @@ -1,6 +1,11 @@ //----------------------------------------------------------------------------- // -// Copyright (C) Microsoft Corporation. All Rights Reserved. +// 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; diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbFile.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbFile.cs index d6d493c..9e56028 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/PdbFile.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbFile.cs @@ -1,6 +1,11 @@ //----------------------------------------------------------------------------- // -// Copyright (C) Microsoft Corporation. All Rights Reserved. +// 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; @@ -21,7 +26,7 @@ namespace Microsoft.Cci.Pdb { bits.ReadGuid(out doctype); } - static Dictionary LoadNameIndex(BitAccess bits, out int age, out Guid guid) { + static Dictionary LoadNameIndex(BitAccess bits, out int age, out Guid guid) { Dictionary result = new Dictionary(); int ver; int sig; @@ -30,9 +35,9 @@ namespace Microsoft.Cci.Pdb { bits.ReadInt32(out age); // 8..11 Age bits.ReadGuid(out guid); // 12..27 GUID - if (ver != 20000404) { - throw new PdbDebugException("Unsupported PDB Stream version {0}", ver); - } + //if (ver != 20000404) { + // throw new PdbDebugException("Unsupported PDB Stream version {0}", ver); + //} // Read string buffer. int buf; @@ -70,7 +75,7 @@ namespace Microsoft.Cci.Pdb { bits.ReadCString(out name); bits.Position = saved; - result.Add(name, ni); + result.Add(name.ToUpperInvariant(), ni); j++; } } @@ -128,15 +133,11 @@ namespace Microsoft.Cci.Pdb { private static PdbFunction match = new PdbFunction(); - private static PdbFunction FindFunction(PdbFunction[] funcs, ushort sec, uint off) { + private static int FindFunction(PdbFunction[] funcs, ushort sec, uint off) { match.segment = sec; match.address = off; - int item = Array.BinarySearch(funcs, match, PdbFunction.byAddress); - if (item >= 0) { - return funcs[item]; - } - return null; + return Array.BinarySearch(funcs, match, PdbFunction.byAddress); } static void LoadManagedLines(PdbFunction[] funcs, @@ -146,7 +147,7 @@ namespace Microsoft.Cci.Pdb { Dictionary nameIndex, PdbReader reader, uint limit) { - Array.Sort(funcs, PdbFunction.byAddress); + Array.Sort(funcs, PdbFunction.byAddressAndToken); IntHashTable checks = new IntHashTable(); // Read the files first @@ -172,15 +173,15 @@ namespace Microsoft.Cci.Pdb { string name = (string)names[(int)chk.name]; int guidStream; Guid doctypeGuid = SymDocumentType.Text; - Guid languageGuid = SymLanguageType.CSharp; - Guid vendorGuid = SymLanguageVendor.Microsoft; - if (nameIndex.TryGetValue("/src/files/"+name, out guidStream)) { + Guid languageGuid = Guid.Empty; + Guid vendorGuid = Guid.Empty; + if (nameIndex.TryGetValue("/SRC/FILES/"+name.ToUpperInvariant(), out guidStream)) { var guidBits = new BitAccess(0x100); dir.streams[guidStream].Read(reader, guidBits); LoadGuidStream(guidBits, out doctypeGuid, out languageGuid, out vendorGuid); } - PdbSource src = new PdbSource((uint)ni, name, doctypeGuid, languageGuid, vendorGuid); + PdbSource src = new PdbSource(/*(uint)ni,*/ name, doctypeGuid, languageGuid, vendorGuid); checks.Add(ni, src); bits.Position += chk.len; bits.Align(4); @@ -211,8 +212,25 @@ namespace Microsoft.Cci.Pdb { bits.ReadUInt16(out sec.sec); bits.ReadUInt16(out sec.flags); bits.ReadUInt32(out sec.cod); - PdbFunction func = FindFunction(funcs, sec.sec, sec.off); - if (func == null) break; + int funcIndex = FindFunction(funcs, sec.sec, sec.off); + if (funcIndex < 0) break; + var func = funcs[funcIndex]; + if (func.lines == null) { + while (funcIndex > 0) { + var f = funcs[funcIndex-1]; + if (f.lines != null || f.segment != sec.sec || f.address != sec.off) break; + func = f; + funcIndex--; + } + } else { + while (funcIndex < funcs.Length-1 && func.lines != null) { + var f = funcs[funcIndex+1]; + if (f.segment != sec.sec || f.address != sec.off) break; + func = f; + funcIndex++; + } + } + if (func.lines != null) break; // Count the line blocks. int begSym = bits.Position; @@ -255,7 +273,7 @@ namespace Microsoft.Cci.Pdb { uint lineBegin = line.flags & (uint)CV_Line_Flags.linenumStart; uint delta = (line.flags & (uint)CV_Line_Flags.deltaLineEnd) >> 24; - bool statement = ((line.flags & (uint)CV_Line_Flags.fStatement) == 0); + //bool statement = ((line.flags & (uint)CV_Line_Flags.fStatement) == 0); if ((sec.flags & 1) != 0) { bits.Position = pcol + 4 * i; bits.ReadUInt16(out column.offColumnStart); @@ -295,7 +313,7 @@ namespace Microsoft.Cci.Pdb { bits.Position = 4; // Console.WriteLine("{0}:", info.moduleName); - funcs = PdbFunction.LoadManagedFunctions(info.moduleName, + funcs = PdbFunction.LoadManagedFunctions(/*info.moduleName,*/ bits, (uint)info.cbSyms, readStrings); if (funcs != null) { @@ -316,10 +334,10 @@ namespace Microsoft.Cci.Pdb { DbiHeader dh = new DbiHeader(bits); header = new DbiDbgHdr(); - if (dh.sig != -1 || dh.ver != 19990903) { - throw new PdbException("Unsupported DBI Stream version, sig={0}, ver={1}", - dh.sig, dh.ver); - } + //if (dh.sig != -1 || dh.ver != 19990903) { + // throw new PdbException("Unsupported DBI Stream version, sig={0}, ver={1}", + // dh.sig, dh.ver); + //} // Read gpmod section. ArrayList modList = new ArrayList(); @@ -377,7 +395,7 @@ namespace Microsoft.Cci.Pdb { dir.streams[1].Read(reader, bits); Dictionary nameIndex = LoadNameIndex(bits, out age, out guid); int nameStream; - if (!nameIndex.TryGetValue("/names", out nameStream)) { + if (!nameIndex.TryGetValue("/NAMES", out nameStream)) { throw new PdbException("No `name' stream"); } @@ -413,7 +431,7 @@ namespace Microsoft.Cci.Pdb { } // - Array.Sort(funcs, PdbFunction.byAddress); + Array.Sort(funcs, PdbFunction.byAddressAndToken); //Array.Sort(funcs, PdbFunction.byToken); return funcs; } diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbFileHeader.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbFileHeader.cs index c351076..e1f56db 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/PdbFileHeader.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbFileHeader.cs @@ -1,6 +1,11 @@ //----------------------------------------------------------------------------- // -// Copyright (C) Microsoft Corporation. All Rights Reserved. +// 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; @@ -9,21 +14,20 @@ 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; - this.zero = 0; - } + //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, 56); + bits.FillBuffer(reader, 52); this.magic = new byte[32]; bits.ReadBytes(this.magic); // 0..31 @@ -32,41 +36,45 @@ namespace Microsoft.Cci.Pdb { bits.ReadInt32(out this.pagesUsed); // 40..43 bits.ReadInt32(out this.directorySize); // 44..47 bits.ReadInt32(out this.zero); // 48..51 - bits.ReadInt32(out this.directoryRoot); // 52..55 - } - internal string Magic { - get { return StringFromBytesUTF8(magic); } + 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 void Write(Stream writer, BitAccess bits) { - bits.MinCapacity(56); - 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 + //internal string Magic { + // get { return StringFromBytesUTF8(magic); } + //} - writer.Seek(0, SeekOrigin.Begin); - bits.WriteBuffer(writer, 56); - } + //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 string StringFromBytesUTF8(byte[] bytes) { - return StringFromBytesUTF8(bytes, 0, bytes.Length); - } + //internal static string StringFromBytesUTF8(byte[] bytes) { + // return StringFromBytesUTF8(bytes, 0, bytes.Length); + //} - internal 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); - } + //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. // @@ -76,7 +84,7 @@ namespace Microsoft.Cci.Pdb { internal int pagesUsed; internal int directorySize; internal readonly int zero; - internal int directoryRoot; + internal int[] directoryRoot; } } diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbFunction.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbFunction.cs index be28420..d1daba1 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/PdbFunction.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbFunction.cs @@ -1,6 +1,11 @@ //----------------------------------------------------------------------------- // -// Copyright (C) Microsoft Corporation. All Rights Reserved. +// 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; @@ -12,20 +17,24 @@ namespace Microsoft.Cci.Pdb { 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 byToken = new PdbFunctionsByToken(); + static internal readonly IComparer byAddressAndToken = new PdbFunctionsByAddressAndToken(); + //static internal readonly IComparer byToken = new PdbFunctionsByToken(); internal uint token; internal uint slotToken; - internal string name; - internal string module; - internal ushort flags; + //internal string name; + //internal string module; + //internal ushort flags; internal uint segment; internal uint address; - internal uint length; + //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/*?*/ namespaceScopes; @@ -41,10 +50,10 @@ namespace Microsoft.Cci.Pdb { } - internal static PdbFunction[] LoadManagedFunctions(string module, + internal static PdbFunction[] LoadManagedFunctions(/*string module,*/ BitAccess bits, uint limit, bool readStrings) { - string mod = StripNamespace(module); + //string mod = StripNamespace(module); int begin = bits.Position; int count = 0; @@ -101,7 +110,7 @@ namespace Microsoft.Cci.Pdb { case SYM.S_GMANPROC: case SYM.S_LMANPROC: ManProcSym proc; - int offset = bits.Position; + //int offset = bits.Position; bits.ReadUInt32(out proc.parent); bits.ReadUInt32(out proc.end); @@ -122,7 +131,7 @@ namespace Microsoft.Cci.Pdb { //Console.WriteLine("token={0:X8} [{1}::{2}]", proc.token, module, proc.name); bits.Position = stop; - funcs[func++] = new PdbFunction(module, proc, bits); + funcs[func++] = new PdbFunction(/*module,*/ proc, bits); break; default: { @@ -190,15 +199,14 @@ namespace Microsoft.Cci.Pdb { internal PdbFunction() { } - internal PdbFunction(string module, ManProcSym proc, BitAccess bits) { + internal PdbFunction(/*string module, */ManProcSym proc, BitAccess bits) { this.token = proc.token; - this.module = module; - this.name = proc.name; - this.flags = proc.flags; + //this.module = module; + //this.name = proc.name; + //this.flags = proc.flags; this.segment = proc.seg; this.address = proc.off; - this.length = proc.len; - this.slotToken = 0; + //this.length = proc.len; if (proc.seg != 1) { throw new PdbDebugException("Segment is {0}, not 1.", proc.seg); @@ -207,18 +215,27 @@ namespace Microsoft.Cci.Pdb { 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); - } + //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); - scopes = new PdbScope[scopeCount]; - int scope = 0; + 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; @@ -266,17 +283,29 @@ namespace Microsoft.Cci.Pdb { bits.ReadUInt32(out block.parent); bits.ReadUInt32(out block.end); bits.ReadUInt32(out block.len); - bits.ReadUInt32(out this.address); + bits.ReadUInt32(out block.off); bits.ReadUInt16(out block.seg); bits.SkipCString(out block.name); bits.Position = stop; - scopes[scope] = new PdbScope(block, bits, out slotToken); + scopes[scope++] = new PdbScope(this.address, block, bits, out slotToken); bits.Position = (int)block.end; break; } + case SYM.S_MANSLOT: + uint typind; + slots[slot++] = new PdbSlot(bits, out typind); + 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; @@ -320,8 +349,8 @@ namespace Microsoft.Cci.Pdb { bits.ReadUInt32(out numberOfBytesInItem); switch (kind) { case 0: this.ReadUsingInfo(bits); break; - case 1: this.ReadForwardInfo(bits); break; - case 2: this.ReadForwardedToModuleInfo(bits); break; + case 1: break; // 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); @@ -346,11 +375,11 @@ namespace Microsoft.Cci.Pdb { } } - private void ReadForwardedToModuleInfo(BitAccess bits) { - } + //private void ReadForwardedToModuleInfo(BitAccess bits) { + //} - private void ReadForwardInfo(BitAccess bits) { - } + //private void ReadForwardInfo(BitAccess bits) { + //} private void ReadUsingInfo(BitAccess bits) { ushort numberOfNamespaces; @@ -380,20 +409,44 @@ namespace Microsoft.Cci.Pdb { } } - internal class PdbFunctionsByToken : IComparer { + internal class PdbFunctionsByAddressAndToken : IComparer { public int Compare(Object x, Object y) { PdbFunction fx = (PdbFunction)x; PdbFunction fy = (PdbFunction)y; - if (fx.token < fy.token) { + 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.token > fy.token) { + } else if (fx.address > fy.address) { return 1; } else { - return 0; + 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; + // } + // } + + //} } } diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbLine.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbLine.cs index 78eb9d6..f6fe3a9 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/PdbLine.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbLine.cs @@ -1,6 +1,11 @@ //----------------------------------------------------------------------------- // -// Copyright (C) Microsoft Corporation. All Rights Reserved. +// 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; diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbLines.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbLines.cs index 9e989cd..382638b 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/PdbLines.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbLines.cs @@ -1,6 +1,11 @@ //----------------------------------------------------------------------------- // -// Copyright (C) Microsoft Corporation. All Rights Reserved. +// 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; diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbReader.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbReader.cs index 52a8f2a..edfd926 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/PdbReader.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbReader.cs @@ -1,6 +1,11 @@ //----------------------------------------------------------------------------- // -// Copyright (C) Microsoft Corporation. All Rights Reserved. +// 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; @@ -25,9 +30,9 @@ namespace Microsoft.Cci.Pdb { return (size + pageSize - 1) / (pageSize); } - internal int PageSize { - get { return pageSize; } - } + //internal int PageSize { + // get { return pageSize; } + //} internal readonly int pageSize; internal readonly Stream reader; diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbScope.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbScope.cs index 72a68d7..c46220b 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/PdbScope.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbScope.cs @@ -1,6 +1,11 @@ //----------------------------------------------------------------------------- // -// Copyright (C) Microsoft Corporation. All Rights Reserved. +// 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; @@ -12,13 +17,25 @@ namespace Microsoft.Cci.Pdb { internal PdbScope[] scopes; internal string[] usedNamespaces; - internal uint segment; + //internal uint segment; internal uint address; + internal uint offset; internal uint length; - internal PdbScope(BlockSym32 block, BitAccess bits, out uint typind) { - this.segment = block.seg; + internal PdbScope(uint address, uint length, PdbSlot[] slots, PdbConstant[] constants, string[] usedNamespaces) { + this.constants = constants; + this.slots = slots; + this.scopes = new PdbScope[0]; + this.usedNamespaces = usedNamespaces; + this.address = address; + this.offset = 0; + this.length = length; + } + + internal PdbScope(uint funcOffset, BlockSym32 block, BitAccess bits, out uint typind) { + //this.segment = block.seg; this.address = block.off; + this.offset = block.off - funcOffset; this.length = block.len; typind = 0; @@ -58,7 +75,7 @@ namespace Microsoft.Cci.Pdb { bits.SkipCString(out sub.name); bits.Position = stop; - scopes[scope++] = new PdbScope(sub, bits, out typind); + scopes[scope++] = new PdbScope(funcOffset, sub, bits, out typind); break; } @@ -82,8 +99,9 @@ namespace Microsoft.Cci.Pdb { break; default: - throw new PdbException("Unknown SYM in scope {0}", (SYM)rec); - // bits.Position = stop; + //throw new PdbException("Unknown SYM in scope {0}", (SYM)rec); + bits.Position = stop; + break; } } diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbSlot.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbSlot.cs index b2cebbe..0dc89ad 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/PdbSlot.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbSlot.cs @@ -1,6 +1,11 @@ //----------------------------------------------------------------------------- // -// Copyright (C) Microsoft Corporation. All Rights Reserved. +// 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; @@ -10,8 +15,8 @@ namespace Microsoft.Cci.Pdb { internal uint slot; internal string name; internal ushort flags; - internal uint segment; - internal uint address; + //internal uint segment; + //internal uint address; internal PdbSlot(BitAccess bits, out uint typind) { AttrSlotSym slot; @@ -26,8 +31,8 @@ namespace Microsoft.Cci.Pdb { this.slot = slot.index; this.name = slot.name; this.flags = slot.flags; - this.segment = slot.segCod; - this.address = slot.offCod; + //this.segment = slot.segCod; + //this.address = slot.offCod; typind = slot.typind; } diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbSource.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbSource.cs index e7b0e34..ac40f85 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/PdbSource.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbSource.cs @@ -1,20 +1,25 @@ //----------------------------------------------------------------------------- // -// Copyright (C) Microsoft Corporation. All Rights Reserved. +// 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 PdbSource { - internal uint index; + //internal uint index; internal string name; internal Guid doctype; internal Guid language; internal Guid vendor; - internal PdbSource(uint index, string name, Guid doctype, Guid language, Guid vendor) { - this.index = index; + internal PdbSource(/*uint index, */string name, Guid doctype, Guid language, Guid vendor) { + //this.index = index; this.name = name; this.doctype = doctype; this.language = language; diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbWriter.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbWriter.cs deleted file mode 100644 index ca4992e..0000000 --- a/symbols/pdb/Microsoft.Cci.Pdb/PdbWriter.cs +++ /dev/null @@ -1,129 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (C) Microsoft Corporation. All Rights Reserved. -// -//----------------------------------------------------------------------------- -using System; -using System.IO; - -namespace Microsoft.Cci.Pdb { - internal class PdbWriter { - internal PdbWriter(Stream writer, int pageSize) { - this.pageSize = pageSize; - this.usedBytes = pageSize * 3; - this.writer = writer; - - writer.SetLength(usedBytes); - } - - internal void WriteMeta(DataStream[] streams, BitAccess bits) { - PdbFileHeader head = new PdbFileHeader(pageSize); - - WriteDirectory(streams, - out head.directoryRoot, - out head.directorySize, - bits); - WriteFreeMap(); - - head.freePageMap = 2; - head.pagesUsed = usedBytes / pageSize; - - writer.Seek(0, SeekOrigin.Begin); - head.Write(writer, bits); - } - - private void WriteDirectory(DataStream[] streams, - out int directoryRoot, - out int directorySize, - BitAccess bits) { - DataStream directory = new DataStream(); - - int pages = 0; - for (int s = 0; s < streams.Length; s++) { - if (streams[s].Length > 0) { - pages += streams[s].Pages; - } - } - - int use = 4 * (1 + streams.Length + pages); - bits.MinCapacity(use); - bits.WriteInt32(streams.Length); - for (int s = 0; s < streams.Length; s++) { - bits.WriteInt32(streams[s].Length); - } - for (int s = 0; s < streams.Length; s++) { - if (streams[s].Length > 0) { - bits.WriteInt32(streams[s].pages); - } - } - directory.Write(this, bits.Buffer, use); - directorySize = directory.Length; - - use = 4 * directory.Pages; - bits.MinCapacity(use); - bits.WriteInt32(directory.pages); - - DataStream ddir = new DataStream(); - ddir.Write(this, bits.Buffer, use); - - directoryRoot = ddir.pages[0]; - } - - private void WriteFreeMap() { - byte[] buffer = new byte[pageSize]; - - // We configure the old free map with only the first 3 pages allocated. - buffer[0] = 0xf8; - for (int i = 1; i < pageSize; i++) { - buffer[i] = 0xff; - } - Seek(1, 0); - Write(buffer, 0, pageSize); - - // We configure the new free map with all of the used pages gone. - int count = usedBytes / pageSize; - int full = count / 8; - for (int i = 0; i < full; i++) { - buffer[i] = 0; - } - int rema = count % 8; - buffer[full] = (byte)(0xff << rema); - - Seek(2, 0); - Write(buffer, 0, pageSize); - } - - internal int AllocatePages(int count) { - int begin = usedBytes; - - usedBytes += count * pageSize; - writer.SetLength(usedBytes); - - if (usedBytes > pageSize * pageSize * 8) { - throw new Exception("PdbWriter does not support multiple free maps."); - } - return begin / pageSize; - } - - internal void Seek(int page, int offset) { - writer.Seek(page * pageSize + offset, SeekOrigin.Begin); - } - - internal void Write(byte[] bytes, int offset, int count) { - writer.Write(bytes, offset, count); - } - - ////////////////////////////////////////////////////////////////////// - // - internal int PageSize { - get { return pageSize; } - } - - ////////////////////////////////////////////////////////////////////// - // - internal readonly int pageSize; - private Stream writer; - private int usedBytes; - } - -} diff --git a/symbols/pdb/Microsoft.Cci.Pdb/SourceLocationProvider.cs b/symbols/pdb/Microsoft.Cci.Pdb/SourceLocationProvider.cs index 2b28971..db3f291 100644 --- a/symbols/pdb/Microsoft.Cci.Pdb/SourceLocationProvider.cs +++ b/symbols/pdb/Microsoft.Cci.Pdb/SourceLocationProvider.cs @@ -13,38 +13,6 @@ using System.Diagnostics.SymbolStore; namespace Microsoft.Cci { - internal sealed class UsedNamespace : IUsedNamespace { - - internal UsedNamespace(IName alias, IName namespaceName) { - this.alias = alias; - this.namespaceName = namespaceName; - } - - public IName Alias { - get { return this.alias; } - } - readonly IName alias; - - public IName NamespaceName { - get { return this.namespaceName; } - } - readonly IName namespaceName; - - } - - internal class NamespaceScope : INamespaceScope { - - internal NamespaceScope(IEnumerable usedNamespaces) { - this.usedNamespaces = usedNamespaces; - } - - public IEnumerable UsedNamespaces { - get { return this.usedNamespaces; } - } - readonly IEnumerable usedNamespaces; - - } - internal sealed class PdbIteratorScope : ILocalScope { internal PdbIteratorScope(uint offset, uint length) { @@ -61,6 +29,5 @@ namespace Microsoft.Cci { get { return this.length; } } uint length; - } } \ No newline at end of file diff --git a/symbols/pdb/Mono.Cecil.Pdb.csproj b/symbols/pdb/Mono.Cecil.Pdb.csproj index 6c9e599..5248bad 100644 --- a/symbols/pdb/Mono.Cecil.Pdb.csproj +++ b/symbols/pdb/Mono.Cecil.Pdb.csproj @@ -108,7 +108,6 @@ - diff --git a/symbols/pdb/Test/Mono.Cecil.Tests/PdbTests.cs b/symbols/pdb/Test/Mono.Cecil.Tests/PdbTests.cs index 60d93a4..056ab68 100644 --- a/symbols/pdb/Test/Mono.Cecil.Tests/PdbTests.cs +++ b/symbols/pdb/Test/Mono.Cecil.Tests/PdbTests.cs @@ -76,6 +76,24 @@ namespace Mono.Cecil.Tests { Assert.AreEqual (DocumentLanguageVendor.Microsoft, document.LanguageVendor); } + [TestModule ("VBConsApp.exe", SymbolReaderProvider = typeof (PdbReaderProvider), SymbolWriterProvider = typeof (PdbWriterProvider))] + public void BasicDocument (ModuleDefinition module) + { + var type = module.GetType ("VBConsApp.Program"); + var method = type.GetMethod ("Main"); + + var sequence_point = method.Body.Instructions.Where (i => i.SequencePoint != null).First ().SequencePoint; + var document = sequence_point.Document; + + Assert.IsNotNull (document); + + Assert.AreEqual (@"c:\tmp\VBConsApp\Program.vb", document.Url); + Assert.AreEqual (DocumentType.Text, document.Type); + Assert.AreEqual (DocumentHashAlgorithm.None, document.HashAlgorithm); + Assert.AreEqual (DocumentLanguage.Basic, document.Language); + Assert.AreEqual (DocumentLanguageVendor.Microsoft, document.LanguageVendor); + } + [Test] public void CreateMethodFromScratch () { diff --git a/symbols/pdb/Test/Resources/assemblies/VBConsApp.exe b/symbols/pdb/Test/Resources/assemblies/VBConsApp.exe new file mode 100755 index 0000000..c86b64b Binary files /dev/null and b/symbols/pdb/Test/Resources/assemblies/VBConsApp.exe differ diff --git a/symbols/pdb/Test/Resources/assemblies/VBConsApp.pdb b/symbols/pdb/Test/Resources/assemblies/VBConsApp.pdb new file mode 100755 index 0000000..2625666 Binary files /dev/null and b/symbols/pdb/Test/Resources/assemblies/VBConsApp.pdb differ -- cgit v1.2.3