Imported Upstream version 5.0.0.42

Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-04-10 11:41:01 +00:00
parent 1190d13a04
commit 6bdd276d05
19939 changed files with 3099680 additions and 93811 deletions

View File

@@ -0,0 +1,16 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
using System.Reflection;
[assembly: AssemblyTitle ("Mono.Cecil.Pdb")]
[assembly: CLSCompliant (false)]

View File

@@ -0,0 +1,22 @@
// Author:
// Juerg Billeter (j@bitron.ch)
//
// (C) 2008 Juerg Billeter
//
// Licensed under the MIT/X11 license.
//
using System.Runtime.InteropServices;
#if !READ_ONLY
namespace Mono.Cecil.Pdb {
[Guid ("B01FAFEB-C450-3A4D-BEEC-B4CEEC01E006")]
[InterfaceType (ComInterfaceType.InterfaceIsIUnknown)]
[ComImport]
interface ISymUnmanagedDocumentWriter {
}
}
#endif

View File

@@ -0,0 +1,84 @@
//
// Author:
// Juerg Billeter (j@bitron.ch)
//
// (C) 2008 Juerg Billeter
//
// Licensed under the MIT/X11 license.
//
using System;
using System.Diagnostics.SymbolStore;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using Mono.Cecil.Cil;
#if !READ_ONLY
namespace Mono.Cecil.Pdb {
[Guid ("0B97726E-9E6D-4f05-9A26-424022093CAA")]
[InterfaceType (ComInterfaceType.InterfaceIsIUnknown)]
[ComImport]
interface ISymUnmanagedWriter2 {
void DefineDocument (
[In, MarshalAs (UnmanagedType.LPWStr)] string url,
[In] ref Guid langauge,
[In] ref Guid languageVendor,
[In] ref Guid documentType,
[Out, MarshalAs (UnmanagedType.Interface)] out ISymUnmanagedDocumentWriter pRetVal);
void SetUserEntryPoint ([In] SymbolToken method);
void OpenMethod ([In] SymbolToken method);
void CloseMethod ();
void OpenScope ([In] int startOffset, [Out] out int pRetVal);
void CloseScope ([In] int endOffset);
void SetScopeRange_Placeholder ();
void DefineLocalVariable_Placeholder ();
void DefineParameter_Placeholder ();
void DefineField_Placeholder ();
void DefineGlobalVariable_Placeholder ();
void Close ();
void SetSymAttribute_Placeholder ();
void OpenNamespace ([In, MarshalAs (UnmanagedType.LPWStr)] string name);
void CloseNamespace ();
void UsingNamespace ([In, MarshalAs (UnmanagedType.LPWStr)] string fullName);
void SetMethodSourceRange_Placeholder ();
void Initialize (
[In, MarshalAs (UnmanagedType.IUnknown)] object emitter,
[In, MarshalAs (UnmanagedType.LPWStr)] string filename,
[In] IStream pIStream,
[In] bool fFullBuild);
void GetDebugInfo (
[Out] out ImageDebugDirectory pIDD,
[In] int cData,
[Out] out int pcData,
[In, Out, MarshalAs (UnmanagedType.LPArray, SizeParamIndex = 1)] byte [] data);
void DefineSequencePoints (
[In, MarshalAs (UnmanagedType.Interface)] ISymUnmanagedDocumentWriter document,
[In] int spCount,
[In, MarshalAs (UnmanagedType.LPArray, SizeParamIndex = 1)] int [] offsets,
[In, MarshalAs (UnmanagedType.LPArray, SizeParamIndex = 1)] int [] lines,
[In, MarshalAs (UnmanagedType.LPArray, SizeParamIndex = 1)] int [] columns,
[In, MarshalAs (UnmanagedType.LPArray, SizeParamIndex = 1)] int [] endLines,
[In, MarshalAs (UnmanagedType.LPArray, SizeParamIndex = 1)] int [] endColumns);
void RemapToken_Placeholder ();
void Initialize2_Placeholder ();
void DefineConstant_Placeholder ();
void Abort_Placeholder ();
void DefineLocalVariable2 (
[In, MarshalAs (UnmanagedType.LPWStr)] string name,
[In] int attributes,
[In] SymbolToken sigToken,
[In] int addrKind,
[In] int addr1,
[In] int addr2,
[In] int addr3,
[In] int startOffset,
[In] int endOffset);
}
}
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,142 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
using System.IO;
using Mono.Cecil.Cil;
namespace Mono.Cecil.Pdb {
public sealed class NativePdbReaderProvider : ISymbolReaderProvider {
public ISymbolReader GetSymbolReader (ModuleDefinition module, string fileName)
{
Mixin.CheckModule (module);
Mixin.CheckFileName (fileName);
return new PdbReader (Disposable.Owned (File.OpenRead (Mixin.GetPdbFileName (fileName)) as Stream));
}
public ISymbolReader GetSymbolReader (ModuleDefinition module, Stream symbolStream)
{
Mixin.CheckModule (module);
Mixin.CheckStream (symbolStream);
return new PdbReader (Disposable.NotOwned (symbolStream));
}
}
public sealed class PdbReaderProvider : ISymbolReaderProvider {
public ISymbolReader GetSymbolReader (ModuleDefinition module, string fileName)
{
Mixin.CheckModule (module);
Mixin.CheckFileName (fileName);
return IsPortablePdb (Mixin.GetPdbFileName (fileName))
? new PortablePdbReaderProvider ().GetSymbolReader (module, fileName)
: new NativePdbReaderProvider ().GetSymbolReader (module, fileName);
}
public ISymbolReader GetSymbolReader (ModuleDefinition module, Stream symbolStream)
{
Mixin.CheckModule (module);
Mixin.CheckStream (symbolStream);
Mixin.CheckReadSeek (symbolStream);
return IsPortablePdb (symbolStream)
? new PortablePdbReaderProvider ().GetSymbolReader (module, symbolStream)
: new NativePdbReaderProvider ().GetSymbolReader (module, symbolStream);
}
static bool IsPortablePdb (string fileName)
{
using (var file = new FileStream (fileName, FileMode.Open, FileAccess.Read, FileShare.None))
return IsPortablePdb (file);
}
static bool IsPortablePdb (Stream stream)
{
const uint ppdb_signature = 0x424a5342;
var position = stream.Position;
try {
var reader = new BinaryReader (stream);
return reader.ReadUInt32 () == ppdb_signature;
} finally {
stream.Position = position;
}
}
}
#if !READ_ONLY
public sealed class NativePdbWriterProvider : ISymbolWriterProvider {
public ISymbolWriter GetSymbolWriter (ModuleDefinition module, string fileName)
{
Mixin.CheckModule (module);
Mixin.CheckFileName (fileName);
return new PdbWriter (module, CreateWriter (module, Mixin.GetPdbFileName (fileName)));
}
static SymWriter CreateWriter (ModuleDefinition module, string pdb)
{
var writer = new SymWriter ();
if (File.Exists (pdb))
File.Delete (pdb);
writer.Initialize (new ModuleMetadata (module), pdb, true);
return writer;
}
public ISymbolWriter GetSymbolWriter (ModuleDefinition module, Stream symbolStream)
{
throw new NotImplementedException ();
}
}
public sealed class PdbWriterProvider : ISymbolWriterProvider {
public ISymbolWriter GetSymbolWriter (ModuleDefinition module, string fileName)
{
Mixin.CheckModule (module);
Mixin.CheckFileName (fileName);
if (HasPortablePdbSymbols (module))
return new PortablePdbWriterProvider ().GetSymbolWriter (module, fileName);
return new NativePdbWriterProvider ().GetSymbolWriter (module, fileName);
}
static bool HasPortablePdbSymbols (ModuleDefinition module)
{
return module.symbol_reader != null && module.symbol_reader is PortablePdbReader;
}
public ISymbolWriter GetSymbolWriter (ModuleDefinition module, Stream symbolStream)
{
Mixin.CheckModule (module);
Mixin.CheckStream (symbolStream);
Mixin.CheckReadSeek (symbolStream);
if (HasPortablePdbSymbols (module))
return new PortablePdbWriterProvider ().GetSymbolWriter (module, symbolStream);
return new NativePdbWriterProvider ().GetSymbolWriter (module, symbolStream);
}
}
#endif
}

