Skip to content

Commit

Permalink
R2RDump - Check disassembler support (dotnet#19664)
Browse files Browse the repository at this point in the history
* Determine if disasm is supported on architectures instead of match

* Readme changes
  • Loading branch information
acmyu committed Aug 26, 2018
1 parent d27fff3 commit d2b76e0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
7 changes: 2 additions & 5 deletions src/tools/r2rdump/R2RDump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,16 +403,13 @@ private int Run(string[] args)

if (_disasm)
{
// TODO: Fix R2RDump issue where an x64 R2R image cannot be dissassembled with the x86 CoreDisTools
// For the short term, we want to error out with a decent message explaining the unexpected error
// Issue #19564: https://github.com/dotnet/coreclr/issues/19564
if (r2r.InputArchitectureMatchesDisassemblerArchitecture())
if (r2r.InputArchitectureSupported() && r2r.DisassemblerArchitectureSupported())
{
disassembler = new Disassembler(r2r.Image, r2r.Machine);
}
else
{
throw new ArgumentException($"The architecture of input file {filename} is {r2r.Machine.ToString()} and does not match the architecture of the disassembler tools {System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture.ToString()}");
throw new ArgumentException($"The architecture of input file {filename} ({r2r.Machine.ToString()}) or the architecture of the disassembler tools ({System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture.ToString()}) is not supported.");
}
}

Expand Down
24 changes: 10 additions & 14 deletions src/tools/r2rdump/R2RReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,22 +174,18 @@ public unsafe R2RReader(string filename)
}
}

public bool InputArchitectureMatchesDisassemblerArchitecture()
public bool InputArchitectureSupported()
{
return Machine != Machine.ArmThumb2; // CoreDisTools often fails to decode when disassembling ARM images (see https://github.com/dotnet/coreclr/issues/19637)
}

// TODO: Fix R2RDump issue where an R2R image cannot be dissassembled with the x86 CoreDisTools
// For the short term, we want to error out with a decent message explaining the unexpected error
// Issue #19564: https://github.com/dotnet/coreclr/issues/19564
public bool DisassemblerArchitectureSupported()
{
System.Runtime.InteropServices.Architecture val = System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture;
switch (Machine)
{
case Machine.Amd64:
return val == System.Runtime.InteropServices.Architecture.X64;
case Machine.I386:
return val == System.Runtime.InteropServices.Architecture.X86;
case Machine.Arm64:
return val == System.Runtime.InteropServices.Architecture.Arm64;
case Machine.ArmThumb2:
return val == System.Runtime.InteropServices.Architecture.Arm;
default:
return false;
}
return val != System.Runtime.InteropServices.Architecture.X86;
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions src/tools/r2rdump/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ In x64/Arm/Arm64, GcTransitions are grouped into chunks where each chunk covers

* Support R2RDump on ARM and ARM64 (https://github.com/dotnet/coreclr/issues/19089)

* Fix issue with invalid machine type in COFF header (https://github.com/dotnet/coreclr/issues/19592)

* Parse R2RSections: READYTORUN_SECTION_EXCEPTION_INFO, READYTORUN_SECTION_DEBUG_INFO, READYTORUN_SECTION_DELAYLOAD_METHODCALL_THUNKS, READYTORUN_SECTION_INLINING_INFO, READYTORUN_SECTION_PROFILEDATA_INFO (https://github.com/dotnet/coreclr/issues/19616)

* Reenable R2RDumpTests after making it less fragile

* Fix issue with disasm on Arm (https://github.com/dotnet/coreclr/issues/19637)
* Fix issues with disasm on Arm (https://github.com/dotnet/coreclr/issues/19637) and disasm using x86 coredistools (https://github.com/dotnet/coreclr/issues/19564)

* Test R2RDump on more test cases to make sure it runs reliably and verify that the output is accurate (list of failing inputs: https://github.com/dotnet/coreclr/issues/19642)

0 comments on commit d2b76e0

Please sign in to comment.