Imported Upstream version 3.6.0

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

View File

@@ -0,0 +1,41 @@
//
// AssemblyInfo.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2011 Jb Evain
//
// 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:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// 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.
//
using System;
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle ("Mono.Cecil.Pdb")]
[assembly: AssemblyProduct ("Mono.Cecil")]
[assembly: AssemblyCopyright ("Copyright <20> 2008 - 2011 Jb Evain")]
[assembly: CLSCompliant (false)]
[assembly: ComVisible (false)]
[assembly: AssemblyVersion ("0.9.5.0")]
[assembly: AssemblyFileVersion ("0.9.5.0")]

View File

@@ -0,0 +1,41 @@
// ISymUnmanagedDocumentWriter.cs
//
// Author:
// Juerg Billeter (j@bitron.ch)
//
// (C) 2008 Juerg Billeter
//
// 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:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// 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.
//
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,103 @@
//
// ISymUnmanagedWriter2.cs
//
// Author:
// Juerg Billeter (j@bitron.ch)
//
// (C) 2008 Juerg Billeter
//
// 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:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// 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.
//
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,206 @@
//
// PdbHelper.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2011 Jb Evain
//
// 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:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// 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.
//
using System;
using System.Collections.Generic;
using System.IO;
using Mono.Cecil.Cil;
namespace Mono.Cecil.Pdb {
class PdbHelper {
#if !READ_ONLY
public 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;
}
#endif
public static string GetPdbFileName (string assemblyFileName)
{
return Path.ChangeExtension (assemblyFileName, ".pdb");
}
}
public class PdbReaderProvider : ISymbolReaderProvider {
public ISymbolReader GetSymbolReader (ModuleDefinition module, string fileName)
{
return new PdbReader (File.OpenRead (PdbHelper.GetPdbFileName (fileName)));
}
public ISymbolReader GetSymbolReader (ModuleDefinition module, Stream symbolStream)
{
return new PdbReader (symbolStream);
}
}
#if !READ_ONLY
public class PdbWriterProvider : ISymbolWriterProvider {
public ISymbolWriter GetSymbolWriter (ModuleDefinition module, string fileName)
{
return new PdbWriter (module, PdbHelper.CreateWriter (module, PdbHelper.GetPdbFileName (fileName)));
}
public ISymbolWriter GetSymbolWriter (ModuleDefinition module, Stream symbolStream)
{
throw new NotImplementedException ();
}
}
#endif
static class GuidMapping {
static readonly Dictionary<Guid, DocumentLanguage> guid_language = new Dictionary<Guid, DocumentLanguage> ();
static readonly Dictionary<DocumentLanguage, Guid> language_guid = new Dictionary<DocumentLanguage, Guid> ();
static GuidMapping ()
{
AddMapping (DocumentLanguage.C, new Guid (0x63a08714, 0xfc37, 0x11d2, 0x90, 0x4c, 0x0, 0xc0, 0x4f, 0xa3, 0x02, 0xa1));
AddMapping (DocumentLanguage.Cpp, new Guid (0x3a12d0b7, 0xc26c, 0x11d0, 0xb4, 0x42, 0x0, 0xa0, 0x24, 0x4a, 0x1d, 0xd2));
AddMapping (DocumentLanguage.CSharp, new Guid (0x3f5162f8, 0x07c6, 0x11d3, 0x90, 0x53, 0x0, 0xc0, 0x4f, 0xa3, 0x02, 0xa1));
AddMapping (DocumentLanguage.Basic, new Guid (0x3a12d0b8, 0xc26c, 0x11d0, 0xb4, 0x42, 0x0, 0xa0, 0x24, 0x4a, 0x1d, 0xd2));
AddMapping (DocumentLanguage.Java, new Guid (0x3a12d0b4, 0xc26c, 0x11d0, 0xb4, 0x42, 0x0, 0xa0, 0x24, 0x4a, 0x1d, 0xd2));
AddMapping (DocumentLanguage.Cobol, new Guid (0xaf046cd1, 0xd0e1, 0x11d2, 0x97, 0x7c, 0x0, 0xa0, 0xc9, 0xb4, 0xd5, 0xc));
AddMapping (DocumentLanguage.Pascal, new Guid (0xaf046cd2, 0xd0e1, 0x11d2, 0x97, 0x7c, 0x0, 0xa0, 0xc9, 0xb4, 0xd5, 0xc));
AddMapping (DocumentLanguage.Cil, new Guid (0xaf046cd3, 0xd0e1, 0x11d2, 0x97, 0x7c, 0x0, 0xa0, 0xc9, 0xb4, 0xd5, 0xc));
AddMapping (DocumentLanguage.JScript, new Guid (0x3a12d0b6, 0xc26c, 0x11d0, 0xb4, 0x42, 0x0, 0xa0, 0x24, 0x4a, 0x1d, 0xd2));
AddMapping (DocumentLanguage.Smc, new Guid (0xd9b9f7b, 0x6611, 0x11d3, 0xbd, 0x2a, 0x0, 0x0, 0xf8, 0x8, 0x49, 0xbd));
AddMapping (DocumentLanguage.MCpp, new Guid (0x4b35fde8, 0x07c6, 0x11d3, 0x90, 0x53, 0x0, 0xc0, 0x4f, 0xa3, 0x02, 0xa1));
AddMapping (DocumentLanguage.FSharp, new Guid (0xab4f38c9, 0xb6e6, 0x43ba, 0xbe, 0x3b, 0x58, 0x08, 0x0b, 0x2c, 0xcc, 0xe3));
}
static void AddMapping (DocumentLanguage language, Guid guid)
{
guid_language.Add (guid, language);
language_guid.Add (language, guid);
}
static readonly Guid type_text = new Guid (0x5a869d0b, 0x6611, 0x11d3, 0xbd, 0x2a, 0x00, 0x00, 0xf8, 0x08, 0x49, 0xbd);
public static DocumentType ToType (this Guid guid)
{
if (guid == type_text)
return DocumentType.Text;
return DocumentType.Other;
}
public static Guid ToGuid (this DocumentType type)
{
if (type == DocumentType.Text)
return type_text;
return new Guid ();
}
static readonly Guid hash_md5 = new Guid (0x406ea660, 0x64cf, 0x4c82, 0xb6, 0xf0, 0x42, 0xd4, 0x81, 0x72, 0xa7, 0x99);
static readonly Guid hash_sha1 = new Guid (0xff1816ec, 0xaa5e, 0x4d10, 0x87, 0xf7, 0x6f, 0x49, 0x63, 0x83, 0x34, 0x60);
public static DocumentHashAlgorithm ToHashAlgorithm (this Guid guid)
{
if (guid == hash_md5)
return DocumentHashAlgorithm.MD5;
if (guid == hash_sha1)
return DocumentHashAlgorithm.SHA1;
return DocumentHashAlgorithm.None;
}
public static Guid ToGuid (this DocumentHashAlgorithm hash_algo)
{
if (hash_algo == DocumentHashAlgorithm.MD5)
return hash_md5;
if (hash_algo == DocumentHashAlgorithm.SHA1)
return hash_sha1;
return new Guid ();
}
public static DocumentLanguage ToLanguage (this Guid guid)
{
DocumentLanguage language;
if (!guid_language.TryGetValue (guid, out language))
return DocumentLanguage.Other;
return language;
}
public static Guid ToGuid (this DocumentLanguage language)
{
Guid guid;
if (!language_guid.TryGetValue (language, out guid))
return new Guid ();
return guid;
}
static readonly Guid vendor_ms = new Guid (0x994b45c4, 0xe6e9, 0x11d2, 0x90, 0x3f, 0x00, 0xc0, 0x4f, 0xa3, 0x02, 0xa1);
public static DocumentLanguageVendor ToVendor (this Guid guid)
{
if (guid == vendor_ms)
return DocumentLanguageVendor.Microsoft;
return DocumentLanguageVendor.Other;
}
public static Guid ToGuid (this DocumentLanguageVendor vendor)
{
if (vendor == DocumentLanguageVendor.Microsoft)
return vendor_ms;
return new Guid ();
}
}
}
#if !NET_3_5 && !NET_4_0
namespace System.Runtime.CompilerServices {
[AttributeUsage (AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly)]
sealed class ExtensionAttribute : Attribute {
}
}
#endif