View File

@@ -0,0 +1,211 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
using System.Collections.Generic;
using System.IO;
using Mono.Collections.Generic;
using Microsoft.Cci.Pdb;
using Mono.Cecil.Cil;
namespace Mono.Cecil.Pdb {
public class PdbReader : ISymbolReader {
int age;
Guid guid;
readonly Disposable<Stream> pdb_file;
readonly Dictionary<string, Document> documents = new Dictionary<string, Document> ();
readonly Dictionary<uint, PdbFunction> functions = new Dictionary<uint, PdbFunction> ();
internal PdbReader (Disposable<Stream> file)
{
this.pdb_file = file;
}
/*
uint Magic = 0x53445352;
Guid Signature;
uint Age;
string FileName;
*/
public bool ProcessDebugHeader (ImageDebugDirectory directory, byte [] header)
{
if (directory.Type != 2) //IMAGE_DEBUG_TYPE_CODEVIEW
return false;
if (directory.MajorVersion != 0 || directory.MinorVersion != 0)
return false;
if (header.Length < 24)
return false;
var magic = ReadInt32 (header, 0);
if (magic != 0x53445352)
return false;
var guid_bytes = new byte [16];
Buffer.BlockCopy (header, 4, guid_bytes, 0, 16);
this.guid = new Guid (guid_bytes);
this.age = ReadInt32 (header, 20);
return PopulateFunctions ();
}
static int ReadInt32 (byte [] bytes, int start)
{
return (bytes [start]
| (bytes [start + 1] << 8)
| (bytes [start + 2] << 16)
| (bytes [start + 3] << 24));
}
bool PopulateFunctions ()
{
using (pdb_file) {
Dictionary<uint, PdbTokenLine> tokenToSourceMapping;
string sourceServerData;
int age;
Guid guid;
var funcs = PdbFile.LoadFunctions (pdb_file.value, out tokenToSourceMapping, out sourceServerData, out age, out guid);
if (this.guid != guid)
return false;
foreach (PdbFunction function in funcs)
functions.Add (function.token, function);
}
return true;
}
public MethodDebugInformation Read (MethodDefinition method)
{
var method_token = method.MetadataToken;
PdbFunction function;
if (!functions.TryGetValue (method_token.ToUInt32 (), out function))
return null;
var symbol = new MethodDebugInformation (method);
ReadSequencePoints (function, symbol);
if (function.scopes.Length > 1)
throw new NotSupportedException ();
else if (function.scopes.Length == 1)
symbol.scope = ReadScopeAndLocals (function.scopes [0], symbol);
return symbol;
}
static Collection<ScopeDebugInformation> ReadScopeAndLocals (PdbScope [] scopes, MethodDebugInformation info)
{
var symbols = new Collection<ScopeDebugInformation> (scopes.Length);
foreach (PdbScope scope in scopes)
if (scope != null)
symbols.Add (ReadScopeAndLocals (scope, info));
return symbols;
}
static ScopeDebugInformation ReadScopeAndLocals (PdbScope scope, MethodDebugInformation info)
{
var parent = new ScopeDebugInformation ();
parent.Start = new InstructionOffset ((int) scope.offset);
parent.End = new InstructionOffset ((int) (scope.offset + scope.length));
if (!scope.slots.IsNullOrEmpty()) {
parent.variables = new Collection<VariableDebugInformation> (scope.slots.Length);
foreach (PdbSlot slot in scope.slots) {
var index = (int) slot.slot;
var variable = new VariableDebugInformation (index, slot.name);
if (slot.flags == 4)
variable.IsDebuggerHidden = true;
parent.variables.Add (variable);
}
}
if (!scope.constants.IsNullOrEmpty ()) {
parent.constants = new Collection<ConstantDebugInformation> (scope.constants.Length);
foreach (var constant in scope.constants) {
parent.constants.Add (new ConstantDebugInformation (
constant.name,
(TypeReference) info.method.Module.LookupToken ((int) constant.token),
constant.value));
}
}
parent.scopes = ReadScopeAndLocals (scope.scopes, info);
return parent;
}
void ReadSequencePoints (PdbFunction function, MethodDebugInformation info)
{
if (function.lines == null)
return;
info.sequence_points = new Collection<SequencePoint> ();
foreach (PdbLines lines in function.lines)
ReadLines (lines, info);
}
void ReadLines (PdbLines lines, MethodDebugInformation info)
{
var document = GetDocument (lines.file);
foreach (var line in lines.lines)
ReadLine (line, document, info);
}
static void ReadLine (PdbLine line, Document document, MethodDebugInformation info)
{
var sequence_point = new SequencePoint ((int) line.offset, document);
sequence_point.StartLine = (int) line.lineBegin;
sequence_point.StartColumn = (int) line.colBegin;
sequence_point.EndLine = (int) line.lineEnd;
sequence_point.EndColumn = (int) line.colEnd;
info.sequence_points.Add (sequence_point);
}
Document GetDocument (PdbSource source)
{
string name = source.name;
Document document;
if (documents.TryGetValue (name, out document))
return document;
document = new Document (name) {
Language = source.language.ToLanguage (),
LanguageVendor = source.vendor.ToVendor (),
Type = source.doctype.ToType (),
};
documents.Add (name, document);
return document;
}
public void Dispose ()
{
pdb_file.Dispose ();
}
}
}

