Imported Upstream version 4.8.0.309

Former-commit-id: 5f9c6ae75f295e057a7d2971f3a6df4656fa8850
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-11-10 13:04:39 +00:00
parent ee1447783b
commit 94b2861243
4912 changed files with 390737 additions and 49310 deletions

View File

@@ -1,4 +0,0 @@
bin
obj
*.xml
*.user

View File

@@ -1,75 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">net_4_0_Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Mono.Cecil.Mdb</RootNamespace>
<AssemblyName>Mono.Cecil.Mdb</AssemblyName>
<FileAlignment>512</FileAlignment>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\mono.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_2_0_Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\net_2_0_Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;CECIL</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_2_0_Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\net_2_0_Release\</OutputPath>
<DefineConstants>TRACE;CECIL</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_3_5_Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\net_3_5_Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;CECIL;NET_3_5</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_3_5_Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\net_3_5_Release\</OutputPath>
<DefineConstants>TRACE;CECIL;NET_3_5</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_0_Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\net_4_0_Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;CECIL;NET_3_5;NET_4_0</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_0_Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\net_4_0_Release\</OutputPath>
<DefineConstants>TRACE;CECIL;NET_3_5;NET_4_0</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<DefineConstants>$(DefineConstants);CECIL</DefineConstants>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFrameworkVersion)' != 'v2.0' ">
<Reference Include="System.Core" />
@@ -84,20 +19,10 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Mono.Cecil.Mdb\AssemblyInfo.cs" />
<Compile Include="Mono.Cecil.Mdb\MdbReader.cs" />
<Compile Include="Mono.Cecil.Mdb\MdbWriter.cs" />
<Compile Include="Mono.CompilerServices.SymbolWriter\MonoSymbolFile.cs" />
<Compile Include="Mono.CompilerServices.SymbolWriter\MonoSymbolTable.cs" />
<Compile Include="Mono.CompilerServices.SymbolWriter\MonoSymbolWriter.cs" />
<Compile Include="Mono.CompilerServices.SymbolWriter\SymbolWriterImpl.cs" />
<Compile Include="..\..\ProjectInfo.cs" />
<Compile Include="Mono.Cecil.Mdb\*.cs" />
<Compile Include="Mono.CompilerServices.SymbolWriter\*.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<Import Project="..\..\Mono.Cecil.props" />
<Import Project="$(MSBuildCSharpTargets)" />
</Project>

View File

