Skip to content

Commit

Permalink
Fixes issue #4850 (#4923)
Browse files Browse the repository at this point in the history
Fix dynamic methods "resolver" field name.
  • Loading branch information
mikem8361 authored Sep 12, 2024
1 parent 4cc147a commit c487080
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 3 deletions.
47 changes: 45 additions & 2 deletions debuggees.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29019.234
# Visual Studio Version 17
VisualStudioVersion = 17.12.35309.182
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestDebuggee", "src\SOS\lldbplugin.tests\TestDebuggee\TestDebuggee.csproj", "{6C43BE85-F8C3-4D76-8050-F25CE953A7FD}"
EndProject
Expand Down Expand Up @@ -39,6 +39,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GCPOH", "src\SOS\SOS.UnitTe
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotnetDumpCommands", "src\SOS\SOS.UnitTests\Debuggees\DotnetDumpCommands\DotnetDumpCommands.csproj", "{F9A69812-DC52-428D-9DB1-8B831A8FF776}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamicMethod", "src\SOS\SOS.UnitTests\Debuggees\DynamicMethod\DynamicMethod.csproj", "{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Checked|Any CPU = Checked|Any CPU
Expand Down Expand Up @@ -663,6 +665,46 @@ Global
{F9A69812-DC52-428D-9DB1-8B831A8FF776}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{F9A69812-DC52-428D-9DB1-8B831A8FF776}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU
{F9A69812-DC52-428D-9DB1-8B831A8FF776}.RelWithDebInfo|x86.Build.0 = Release|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Checked|Any CPU.Build.0 = Debug|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Checked|ARM.ActiveCfg = Debug|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Checked|ARM.Build.0 = Debug|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Checked|ARM64.ActiveCfg = Debug|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Checked|ARM64.Build.0 = Debug|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Checked|x64.ActiveCfg = Debug|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Checked|x64.Build.0 = Debug|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Checked|x86.ActiveCfg = Debug|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Checked|x86.Build.0 = Debug|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Debug|ARM.ActiveCfg = Debug|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Debug|ARM.Build.0 = Debug|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Debug|ARM64.Build.0 = Debug|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Debug|x64.ActiveCfg = Debug|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Debug|x64.Build.0 = Debug|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Debug|x86.ActiveCfg = Debug|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Debug|x86.Build.0 = Debug|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Release|Any CPU.Build.0 = Release|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Release|ARM.ActiveCfg = Release|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Release|ARM.Build.0 = Release|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Release|ARM64.ActiveCfg = Release|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Release|ARM64.Build.0 = Release|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Release|x64.ActiveCfg = Release|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Release|x64.Build.0 = Release|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Release|x86.ActiveCfg = Release|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.Release|x86.Build.0 = Release|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.RelWithDebInfo|ARM.ActiveCfg = Release|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.RelWithDebInfo|ARM.Build.0 = Release|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.RelWithDebInfo|ARM64.ActiveCfg = Release|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.RelWithDebInfo|ARM64.Build.0 = Release|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91}.RelWithDebInfo|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -685,6 +727,7 @@ Global
{84881FB8-37E1-4D9B-B27E-9831C30DCC04} = {C3072949-6D24-451B-A308-2F3621F858B0}
{0A34CA51-8B8C-41A1-BE24-AB2C574EA144} = {C3072949-6D24-451B-A308-2F3621F858B0}
{F9A69812-DC52-428D-9DB1-8B831A8FF776} = {C3072949-6D24-451B-A308-2F3621F858B0}
{2F9AA5A9-D42A-42C6-B483-1B9284C62F91} = {C3072949-6D24-451B-A308-2F3621F858B0}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {46465737-C938-44FC-BE1A-4CE139EBB5E0}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework Condition="'$(BuildProjectFramework)' != ''">$(BuildProjectFramework)</TargetFramework>
<TargetFrameworks Condition="'$(BuildProjectFramework)' == ''">$(BuildTargetFrameworks)</TargetFrameworks>
</PropertyGroup>

</Project>
67 changes: 67 additions & 0 deletions src/SOS/SOS.UnitTests/Debuggees/DynamicMethod/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;