View File

@@ -0,0 +1,281 @@
//
// PdbReader.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2011 Jb Evain
//
// 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:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// 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.
//
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Cci.Pdb;
using Mono.Cecil.Cil;
namespace Mono.Cecil.Pdb {
public class PdbReader : ISymbolReader {
int age;
Guid guid;
readonly Stream pdb_file;
readonly Dictionary<string, Document> documents = new Dictionary<string, Document> ();
readonly Dictionary<uint, PdbFunction> functions = new Dictionary<uint, PdbFunction> ();
internal PdbReader (Stream file)
{
this.pdb_file = file;
}
/*
uint Magic = 0x53445352;
Guid Signature;
uint Age;
string FileName;
*/
public bool ProcessDebugHeader (ImageDebugDirectory directory, byte [] header)
{
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, 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 void Read (MethodBody body, InstructionMapper mapper)
{
var method_token = body.Method.MetadataToken;
PdbFunction function;
if (!functions.TryGetValue (method_token.ToUInt32 (), out function))
return;
ReadSequencePoints (function, mapper);
ReadScopeAndLocals (function.scopes, null, body, mapper);
}
static void ReadScopeAndLocals (PdbScope [] scopes, Scope parent, MethodBody body, InstructionMapper mapper)
{
foreach (PdbScope scope in scopes)
ReadScopeAndLocals (scope, parent, body, mapper);
CreateRootScope (body);
}
static void CreateRootScope (MethodBody body)
{
if (!body.HasVariables)
return;
var instructions = body.Instructions;
var root = new Scope ();
root.Start = instructions [0];
root.End = instructions [instructions.Count - 1];
var variables = body.Variables;
for (int i = 0; i < variables.Count; i++)
root.Variables.Add (variables [i]);
body.Scope = root;
}
static void ReadScopeAndLocals (PdbScope scope, Scope parent, MethodBody body, InstructionMapper mapper)
{
//Scope s = new Scope ();
//s.Start = GetInstruction (body, instructions, (int) scope.address);
//s.End = GetInstruction (body, instructions, (int) scope.length - 1);
//if (parent != null)
// parent.Scopes.Add (s);
//else
// body.Scopes.Add (s);
if (scope == null)
return;
foreach (PdbSlot slot in scope.slots) {
int index = (int) slot.slot;
if (index < 0 || index >= body.Variables.Count)
continue;
VariableDefinition variable = body.Variables [index];
variable.Name = slot.name;
//s.Variables.Add (variable);
}
ReadScopeAndLocals (scope.scopes, null /* s */, body, mapper);
}
void ReadSequencePoints (PdbFunction function, InstructionMapper mapper)
{
if (function.lines == null)
return;
foreach (PdbLines lines in function.lines)
ReadLines (lines, mapper);
}
void ReadLines (PdbLines lines, InstructionMapper mapper)
{
var document = GetDocument (lines.file);
foreach (var line in lines.lines)
ReadLine (line, document, mapper);
}
static void ReadLine (PdbLine line, Document document, InstructionMapper mapper)
{
var instruction = mapper ((int) line.offset);
if (instruction == null)
return;
var sequence_point = new SequencePoint (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;
instruction.SequencePoint = 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 Read (MethodSymbols symbols)
{
PdbFunction function;
if (!functions.TryGetValue (symbols.MethodToken.ToUInt32 (), out function))
return;
ReadSequencePoints (function, symbols);
ReadLocals (function.scopes, symbols);
}
void ReadLocals (PdbScope [] scopes, MethodSymbols symbols)
{
foreach (var scope in scopes)
ReadLocals (scope, symbols);
}
void ReadLocals (PdbScope scope, MethodSymbols symbols)
{
if (scope == null)
return;
foreach (var slot in scope.slots) {
int index = (int) slot.slot;
if (index < 0 || index >= symbols.Variables.Count)
continue;
var variable = symbols.Variables [index];
variable.Name = slot.name;
}
ReadLocals (scope.scopes, symbols);
}
void ReadSequencePoints (PdbFunction function, MethodSymbols symbols)
{
if (function.lines == null)
return;
foreach (PdbLines lines in function.lines)
ReadLines (lines, symbols);
}
void ReadLines (PdbLines lines, MethodSymbols symbols)
{
for (int i = 0; i < lines.lines.Length; i++) {
var line = lines.lines [i];
symbols.Instructions.Add (new InstructionSymbol ((int) line.offset, new SequencePoint (GetDocument (lines.file)) {
StartLine = (int) line.lineBegin,
StartColumn = (int) line.colBegin,
EndLine = (int) line.lineEnd,
EndColumn = (int) line.colEnd,
}));
}
}
public void Dispose ()
{
pdb_file.Close ();
}
}
}

View File

@@ -0,0 +1,222 @@
//
// PdbWriter.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2011 Jb Evain
//
// 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:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// 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.
//
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 (MethodBody body)
{
var method_token = body.Method.MetadataToken;
var sym_token = new SymbolToken (method_token.ToInt32 ());
var instructions = CollectInstructions (body);
if (instructions.Count == 0)
return;
var start_offset = 0;
var end_offset = body.CodeSize;
writer.OpenMethod (sym_token);
writer.OpenScope (start_offset);
DefineSequencePoints (instructions);
DefineVariables (body, start_offset, end_offset);
writer.CloseScope (end_offset);
writer.CloseMethod ();
}
Collection<Instruction> CollectInstructions (MethodBody body)
{
var collection = new Collection<Instruction> ();
var instructions = body.Instructions;
for (int i = 0; i < instructions.Count; i++) {
var instruction = instructions [i];
var sequence_point = instruction.SequencePoint;
if (sequence_point == null)
continue;
GetDocument (sequence_point.Document);
collection.Add (instruction);
}
return collection;
}
void DefineVariables (MethodBody body, int start_offset, int end_offset)
{
if (!body.HasVariables)
return;
var sym_token = new SymbolToken (body.LocalVarToken.ToInt32 ());
var variables = body.Variables;
for (int i = 0; i < variables.Count; i++) {
var variable = variables [i];
CreateLocalVariable (variable, sym_token, start_offset, end_offset);
}
}
void DefineSequencePoints (Collection<Instruction> instructions)
{
for (int i = 0; i < instructions.Count; i++) {
var instruction = instructions [i];
var sequence_point = instruction.SequencePoint;
writer.DefineSequencePoints (
GetDocument (sequence_point.Document),
new [] { instruction.Offset },
new [] { sequence_point.StartLine },
new [] { sequence_point.StartColumn },
new [] { sequence_point.EndLine },
new [] { sequence_point.EndColumn });
}
}
void CreateLocalVariable (VariableDefinition variable, SymbolToken local_var_token, int start_offset, int end_offset)
{
writer.DefineLocalVariable2 (
variable.Name,
0,
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 Write (MethodSymbols symbols)
{
var sym_token = new SymbolToken (symbols.MethodToken.ToInt32 ());
var start_offset = 0;
var end_offset = symbols.CodeSize;
writer.OpenMethod (sym_token);
writer.OpenScope (start_offset);
DefineSequencePoints (symbols);
DefineVariables (symbols, start_offset, end_offset);
writer.CloseScope (end_offset);
writer.CloseMethod ();
}
void DefineSequencePoints (MethodSymbols symbols)
{
var instructions = symbols.instructions;
for (int i = 0; i < instructions.Count; i++) {
var instruction = instructions [i];
var sequence_point = instruction.SequencePoint;
writer.DefineSequencePoints (
GetDocument (sequence_point.Document),
new [] { instruction.Offset },
new [] { sequence_point.StartLine },
new [] { sequence_point.StartColumn },
new [] { sequence_point.EndLine },
new [] { sequence_point.EndColumn });
}
}
void DefineVariables (MethodSymbols symbols, int start_offset, int end_offset)
{
if (!symbols.HasVariables)
return;
var sym_token = new SymbolToken (symbols.LocalVarToken.ToInt32 ());
var variables = symbols.Variables;
for (int i = 0; i < variables.Count; i++) {
var variable = variables [i];
CreateLocalVariable (variable, sym_token, start_offset, end_offset);
}
}
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,51 @@
//
// SymDocumentWriter.cs
//
// Author:
// Juerg Billeter (j@bitron.ch)
//
// (C) 2008 Juerg Billeter
//
// 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:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// 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.
//
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,170 @@
//
// SymWriter.cs
//
// Author:
// Juerg Billeter (j@bitron.ch)
//
// (C) 2008 Juerg Billeter
//
// 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:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// 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.
//
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,
FieldAttributes 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