You've already forked linux-packaging-mono
Imported Upstream version 4.8.0.309
Former-commit-id: 5f9c6ae75f295e057a7d2971f3a6df4656fa8850
This commit is contained in:
parent
ee1447783b
commit
94b2861243
@@ -1,41 +1,16 @@
|
||||
//
|
||||
// AssemblyInfo.cs
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2011 Jb Evain
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// 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.
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
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")]
|
||||
|
||||
@@ -1,28 +1,9 @@
|
||||
// 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.
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
@@ -1,29 +1,10 @@
|
||||
//
|
||||
// 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.
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
@@ -487,7 +487,7 @@ namespace Mono.Cecil.Pdb {
|
||||
return 0;
|
||||
}
|
||||
|
||||
WriteString (type.Name, szTypeDef, cchTypeDef, out pchTypeDef);
|
||||
WriteString (type.IsNested ? type.Name : type.FullName, szTypeDef, cchTypeDef, out pchTypeDef);
|
||||
WriteIntPtr (pdwTypeDefFlags, (uint) type.Attributes);
|
||||
return type.BaseType != null ? type.BaseType.MetadataToken.ToUInt32 () : 0;
|
||||
}
|
||||
|
||||
@@ -1,43 +1,95 @@
|
||||
//
|
||||
// PdbHelper.cs
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2011 Jb Evain
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// 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.
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using Mono.Cecil.Cil;
|
||||
|
||||
namespace Mono.Cecil.Pdb {
|
||||
|
||||
class PdbHelper {
|
||||
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 static SymWriter CreateWriter (ModuleDefinition module, string pdb)
|
||||
|
||||
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 ();
|
||||
|
||||
@@ -48,35 +100,6 @@ namespace Mono.Cecil.Pdb {
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -84,123 +107,36 @@ namespace Mono.Cecil.Pdb {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
public sealed class PdbWriterProvider : ISymbolWriterProvider {
|
||||
|
||||
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 ()
|
||||
public ISymbolWriter GetSymbolWriter (ModuleDefinition module, string fileName)
|
||||
{
|
||||
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));
|
||||
Mixin.CheckModule (module);
|
||||
Mixin.CheckFileName (fileName);
|
||||
|
||||
if (HasPortablePdbSymbols (module))
|
||||
return new PortablePdbWriterProvider ().GetSymbolWriter (module, fileName);
|
||||
|
||||
return new NativePdbWriterProvider ().GetSymbolWriter (module, fileName);
|
||||
}
|
||||
|
||||
static void AddMapping (DocumentLanguage language, Guid guid)
|
||||
static bool HasPortablePdbSymbols (ModuleDefinition module)
|
||||
{
|
||||
guid_language.Add (guid, language);
|
||||
language_guid.Add (language, guid);
|
||||
return module.symbol_reader != null && module.symbol_reader is PortablePdbReader;
|
||||
}
|
||||
|
||||
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)
|
||||
public ISymbolWriter GetSymbolWriter (ModuleDefinition module, Stream symbolStream)
|
||||
{
|
||||
if (guid == type_text)
|
||||
return DocumentType.Text;
|
||||
Mixin.CheckModule (module);
|
||||
Mixin.CheckStream (symbolStream);
|
||||
Mixin.CheckReadSeek (symbolStream);
|
||||
|
||||
return DocumentType.Other;
|
||||
}
|
||||
if (HasPortablePdbSymbols (module))
|
||||
return new PortablePdbWriterProvider ().GetSymbolWriter (module, symbolStream);
|
||||
|
||||
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 ();
|
||||
return new NativePdbWriterProvider ().GetSymbolWriter (module, symbolStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if !NET_3_5 && !NET_4_0
|
||||
|
||||
namespace System.Runtime.CompilerServices {
|
||||
|
||||
[AttributeUsage (AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly)]
|
||||
sealed class ExtensionAttribute : Attribute {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,35 +1,19 @@
|
||||
//
|
||||
// PdbReader.cs
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2011 Jb Evain
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// 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.
|
||||
// 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;
|
||||
@@ -41,11 +25,11 @@ namespace Mono.Cecil.Pdb {
|
||||
int age;
|
||||
Guid guid;
|
||||
|
||||
readonly Stream pdb_file;
|
||||
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 (Stream file)
|
||||
internal PdbReader (Disposable<Stream> file)
|
||||
{
|
||||
this.pdb_file = file;
|
||||
}
|
||||
@@ -59,6 +43,11 @@ namespace Mono.Cecil.Pdb {
|
||||
|
||||
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;
|
||||
|
||||
@@ -91,7 +80,7 @@ namespace Mono.Cecil.Pdb {
|
||||
int age;
|
||||
Guid guid;
|
||||
|
||||
var funcs = PdbFile.LoadFunctions (pdb_file, out tokenToSourceMapping, out sourceServerData, out age, out guid);
|
||||
var funcs = PdbFile.LoadFunctions (pdb_file.value, out tokenToSourceMapping, out sourceServerData, out age, out guid);
|
||||
|
||||
if (this.guid != guid)
|
||||
return false;
|
||||
@@ -103,102 +92,99 @@ namespace Mono.Cecil.Pdb {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Read (MethodBody body, InstructionMapper mapper)
|
||||
public MethodDebugInformation Read (MethodDefinition method)
|
||||
{
|
||||
var method_token = body.Method.MetadataToken;
|
||||
var method_token = method.MetadataToken;
|
||||
|
||||
PdbFunction function;
|
||||
if (!functions.TryGetValue (method_token.ToUInt32 (), out function))
|
||||
return;
|
||||
return null;
|
||||
|
||||
ReadSequencePoints (function, mapper);
|
||||
ReadScopeAndLocals (function.scopes, null, body, mapper);
|
||||
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 void ReadScopeAndLocals (PdbScope [] scopes, Scope parent, MethodBody body, InstructionMapper mapper)
|
||||
static Collection<ScopeDebugInformation> ReadScopeAndLocals (PdbScope [] scopes, MethodDebugInformation info)
|
||||
{
|
||||
var symbols = new Collection<ScopeDebugInformation> (scopes.Length);
|
||||
|
||||
foreach (PdbScope scope in scopes)
|
||||
ReadScopeAndLocals (scope, parent, body, mapper);
|
||||
if (scope != null)
|
||||
symbols.Add (ReadScopeAndLocals (scope, info));
|
||||
|
||||
CreateRootScope (body);
|
||||
return symbols;
|
||||
}
|
||||
|
||||
static void CreateRootScope (MethodBody body)
|
||||
static ScopeDebugInformation ReadScopeAndLocals (PdbScope scope, MethodDebugInformation info)
|
||||
{
|
||||
if (!body.HasVariables)
|
||||
return;
|
||||
var parent = new ScopeDebugInformation ();
|
||||
parent.Start = new InstructionOffset ((int) scope.offset);
|
||||
parent.End = new InstructionOffset ((int) (scope.offset + scope.length));
|
||||
|
||||
var instructions = body.Instructions;
|
||||
if (!scope.slots.IsNullOrEmpty()) {
|
||||
parent.variables = new Collection<VariableDebugInformation> (scope.slots.Length);
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
ReadScopeAndLocals (scope.scopes, null /* s */, body, mapper);
|
||||
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, InstructionMapper mapper)
|
||||
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, mapper);
|
||||
ReadLines (lines, info);
|
||||
}
|
||||
|
||||
void ReadLines (PdbLines lines, InstructionMapper mapper)
|
||||
void ReadLines (PdbLines lines, MethodDebugInformation info)
|
||||
{
|
||||
var document = GetDocument (lines.file);
|
||||
|
||||
foreach (var line in lines.lines)
|
||||
ReadLine (line, document, mapper);
|
||||
ReadLine (line, document, info);
|
||||
}
|
||||
|
||||
static void ReadLine (PdbLine line, Document document, InstructionMapper mapper)
|
||||
static void ReadLine (PdbLine line, Document document, MethodDebugInformation info)
|
||||
{
|
||||
var instruction = mapper ((int) line.offset);
|
||||
if (instruction == null)
|
||||
return;
|
||||
|
||||
var sequence_point = new SequencePoint (document);
|
||||
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;
|
||||
|
||||
instruction.SequencePoint = sequence_point;
|
||||
info.sequence_points.Add (sequence_point);
|
||||
}
|
||||
|
||||
Document GetDocument (PdbSource source)
|
||||
@@ -217,65 +203,9 @@ namespace Mono.Cecil.Pdb {
|
||||
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 ();
|
||||
pdb_file.Dispose ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,11 @@
|
||||
//
|
||||
// PdbWriter.cs
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2011 Jb Evain
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// 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.
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
using System;
|
||||
@@ -56,69 +38,55 @@ namespace Mono.Cecil.Pdb {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Write (MethodBody body)
|
||||
public void Write (MethodDebugInformation info)
|
||||
{
|
||||
var method_token = body.Method.MetadataToken;
|
||||
var method_token = info.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);
|
||||
DefineSequencePoints (info.sequence_points);
|
||||
|
||||
if (info.scope != null)
|
||||
DefineScope (info.scope, info);
|
||||
|
||||
writer.CloseScope (end_offset);
|
||||
writer.CloseMethod ();
|
||||
}
|
||||
|
||||
Collection<Instruction> CollectInstructions (MethodBody body)
|
||||
void DefineScope (ScopeDebugInformation scope, MethodDebugInformation info)
|
||||
{
|
||||
var collection = new Collection<Instruction> ();
|
||||
var instructions = body.Instructions;
|
||||
var start_offset = scope.Start.Offset;
|
||||
var end_offset = scope.End.IsEndOfMethod
|
||||
? info.code_size
|
||||
: scope.End.Offset;
|
||||
|
||||
for (int i = 0; i < instructions.Count; i++) {
|
||||
var instruction = instructions [i];
|
||||
var sequence_point = instruction.SequencePoint;
|
||||
if (sequence_point == null)
|
||||
continue;
|
||||
writer.OpenScope (start_offset);
|
||||
|
||||
GetDocument (sequence_point.Document);
|
||||
collection.Add (instruction);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
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<Instruction> instructions)
|
||||
void DefineSequencePoints (Collection<SequencePoint> sequence_points)
|
||||
{
|
||||
for (int i = 0; i < instructions.Count; i++) {
|
||||
var instruction = instructions [i];
|
||||
var sequence_point = instruction.SequencePoint;
|
||||
for (int i = 0; i < sequence_points.Count; i++) {
|
||||
var sequence_point = sequence_points [i];
|
||||
|
||||
writer.DefineSequencePoints (
|
||||
GetDocument (sequence_point.Document),
|
||||
new [] { instruction.Offset },
|
||||
new [] { sequence_point.Offset },
|
||||
new [] { sequence_point.StartLine },
|
||||
new [] { sequence_point.StartColumn },
|
||||
new [] { sequence_point.EndLine },
|
||||
@@ -126,11 +94,11 @@ namespace Mono.Cecil.Pdb {
|
||||
}
|
||||
}
|
||||
|
||||
void CreateLocalVariable (VariableDefinition variable, SymbolToken local_var_token, int start_offset, int end_offset)
|
||||
void CreateLocalVariable (VariableDebugInformation variable, SymbolToken local_var_token, int start_offset, int end_offset)
|
||||
{
|
||||
writer.DefineLocalVariable2 (
|
||||
variable.Name,
|
||||
0,
|
||||
variable.Attributes,
|
||||
local_var_token,
|
||||
SymAddressKind.ILOffset,
|
||||
variable.Index,
|
||||
@@ -159,55 +127,6 @@ namespace Mono.Cecil.Pdb {
|
||||
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;
|
||||
|
||||
@@ -1,29 +1,10 @@
|
||||
//
|
||||
// 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.
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
@@ -1,29 +1,10 @@
|
||||
//
|
||||
// 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.
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
using System;
|
||||
@@ -78,7 +59,7 @@ namespace Mono.Cecil.Pdb
|
||||
|
||||
public void DefineLocalVariable2 (
|
||||
string name,
|
||||
FieldAttributes attributes,
|
||||
VariableAttributes attributes,
|
||||
SymbolToken sigToken,
|
||||
SymAddressKind addrKind,
|
||||
int addr1,
|
||||
|
||||
Reference in New Issue
Block a user