View File

@@ -0,0 +1,141 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
using System.Collections.Generic;
using System.Diagnostics.SymbolStore;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;
#if !READ_ONLY
namespace Mono.Cecil.Pdb {
public class PdbWriter : Cil.ISymbolWriter {
readonly ModuleDefinition module;
readonly SymWriter writer;
readonly Dictionary<string, SymDocumentWriter> documents;
internal PdbWriter (ModuleDefinition module, SymWriter writer)
{
this.module = module;
this.writer = writer;
this.documents = new Dictionary<string, SymDocumentWriter> ();
}
public bool GetDebugHeader (out ImageDebugDirectory directory, out byte [] header)
{
header = writer.GetDebugInfo (out directory);
return true;
}
public void Write (MethodDebugInformation info)
{
var method_token = info.method.MetadataToken;
var sym_token = new SymbolToken (method_token.ToInt32 ());
writer.OpenMethod (sym_token);
DefineSequencePoints (info.sequence_points);
if (info.scope != null)
DefineScope (info.scope, info);
writer.CloseMethod ();
}
void DefineScope (ScopeDebugInformation scope, MethodDebugInformation info)
{
var start_offset = scope.Start.Offset;
var end_offset = scope.End.IsEndOfMethod
? info.code_size
: scope.End.Offset;
writer.OpenScope (start_offset);
var sym_token = new SymbolToken (info.local_var_token.ToInt32 ());
if (!scope.variables.IsNullOrEmpty ()) {
for (int i = 0; i < scope.variables.Count; i++) {
var variable = scope.variables [i];
CreateLocalVariable (variable, sym_token, start_offset, end_offset);
}
}
if (!scope.scopes.IsNullOrEmpty ()) {
for (int i = 0; i < scope.scopes.Count; i++)
DefineScope (scope.scopes [i], info);
}
writer.CloseScope (end_offset);
}
void DefineSequencePoints (Collection<SequencePoint> sequence_points)
{
for (int i = 0; i < sequence_points.Count; i++) {
var sequence_point = sequence_points [i];
writer.DefineSequencePoints (
GetDocument (sequence_point.Document),
new [] { sequence_point.Offset },
new [] { sequence_point.StartLine },
new [] { sequence_point.StartColumn },
new [] { sequence_point.EndLine },
new [] { sequence_point.EndColumn });
}
}
void CreateLocalVariable (VariableDebugInformation variable, SymbolToken local_var_token, int start_offset, int end_offset)
{
writer.DefineLocalVariable2 (
variable.Name,
variable.Attributes,
local_var_token,
SymAddressKind.ILOffset,
variable.Index,
0,
0,
start_offset,
end_offset);
}
SymDocumentWriter GetDocument (Document document)
{
if (document == null)
return null;
SymDocumentWriter doc_writer;
if (documents.TryGetValue (document.Url, out doc_writer))
return doc_writer;
doc_writer = writer.DefineDocument (
document.Url,
document.Language.ToGuid (),
document.LanguageVendor.ToGuid (),
document.Type.ToGuid ());
documents [document.Url] = doc_writer;
return doc_writer;
}
public void Dispose ()
{
var entry_point = module.EntryPoint;
if (entry_point != null)
writer.SetUserEntryPoint (new SymbolToken (entry_point.MetadataToken.ToInt32 ()));
writer.Close ();
}
}
}
#endif

