Skip to content

Commit

Permalink
Debugging Crossgen2 documentation (#47363)
Browse files Browse the repository at this point in the history
* Debugging Crossgen2 documentation and such
- Also new --print-repro-instructions command line switch to crossgen2 as requested by the JIT team
  • Loading branch information
davidwrighton authored Jan 26, 2021
1 parent abcf07b commit d7ee51c
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 14 deletions.
162 changes: 162 additions & 0 deletions docs/workflow/debugging/coreclr/debugging-crossgen2.md

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions docs/workflow/debugging/coreclr/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ The "COMPlus_EnableDiagnostics" environment variable can be used to disable mana

export COMPlus_EnableDiagnostics=0

Debugging Crossgen2
==================================

Debugging Crossgen2 is described in [this](debugging-crossgen2.md) document.

Using Visual Studio Code
========================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ public sealed class ReadyToRunCodegenCompilation : Compilation
private bool _generateMapFile;
private bool _generateMapCsvFile;
private bool _generatePdbFile;
private Func<MethodDesc, string> _printReproInstructions;
private string _pdbPath;
private bool _generatePerfMapFile;
private string _perfMapPath;
Expand Down Expand Up @@ -262,6 +263,7 @@ internal ReadyToRunCodegenCompilation(
bool generateMapFile,
bool generateMapCsvFile,
bool generatePdbFile,
Func<MethodDesc, string> printReproInstructions,
string pdbPath,
bool generatePerfMapFile,
string perfMapPath,
Expand Down Expand Up @@ -294,6 +296,7 @@ internal ReadyToRunCodegenCompilation(
_corInfoImpls = new ConditionalWeakTable<Thread, CorInfoImpl>();
_inputFiles = inputFiles;
_compositeRootPath = compositeRootPath;
_printReproInstructions = printReproInstructions;
CompilationModuleGroup = (ReadyToRunCompilationModuleGroupBase)nodeFactory.CompilationModuleGroup;

// Generate baseline support specification for InstructionSetSupport. This will prevent usage of the generated
Expand Down Expand Up @@ -524,6 +527,11 @@ protected override void ComputeDependencyNodeDependencies(List<DependencyNodeCor
Logger.Writer.WriteLine("Compiling " + methodName);
}
if (_printReproInstructions != null)
{
Logger.Writer.WriteLine($"Single method repro args:{_printReproInstructions(method)}");
}
try
{
using (PerfEventSource.StartStopEvents.JitMethodEvents())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Internal.IL;
using Internal.JitInterface;
using Internal.ReadyToRunConstants;
using Internal.TypeSystem;
using Internal.TypeSystem.Ecma;

namespace ILCompiler
Expand All @@ -29,6 +30,7 @@ public sealed class ReadyToRunCodegenCompilationBuilder : CompilationBuilder
private bool _generatePerfMapFile;
private string _perfMapPath;
private int _parallelism;
Func<MethodDesc, string> _printReproInstructions;
private InstructionSetSupport _instructionSetSupport;
private ProfileDataManager _profileData;
private ReadyToRunMethodLayoutAlgorithm _r2rMethodLayoutAlgorithm;
Expand Down Expand Up @@ -157,6 +159,12 @@ public ReadyToRunCodegenCompilationBuilder UseParallelism(int parallelism)
return this;
}

public ReadyToRunCodegenCompilationBuilder UsePrintReproInstructions(Func<MethodDesc, string> printReproInstructions)
{
_printReproInstructions = printReproInstructions;
return this;
}

public ReadyToRunCodegenCompilationBuilder UseInstructionSetSupport(InstructionSetSupport instructionSetSupport)
{
_instructionSetSupport = instructionSetSupport;
Expand Down Expand Up @@ -267,6 +275,7 @@ public override ICompilation ToCompilation()
generateMapFile: _generateMapFile,
generateMapCsvFile: _generateMapCsvFile,
generatePdbFile: _generatePdbFile,
printReproInstructions: _printReproInstructions,
pdbPath: _pdbPath,
generatePerfMapFile: _generatePerfMapFile,
perfMapPath: _perfMapPath,
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/tools/aot/crossgen2/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ internal class CommandLineOptions
public bool Resilient;
public bool Map;
public bool MapCsv;
public bool PrintReproInstructions;
public bool Pdb;
public string PdbPath;
public bool PerfMap;
Expand Down Expand Up @@ -113,6 +114,7 @@ public CommandLineOptions(string[] args)
syntax.DefineOption("targetos", ref TargetOS, SR.TargetOSOption);
syntax.DefineOption("jitpath", ref JitPath, SR.JitPathOption);
syntax.DefineOption("print-repro-instructions", ref PrintReproInstructions, SR.PrintReproInstructionsOption);
syntax.DefineOption("singlemethodtypename", ref SingleMethodTypeName, SR.SingleMethodTypeName);
syntax.DefineOption("singlemethodname", ref SingleMethodName, SR.SingleMethodMethodName);
syntax.DefineOption("singlemethodindex", ref SingleMethodIndex, SR.SingleMethodIndex);
Expand Down
38 changes: 24 additions & 14 deletions src/coreclr/tools/aot/crossgen2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;
using System.Runtime.InteropServices;
using System.Text;

using Internal.CommandLine;
using Internal.IL;
Expand Down Expand Up @@ -607,6 +608,9 @@ private int Run(string[] args)
.UseCompilationRoots(compilationRoots)
.UseOptimizationMode(_optimizationMode);

if (_commandLineOptions.PrintReproInstructions)
builder.UsePrintReproInstructions(CreateReproArgumentString);

compilation = builder.ToCompilation();

}
Expand Down Expand Up @@ -722,35 +726,41 @@ private MethodDesc CheckAndParseSingleMethodModeArguments(CompilerTypeSystemCont
return method;
}

private static bool DumpReproArguments(CodeGenerationFailedException ex)
private static string CreateReproArgumentString(MethodDesc method)
{
Console.WriteLine(SR.DumpReproInstructions);
StringBuilder sb = new StringBuilder();

MethodDesc failingMethod = ex.Method;

var formatter = new CustomAttributeTypeNameFormatter((IAssemblyDesc)failingMethod.Context.SystemModule);
var formatter = new CustomAttributeTypeNameFormatter((IAssemblyDesc)method.Context.SystemModule);

Console.Write($"--singlemethodtypename \"{formatter.FormatName(failingMethod.OwningType, true)}\"");
Console.Write($" --singlemethodname {failingMethod.Name}");
sb.Append($"--singlemethodtypename \"{formatter.FormatName(method.OwningType, true)}\"");
sb.Append($" --singlemethodname {method.Name}");
{
int curIndex = 0;
foreach (var searchMethod in failingMethod.OwningType.GetMethods())
foreach (var searchMethod in method.OwningType.GetMethods())
{
if (searchMethod.Name != failingMethod.Name)
if (searchMethod.Name != method.Name)
continue;

curIndex++;
if (searchMethod == failingMethod.GetMethodDefinition())
if (searchMethod == method.GetMethodDefinition())
{
Console.Write($" --singlemethodindex {curIndex}");
sb.Append($" --singlemethodindex {curIndex}");
}
}
}

for (int i = 0; i < failingMethod.Instantiation.Length; i++)
Console.Write($" --singlemethodgenericarg \"{formatter.FormatName(failingMethod.Instantiation[i], true)}\"");
for (int i = 0; i < method.Instantiation.Length; i++)
sb.Append($" --singlemethodgenericarg \"{formatter.FormatName(method.Instantiation[i], true)}\"");

return sb.ToString();
}

private static bool DumpReproArguments(CodeGenerationFailedException ex)
{
Console.WriteLine(SR.DumpReproInstructions);

Console.WriteLine();
MethodDesc failingMethod = ex.Method;
Console.WriteLine(CreateReproArgumentString(failingMethod));
return false;
}

Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/tools/aot/crossgen2/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@
<data name="SaveDetailedLogOption" xml:space="preserve">
<value>Save detailed log of dependency analysis</value>
</data>
<data name="PrintReproInstructionsOption" xml:space="preserve">
<value>When compiling each method, print out the set of arguments needed to compile that method only</value>
</data>
<data name="SingleMethodGenericArgs" xml:space="preserve">
<value>Single method compilation: generic arguments to the method</value>
</data>
Expand Down

0 comments on commit d7ee51c

Please sign in to comment.