From 1c436272acb6b06ade8d67caa20e1650164c7fa3 Mon Sep 17 00:00:00 2001 From: "Philip R. Saxton" Date: Thu, 3 Nov 2022 08:44:47 -0600 Subject: [PATCH] Revert "Fix debug information by just using the debug scopes from original method" This reverts commit 9d451fbff2290110dc53d0a82caacb744fe782f4. --- .../Program.cs | 3 -- .../WrongDebugVariableNames.cs | 54 ------------------- src/MethodBoundaryAspect.Fody/MethodWeaver.cs | 19 ++++++- 3 files changed, 17 insertions(+), 59 deletions(-) delete mode 100644 src/MethodBoundaryAspect.Fody.UnitTests.TestProgram.NetFramework/WrongDebugVariableNames.cs diff --git a/src/MethodBoundaryAspect.Fody.UnitTests.TestProgram.NetFramework/Program.cs b/src/MethodBoundaryAspect.Fody.UnitTests.TestProgram.NetFramework/Program.cs index 05d5acf..57ef3e8 100644 --- a/src/MethodBoundaryAspect.Fody.UnitTests.TestProgram.NetFramework/Program.cs +++ b/src/MethodBoundaryAspect.Fody.UnitTests.TestProgram.NetFramework/Program.cs @@ -12,9 +12,6 @@ private static void Main() Debugger.Launch(); Debugger.Break(); - var t0 = new WrongDebugVariableNames(); - t0.Call(); - var t1 = new LogTest(); t1.DoIt(7); diff --git a/src/MethodBoundaryAspect.Fody.UnitTests.TestProgram.NetFramework/WrongDebugVariableNames.cs b/src/MethodBoundaryAspect.Fody.UnitTests.TestProgram.NetFramework/WrongDebugVariableNames.cs deleted file mode 100644 index b61dbed..0000000 --- a/src/MethodBoundaryAspect.Fody.UnitTests.TestProgram.NetFramework/WrongDebugVariableNames.cs +++ /dev/null @@ -1,54 +0,0 @@ -using MethodBoundaryAspect.Fody.Attributes; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MethodBoundaryAspect.Fody.UnitTests.TestProgram.NetFramework -{ - internal class WrongDebugVariableNames - { - public void Call() - { - DoSomeStuff2(new List{42}); - } - - [MethodInterceptor] - private void DoSomeStuff2(List youcanseethis) - { - var andThis = youcanseethis.Take(1); - var rand = new Random(); - if (rand.NextDouble() > 0.5) - { - var butNotThis = youcanseethis.Take(1); - Console.WriteLine("Larger than 0.5"); - Console.WriteLine($"{butNotThis}"); - } - else - { - var butNotThis = youcanseethis.Take(1); - Console.WriteLine("Smaller than 0.5"); - Console.WriteLine($"{butNotThis}"); - } - } - } - - public sealed class MethodInterceptor : OnMethodBoundaryAspect - { - public override void OnEntry(MethodExecutionArgs args) - { - Console.WriteLine("Enter: " + args.Instance.GetType().FullName + "." + args.Method.Name); - } - - public override void OnExit(MethodExecutionArgs args) - { - Console.WriteLine("Exit: "+ args.Instance.GetType().FullName +"."+args.Method.Name); - } - - public override void OnException(MethodExecutionArgs args) - { - Console.WriteLine(args.Exception); - } - } -} diff --git a/src/MethodBoundaryAspect.Fody/MethodWeaver.cs b/src/MethodBoundaryAspect.Fody/MethodWeaver.cs index b23893b..206d34c 100644 --- a/src/MethodBoundaryAspect.Fody/MethodWeaver.cs +++ b/src/MethodBoundaryAspect.Fody/MethodWeaver.cs @@ -98,7 +98,7 @@ private static MethodDefinition CloneMethod(MethodDefinition method) }; foreach (var parameter in method.Parameters) - clonedMethod.Parameters.Add(parameter); + clonedMethod.Parameters.Add(parameter); foreach (var variable in method.Body.Variables) clonedMethod.Body.Variables.Add(variable); @@ -162,7 +162,22 @@ private static MethodDefinition CloneMethod(MethodDefinition method) } } - clonedMethod.DebugInformation.Scope = method.DebugInformation.Scope; + if (method.DebugInformation.HasSequencePoints) + { + foreach (var sequencePoint in method.DebugInformation.SequencePoints) + clonedMethod.DebugInformation.SequencePoints.Add(sequencePoint); + } + + clonedMethod.DebugInformation.Scope = new ScopeDebugInformation(method.Body.Instructions.First(), method.Body.Instructions.Last()); + + if (method.DebugInformation?.Scope?.Variables != null) + { + foreach (var variableDebugInformation in method.DebugInformation.Scope.Variables) + { + clonedMethod.DebugInformation.Scope.Variables.Add(variableDebugInformation); + } + } + return clonedMethod; }