View File

@@ -0,0 +1,32 @@
//
// Author:
// Juerg Billeter (j@bitron.ch)
//
// (C) 2008 Juerg Billeter
//
// Licensed under the MIT/X11 license.
//
using System;
#if !READ_ONLY
namespace Mono.Cecil.Pdb
{
internal class SymDocumentWriter
{
readonly ISymUnmanagedDocumentWriter m_unmanagedDocumentWriter;
public SymDocumentWriter (ISymUnmanagedDocumentWriter unmanagedDocumentWriter)
{
m_unmanagedDocumentWriter = unmanagedDocumentWriter;
}
public ISymUnmanagedDocumentWriter GetUnmanaged ()
{
return m_unmanagedDocumentWriter;
}
}
}
#endif

View File

@@ -0,0 +1,151 @@
//
// Author:
// Juerg Billeter (j@bitron.ch)
//
// (C) 2008 Juerg Billeter
//
// Licensed under the MIT/X11 license.
//
using System;
using System.Collections.Generic;
using System.Diagnostics.SymbolStore;
using System.Runtime.InteropServices;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;
#if !READ_ONLY
namespace Mono.Cecil.Pdb
{
internal class SymWriter
{
[DllImport("ole32.dll")]
static extern int CoCreateInstance (
[In] ref Guid rclsid,
[In, MarshalAs (UnmanagedType.IUnknown)] object pUnkOuter,
[In] uint dwClsContext,
[In] ref Guid riid,
[Out, MarshalAs (UnmanagedType.Interface)] out object ppv);
static Guid s_symUnmangedWriterIID = new Guid("0b97726e-9e6d-4f05-9a26-424022093caa");
static Guid s_CorSymWriter_SxS_ClassID = new Guid ("108296c1-281e-11d3-bd22-0000f80849bd");
readonly ISymUnmanagedWriter2 m_writer;
readonly Collection<ISymUnmanagedDocumentWriter> documents;
public SymWriter ()
{
object objWriter;
CoCreateInstance (ref s_CorSymWriter_SxS_ClassID, null, 1, ref s_symUnmangedWriterIID, out objWriter);
m_writer = (ISymUnmanagedWriter2) objWriter;
documents = new Collection<ISymUnmanagedDocumentWriter> ();
}
public byte[] GetDebugInfo (out ImageDebugDirectory idd)
{
int size;
// get size of debug info
m_writer.GetDebugInfo (out idd, 0, out size, null);
byte[] debug_info = new byte[size];
m_writer.GetDebugInfo (out idd, size, out size, debug_info);
return debug_info;
}
public void DefineLocalVariable2 (
string name,
VariableAttributes attributes,
SymbolToken sigToken,
SymAddressKind addrKind,
int addr1,
int addr2,
int addr3,
int startOffset,
int endOffset)
{
m_writer.DefineLocalVariable2 (name, (int)attributes, sigToken, (int)addrKind, addr1, addr2, addr3, startOffset, endOffset);
}
public void Close ()
{
m_writer.Close ();
Marshal.ReleaseComObject (m_writer);
foreach (var document in documents)
Marshal.ReleaseComObject (document);
}
public void CloseMethod ()
{
m_writer.CloseMethod ();
}
public void CloseNamespace ()
{
m_writer.CloseNamespace ();
}
public void CloseScope (int endOffset)
{
m_writer.CloseScope (endOffset);
}
public SymDocumentWriter DefineDocument (string url, Guid language, Guid languageVendor, Guid documentType)
{
ISymUnmanagedDocumentWriter unmanagedDocumentWriter;
m_writer.DefineDocument (url, ref language, ref languageVendor, ref documentType, out unmanagedDocumentWriter);
documents.Add (unmanagedDocumentWriter);
return new SymDocumentWriter (unmanagedDocumentWriter);
}
public void DefineParameter (string name, ParameterAttributes attributes, int sequence, SymAddressKind addrKind, int addr1, int addr2, int addr3)
{
throw new Exception ("The method or operation is not implemented.");
}
public void DefineSequencePoints (SymDocumentWriter document, int[] offsets, int[] lines, int[] columns, int[] endLines, int[] endColumns)
{
m_writer.DefineSequencePoints (document.GetUnmanaged(), offsets.Length, offsets, lines, columns, endLines, endColumns);
}
public void Initialize (object emitter, string filename, bool fFullBuild)
{
m_writer.Initialize (emitter, filename, null, fFullBuild);
}
public void SetUserEntryPoint (SymbolToken method)
{
m_writer.SetUserEntryPoint (method);
}
public void OpenMethod (SymbolToken method)
{
m_writer.OpenMethod (method);
}
public void OpenNamespace (string name)
{
m_writer.OpenNamespace (name);
}
public int OpenScope (int startOffset)
{
int result;
m_writer.OpenScope (startOffset, out result);
return result;
}
public void UsingNamespace (string fullName)
{
m_writer.UsingNamespace (fullName);
}
}
}
#endif