Skip to content

Commit

Permalink
Merge branch 'hotfix/2.16.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
GeertvanHorrik committed Apr 28, 2017
2 parents 4cc0007 + 8d4ddc4 commit 85d6f10
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Catel.Fody/Catel.Fody.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<Compile Include="Configuration.cs" />
<Compile Include="Core\Models\CatelTypeProperty.cs" />
<Compile Include="Extensions\CecilExtensions.assembly.cs" />
<Compile Include="Extensions\CecilExtensions.debuginfo.cs" />
<Compile Include="Extensions\TypeReferenceExtensions.cs" />
<Compile Include="Extensions\CecilCatelExtensions.cs" />
<Compile Include="Extensions\CecilExtensions.attributes.cs" />
Expand Down
1 change: 1 addition & 0 deletions src/Catel.Fody/Core/CatelPropertyWeaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ private void RemoveBackingField(PropertyDefinition property)
}

ctorBody.OptimizeMacros();
ctor.UpdateDebugInfo();
}

declaringType.Fields.Remove(field);
Expand Down
98 changes: 98 additions & 0 deletions src/Catel.Fody/Extensions/CecilExtensions.debuginfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CecilExtensions.debuginfo.cs" company="Catel development team">
// Copyright (c) 2008 - 2017 Catel development team. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------


namespace Catel.Fody
{
using System.Linq;
using System.Reflection;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;

public static partial class CecilExtensions
{
private const long AddressToIgnore = 16707566;

private static readonly FieldInfo SequencePointOffsetFieldInfo = typeof(SequencePoint).GetField("offset", BindingFlags.Instance | BindingFlags.NonPublic);
private static readonly FieldInfo InstructionOffsetInstructionFieldInfo = typeof(InstructionOffset).GetField("instruction", BindingFlags.Instance | BindingFlags.NonPublic);

public static void UpdateDebugInfo(this MethodDefinition method)
{
var debugInfo = method.DebugInformation;
var instructions = method.Body.Instructions;
var scope = debugInfo.Scope;

if (scope == null || instructions.Count == 0)
{
return;
}

var oldSequencePoints = debugInfo.SequencePoints;
var newSequencePoints = new Collection<SequencePoint>();

// Step 1: check if all variables are present
foreach (var variable in method.Body.Variables)
{
var hasVariable = scope.Variables.Any(x => x.Index == variable.Index);
if (!hasVariable)
{
var variableDebugInfo = new VariableDebugInformation(variable, $"__var_{variable.Index}");
scope.Variables.Add(variableDebugInfo);
}
}

// Step 2: Make sure the instructions point to the correct items
foreach (var oldSequencePoint in oldSequencePoints)
{
//var isValid = false;

//// Special cases we need to ignore
//if (oldSequencePoint.StartLine == AddressToIgnore ||
// oldSequencePoint.EndLine == AddressToIgnore)
//{
// continue;
//}

var instructionOffset = (InstructionOffset)SequencePointOffsetFieldInfo.GetValue(oldSequencePoint);
var offsetInstruction = (Instruction)InstructionOffsetInstructionFieldInfo.GetValue(instructionOffset);

// Fix offset
for (var i = 0; i < instructions.Count; i++)
{
var instruction = instructions[i];
if (instruction == offsetInstruction)
{
var newSequencePoint = new SequencePoint(instruction, oldSequencePoint.Document)
{
StartLine = oldSequencePoint.StartLine,
StartColumn = oldSequencePoint.StartColumn,
EndLine = oldSequencePoint.EndLine,
EndColumn = oldSequencePoint.EndColumn
};

newSequencePoints.Add(newSequencePoint);

//isValid = true;

break;
}
}
}

debugInfo.SequencePoints.Clear();

foreach (var newSequencePoint in newSequencePoints)
{
debugInfo.SequencePoints.Add(newSequencePoint);
}

// Step 3: update the scopes by setting the indices
scope.Start = new InstructionOffset(instructions.First());
scope.End = new InstructionOffset(instructions.Last());
}
}
}
1 change: 1 addition & 0 deletions src/Catel.Fody/Weaving/Argument/ArgumentWeaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ private void ProcessMethod(MethodDefinition method)
if (instructions != null)
{
method.Body.OptimizeMacros();
method.UpdateDebugInfo();
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Catel.Fody/Weaving/Logging/LoggingWeaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void Execute()
}

body.OptimizeMacros();
staticConstructor.UpdateDebugInfo();
}

private void UpdateCallsToGetCurrentClassLogger(MethodBody ctorBody)
Expand Down

0 comments on commit 85d6f10

Please # to comment.