namespace TestInfiniteDynamicMethods
{
internal class Program
{
[MethodImpl(MethodImplOptions.NoInlining)]
static Func<int, int> GetFibDynamicMethod()
{
DynamicMethod dynamicMethod = new DynamicMethod("Fibonacci", typeof(int), new Type[] { typeof(int) });
ILGenerator ilgen = dynamicMethod.GetILGenerator();
Label labelAfterCmp0 = ilgen.DefineLabel();
ilgen.Emit(OpCodes.Ldarg_0);
ilgen.Emit(OpCodes.Ldc_I4_0);
ilgen.Emit(OpCodes.Bne_Un_S, labelAfterCmp0);
ilgen.Emit(OpCodes.Ldc_I4_0);
ilgen.Emit(OpCodes.Ret);
ilgen.MarkLabel(labelAfterCmp0);

Label labelAfterCmp1 = ilgen.DefineLabel();
ilgen.Emit(OpCodes.Ldarg_0);
ilgen.Emit(OpCodes.Ldc_I4_1);
ilgen.Emit(OpCodes.Bne_Un_S, labelAfterCmp1);
ilgen.Emit(OpCodes.Ldc_I4_1);
ilgen.Emit(OpCodes.Ret);
ilgen.MarkLabel(labelAfterCmp1);

ilgen.Emit(OpCodes.Ldarg_0);
ilgen.Emit(OpCodes.Ldc_I4_1);
ilgen.Emit(OpCodes.Sub);
ilgen.Emit(OpCodes.Call, dynamicMethod);

ilgen.Emit(OpCodes.Ldarg_0);
ilgen.Emit(OpCodes.Ldc_I4_2);
ilgen.Emit(OpCodes.Sub);
ilgen.Emit(OpCodes.Call, dynamicMethod);

ilgen.Emit(OpCodes.Add);
ilgen.Emit(OpCodes.Ret);

var result = dynamicMethod.CreateDelegate<Func<int, int>>();
throw new Exception();
}

static void Main(string[] args)
{
Console.WriteLine("Hello, World!");

int count = 0;
while (true)
{
int result = GetFibDynamicMethod()(4);

if (((++count) % 200) == 0)
{
GC.Collect();
GC.WaitForPendingFinalizers();
}

if (((++count) % 1000) == 0)
Console.WriteLine(count);
}
}
}
}
10 changes: 10 additions & 0 deletions src/SOS/SOS.UnitTests/SOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,16 @@ await SOSTestHelpers.RunTest(
Output);
}

[SkippableTheory, MemberData(nameof(Configurations))]
public async Task DynamicMethod(TestConfiguration config)
{
if (config.PublishSingleFile || config.IsDesktop)
{
throw new SkipTestException("Single file and desktop framework not supported");
}
await SOSTestHelpers.RunTest(config, debuggeeName: "DynamicMethod", scriptName: "DynamicMethod.script", Output);
}

[SkippableTheory, MemberData(nameof(Configurations))]
public async Task Reflection(TestConfiguration config)
{
Expand Down
11 changes: 11 additions & 0 deletions src/SOS/SOS.UnitTests/Scripts/DynamicMethod.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

CONTINUE

LOADSOS

SOSCOMMAND:ClrStack -i -a
VERIFY:\s+LOCALS:\s+

SOSCOMMAND:DumpIL <POUT>.*System\.Reflection\.Emit\.DynamicMethod dynamicMethod @ 0x(<HEXVAL>).*\s+<POUT>
VERIFY:\s+IL_0000: ldarg.0\s+
VERIFY:\s+IL_0001: ldc.i4.0\s+
6 changes: 5 additions & 1 deletion src/SOS/Strike/strike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,11 @@ BOOL GatherDynamicInfo(TADDR DynamicMethodObj, DacpObjectData *codeArray,

iOffset = GetObjFieldOffset(TO_CDADDR(DynamicMethodObj), objData.MethodTable, W("m_resolver"));
if (iOffset <= 0)
return bRet;
{
iOffset = GetObjFieldOffset(TO_CDADDR(DynamicMethodObj), objData.MethodTable, W("_resolver"));
if (iOffset <= 0)
return bRet;
}

TADDR resolverPtr;
if (FAILED(MOVE(resolverPtr, DynamicMethodObj + iOffset)))
Expand Down

0 comments on commit c487080

Please sign in to comment.