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,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;