Imported Upstream version 6.8.0.73

Former-commit-id: d18deab1b47cfd3ad8cba82b3f37d00eec2170af
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-12-10 18:00:56 +00:00
parent bceda29824
commit 73ee7591e8
1043 changed files with 16271 additions and 22080 deletions

View File

@@ -1,13 +1,6 @@
//-----------------------------------------------------------------------------
//
// 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.
//
//-----------------------------------------------------------------------------
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using System.Text;
@@ -19,6 +12,11 @@ namespace Microsoft.Cci.Pdb {
this.buffer = new byte[capacity];
}
internal BitAccess(byte[] buffer) {
this.buffer = buffer;
offset = 0;
}
internal byte[] Buffer {
get { return buffer; }
}

View File

@@ -1,13 +1,6 @@
//-----------------------------------------------------------------------------
//
// 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.
//
//-----------------------------------------------------------------------------
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
namespace Microsoft.Cci.Pdb {

View File

@@ -1,32 +1,6 @@
//-----------------------------------------------------------------------------
//
// 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.
//
//-----------------------------------------------------------------------------
//
// File: CvInfo.cs
//
// Generic CodeView information definitions
//
// Structures, constants, etc. for accessing and interpreting
// CodeView information.
//
// The master copy of this file resides in the langapi project (in C++).
// All Microsoft projects are required to use the master copy without
// modification. Modification of the master version or a copy
// without consultation with all parties concerned is extremely
// risky.
//
// When this file is modified, the corresponding documentation file
// omfdeb.doc in the langapi project must be updated.
//
// This is a read-only copy of the C++ file converted to C#.
//
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
namespace Microsoft.Cci.Pdb {

View File

@@ -1,13 +1,6 @@
//-----------------------------------------------------------------------------
//
// 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.
//
//-----------------------------------------------------------------------------
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;

View File

@@ -1,13 +1,6 @@
//-----------------------------------------------------------------------------
//
// 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.
//
//-----------------------------------------------------------------------------
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
namespace Microsoft.Cci.Pdb {

View File

@@ -1,13 +1,6 @@
//-----------------------------------------------------------------------------
//
// 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.
//
//-----------------------------------------------------------------------------
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
namespace Microsoft.Cci.Pdb {

View File

@@ -1,13 +1,6 @@
//-----------------------------------------------------------------------------
//
// 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.
//
//-----------------------------------------------------------------------------
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
namespace Microsoft.Cci.Pdb {

View File

@@ -1,13 +1,6 @@
//-----------------------------------------------------------------------------
//
// 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.
//
//-----------------------------------------------------------------------------
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
namespace Microsoft.Cci.Pdb {

View File

@@ -1,13 +1,6 @@
//-----------------------------------------------------------------------------
//
// 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.
//
//-----------------------------------------------------------------------------
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections;
@@ -114,14 +107,14 @@ namespace Microsoft.Cci.Pdb {
*/
// A typical resize algorithm would pick the smallest prime number in this array
// that is larger than twice the previous capacity.
// Suppose our Hashtable currently has capacity x and enough elements are added
// such that a resize needs to occur. Resizing first computes 2x then finds the
// first prime in the table greater than 2x, i.e. if primes are ordered
// p_1, p_2, <20>, p_i,<2C>, it finds p_n such that p_n-1 < 2x < p_n.
// Doubling is important for preserving the asymptotic complexity of the
// hashtable operations such as add. Having a prime guarantees that double
// hashing does not lead to infinite loops. IE, your hash function will be
// that is larger than twice the previous capacity.
// Suppose our Hashtable currently has capacity x and enough elements are added
// such that a resize needs to occur. Resizing first computes 2x then finds the
// first prime in the table greater than 2x, i.e. if primes are ordered
// p_1, p_2, <20>, p_i,<2C>, it finds p_n such that p_n-1 < 2x < p_n.
// Doubling is important for preserving the asymptotic complexity of the
// hashtable operations such as add. Having a prime guarantees that double
// hashing does not lead to infinite loops. IE, your hash function will be
// h1(key) + i*h2(key), 0 <= i < size. h2 and the size must be relatively prime.
private static readonly int[] primes = {
3, 7, 11, 17, 23, 29, 37, 47, 59, 71, 89, 107, 131, 163, 197, 239, 293, 353, 431, 521, 631, 761, 919,

View File

@@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
namespace Microsoft.Cci {
namespace Microsoft.Cci.Pdb {
/// <summary>
/// A range of CLR IL operations that comprise a lexical scope, specified as an IL offset and a length.
/// </summary>
public interface ILocalScope {
interface ILocalScope {
/// <summary>
/// The offset of the first operation in the scope.
/// </summary>
@@ -22,7 +22,7 @@ namespace Microsoft.Cci {
/// 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 {
interface INamespaceScope {
/// <summary>
/// Zero or more used namespaces. These correspond to using clauses in C#.
@@ -35,7 +35,7 @@ namespace Microsoft.Cci {
/// <summary>
/// A namespace that is used (imported) inside a namespace scope.
/// </summary>
public interface IUsedNamespace {
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>
@@ -50,7 +50,7 @@ namespace Microsoft.Cci {
/// <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 {
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>

View File

@@ -1,22 +1,21 @@
Microsoft Public License (Ms-PL)
The MIT License (MIT)
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.
Copyright (c) Microsoft
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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
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.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of 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.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,13 +1,6 @@
//-----------------------------------------------------------------------------
//
// 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.
//
//-----------------------------------------------------------------------------
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
namespace Microsoft.Cci.Pdb {

View File

@@ -1,22 +1,22 @@
//-----------------------------------------------------------------------------
//
// 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.
//
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Runtime.InteropServices;
namespace Microsoft.Cci.Pdb {
/// <summary />
internal class PdbConstant {
internal string name;
internal uint token;
internal object value;
internal PdbConstant(string name, uint token, object value) {
this.name = name;
this.token = token;
this.value = value;
}
internal PdbConstant(BitAccess bits) {
bits.ReadUInt32(out this.token);
byte tag1;
@@ -78,7 +78,7 @@ namespace Microsoft.Cci.Pdb {
break;
default:
//TODO: error
break;
break;
}
} else {
//TODO: error

View File

@@ -1,13 +1,6 @@
//-----------------------------------------------------------------------------
//
// 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.
//
//-----------------------------------------------------------------------------
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;

View File

@@ -1,13 +1,6 @@
//-----------------------------------------------------------------------------
//
// 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.
//
//-----------------------------------------------------------------------------
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;

View File

@@ -1,29 +1,40 @@
//-----------------------------------------------------------------------------
//
// 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;
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using Mono.Cecil.Cil;
namespace Microsoft.Cci.Pdb {
internal class PdbFile {
/// <summary>
/// GUID of the Basic source language.
/// </summary>
private static readonly Guid BasicLanguageGuid = new Guid(974311608, -15764, 4560, 180, 66, 0, 160, 36, 74, 29, 210);
private PdbFile() // This class can't be instantiated.
{
}
static void LoadGuidStream(BitAccess bits, out Guid doctype, out Guid language, out Guid vendor) {
static void LoadInjectedSourceInformation(BitAccess bits, out Guid doctype, out Guid language, out Guid vendor, out Guid checksumAlgo, out byte[] checksum) {
int checksumSize;
int injectedSourceSize;
checksum = null;
bits.ReadGuid(out language);
bits.ReadGuid(out vendor);
bits.ReadGuid(out doctype);
bits.ReadGuid(out checksumAlgo);
bits.ReadInt32(out checksumSize);
bits.ReadInt32(out injectedSourceSize);
if (checksumSize > 0) {
checksum = new byte[checksumSize];
bits.ReadBytes(checksum);
}
}
static Dictionary<string, int> LoadNameIndex(BitAccess bits, out int age, out Guid guid) {
@@ -131,11 +142,11 @@ namespace Microsoft.Cci.Pdb {
return ht;
}
private static PdbFunction match = new PdbFunction();
private static int FindFunction(PdbFunction[] funcs, ushort sec, uint off) {
var match = new PdbFunction {
segment = sec,
address = off,
};
match.segment = sec;
match.address = off;
return Array.BinarySearch(funcs, match, PdbFunction.byAddress);
}
@@ -146,11 +157,13 @@ namespace Microsoft.Cci.Pdb {
MsfDirectory dir,
Dictionary<string, int> nameIndex,
PdbReader reader,
uint limit) {
uint limit,
Dictionary<string, PdbSource> sourceCache)
{
Array.Sort(funcs, PdbFunction.byAddressAndToken);
int begin = bits.Position;
IntHashTable checks = ReadSourceFileInfo(bits, limit, names, dir, nameIndex, reader);
IntHashTable checks = ReadSourceFileInfo(bits, limit, names, dir, nameIndex, reader, sourceCache);
// Read the lines next.
bits.Position = begin;
@@ -213,6 +226,11 @@ namespace Microsoft.Cci.Pdb {
bits.ReadUInt32(out file.linsiz); // Size of payload.
PdbSource src = (PdbSource)checks[(int)file.index];
if (src.language.Equals(BasicLanguageGuid))
{
func.AdjustVisualBasicScopes();
}
PdbLines tmp = new PdbLines(src, file.count);
func.lines[block++] = tmp;
PdbLine[] lines = tmp.lines;
@@ -258,7 +276,9 @@ namespace Microsoft.Cci.Pdb {
bool readStrings,
MsfDirectory dir,
Dictionary<string, int> nameIndex,
PdbReader reader) {
PdbReader reader,
Dictionary<string, PdbSource> sourceCache)
{
PdbFunction[] funcs = null;
bits.Position = 0;
@@ -276,7 +296,8 @@ namespace Microsoft.Cci.Pdb {
if (funcs != null) {
bits.Position = info.cbSyms + info.cbOldLines;
LoadManagedLines(funcs, names, bits, dir, nameIndex, reader,
(uint)(info.cbSyms + info.cbOldLines + info.cbLines));
(uint)(info.cbSyms + info.cbOldLines + info.cbLines),
sourceCache);
for (int i = 0; i < funcs.Length; i++) {
funcList.Add(funcs[i]);
@@ -337,32 +358,43 @@ namespace Microsoft.Cci.Pdb {
bits.Position = end;
}
internal static PdbFunction[] LoadFunctions(Stream read, out Dictionary<uint, PdbTokenLine> tokenToSourceMapping, out string sourceServerData, out int age, out Guid guid) {
tokenToSourceMapping = new Dictionary<uint, PdbTokenLine>();
BitAccess bits = new BitAccess(512 * 1024);
internal static PdbInfo LoadFunctions(Stream read) {
PdbInfo pdbInfo = new PdbInfo();
pdbInfo.TokenToSourceMapping = new Dictionary<uint, PdbTokenLine>();
BitAccess bits = new BitAccess(64 * 1024);
PdbFileHeader head = new PdbFileHeader(read, bits);
PdbReader reader = new PdbReader(read, head.pageSize);
MsfDirectory dir = new MsfDirectory(reader, head, bits);
DbiModuleInfo[] modules = null;
DbiDbgHdr header;
Dictionary<string, PdbSource> sourceCache = new Dictionary<string, PdbSource>();
dir.streams[1].Read(reader, bits);
Dictionary<string, int> nameIndex = LoadNameIndex(bits, out age, out guid);
Dictionary<string, int> nameIndex = LoadNameIndex(bits, out pdbInfo.Age, out pdbInfo.Guid);
int nameStream;
if (!nameIndex.TryGetValue("/NAMES", out nameStream)) {
throw new PdbException("No `name' stream");
throw new PdbException("Could not find the '/NAMES' stream: the PDB file may be a public symbol file instead of a private symbol file");
}
dir.streams[nameStream].Read(reader, bits);
IntHashTable names = LoadNameStream(bits);
int srcsrvStream;
if (!nameIndex.TryGetValue("SRCSRV", out srcsrvStream))
sourceServerData = string.Empty;
pdbInfo.SourceServerData = string.Empty;
else {
DataStream dataStream = dir.streams[srcsrvStream];
byte[] bytes = new byte[dataStream.contentSize];
dataStream.Read(reader, bits);
sourceServerData = bits.ReadBString(bytes.Length);
pdbInfo.SourceServerData = bits.ReadBString(bytes.Length);
}
int sourceLinkStream;
if (nameIndex.TryGetValue("SOURCELINK", out sourceLinkStream)) {
DataStream dataStream = dir.streams[sourceLinkStream];
pdbInfo.SourceLinkData = new byte[dataStream.contentSize];
dataStream.Read(reader, bits);
bits.ReadBytes(pdbInfo.SourceLinkData);
}
dir.streams[3].Read(reader, bits);
@@ -376,10 +408,10 @@ namespace Microsoft.Cci.Pdb {
if (module.stream > 0) {
dir.streams[module.stream].Read(reader, bits);
if (module.moduleName == "TokenSourceLineInfo") {
LoadTokenToSourceInfo(bits, module, names, dir, nameIndex, reader, tokenToSourceMapping);
LoadTokenToSourceInfo(bits, module, names, dir, nameIndex, reader, pdbInfo.TokenToSourceMapping, sourceCache);
continue;
}
LoadFuncsFromDbiModule(bits, module, names, funcList, true, dir, nameIndex, reader);
LoadFuncsFromDbiModule(bits, module, names, funcList, true, dir, nameIndex, reader, sourceCache);
}
}
}
@@ -400,11 +432,12 @@ namespace Microsoft.Cci.Pdb {
//
Array.Sort(funcs, PdbFunction.byAddressAndToken);
//Array.Sort(funcs, PdbFunction.byToken);
return funcs;
pdbInfo.Functions = funcs;
return pdbInfo;
}
private static void LoadTokenToSourceInfo(BitAccess bits, DbiModuleInfo module, IntHashTable names, MsfDirectory dir,
Dictionary<string, int> nameIndex, PdbReader reader, Dictionary<uint, PdbTokenLine> tokenToSourceMapping) {
Dictionary<string, int> nameIndex, PdbReader reader, Dictionary<uint, PdbTokenLine> tokenToSourceMapping, Dictionary<string,PdbSource> sourceCache) {
bits.Position = 0;
int sig;
bits.ReadInt32(out sig);
@@ -477,15 +510,18 @@ namespace Microsoft.Cci.Pdb {
bits.Position = module.cbSyms + module.cbOldLines;
int limit = module.cbSyms + module.cbOldLines + module.cbLines;
IntHashTable sourceFiles = ReadSourceFileInfo(bits, (uint)limit, names, dir, nameIndex, reader);
IntHashTable sourceFiles = ReadSourceFileInfo(bits, (uint)limit, names, dir, nameIndex, reader, sourceCache);
foreach (var tokenLine in tokenToSourceMapping.Values) {
tokenLine.sourceFile = (PdbSource)sourceFiles[(int)tokenLine.file_id];
}
}
public static readonly Guid SymDocumentType_Text = new Guid(1518771467, 26129, 4563, 189, 42, 0, 0, 248, 8, 73, 189);
private static IntHashTable ReadSourceFileInfo(BitAccess bits, uint limit, IntHashTable names, MsfDirectory dir,
Dictionary<string, int> nameIndex, PdbReader reader) {
Dictionary<string, int> nameIndex, PdbReader reader, Dictionary<string, PdbSource> sourceCache)
{
IntHashTable checks = new IntHashTable();
int begin = bits.Position;
@@ -508,17 +544,26 @@ namespace Microsoft.Cci.Pdb {
bits.ReadUInt8(out chk.type);
string name = (string)names[(int)chk.name];
int guidStream;
Guid doctypeGuid = DocumentType.Text.ToGuid();
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;
if (!sourceCache.TryGetValue(name, out src))
{
int guidStream;
Guid doctypeGuid = SymDocumentType_Text;
Guid languageGuid = Guid.Empty;
Guid vendorGuid = Guid.Empty;
Guid checksumAlgoGuid = Guid.Empty;
byte[] checksum = null;
if (nameIndex.TryGetValue("/SRC/FILES/" + name.ToUpperInvariant(), out guidStream))
{
var guidBits = new BitAccess(0x100);
dir.streams[guidStream].Read(reader, guidBits);
LoadInjectedSourceInformation(guidBits, out doctypeGuid, out languageGuid, out vendorGuid, out checksumAlgoGuid, out checksum);
}
src = new PdbSource(name, doctypeGuid, languageGuid, vendorGuid, checksumAlgoGuid, checksum);
sourceCache.Add(name, src);
}
checks.Add(ni, src);
bits.Position += chk.len;
bits.Align(4);

View File

@@ -1,19 +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.
//
//-----------------------------------------------------------------------------
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using System.Linq;
using System.Text;
namespace Microsoft.Cci.Pdb {
internal class PdbFileHeader {
private readonly byte[] windowsPdbMagic = 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^^^"
};
//internal PdbFileHeader(int pageSize) {
// this.magic = new byte[32] {
// 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, // "Microsof"
@@ -24,8 +25,6 @@ namespace Microsoft.Cci.Pdb {
// this.pageSize = pageSize;
//}
const string MAGIC = "Microsoft C/C++ MSF 7.00";
internal PdbFileHeader(Stream reader, BitAccess bits) {
bits.MinCapacity(56);
reader.Seek(0, SeekOrigin.Begin);
@@ -39,18 +38,20 @@ namespace Microsoft.Cci.Pdb {
bits.ReadInt32(out this.directorySize); // 44..47
bits.ReadInt32(out this.zero); // 48..51
if (Magic != MAGIC) {
throw new InvalidOperationException("Magic is wrong.");
if (!this.magic.SequenceEqual(windowsPdbMagic))
{
throw new PdbException("The PDB file is not recognized as a Windows PDB file");
}
int directoryPages = ((((directorySize + pageSize - 1) / pageSize) * 4) + pageSize - 1) / pageSize;
this.directoryRoot = new int[directoryPages];
bits.FillBuffer(reader, directoryPages * 4);
bits.ReadInt32(this.directoryRoot);
}
string Magic {
get { return StringFromBytesUTF8(magic, 0, MAGIC.Length); }
}
//internal string Magic {
// get { return StringFromBytesUTF8(magic); }
//}
//internal void Write(Stream writer, BitAccess bits) {
// bits.MinCapacity(pageSize);
@@ -68,18 +69,18 @@ namespace Microsoft.Cci.Pdb {
//////////////////////////////////////////////////// Helper Functions.
//
static string StringFromBytesUTF8(byte[] bytes) {
return StringFromBytesUTF8(bytes, 0, bytes.Length);
}
//internal static string StringFromBytesUTF8(byte[] bytes) {
// return StringFromBytesUTF8(bytes, 0, bytes.Length);
//}
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);
}
//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.
//

View File

@@ -1,17 +1,12 @@
//-----------------------------------------------------------------------------
//
// 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.
//
//-----------------------------------------------------------------------------
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections;
using System.Collections.Generic;
#pragma warning disable 1591 // TODO: doc comments
namespace Microsoft.Cci.Pdb {
internal class PdbFunction {
static internal readonly Guid msilMetaData = new Guid(0xc6ea3fc9, 0x59b3, 0x49d6, 0xbc, 0x25,
@@ -43,6 +38,13 @@ namespace Microsoft.Cci.Pdb {
internal List<ILocalScope>/*?*/ iteratorScopes;
internal PdbSynchronizationInformation/*?*/ synchronizationInformation;
/// <summary>
/// Flag saying whether the method has been identified as a product of VB compilation using
/// the legacy Windows PDB symbol format, in which case scope ends need to be shifted by 1
/// due to different semantics of scope limits in VB and C# compilers.
/// </summary>
private bool visualBasicScopesAdjusted = false;
private static string StripNamespace(string module) {
int li = module.LastIndexOf('.');
if (li > 0) {
@@ -51,6 +53,36 @@ namespace Microsoft.Cci.Pdb {
return module;
}
/// <summary>
/// When the Windows PDB reader identifies a PdbFunction as having 'Basic' as its source language,
/// it calls this method which adjusts all scopes by adding 1 to their lengths to compensate
/// for different behavior of VB vs. the C# compiler w.r.t. emission of scope info.
/// </summary>
internal void AdjustVisualBasicScopes()
{
if (!visualBasicScopesAdjusted)
{
visualBasicScopesAdjusted = true;
// Don't adjust root scope as that one is correct
foreach (PdbScope scope in scopes)
{
AdjustVisualBasicScopes(scope.scopes);
}
}
}
/// <summary>
/// Recursively update the entire scope tree by adding 1 to the length of each scope.
/// </summary>
private void AdjustVisualBasicScopes(PdbScope[] scopes)
{
foreach (PdbScope scope in scopes)
{
scope.length++;
AdjustVisualBasicScopes(scope.scopes);
}
}
internal static PdbFunction[] LoadManagedFunctions(/*string module,*/
BitAccess bits, uint limit,
@@ -260,15 +292,7 @@ namespace Microsoft.Cci.Pdb {
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);
}
ReadMD2CustomMetadata(bits);
} else if (name == "asyncMethodInfo") {
this.synchronizationInformation = new PdbSynchronizationInformation(bits);
}
@@ -338,27 +362,47 @@ namespace Microsoft.Cci.Pdb {
}
}
private void ReadCustomMetadata(BitAccess bits) {
int savedPosition = bits.Position;
internal void ReadMD2CustomMetadata(BitAccess bits)
{
byte version;
bits.ReadUInt8(out version);
if (version != 4) {
throw new PdbDebugException("Unknown custom metadata item version: {0}", version);
if (version == 4) {
byte count;
bits.ReadUInt8(out count);
bits.Align(4);
while (count-- > 0)
this.ReadCustomMetadata(bits);
}
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;
// TODO: handle unknown custom metadata, 5 & 6 are new with roslyn, see https://roslyn.codeplex.com/workitem/54
}
bits.Position = savedPosition+(int)numberOfBytesInItem;
}
private void ReadCustomMetadata(BitAccess bits)
{
int savedPosition = bits.Position;
byte version;
bits.ReadUInt8(out version);
byte kind;
bits.ReadUInt8(out kind);
bits.Position += 2; // 2-bytes padding
uint numberOfBytesInItem;
bits.ReadUInt32(out numberOfBytesInItem);
if (version == 4)
{
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;
case 5: break; // dynamic locals - see http://index/#Microsoft.VisualStudio.LanguageServices/Shared/CustomDebugInfoReader.cs,a3031f7681d76e93
case 6: break; // EnC data
case 7: break; // EnC data for lambdas and closures
// ignore any other unknown record types that may be added in future, instead of throwing an exception
// see more details here: https://github.com/tmat/roslyn/blob/portable-pdb/docs/specs/PortablePdb-Metadata.md
default: break; // throw new PdbDebugException("Unknown custom metadata item kind: {0}", kind);
}
}
bits.Position = savedPosition + (int)numberOfBytesInItem;
}
private void ReadForwardIterator(BitAccess bits) {

View File

@@ -0,0 +1,43 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
namespace Microsoft.Cci.Pdb {
/// <summary>
/// This class represents the information read from a PDB file (both legacy Windows and Portable).
/// </summary>
internal class PdbInfo {
/// <summary>
/// Enumeration of per-function information contained in the PDB file.
/// </summary>
public PdbFunction[] Functions;
/// <summary>
/// Mapping from tokens to source files and line numbers.
/// </summary>
public Dictionary<uint, PdbTokenLine> TokenToSourceMapping;
/// <summary>
/// Source server data information.
/// </summary>
public string SourceServerData;
/// <summary>
/// Age of the PDB file is used to match the PDB against the PE binary.
/// </summary>
public int Age;
/// <summary>
/// GUID of the PDB file is used to match the PDB against the PE binary.
/// </summary>
public Guid Guid;
/// <summary>
/// Source link data information.
/// </summary>
public byte[] SourceLinkData;
}
}

View File

@@ -1,13 +1,6 @@
//-----------------------------------------------------------------------------
//
// 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.
//
//-----------------------------------------------------------------------------
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
namespace Microsoft.Cci.Pdb {

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