diff options
author | Amy <amycmyu@gmail.com> | 2018-06-01 13:44:28 -0700 |
---|---|---|
committer | Zach Montoya <zamont@microsoft.com> | 2018-06-01 13:44:28 -0700 |
commit | 15f2475fc4ced34607f74830d406989d7cf5f9ca (patch) | |
tree | 027371818b4dc195be62054334b2b3bd38899fa2 /src | |
parent | 93955d4b58380068df9d99c58a699de6ad03f532 (diff) | |
download | coreclr-15f2475fc4ced34607f74830d406989d7cf5f9ca.tar.gz coreclr-15f2475fc4ced34607f74830d406989d7cf5f9ca.tar.bz2 coreclr-15f2475fc4ced34607f74830d406989d7cf5f9ca.zip |
Added disassembler CoreDisTools to dump runtime functions (#18180)
Remove obsolete targets
Remove unused NewDiffer function, fix error with uninitialized declaringTypeHandle
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/r2rdump/CoreDisTools.cs | 62 | ||||
-rw-r--r-- | src/tools/r2rdump/NativeReader.cs | 6 | ||||
-rw-r--r-- | src/tools/r2rdump/R2RDump.cs | 25 | ||||
-rw-r--r-- | src/tools/r2rdump/R2RDump.csproj | 2 | ||||
-rw-r--r-- | src/tools/r2rdump/R2RMethod.cs | 5 | ||||
-rw-r--r-- | src/tools/r2rdump/R2RSection.cs | 6 |
6 files changed, 99 insertions, 7 deletions
diff --git a/src/tools/r2rdump/CoreDisTools.cs b/src/tools/r2rdump/CoreDisTools.cs new file mode 100644 index 0000000000..52cb9009ec --- /dev/null +++ b/src/tools/r2rdump/CoreDisTools.cs @@ -0,0 +1,62 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Reflection.PortableExecutable; +using System.Runtime.InteropServices; + +namespace R2RDump +{ + class CoreDisTools + { + public enum TargetArch + { + Target_Host, // Target is the same as host architecture + Target_X86, + Target_X64, + Target_Thumb, + Target_Arm64 + }; + + [DllImport("coredistools.dll")] + [return: MarshalAs(UnmanagedType.I8)] + public static extern long InitDisasm(TargetArch Target); + + [DllImport("coredistools.dll")] + public static extern void DumpCodeBlock(long Disasm, ulong Address, IntPtr Bytes, int Size); + + [DllImport("coredistools.dll")] + public static extern void FinishDisasm(long Disasm); + + public unsafe static void DumpCodeBlock(long Disasm, int Address, int Offset, byte[] image, int Size) + { + fixed (byte* p = image) + { + IntPtr ptr = (IntPtr)(p + Offset); + DumpCodeBlock(Disasm, (ulong)Address, ptr, Size); + } + } + + public static long GetDisasm(Machine machine) + { + TargetArch target = TargetArch.Target_Host; + switch (machine) + { + case Machine.Amd64: + target = TargetArch.Target_X64; + break; + case Machine.I386: + target = TargetArch.Target_X86; + break; + case Machine.Arm64: + target = TargetArch.Target_Arm64; + break; + case Machine.ArmThumb2: + target = TargetArch.Target_Thumb; + break; + } + return InitDisasm(target); + } + } +} diff --git a/src/tools/r2rdump/NativeReader.cs b/src/tools/r2rdump/NativeReader.cs index b3359f7632..59fd2881a6 100644 --- a/src/tools/r2rdump/NativeReader.cs +++ b/src/tools/r2rdump/NativeReader.cs @@ -1,4 +1,8 @@ -using System; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; using System.Collections.Generic; using System.Text; diff --git a/src/tools/r2rdump/R2RDump.cs b/src/tools/r2rdump/R2RDump.cs index 9aa80395f5..f7fc729c1f 100644 --- a/src/tools/r2rdump/R2RDump.cs +++ b/src/tools/r2rdump/R2RDump.cs @@ -22,6 +22,7 @@ namespace R2RDump private IReadOnlyList<int> _runtimeFunctions = Array.Empty<int>(); private IReadOnlyList<string> _sections = Array.Empty<string>(); private bool _diff = false; + private long _disassembler; private TextWriter _writer; private R2RDump() @@ -90,7 +91,7 @@ namespace R2RDump private void WriteSubDivider() { - _writer.WriteLine("------------------"); + _writer.WriteLine("_______________________________________________"); _writer.WriteLine(); } @@ -146,7 +147,15 @@ namespace R2RDump /// </summary> private void DumpRuntimeFunction(R2RReader r2r, RuntimeFunction rtf) { - _writer.WriteLine(rtf.ToString()); + if (_disasm) + { + _writer.WriteLine($"Id: {rtf.Id}"); + CoreDisTools.DumpCodeBlock(_disassembler, rtf.StartAddress, r2r.GetOffset(rtf.StartAddress), r2r.Image, rtf.Size); + } + else + { + _writer.Write($"{rtf}"); + } if (_raw) { DumpBytes(r2r, rtf.StartAddress, (uint)rtf.Size); @@ -302,7 +311,7 @@ namespace R2RDump QueryMethod(r2r, "R2R Methods by Keyword", _keywords, false); } - _writer.WriteLine("========================================================"); + _writer.WriteLine("============================================================="); _writer.WriteLine(); } @@ -440,7 +449,17 @@ namespace R2RDump foreach (string filename in _inputFilenames) { R2RReader r2r = new R2RReader(filename); + if (_disasm) + { + _disassembler = CoreDisTools.GetDisasm(r2r.Machine); + } + Dump(r2r); + + if (_disasm) + { + CoreDisTools.FinishDisasm(_disassembler); + } } } catch (Exception e) diff --git a/src/tools/r2rdump/R2RDump.csproj b/src/tools/r2rdump/R2RDump.csproj index cb9e76fb4d..e783e1698a 100644 --- a/src/tools/r2rdump/R2RDump.csproj +++ b/src/tools/r2rdump/R2RDump.csproj @@ -10,7 +10,9 @@ </PropertyGroup> <ItemGroup> + <PackageReference Include="Microsoft.NETCore.CoreDisTools" Version="1.0.1-prerelease-00003" /> <PackageReference Include="System.CommandLine" Version="0.1.0-e160119-1" /> + <PackageReference Include="System.Reflection.Metadata" Version="1.7.0-preview1-26530-04" /> </ItemGroup> </Project> diff --git a/src/tools/r2rdump/R2RMethod.cs b/src/tools/r2rdump/R2RMethod.cs index 1b658df40a..95cf8929c3 100644 --- a/src/tools/r2rdump/R2RMethod.cs +++ b/src/tools/r2rdump/R2RMethod.cs @@ -189,13 +189,14 @@ namespace R2RDump TypeDefinitionHandle declaringTypeHandle = _methodDef.GetDeclaringType(); TypeDefinition declaringTypeDef; - while (!declaringTypeHandle.IsNil) + do { declaringTypeDef = mdReader.GetTypeDefinition(declaringTypeHandle); DeclaringType = mdReader.GetString(declaringTypeDef.Name) + "." + DeclaringType; declaringTypeHandle = declaringTypeDef.GetDeclaringType(); } - + while (!declaringTypeHandle.IsNil); + NamespaceDefinitionHandle namespaceHandle = declaringTypeDef.NamespaceDefinition; while (!namespaceHandle.IsNil) { diff --git a/src/tools/r2rdump/R2RSection.cs b/src/tools/r2rdump/R2RSection.cs index aef32d24ba..8d6d7cf99c 100644 --- a/src/tools/r2rdump/R2RSection.cs +++ b/src/tools/r2rdump/R2RSection.cs @@ -1,4 +1,8 @@ -using System; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; using System.Collections.Generic; using System.Text; |