Skip to content

Commit

Permalink
Swap usages of DEBUG with TRACE
Browse files Browse the repository at this point in the history
This was done because I could not get the DEBUG symbol to not be generated.
Thus, the output console would be swarmed with debug information even if the solution was executed in release mode.
  • Loading branch information
Miista committed May 2, 2024
1 parent 8db27e6 commit 3663b77
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Pose/IL/MethodRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ public MethodBase Rewrite()
targetInstructions.TryAdd(instruction.Offset, ilGenerator.DefineLabel());
}

#if DEBUG
#if TRACE
Console.WriteLine("\n" + _method);
#endif

foreach (var instruction in instructions)
{
#if DEBUG
#if TRACE
Console.WriteLine(instruction);
#endif

Expand Down Expand Up @@ -181,7 +181,7 @@ public MethodBase Rewrite()
}
}

#if DEBUG
#if TRACE
var ilBytes = ilGenerator.GetILBytes();
var browsableDynamicMethod = new BrowsableDynamicMethod(dynamicMethod, new DynamicMethodBody(ilBytes, locals));
Console.WriteLine("\n" + dynamicMethod);
Expand Down
4 changes: 4 additions & 0 deletions src/Pose/IL/Stubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ public static DynamicMethod GenerateStubForDirectCall(MethodBase method)
StubHelper.GetOwningModule(),
true);

#if TRACE
Console.WriteLine("\n" + method);
#endif

var ilGenerator = stub.GetILGenerator();

Expand Down Expand Up @@ -280,7 +282,9 @@ public static DynamicMethod GenerateStubForVirtualCall(MethodInfo method)
StubHelper.GetOwningModule(),
true);

#if TRACE
Console.WriteLine("\n" + method);
#endif

var ilGenerator = stub.GetILGenerator();

Expand Down
6 changes: 5 additions & 1 deletion src/Pose/Pose.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp2.0;netcoreapp3.0;net48;net7.0;net8.0</TargetFrameworks>
<DebugType>portable</DebugType>
<AssemblyName>Pose</AssemblyName>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
<DefineConstants />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Mono.Reflection.Core" Version="1.1.1" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
Expand Down
8 changes: 8 additions & 0 deletions src/Pose/PoseContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ public static void Isolate(Action entryPoint, params Shim[] shims)

var delegateType = typeof(Action<>).MakeGenericType(entryPoint.Target.GetType());
var rewriter = MethodRewriter.CreateRewriter(entryPoint.Method, false);
#if TRACE
Console.WriteLine("----------------------------- Rewriting ----------------------------- ");
#endif
var methodInfo = (MethodInfo)(rewriter.Rewrite());

#if TRACE
Console.WriteLine("----------------------------- Invoking ----------------------------- ");
#endif
methodInfo.CreateDelegate(delegateType).DynamicInvoke(entryPoint.Target);
}

Expand All @@ -45,10 +49,14 @@ public static async Task Isolate(Func<Task> entryPoint, params Shim[] shims)

var delegateType = typeof(Func<Task>);
var rewriter = MethodRewriter.CreateRewriter(entryPoint.Method, false);
#if TRACE
Console.WriteLine("----------------------------- Rewriting ----------------------------- ");
#endif
var methodInfo = (MethodInfo)(rewriter.Rewrite());

#if TRACE
Console.WriteLine("----------------------------- Invoking ----------------------------- ");
#endif

// ReSharper disable once PossibleNullReferenceException
await (methodInfo.CreateDelegate(delegateType).DynamicInvoke() as Task);
Expand Down

0 comments on commit 3663b77

Please sign in to comment.