@@ -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.Mdb")]
[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

@@ -1,29 +1,11 @@
//
// MdbReader.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;
@@ -36,20 +18,34 @@ using Mono.CompilerServices.SymbolWriter;
namespace Mono.Cecil.Mdb {
public class MdbReaderProvider : ISymbolReaderProvider {
public sealed class MdbReaderProvider : ISymbolReaderProvider {
public ISymbolReader GetSymbolReader (ModuleDefinition module, string fileName)
{
return new MdbReader (module, MonoSymbolFile.ReadSymbolFile (module, fileName));
Mixin.CheckModule (module);
Mixin.CheckFileName (fileName);
return new MdbReader (module, MonoSymbolFile.ReadSymbolFile (Mixin.GetMdbFileName (fileName), module.Mvid));
}
public ISymbolReader GetSymbolReader (ModuleDefinition module, Stream symbolStream)
{
throw new NotImplementedException ();
Mixin.CheckModule (module);
Mixin.CheckStream (symbolStream);
var file = MonoSymbolFile.ReadSymbolFile (symbolStream);
if (module.Mvid != file.Guid) {
var file_stream = symbolStream as FileStream;
if (file_stream != null)
throw new MonoSymbolFileException ("Symbol file `{0}' does not match assembly", file_stream.Name);
throw new MonoSymbolFileException ("Symbol file from stream does not match assembly");
}
return new MdbReader (module, file);
}
}
public class MdbReader : ISymbolReader {
public sealed class MdbReader : ISymbolReader {
readonly ModuleDefinition module;
readonly MonoSymbolFile symbol_file;
@@ -67,28 +63,28 @@ namespace Mono.Cecil.Mdb {
return symbol_file.Guid == module.Mvid;
}
public void Read (MethodBody body, InstructionMapper mapper)
public MethodDebugInformation Read (MethodDefinition method)
{
var method_token = body.Method.MetadataToken;
var method_token = method.MetadataToken;
var entry = symbol_file.GetMethodByToken (method_token.ToInt32 ());
if (entry == null)
return;
return null;
var scopes = ReadScopes (entry, body, mapper);
ReadLineNumbers (entry, mapper);
ReadLocalVariables (entry, body, scopes);
var info = new MethodDebugInformation (method);
var scopes = ReadScopes (entry, info);
ReadLineNumbers (entry, info);
ReadLocalVariables (entry, scopes);
return info;
}
static void ReadLocalVariables (MethodEntry entry, MethodBody body, Scope [] scopes)
static void ReadLocalVariables (MethodEntry entry, ScopeDebugInformation [] scopes)
{
var locals = entry.GetLocals ();
foreach (var local in locals) {
if (local.Index < 0 || local.Index >= body.Variables.Count) // Mono 2.6 emits wrong local infos for iterators
continue;
var variable = body.Variables [local.Index];
variable.Name = local.Name;
var variable = new VariableDebugInformation (local.Index, local.Name);
var index = local.BlockIndex;
if (index < 0 || index >= scopes.Length)
@@ -102,23 +98,18 @@ namespace Mono.Cecil.Mdb {
}
}
void ReadLineNumbers (MethodEntry entry, InstructionMapper mapper)
void ReadLineNumbers (MethodEntry entry, MethodDebugInformation info)
{
Document document = null;
var table = entry.GetLineNumberTable ();
foreach (var line in table.LineNumbers) {
var instruction = mapper (line.Offset);
if (instruction == null)
info.sequence_points = new Collection<SequencePoint> (table.LineNumbers.Length);
for (var i = 0; i < table.LineNumbers.Length; i++) {
var line = table.LineNumbers [i];
if (i > 0 && table.LineNumbers [i - 1].Offset == line.Offset)
continue;
if (document == null)
document = GetDocument (entry.CompileUnit.SourceFile);
instruction.SequencePoint = new SequencePoint (document) {
StartLine = line.Row,
EndLine = line.Row,
};
info.sequence_points.Add (LineToSequencePoint (line));
}
}
@@ -130,41 +121,46 @@ namespace Mono.Cecil.Mdb {
if (documents.TryGetValue (file_name, out document))
return document;
document = new Document (file_name);
document = new Document (file_name) {
Hash = file.Checksum,
};
documents.Add (file_name, document);
return document;
}
static Scope [] ReadScopes (MethodEntry entry, MethodBody body, InstructionMapper mapper)
static ScopeDebugInformation [] ReadScopes (MethodEntry entry, MethodDebugInformation info)
{
var blocks = entry.GetCodeBlocks ();
var scopes = new Scope [blocks.Length];
var scopes = new ScopeDebugInformation [blocks.Length + 1];
info.scope = scopes [0] = new ScopeDebugInformation {
Start = new InstructionOffset (0),
End = new InstructionOffset (info.code_size),
};
foreach (var block in blocks) {
if (block.BlockType != CodeBlockEntry.Type.Lexical)
if (block.BlockType != CodeBlockEntry.Type.Lexical && block.BlockType != CodeBlockEntry.Type.CompilerGenerated)
continue;
var scope = new Scope ();
scope.Start = mapper (block.StartOffset);
scope.End = mapper (block.EndOffset);
var scope = new ScopeDebugInformation ();
scope.Start = new InstructionOffset (block.StartOffset);
scope.End = new InstructionOffset (block.EndOffset);
scopes [block.Index] = scope;
scopes [block.Index + 1] = scope;
if (body.Scope == null)
body.Scope = scope;
if (!AddScope (body.Scope, scope))
body.Scope = scope;
if (!AddScope (info.scope.Scopes, scope))
info.scope.Scopes.Add (scope);
}
return scopes;
}
static bool AddScope (Scope provider, Scope scope)
static bool AddScope (Collection<ScopeDebugInformation> scopes, ScopeDebugInformation scope)
{
foreach (var sub_scope in provider.Scopes) {
if (AddScope (sub_scope, scope))
foreach (var sub_scope in scopes) {
if (sub_scope.HasScopes && AddScope (sub_scope.Scopes, scope))
return true;
if (scope.Start.Offset >= sub_scope.Start.Offset && scope.End.Offset <= sub_scope.End.Offset) {
@@ -176,42 +172,15 @@ namespace Mono.Cecil.Mdb {
return false;
}
public void Read (MethodSymbols symbols)
SequencePoint LineToSequencePoint (LineNumberEntry line)
{
var entry = symbol_file.GetMethodByToken (symbols.MethodToken.ToInt32 ());
if (entry == null)
return;
ReadLineNumbers (entry, symbols);
ReadLocalVariables (entry, symbols);
}
void ReadLineNumbers (MethodEntry entry, MethodSymbols symbols)
{
var table = entry.GetLineNumberTable ();
var lines = table.LineNumbers;
var instructions = symbols.instructions = new Collection<InstructionSymbol> (lines.Length);
for (int i = 0; i < lines.Length; i++) {
var line = lines [i];
instructions.Add (new InstructionSymbol (line.Offset, new SequencePoint (GetDocument (entry.CompileUnit.SourceFile)) {
StartLine = line.Row,
EndLine = line.Row,
}));
}
}
static void ReadLocalVariables (MethodEntry entry, MethodSymbols symbols)
{
foreach (var local in entry.GetLocals ()) {
if (local.Index < 0 || local.Index >= symbols.Variables.Count) // Mono 2.6 emits wrong local infos for iterators
continue;
var variable = symbols.Variables [local.Index];
variable.Name = local.Name;
}
var source = symbol_file.GetSourceFile (line.File);
return new SequencePoint (line.Offset, GetDocument (source)) {
StartLine = line.Row,
EndLine = line.EndRow,
StartColumn = line.Column,
EndColumn = line.EndColumn,
};
}
public void Dispose ()
@@ -219,4 +188,17 @@ namespace Mono.Cecil.Mdb {
symbol_file.Dispose ();
}
}
static class MethodEntryExtensions {
public static bool HasColumnInfo (this MethodEntry entry)
{
return (entry.MethodFlags & MethodEntry.Flags.ColumnsInfoIncluded) != 0;
}
public static bool HasEndInfo (this MethodEntry entry)
{
return (entry.MethodFlags & MethodEntry.Flags.EndInfoIncluded) != 0;
}
}
}

View File

@@ -1,29 +1,11 @@
//
// MdbWriter.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;
@@ -37,10 +19,13 @@ using Mono.CompilerServices.SymbolWriter;
namespace Mono.Cecil.Mdb {
#if !READ_ONLY
public class MdbWriterProvider : ISymbolWriterProvider {
public sealed class MdbWriterProvider : ISymbolWriterProvider {
public ISymbolWriter GetSymbolWriter (ModuleDefinition module, string fileName)
{
Mixin.CheckModule (module);
Mixin.CheckFileName (fileName);
return new MdbWriter (module.Mvid, fileName);
}
@@ -50,7 +35,7 @@ namespace Mono.Cecil.Mdb {
}
}
public class MdbWriter : ISymbolWriter {
public sealed class MdbWriter : ISymbolWriter {
readonly Guid mvid;
readonly MonoSymbolWriter writer;
@@ -63,16 +48,6 @@ namespace Mono.Cecil.Mdb {
this.source_files = new Dictionary<string, SourceFile> ();
}
static Collection<Instruction> GetInstructions (MethodBody body)
{
var instructions = new Collection<Instruction> ();
foreach (var instruction in body.Instructions)
if (instruction.SequencePoint != null)
instructions.Add (instruction);
return instructions;
}
SourceFile GetSourceFile (Document document)
{
var url = document.Url;
@@ -81,7 +56,7 @@ namespace Mono.Cecil.Mdb {
if (source_files.TryGetValue (url, out source_file))
return source_file;
var entry = writer.DefineDocument (url);
var entry = writer.DefineDocument (url, null, document.Hash != null && document.Hash.Length == 16 ? document.Hash : null);
var compile_unit = writer.DefineCompilationUnit (entry);
source_file = new SourceFile (compile_unit, entry);
@@ -89,101 +64,107 @@ namespace Mono.Cecil.Mdb {
return source_file;
}
void Populate (Collection<Instruction> instructions, int [] offsets,
int [] startRows, int [] startCols, out SourceFile file)
void Populate (Collection<SequencePoint> sequencePoints, int [] offsets,
int [] startRows, int [] endRows, int [] startCols, int [] endCols, out SourceFile file)
{
SourceFile source_file = null;
for (int i = 0; i < instructions.Count; i++) {
var instruction = instructions [i];
offsets [i] = instruction.Offset;
for (int i = 0; i < sequencePoints.Count; i++) {
var sequence_point = sequencePoints [i];
offsets [i] = sequence_point.Offset;
var sequence_point = instruction.SequencePoint;
if (source_file == null)
source_file = GetSourceFile (sequence_point.Document);
startRows [i] = sequence_point.StartLine;
endRows [i] = sequence_point.EndLine;
startCols [i] = sequence_point.StartColumn;
endCols [i] = sequence_point.EndColumn;
}
file = source_file;
}
public void Write (MethodBody body)
public void Write (MethodDebugInformation info)
{
var method = new SourceMethod (body.Method);
var method = new SourceMethod (info.method);
var instructions = GetInstructions (body);
int count = instructions.Count;
var sequence_points = info.SequencePoints;
int count = sequence_points.Count;
if (count == 0)
return;
var offsets = new int [count];
var start_rows = new int [count];
var end_rows = new int [count];
var start_cols = new int [count];
var end_cols = new int [count];
SourceFile file;
Populate (instructions, offsets, start_rows, start_cols, out file);
Populate (sequence_points, offsets, start_rows, end_rows, start_cols, end_cols, out file);
var builder = writer.OpenMethod (file.CompilationUnit, 0, method);
for (int i = 0; i < count; i++)
for (int i = 0; i < count; i++) {
builder.MarkSequencePoint (
offsets [i],
file.CompilationUnit.SourceFile,
start_rows [i],
start_cols [i],
end_rows [i],
end_cols [i],
false);
}
if (body.HasVariables)
AddVariables (body.Variables);
if (info.scope != null)
WriteRootScope (info.scope, info);
writer.CloseMethod ();
}
readonly static byte [] empty_header = new byte [0];
void WriteRootScope (ScopeDebugInformation scope, MethodDebugInformation info)
{
WriteScopeVariables (scope);
if (scope.HasScopes)
WriteScopes (scope.Scopes, info);
}
void WriteScope (ScopeDebugInformation scope, MethodDebugInformation info)
{
writer.OpenScope (scope.Start.Offset);
WriteScopeVariables (scope);
if (scope.HasScopes)
WriteScopes (scope.Scopes, info);
writer.CloseScope (scope.End.IsEndOfMethod ? info.code_size : scope.End.Offset);
}
void WriteScopes (Collection<ScopeDebugInformation> scopes, MethodDebugInformation info)
{
for (int i = 0; i < scopes.Count; i++)
WriteScope (scopes [i], info);
}
void WriteScopeVariables (ScopeDebugInformation scope)
{
if (!scope.HasVariables)
return;
foreach (var variable in scope.variables)
if (!string.IsNullOrEmpty (variable.Name))
writer.DefineLocalVariable (variable.Index, variable.Name);
}
public bool GetDebugHeader (out ImageDebugDirectory directory, out byte [] header)
{
directory = new ImageDebugDirectory ();
header = empty_header;
header = Empty<byte>.Array;
return false;
}
void AddVariables (IList<VariableDefinition> variables)
{
for (int i = 0; i < variables.Count; i++) {
var variable = variables [i];
writer.DefineLocalVariable (i, variable.Name);
}
}
public void Write (MethodSymbols symbols)
{
var method = new SourceMethodSymbol (symbols);
var file = GetSourceFile (symbols.Instructions [0].SequencePoint.Document);
var builder = writer.OpenMethod (file.CompilationUnit, 0, method);
var count = symbols.Instructions.Count;
for (int i = 0; i < count; i++) {
var instruction = symbols.Instructions [i];
var sequence_point = instruction.SequencePoint;
builder.MarkSequencePoint (
instruction.Offset,
GetSourceFile (sequence_point.Document).CompilationUnit.SourceFile,
sequence_point.StartLine,
sequence_point.EndLine,
false);
}
if (symbols.HasVariables)
AddVariables (symbols.Variables);
writer.CloseMethod ();
}
public void Dispose ()
{
writer.WriteSymbolFile (mvid);
@@ -209,26 +190,6 @@ namespace Mono.Cecil.Mdb {
}
}
class SourceMethodSymbol : IMethodDef {
readonly string name;
readonly int token;
public string Name {
get { return name;}
}
public int Token {
get { return token; }
}
public SourceMethodSymbol (MethodSymbols symbols)
{
name = symbols.MethodName;
token = symbols.MethodToken.ToInt32 ();
}
}
class SourceMethod : IMethodDef {
readonly MethodDefinition method;

View File

@@ -1,12 +1,13 @@
//
// Mono.CSharp.Debugger/MonoSymbolFile.cs
// MonoSymbolFile.cs
//
// Author:
// Authors:
// Martin Baulig (martin@ximian.com)
// Marek Safar (marek.safar@gmail.com)
//
// (C) 2003 Ximian, Inc. http://www.ximian.com
// Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -30,10 +31,7 @@
using System;
using System.Reflection;
using SRE = System.Reflection.Emit;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.IO;
namespace Mono.CompilerServices.SymbolWriter
@@ -46,10 +44,16 @@ namespace Mono.CompilerServices.SymbolWriter
public MonoSymbolFileException (string message, params object[] args)
: base (String.Format (message, args))
{ }
{
}
public MonoSymbolFileException (string message, Exception innerException)
: base (message, innerException)
{
}
}
internal class MyBinaryWriter : BinaryWriter
sealed class MyBinaryWriter : BinaryWriter
{
public MyBinaryWriter (Stream stream)
: base (stream)
@@ -109,64 +113,11 @@ namespace Mono.CompilerServices.SymbolWriter
}
}
#if !CECIL
internal class MonoDebuggerSupport
{
static GetMethodTokenFunc get_method_token;
static GetGuidFunc get_guid;
static GetLocalIndexFunc get_local_index;
delegate int GetMethodTokenFunc (MethodBase method);
delegate Guid GetGuidFunc (Module module);
delegate int GetLocalIndexFunc (SRE.LocalBuilder local);
static Delegate create_delegate (Type type, Type delegate_type, string name)
{
MethodInfo mi = type.GetMethod (name, BindingFlags.Static |
BindingFlags.NonPublic);
if (mi == null)
throw new Exception ("Can't find " + name);
return Delegate.CreateDelegate (delegate_type, mi);
}
static MonoDebuggerSupport ()
{
get_method_token = (GetMethodTokenFunc) create_delegate (
typeof (Assembly), typeof (GetMethodTokenFunc),
"MonoDebugger_GetMethodToken");
get_guid = (GetGuidFunc) create_delegate (
typeof (Module), typeof (GetGuidFunc), "Mono_GetGuid");
get_local_index = (GetLocalIndexFunc) create_delegate (
typeof (SRE.LocalBuilder), typeof (GetLocalIndexFunc),
"Mono_GetLocalIndex");
}
public static int GetMethodToken (MethodBase method)
{
return get_method_token (method);
}
public static Guid GetGuid (Module module)
{
return get_guid (module);
}
public static int GetLocalIndex (SRE.LocalBuilder local)
{
return get_local_index (local);
}
}
#endif
public class MonoSymbolFile : IDisposable
{
List<MethodEntry> methods = new List<MethodEntry> ();
List<SourceFileEntry> sources = new List<SourceFileEntry> ();
List<CompileUnitEntry> comp_units = new List<CompileUnitEntry> ();
Dictionary<Type, int> type_hash = new Dictionary<Type, int> ();
Dictionary<int, AnonymousScopeEntry> anonymous_scopes;
OffsetTable ot;
@@ -174,41 +125,29 @@ namespace Mono.CompilerServices.SymbolWriter
int last_method_index;
int last_namespace_index;
public readonly string FileName = "<dynamic>";
public readonly int MajorVersion = OffsetTable.MajorVersion;
public readonly int MinorVersion = OffsetTable.MinorVersion;
public int NumLineNumbers;
internal MonoSymbolFile ()
public MonoSymbolFile ()
{
ot = new OffsetTable ();
}
internal int AddSource (SourceFileEntry source)
public int AddSource (SourceFileEntry source)
{
sources.Add (source);
return sources.Count;
}
internal int AddCompileUnit (CompileUnitEntry entry)
public int AddCompileUnit (CompileUnitEntry entry)
{
comp_units.Add (entry);
return comp_units.Count;
}
internal int DefineType (Type type)
{
int index;
if (type_hash.TryGetValue (type, out index))
return index;
index = ++last_type_index;
type_hash.Add (type, index);
return index;
}
internal void AddMethod (MethodEntry entry)
public void AddMethod (MethodEntry entry)
{
methods.Add (entry);
}
@@ -295,7 +234,7 @@ namespace Mono.CompilerServices.SymbolWriter
//
methods.Sort ();
for (int i = 0; i < methods.Count; i++)
((MethodEntry) methods [i]).Index = i + 1;
methods [i].Index = i + 1;
//
// Write data sections.
@@ -314,7 +253,7 @@ namespace Mono.CompilerServices.SymbolWriter
//
ot.MethodTableOffset = (int) bw.BaseStream.Position;
for (int i = 0; i < methods.Count; i++) {
MethodEntry entry = (MethodEntry) methods [i];
MethodEntry entry = methods [i];
entry.Write (bw);
}
ot.MethodTableSize = (int) bw.BaseStream.Position - ot.MethodTableOffset;
@@ -324,7 +263,7 @@ namespace Mono.CompilerServices.SymbolWriter
//
ot.SourceTableOffset = (int) bw.BaseStream.Position;
for (int i = 0; i < sources.Count; i++) {
SourceFileEntry source = (SourceFileEntry) sources [i];
SourceFileEntry source = sources [i];
source.Write (bw);
}
ot.SourceTableSize = (int) bw.BaseStream.Position - ot.SourceTableOffset;
@@ -334,7 +273,7 @@ namespace Mono.CompilerServices.SymbolWriter
//
ot.CompileUnitTableOffset = (int) bw.BaseStream.Position;
for (int i = 0; i < comp_units.Count; i++) {
CompileUnitEntry unit = (CompileUnitEntry) comp_units [i];
CompileUnitEntry unit = comp_units [i];
unit.Write (bw);
}
ot.CompileUnitTableSize = (int) bw.BaseStream.Position - ot.CompileUnitTableOffset;
@@ -391,10 +330,8 @@ namespace Mono.CompilerServices.SymbolWriter
Guid guid;
MonoSymbolFile (string filename)
MonoSymbolFile (Stream stream)
{
this.FileName = filename;
FileStream stream = new FileStream (filename, FileMode.Open, FileAccess.Read);
reader = new MyBinaryReader (stream);
try {
@@ -403,94 +340,56 @@ namespace Mono.CompilerServices.SymbolWriter
int minor_version = reader.ReadInt32 ();
if (magic != OffsetTable.Magic)
throw new MonoSymbolFileException (
"Symbol file `{0}' is not a valid " +
"Mono symbol file", filename);
throw new MonoSymbolFileException ("Symbol file is not a valid");
if (major_version != OffsetTable.MajorVersion)
throw new MonoSymbolFileException (
"Symbol file `{0}' has version {1}, " +
"but expected {2}", filename, major_version,
OffsetTable.MajorVersion);
"Symbol file has version {0} but expected {1}", major_version, OffsetTable.MajorVersion);
if (minor_version != OffsetTable.MinorVersion)
throw new MonoSymbolFileException (
"Symbol file `{0}' has version {1}.{2}, " +
"but expected {3}.{4}", filename, major_version,
minor_version, OffsetTable.MajorVersion,
OffsetTable.MinorVersion);
throw new MonoSymbolFileException ("Symbol file has version {0}.{1} but expected {2}.{3}",
major_version, minor_version,
OffsetTable.MajorVersion, OffsetTable.MinorVersion);
MajorVersion = major_version;
MinorVersion = minor_version;
guid = new Guid (reader.ReadBytes (16));
ot = new OffsetTable (reader, major_version, minor_version);
} catch {
throw new MonoSymbolFileException (
"Cannot read symbol file `{0}'", filename);
} catch (Exception e) {
throw new MonoSymbolFileException ("Cannot read symbol file", e);
}
source_file_hash = new Dictionary<int, SourceFileEntry> ();
compile_unit_hash = new Dictionary<int, CompileUnitEntry> ();
}
void CheckGuidMatch (Guid other, string filename, string assembly)
{
if (other == guid)
return;
throw new MonoSymbolFileException (
"Symbol file `{0}' does not match assembly `{1}'",
filename, assembly);
}
#if CECIL
protected MonoSymbolFile (string filename, Mono.Cecil.ModuleDefinition module)
: this (filename)
{
// Check that the MDB file matches the module, if we have been
// passed a module.
if (module == null)
return;
CheckGuidMatch (module.Mvid, filename, module.FullyQualifiedName);
}
public static MonoSymbolFile ReadSymbolFile (Mono.Cecil.ModuleDefinition module)
{
return ReadSymbolFile (module, module.FullyQualifiedName);
}
public static MonoSymbolFile ReadSymbolFile (Mono.Cecil.ModuleDefinition module, string filename)
{
string name = filename + ".mdb";
return new MonoSymbolFile (name, module);
}
#else
protected MonoSymbolFile (string filename, Assembly assembly) : this (filename)
{
// Check that the MDB file matches the assembly, if we have been
// passed an assembly.
if (assembly == null)
return;
Module[] modules = assembly.GetModules ();
Guid assembly_guid = MonoDebuggerSupport.GetGuid (modules [0]);
CheckGuidMatch (assembly_guid, filename, assembly.Location);
}
public static MonoSymbolFile ReadSymbolFile (Assembly assembly)
{
string filename = assembly.Location;
string name = filename + ".mdb";
return new MonoSymbolFile (name, assembly);
Module[] modules = assembly.GetModules ();
Guid assembly_guid = modules[0].ModuleVersionId;
return ReadSymbolFile (name, assembly_guid);
}
#endif
public static MonoSymbolFile ReadSymbolFile (string mdbFilename)
{
return new MonoSymbolFile (mdbFilename);
return ReadSymbolFile (new FileStream (mdbFilename, FileMode.Open, FileAccess.Read));
}
public static MonoSymbolFile ReadSymbolFile (string mdbFilename, Guid assemblyGuid)
{
var sf = ReadSymbolFile (mdbFilename);
if (assemblyGuid != sf.guid)
throw new MonoSymbolFileException ("Symbol file `{0}' does not match assembly", mdbFilename);
return sf;
}
public static MonoSymbolFile ReadSymbolFile (Stream stream)
{
return new MonoSymbolFile (stream);
}
public int CompileUnitCount {
@@ -648,7 +547,7 @@ namespace Mono.CompilerServices.SymbolWriter
lock (this) {
read_methods ();
return (MethodEntry) method_list [index - 1];
return method_list [index - 1];
}
}

View File

@@ -183,57 +183,56 @@ namespace Mono.CompilerServices.SymbolWriter
{
#region This is actually written to the symbol file
public readonly int Row;
public int Column;
public int EndRow, EndColumn;
public readonly int File;
public readonly int Offset;
public readonly bool IsHidden;
public readonly bool IsHidden; // Obsolete is never used
#endregion
public LineNumberEntry (int file, int row, int offset)
: this (file, row, offset, false)
{ }
public sealed class LocationComparer : IComparer<LineNumberEntry>
{
public static readonly LocationComparer Default = new LocationComparer ();
public LineNumberEntry (int file, int row, int offset, bool is_hidden)
public int Compare (LineNumberEntry l1, LineNumberEntry l2)
{
return l1.Row == l2.Row ?
l1.Column.CompareTo (l2.Column) :
l1.Row.CompareTo (l2.Row);
}
}
public static readonly LineNumberEntry Null = new LineNumberEntry (0, 0, 0, 0);
public LineNumberEntry (int file, int row, int column, int offset)
: this (file, row, column, offset, false)
{
}
public LineNumberEntry (int file, int row, int offset)
: this (file, row, -1, offset, false)
{
}
public LineNumberEntry (int file, int row, int column, int offset, bool is_hidden)
: this (file, row, column, -1, -1, offset, is_hidden)
{
}
public LineNumberEntry (int file, int row, int column, int end_row, int end_column, int offset, bool is_hidden)
{
this.File = file;
this.Row = row;
this.Column = column;
this.EndRow = end_row;
this.EndColumn = end_column;
this.Offset = offset;
this.IsHidden = is_hidden;
}
public static LineNumberEntry Null = new LineNumberEntry (0, 0, 0);
private class OffsetComparerClass : IComparer<LineNumberEntry>
{
public int Compare (LineNumberEntry l1, LineNumberEntry l2)
{
if (l1.Offset < l2.Offset)
return -1;
else if (l1.Offset > l2.Offset)
return 1;
else
return 0;
}
}
private class RowComparerClass : IComparer<LineNumberEntry>
{
public int Compare (LineNumberEntry l1, LineNumberEntry l2)
{
if (l1.Row < l2.Row)
return -1;
else if (l1.Row > l2.Row)
return 1;
else
return 0;
}
}
public static readonly IComparer<LineNumberEntry> OffsetComparer = new OffsetComparerClass ();
public static readonly IComparer<LineNumberEntry> RowComparer = new RowComparerClass ();
public override string ToString ()
{
return String.Format ("[Line {0}:{1}:{2}]", File, Row, Offset);
return String.Format ("[Line {0}:{1,2}-{3,4}:{5}]", File, Row, Column, EndRow, EndColumn, Offset);
}
}
@@ -610,6 +609,11 @@ namespace Mono.CompilerServices.SymbolWriter
DataOffset = reader.ReadInt32 ();
}
public void ReadAll ()
{
ReadData ();
}
void ReadData ()
{
if (creating)
@@ -692,36 +696,50 @@ namespace Mono.CompilerServices.SymbolWriter
creating = true;
}
public SourceFileEntry (MonoSymbolFile file, string file_name,
byte[] guid, byte[] checksum)
public SourceFileEntry (MonoSymbolFile file, string file_name, byte[] guid, byte[] checksum)
: this (file, file_name)
{
this.guid = guid;
this.hash = checksum;
}
public byte[] Checksum {
get {
return hash;
}
}
internal void WriteData (MyBinaryWriter bw)
{
DataOffset = (int) bw.BaseStream.Position;
bw.Write (file_name);
if (guid == null) {
guid = Guid.NewGuid ().ToByteArray ();
try {
using (FileStream fs = new FileStream (file_name, FileMode.Open, FileAccess.Read)) {
MD5 md5 = MD5.Create ();
hash = md5.ComputeHash (fs);
}
} catch {
hash = new byte [16];
}
}
if (guid == null)
guid = new byte[16];
if (hash == null)
hash = ComputeHash ();
bw.Write (guid);
bw.Write (hash);
bw.Write ((byte) (auto_generated ? 1 : 0));
}
private byte [] ComputeHash ()
{
if (!File.Exists (file_name))
return new byte [16];
try {
using (FileStream fs = new FileStream (file_name, FileMode.Open, FileAccess.Read)) {
MD5 md5 = MD5.Create ();
return md5.ComputeHash (fs);
}
} catch {
return new byte [16];
}
}
internal void Write (BinaryWriter bw)
{
bw.Write (Index);
@@ -748,6 +766,7 @@ namespace Mono.CompilerServices.SymbolWriter
public string FileName {
get { return file_name; }
set { file_name = value; }
}
public bool AutoGenerated {
@@ -802,7 +821,6 @@ namespace Mono.CompilerServices.SymbolWriter
public const int Default_LineRange = 8;
public const byte Default_OpcodeBase = 9;
public const bool SuppressDuplicates = true;
#endregion
public const byte DW_LNS_copy = 1;
@@ -833,7 +851,7 @@ namespace Mono.CompilerServices.SymbolWriter
this._line_numbers = lines;
}
internal void Write (MonoSymbolFile file, MyBinaryWriter bw)
internal void Write (MonoSymbolFile file, MyBinaryWriter bw, bool hasColumnsInfo, bool hasEndInfo)
{
int start = (int) bw.BaseStream.Position;
@@ -843,11 +861,6 @@ namespace Mono.CompilerServices.SymbolWriter
int line_inc = LineNumbers [i].Row - last_line;
int offset_inc = LineNumbers [i].Offset - last_offset;
if (SuppressDuplicates && (i+1 < LineNumbers.Length)) {
if (LineNumbers [i+1].Equals (LineNumbers [i]))
continue;
}
if (LineNumbers [i].File != last_file) {
bw.Write (DW_LNS_set_file);
bw.WriteLeb128 (LineNumbers [i].File);
@@ -895,17 +908,37 @@ namespace Mono.CompilerServices.SymbolWriter
bw.Write ((byte) 1);
bw.Write (DW_LNE_end_sequence);
if (hasColumnsInfo) {
for (int i = 0; i < LineNumbers.Length; i++) {
var ln = LineNumbers [i];
if (ln.Row >= 0)
bw.WriteLeb128 (ln.Column);
}
}
if (hasEndInfo) {
for (int i = 0; i < LineNumbers.Length; i++) {
var ln = LineNumbers [i];
if (ln.EndRow == -1 || ln.EndColumn == -1 || ln.Row > ln.EndRow) {
bw.WriteLeb128 (0xffffff);
} else {
bw.WriteLeb128 (ln.EndRow - ln.Row);
bw.WriteLeb128 (ln.EndColumn);
}
}
}
file.ExtendedLineNumberSize += (int) bw.BaseStream.Position - start;
}
internal static LineNumberTable Read (MonoSymbolFile file, MyBinaryReader br)
internal static LineNumberTable Read (MonoSymbolFile file, MyBinaryReader br, bool readColumnsInfo, bool readEndInfo)
{
LineNumberTable lnt = new LineNumberTable (file);
lnt.DoRead (file, br);
lnt.DoRead (file, br, readColumnsInfo, readEndInfo);
return lnt;
}
void DoRead (MonoSymbolFile file, MyBinaryReader br)
void DoRead (MonoSymbolFile file, MyBinaryReader br, bool includesColumns, bool includesEnds)
{
var lines = new List<LineNumberEntry> ();
@@ -922,7 +955,7 @@ namespace Mono.CompilerServices.SymbolWriter
if (opcode == DW_LNE_end_sequence) {
if (modified)
lines.Add (new LineNumberEntry (
stm_file, stm_line, stm_offset, is_hidden));
stm_file, stm_line, -1, stm_offset, is_hidden));
break;
} else if (opcode == DW_LNE_MONO_negate_is_hidden) {
is_hidden = !is_hidden;
@@ -931,9 +964,7 @@ namespace Mono.CompilerServices.SymbolWriter
(opcode <= DW_LNE_MONO__extensions_end)) {
; // reserved for future extensions
} else {
throw new MonoSymbolFileException (
"Unknown extended opcode {0:x} in LNT ({1})",
opcode, file.FileName);
throw new MonoSymbolFileException ("Unknown extended opcode {0:x}", opcode);
}
br.BaseStream.Position = end_pos;
@@ -942,7 +973,7 @@ namespace Mono.CompilerServices.SymbolWriter
switch (opcode) {
case DW_LNS_copy:
lines.Add (new LineNumberEntry (
stm_file, stm_line, stm_offset, is_hidden));
stm_file, stm_line, -1, stm_offset, is_hidden));
modified = false;
break;
case DW_LNS_advance_pc:
@@ -972,13 +1003,34 @@ namespace Mono.CompilerServices.SymbolWriter
stm_offset += opcode / LineRange;
stm_line += LineBase + (opcode % LineRange);
lines.Add (new LineNumberEntry (
stm_file, stm_line, stm_offset, is_hidden));
stm_file, stm_line, -1, stm_offset, is_hidden));
modified = false;
}
}
_line_numbers = new LineNumberEntry [lines.Count];
lines.CopyTo (_line_numbers, 0);
_line_numbers = lines.ToArray ();
if (includesColumns) {
for (int i = 0; i < _line_numbers.Length; ++i) {
var ln = _line_numbers[i];
if (ln.Row >= 0)
ln.Column = br.ReadLeb128 ();
}
}
if (includesEnds) {
for (int i = 0; i < _line_numbers.Length; ++i) {
var ln = _line_numbers[i];
int row = br.ReadLeb128 ();
if (row == 0xffffff) {
ln.EndRow = -1;
ln.EndColumn = -1;
} else {
ln.EndRow = ln.Row + row;
ln.EndColumn = br.ReadLeb128 ();
}
}
}
}
public bool GetMethodBounds (out LineNumberEntry start, out LineNumberEntry end)
@@ -1035,7 +1087,9 @@ namespace Mono.CompilerServices.SymbolWriter
[Flags]
public enum Flags
{
LocalNamesAmbiguous = 1
LocalNamesAmbiguous = 1,
ColumnsInfoIncluded = 1 << 1,
EndInfoIncluded = 1 << 2
}
public const int Size = 12;
@@ -1123,7 +1177,7 @@ namespace Mono.CompilerServices.SymbolWriter
}
}
void CheckLineNumberTable (LineNumberEntry[] line_numbers)
static void CheckLineNumberTable (LineNumberEntry[] line_numbers)
{
int last_offset = -1;
int last_row = -1;
@@ -1188,8 +1242,13 @@ namespace Mono.CompilerServices.SymbolWriter
bw.Write (real_name);
}
foreach (var lne in lnt.LineNumbers) {
if (lne.EndRow != -1 || lne.EndColumn != -1)
flags |= Flags.EndInfoIncluded;
}
LineNumberTableOffset = (int) bw.BaseStream.Position;
lnt.Write (file, bw);
lnt.Write (file, bw, (flags & Flags.ColumnsInfoIncluded) != 0, (flags & Flags.EndInfoIncluded) != 0);
DataOffset = (int) bw.BaseStream.Position;
@@ -1204,6 +1263,15 @@ namespace Mono.CompilerServices.SymbolWriter
bw.WriteLeb128 ((int) flags);
}
public void ReadAll ()
{
GetLineNumberTable ();
GetLocals ();
GetCodeBlocks ();
GetScopeVariables ();
GetRealName ();
}
public LineNumberTable GetLineNumberTable ()
{
lock (SymbolFile) {
@@ -1217,7 +1285,7 @@ namespace Mono.CompilerServices.SymbolWriter
long old_pos = reader.BaseStream.Position;
reader.BaseStream.Position = LineNumberTableOffset;
lnt = LineNumberTable.Read (SymbolFile, reader);
lnt = LineNumberTable.Read (SymbolFile, reader, (flags & Flags.ColumnsInfoIncluded) != 0, (flags & Flags.EndInfoIncluded) != 0);
reader.BaseStream.Position = old_pos;
return lnt;

View File

@@ -47,11 +47,7 @@ namespace Mono.CompilerServices.SymbolWriter
string filename;
private SourceMethodBuilder current_method;
#if NET_2_1
System.Collections.Stack current_method_stack = new System.Collections.Stack ();
#else
Stack<SourceMethodBuilder> current_method_stack = new Stack<SourceMethodBuilder> ();
#endif
public MonoSymbolWriter (string filename)
{
@@ -239,165 +235,4 @@ namespace Mono.CompilerServices.SymbolWriter
}
}
}
public class SourceMethodBuilder
{
List<LocalVariableEntry> _locals;
List<CodeBlockEntry> _blocks;
List<ScopeVariable> _scope_vars;
#if NET_2_1
System.Collections.Stack _block_stack;
#else
Stack<CodeBlockEntry> _block_stack;
#endif
string _real_name;
IMethodDef _method;
ICompileUnit _comp_unit;
// MethodEntry.Flags _method_flags;
int _ns_id;
public SourceMethodBuilder (ICompileUnit comp_unit, int ns_id, IMethodDef method)
{
this._comp_unit = comp_unit;
this._method = method;
this._ns_id = ns_id;
method_lines = new LineNumberEntry [32];
}
private LineNumberEntry [] method_lines;
private int method_lines_pos = 0;
public void MarkSequencePoint (int offset, SourceFileEntry file, int line, int column,
bool is_hidden)
{
if (method_lines_pos == method_lines.Length) {
LineNumberEntry [] tmp = method_lines;
method_lines = new LineNumberEntry [method_lines.Length * 2];
Array.Copy (tmp, method_lines, method_lines_pos);
}
int file_idx = file != null ? file.Index : 0;
method_lines [method_lines_pos++] = new LineNumberEntry (
file_idx, line, offset, is_hidden);
}
public void StartBlock (CodeBlockEntry.Type type, int start_offset)
{
if (_block_stack == null) {
#if NET_2_1
_block_stack = new System.Collections.Stack ();
#else
_block_stack = new Stack<CodeBlockEntry> ();
#endif
}
if (_blocks == null)
_blocks = new List<CodeBlockEntry> ();
int parent = CurrentBlock != null ? CurrentBlock.Index : -1;
CodeBlockEntry block = new CodeBlockEntry (
_blocks.Count + 1, parent, type, start_offset);
_block_stack.Push (block);
_blocks.Add (block);
}
public void EndBlock (int end_offset)
{
CodeBlockEntry block = (CodeBlockEntry) _block_stack.Pop ();
block.Close (end_offset);
}
public CodeBlockEntry[] Blocks {
get {
if (_blocks == null)
return new CodeBlockEntry [0];
CodeBlockEntry[] retval = new CodeBlockEntry [_blocks.Count];
_blocks.CopyTo (retval, 0);
return retval;
}
}
public CodeBlockEntry CurrentBlock {
get {
if ((_block_stack != null) && (_block_stack.Count > 0))
return (CodeBlockEntry) _block_stack.Peek ();
else
return null;
}
}
public LocalVariableEntry[] Locals {
get {
if (_locals == null)
return new LocalVariableEntry [0];
else {
LocalVariableEntry[] retval =
new LocalVariableEntry [_locals.Count];
_locals.CopyTo (retval, 0);
return retval;
}
}
}
public void AddLocal (int index, string name)
{
if (_locals == null)
_locals = new List<LocalVariableEntry> ();
int block_idx = CurrentBlock != null ? CurrentBlock.Index : 0;
_locals.Add (new LocalVariableEntry (index, name, block_idx));
}
public ScopeVariable[] ScopeVariables {
get {
if (_scope_vars == null)
return new ScopeVariable [0];
ScopeVariable[] retval = new ScopeVariable [_scope_vars.Count];
_scope_vars.CopyTo (retval);
return retval;
}
}
public void AddScopeVariable (int scope, int index)
{
if (_scope_vars == null)
_scope_vars = new List<ScopeVariable> ();
_scope_vars.Add (
new ScopeVariable (scope, index));
}
public string RealMethodName {
get { return _real_name; }
}
public void SetRealMethodName (string name)
{
_real_name = name;
}
public ICompileUnit SourceFile {
get { return _comp_unit; }
}
public IMethodDef Method {
get { return _method; }
}
public void DefineMethod (MonoSymbolFile file)
{
LineNumberEntry[] lines = new LineNumberEntry [method_lines_pos];
Array.Copy (method_lines, lines, method_lines_pos);
MethodEntry entry = new MethodEntry (
file, _comp_unit.Entry, _method.Token, ScopeVariables,
Locals, lines, Blocks, RealMethodName, 0, //_method_flags,
_ns_id);
file.AddMethod (entry);
}
}
}

View File

@@ -0,0 +1,190 @@
//
// SourceMethodBuilder.cs
//
// Authors:
// Martin Baulig (martin@ximian.com)
// Marek Safar (marek.safar@gmail.com)
//
// (C) 2002 Ximian, Inc. http://www.ximian.com
// Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
//
// 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.Collections.Generic;
namespace Mono.CompilerServices.SymbolWriter
{
public class SourceMethodBuilder
{
List<LocalVariableEntry> _locals;
List<CodeBlockEntry> _blocks;
List<ScopeVariable> _scope_vars;
Stack<CodeBlockEntry> _block_stack;
readonly List<LineNumberEntry> method_lines;
readonly ICompileUnit _comp_unit;
readonly int ns_id;
readonly IMethodDef method;
public SourceMethodBuilder (ICompileUnit comp_unit)
{
this._comp_unit = comp_unit;
method_lines = new List<LineNumberEntry> ();
}
public SourceMethodBuilder (ICompileUnit comp_unit, int ns_id, IMethodDef method)
: this (comp_unit)
{
this.ns_id = ns_id;
this.method = method;
}
public void MarkSequencePoint (int offset, SourceFileEntry file, int line, int column, bool is_hidden)
{
MarkSequencePoint (offset, file, line, column, -1, -1, is_hidden);
}
public void MarkSequencePoint (int offset, SourceFileEntry file, int line, int column, int end_line, int end_column, bool is_hidden)
{
int file_idx = file != null ? file.Index : 0;
var lne = new LineNumberEntry (file_idx, line, column, end_line, end_column, offset, is_hidden);
if (method_lines.Count > 0) {
var prev = method_lines[method_lines.Count - 1];
//
// Same offset cannot be used for multiple lines
//
if (prev.Offset == offset) {
//
// Use the new location because debugger will adjust
// the breakpoint to next line with sequence point
//
if (LineNumberEntry.LocationComparer.Default.Compare (lne, prev) > 0)
method_lines[method_lines.Count - 1] = lne;
return;
}
}
method_lines.Add (lne);
}
public void StartBlock (CodeBlockEntry.Type type, int start_offset)
{
if (_block_stack == null) {
_block_stack = new Stack<CodeBlockEntry> ();
}
if (_blocks == null)
_blocks = new List<CodeBlockEntry> ();
int parent = CurrentBlock != null ? CurrentBlock.Index : -1;
CodeBlockEntry block = new CodeBlockEntry (
_blocks.Count + 1, parent, type, start_offset);
_block_stack.Push (block);
_blocks.Add (block);
}
public void EndBlock (int end_offset)
{
CodeBlockEntry block = (CodeBlockEntry) _block_stack.Pop ();
block.Close (end_offset);
}
public CodeBlockEntry[] Blocks {
get {
if (_blocks == null)
return new CodeBlockEntry [0];
CodeBlockEntry[] retval = new CodeBlockEntry [_blocks.Count];
_blocks.CopyTo (retval, 0);
return retval;
}
}
public CodeBlockEntry CurrentBlock {
get {
if ((_block_stack != null) && (_block_stack.Count > 0))
return (CodeBlockEntry) _block_stack.Peek ();
else
return null;
}
}
public LocalVariableEntry[] Locals {
get {
if (_locals == null)
return new LocalVariableEntry [0];
else {
return _locals.ToArray ();
}
}
}
public ICompileUnit SourceFile {
get {
return _comp_unit;
}
}
public void AddLocal (int index, string name)
{
if (_locals == null)
_locals = new List<LocalVariableEntry> ();
int block_idx = CurrentBlock != null ? CurrentBlock.Index : 0;
_locals.Add (new LocalVariableEntry (index, name, block_idx));
}
public ScopeVariable[] ScopeVariables {
get {
if (_scope_vars == null)
return new ScopeVariable [0];
return _scope_vars.ToArray ();
}
}
public void AddScopeVariable (int scope, int index)
{
if (_scope_vars == null)
_scope_vars = new List<ScopeVariable> ();
_scope_vars.Add (
new ScopeVariable (scope, index));
}
public void DefineMethod (MonoSymbolFile file)
{
DefineMethod (file, method.Token);
}
public void DefineMethod (MonoSymbolFile file, int token)
{
MethodEntry entry = new MethodEntry (
file, _comp_unit.Entry, token, ScopeVariables,
Locals, method_lines.ToArray (), Blocks, null, MethodEntry.Flags.ColumnsInfoIncluded, ns_id);
file.AddMethod (entry);
}
}
}

View File

@@ -1,4 +0,0 @@
bin
obj
*.xml
*.user

View File

@@ -1,77 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">net_4_0_Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{AC71DF9C-99FA-4A63-990A-66C8010355A6}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Mono.Cecil.Mdb.Tests</RootNamespace>
<AssemblyName>Mono.Cecil.Mdb.Tests</AssemblyName>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_2_0_Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\net_2_0_Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_2_0_Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\net_2_0_Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_3_5_Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\net_3_5_Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NET_3_5</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_3_5_Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\net_3_5_Release\</OutputPath>
<DefineConstants>TRACE;NET_3_5</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_0_Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\net_4_0_Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NET_3_5;NET_4_0</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_0_Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\net_4_0_Release\</OutputPath>
<DefineConstants>TRACE;NET_3_5;NET_4_0</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFrameworkVersion)' != 'v2.0' ">
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Mono.Cecil.csproj">
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project>
@@ -87,33 +20,11 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Mono.Cecil.Tests\Addin.cs" />
<Compile Include="Mono.Cecil.Tests\MdbTests.cs" />
<Compile Include="Mono.Cecil.Tests\*.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Resources\assemblies\hello.exe" />
<Content Include="Resources\assemblies\hello.exe.mdb" />
<None Include="Resources\**\*" />
</ItemGroup>
<ItemGroup>
<Reference Include="nunit.core">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Test\libs\nunit-2.6.2\nunit.core.dll</HintPath>
</Reference>
<Reference Include="nunit.core.interfaces">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Test\libs\nunit-2.6.2\nunit.core.interfaces.dll</HintPath>
</Reference>
<Reference Include="nunit.framework">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Test\libs\nunit-2.6.2\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<Import Project="..\..\..\Mono.Cecil.Tests.props" />
<Import Project="$(MSBuildCSharpTargets)" />
</Project>

View File

@@ -1,8 +0,0 @@
using NUnit.Core.Extensibility;
namespace Mono.Cecil.Tests {
[NUnitAddin]
public class CecilMdbAddin : CecilTestAddin {
}
}

View File

@@ -8,25 +8,26 @@ namespace Mono.Cecil.Tests {
[TestFixture]
public class MdbTests : BaseTestFixture {
[TestModule ("hello.exe", SymbolReaderProvider = typeof (MdbReaderProvider), SymbolWriterProvider = typeof (MdbWriterProvider))]
public void Main (ModuleDefinition module)
[Test]
public void MdbWithJustLineInfo ()
{
var type = module.GetType ("Program");
var main = type.GetMethod ("Main");
TestModule ("hello.exe", module => {
var type = module.GetType ("Program");
var main = type.GetMethod ("Main");
AssertCode (@"
AssertCode (@"
.locals init (System.Int32 i)
.line 7,7:0,0 'C:\sources\cecil\symbols\Mono.Cecil.Mdb\Test\Resources\assemblies\hello.cs'
.line 6,-1:-1,-1 'C:\sources\cecil\symbols\Mono.Cecil.Mdb\Test\Resources\assemblies\hello.cs'
IL_0000: ldc.i4.0
IL_0001: stloc.0
.line 7,7:0,0 'C:\sources\cecil\symbols\Mono.Cecil.Mdb\Test\Resources\assemblies\hello.cs'
.line 7,-1:-1,-1 'C:\sources\cecil\symbols\Mono.Cecil.Mdb\Test\Resources\assemblies\hello.cs'
IL_0002: br IL_0013
.line 8,8:0,0 'C:\sources\cecil\symbols\Mono.Cecil.Mdb\Test\Resources\assemblies\hello.cs'
.line 8,-1:-1,-1 'C:\sources\cecil\symbols\Mono.Cecil.Mdb\Test\Resources\assemblies\hello.cs'
IL_0007: ldarg.0
IL_0008: ldloc.0
IL_0009: ldelem.ref
IL_000a: call System.Void Program::Print(System.String)
.line 7,7:0,0 'C:\sources\cecil\symbols\Mono.Cecil.Mdb\Test\Resources\assemblies\hello.cs'
.line 7,-1:-1,-1 'C:\sources\cecil\symbols\Mono.Cecil.Mdb\Test\Resources\assemblies\hello.cs'
IL_000f: ldloc.0
IL_0010: ldc.i4.1
IL_0011: add
@@ -36,23 +37,50 @@ namespace Mono.Cecil.Tests {
IL_0015: ldlen
IL_0016: conv.i4
IL_0017: blt IL_0007
.line 10,10:0,0 'C:\sources\cecil\symbols\Mono.Cecil.Mdb\Test\Resources\assemblies\hello.cs'
.line 10,-1:-1,-1 'C:\sources\cecil\symbols\Mono.Cecil.Mdb\Test\Resources\assemblies\hello.cs'
IL_001c: ldc.i4.0
IL_001d: ret
", main);
}, symbolReaderProvider: typeof(MdbReaderProvider), symbolWriterProvider: typeof(MdbWriterProvider));
}
static void AssertCode (string expected, MethodDefinition method)
[Test]
public void RoundTripCoreLib ()
{
Assert.IsTrue (method.HasBody);
Assert.IsNotNull (method.Body);
TestModule ("mscorlib.dll", module => {
var type = module.GetType ("System.IO.__Error");
var method = type.GetMethod ("WinIOError");
Assert.AreEqual (Normalize (expected), Normalize (Formatter.FormatMethodBody (method)));
Assert.IsNotNull (method.Body);
}, verify: !Platform.OnMono, symbolReaderProvider: typeof(MdbReaderProvider), symbolWriterProvider: typeof(MdbWriterProvider));
}
static string Normalize (string str)
[Test]
public void PartialClass ()
{
return str.Trim ().Replace ("\r\n", "\n");
TestModule ("BreakpointTest.Portable.dll", module => {
var type = module.GetType ("BreakpointTest.Portable.TestService/<MyAsyncAction1>c__async3");
var method = type.GetMethod ("MoveNext");
Assert.IsNotNull (method);
var info = method.DebugInformation;
Assert.AreEqual (5, info.SequencePoints.Count);
foreach (var sp in info.SequencePoints)
Assert.AreEqual(@"C:\tmp\repropartial\BreakpointTest.Portable\TestService.Actions.cs", sp.Document.Url);
type = module.GetType("BreakpointTest.Portable.TestService/<MyAsyncAction2>c__async2");
method = type.GetMethod("MoveNext");
Assert.IsNotNull(method);
info = method.DebugInformation;
Assert.AreEqual(5, info.SequencePoints.Count);
foreach (var sp in info.SequencePoints)
Assert.AreEqual(@"C:\tmp\repropartial\BreakpointTest.Portable\TestService.cs", sp.Document.Url);
}, symbolReaderProvider: typeof(MdbReaderProvider), symbolWriterProvider: typeof(MdbWriterProvider));
}
}
}

View File

@@ -0,0 +1 @@
f997a8c39889b310ac6995842263f24ef6d94396