Skip to content

Commit

Permalink
Add IMAGE_FILE_MACHINE_ARM64X and IMAGE_FILE_MACHINE_ARM64EC support
Browse files Browse the repository at this point in the history
  • Loading branch information
hoyosjs authored and mikem8361 committed Sep 11, 2024
1 parent a5c4167 commit 9e6e688
Show file tree
Hide file tree
Showing 23 changed files with 202 additions and 166 deletions.
23 changes: 22 additions & 1 deletion diagnostics.sln
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "inc", "inc", "{41BDFD6D-D16
src\shared\inc\readytoruninstructionset.h = src\shared\inc\readytoruninstructionset.h
src\shared\inc\regdisp.h = src\shared\inc\regdisp.h
src\shared\inc\registrywrapper.h = src\shared\inc\registrywrapper.h
src\shared\inc\releaseholder.h = src\shared\inc\releaseholder.h
src\shared\inc\resource.h = src\shared\inc\resource.h
src\shared\inc\runtimeinfo.h = src\shared\inc\runtimeinfo.h
src\shared\inc\safemath.h = src\shared\inc\safemath.h
Expand Down Expand Up @@ -333,6 +332,26 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "minipal", "minipal", "{D9A9
src\shared\native\minipal\utils.h = src\shared\native\minipal\utils.h
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "inc", "inc", "{9E51C821-4095-4250-BD8A-2A29396DB1B4}"
ProjectSection(SolutionItems) = preProject
src\inc\corcompile.h = src\inc\corcompile.h
src\inc\ntimageex.h = src\inc\ntimageex.h
src\inc\releaseholder.h = src\inc\releaseholder.h
src\inc\stacktrace.h = src\inc\stacktrace.h
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "rt", "rt", "{D2D76252-D225-4B79-9DDB-A36867A4720E}"
ProjectSection(SolutionItems) = preProject
src\inc\rt\intsafe.h = src\inc\rt\intsafe.h
src\inc\rt\oaidl.h = src\inc\rt\oaidl.h
src\inc\rt\psapi.h = src\inc\rt\psapi.h
src\inc\rt\tchar.h = src\inc\rt\tchar.h
src\inc\rt\tlhelp32.h = src\inc\rt\tlhelp32.h
src\inc\rt\winapifamily.h = src\inc\rt\winapifamily.h
src\inc\rt\winternl.h = src\inc\rt\winternl.h
src\inc\rt\winver.h = src\inc\rt\winver.h
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Checked|Any CPU = Checked|Any CPU
Expand Down Expand Up @@ -2365,6 +2384,8 @@ Global
{06FB18BC-F4DD-4DB9-A566-551254CD1064} = {795B7A50-1B1F-406E-94E0-F9B35104EF22}
{641F00F0-2693-451B-A96A-13E4E115BF0F} = {7852EDE4-93DF-4DB1-8A86-C521703811AF}
{D9A91544-CDF8-4C68-BAD2-47F4968A8652} = {641F00F0-2693-451B-A96A-13E4E115BF0F}
{9E51C821-4095-4250-BD8A-2A29396DB1B4} = {19FAB78C-3351-4911-8F0C-8C6056401740}
{D2D76252-D225-4B79-9DDB-A36867A4720E} = {9E51C821-4095-4250-BD8A-2A29396DB1B4}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {46465737-C938-44FC-BE1A-4CE139EBB5E0}
Expand Down
6 changes: 3 additions & 3 deletions src/SOS/SOS.Extensions/DebuggerServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public HResult GetDebuggeeType(out DEBUG_CLASS debugClass, out DEBUG_CLASS_QUALI
return VTable.GetDebuggeeType(Self, out debugClass, out qualifier);
}

public HResult GetExecutingProcessorType(out IMAGE_FILE_MACHINE type)
public HResult GetProcessorType(out IMAGE_FILE_MACHINE type)
{
return VTable.GetExecutingProcessorType(Self, out type);
return VTable.GetProcessorType(Self, out type);
}

public HResult AddCommand(string command, string help, IEnumerable<string> aliases)
Expand Down Expand Up @@ -519,7 +519,7 @@ private readonly unsafe struct IDebuggerServicesVTable
{
public readonly delegate* unmanaged[Stdcall]<IntPtr, out OperatingSystem, int> GetOperatingSystem;
public readonly delegate* unmanaged[Stdcall]<IntPtr, out DEBUG_CLASS, out DEBUG_CLASS_QUALIFIER, int> GetDebuggeeType;
public readonly delegate* unmanaged[Stdcall]<IntPtr, out IMAGE_FILE_MACHINE, int> GetExecutingProcessorType;
public readonly delegate* unmanaged[Stdcall]<IntPtr, out IMAGE_FILE_MACHINE, int> GetProcessorType;
public readonly delegate* unmanaged[Stdcall]<IntPtr, byte*, byte*, IntPtr*, int, int> AddCommand;
public readonly delegate* unmanaged[Stdcall]<IntPtr, DEBUG_OUTPUT, byte*, void> OutputString;
public readonly delegate* unmanaged[Stdcall]<IntPtr, ulong, byte*, uint, out int, int> ReadVirtual;
Expand Down
6 changes: 4 additions & 2 deletions src/SOS/SOS.Extensions/TargetFromFromDebuggerServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal TargetFromDebuggerServices(DebuggerServices debuggerServices, IHost hos
IsDump = true;
}

hr = debuggerServices.GetExecutingProcessorType(out IMAGE_FILE_MACHINE type);
hr = debuggerServices.GetProcessorType(out IMAGE_FILE_MACHINE type);
if (hr == HResult.S_OK)
{
Architecture = type switch
Expand All @@ -55,14 +55,16 @@ internal TargetFromDebuggerServices(DebuggerServices debuggerServices, IHost hos
IMAGE_FILE_MACHINE.ARMNT => Architecture.Arm,
IMAGE_FILE_MACHINE.AMD64 => Architecture.X64,
IMAGE_FILE_MACHINE.ARM64 => Architecture.Arm64,
IMAGE_FILE_MACHINE.ARM64X => Architecture.Arm64,
IMAGE_FILE_MACHINE.ARM64EC => Architecture.Arm64,
IMAGE_FILE_MACHINE.LOONGARCH64 => (Architecture)6 /* Architecture.LoongArch64 */,
IMAGE_FILE_MACHINE.RISCV64 => (Architecture)9 /* Architecture.RiscV64 */,
_ => throw new PlatformNotSupportedException($"Machine type not supported: {type}"),
};
}
else
{
throw new PlatformNotSupportedException($"GetExecutingProcessorType() FAILED {hr:X8}");
throw new PlatformNotSupportedException($"GetProcessorType() FAILED {hr:X8}");
}

hr = debuggerServices.GetCurrentProcessId(out uint processId);
Expand Down
2 changes: 1 addition & 1 deletion src/SOS/SOS.Hosting/DbgEng/DebugControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static void AddDebugControl(VTableBuilder builder, SOSHost soshost)
builder.AddMethod(new GetReturnOffsetDelegate((self, offset) => DebugClient.NotImplemented));
builder.AddMethod(new OutputStackTraceDelegate((self, outputControl, frames, frameSize, flags) => DebugClient.NotImplemented));
builder.AddMethod(new GetDebuggeeTypeDelegate(soshost.GetDebuggeeType));
builder.AddMethod(new GetActualProcessorTypeDelegate((self, type) => DebugClient.NotImplemented));
builder.AddMethod(new GetActualProcessorTypeDelegate(soshost.GetExecutingProcessorType));
builder.AddMethod(new GetExecutingProcessorTypeDelegate(soshost.GetExecutingProcessorType));
builder.AddMethod(new GetNumberPossibleExecutingProcessorTypesDelegate((self, number) => DebugClient.NotImplemented));
builder.AddMethod(new GetPossibleExecutingProcessorTypesDelegate((self, start, count, types) => DebugClient.NotImplemented));
Expand Down
2 changes: 2 additions & 0 deletions src/SOS/SOS.Hosting/DbgEng/Interop/Enums/ImageFileMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public enum IMAGE_FILE_MACHINE : uint
AMD64 = 0x8664, // AMD64 (K8)
M32R = 0x9041, // M32R little-endian
ARM64 = 0xAA64, // ARM64 Little-endian
ARM64EC = 0xA641,
ARM64X = 0xA64E,
CEE = 0xC0EE,
LOONGARCH64 = 0x6264,
RISCV64 = 0x5064
Expand Down
34 changes: 10 additions & 24 deletions src/SOS/SOS.Hosting/SOSHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,30 +165,16 @@ internal unsafe int GetExecutingProcessorType(
IntPtr self,
IMAGE_FILE_MACHINE* type)
{
switch (Target.Architecture)
{
case Architecture.X64:
*type = IMAGE_FILE_MACHINE.AMD64;
break;
case Architecture.X86:
*type = IMAGE_FILE_MACHINE.I386;
break;
case Architecture.Arm:
*type = IMAGE_FILE_MACHINE.ARMNT;
break;
case Architecture.Arm64:
*type = IMAGE_FILE_MACHINE.ARM64;
break;
case (Architecture)6 /* Architecture.LoongArch64 */:
*type = IMAGE_FILE_MACHINE.LOONGARCH64;
break;
case (Architecture)9 /* Architecture.RiscV64 */:
*type = IMAGE_FILE_MACHINE.RISCV64;
break;
default:
*type = IMAGE_FILE_MACHINE.UNKNOWN;
break;
}
*type = Target.Architecture switch
{
Architecture.X64 => IMAGE_FILE_MACHINE.AMD64,
Architecture.X86 => IMAGE_FILE_MACHINE.I386,
Architecture.Arm => IMAGE_FILE_MACHINE.ARMNT,
Architecture.Arm64 => IMAGE_FILE_MACHINE.ARM64,
(Architecture)6 /* Architecture.LoongArch64 */=> IMAGE_FILE_MACHINE.LOONGARCH64,
(Architecture)9 /* Architecture.RiscV64 */=> IMAGE_FILE_MACHINE.RISCV64,
_ => IMAGE_FILE_MACHINE.UNKNOWN,
};
return HResult.S_OK;
}

Expand Down
20 changes: 0 additions & 20 deletions src/SOS/Strike/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ if(CLR_CMAKE_HOST_ARCH_AMD64)
message(STATUS "CLR_CMAKE_HOST_ARCH_AMD64")
add_definitions(-DSOS_TARGET_AMD64=1)
add_definitions(-D_TARGET_WIN64_=1)
add_definitions(-DDBG_TARGET_64BIT=1)
add_definitions(-DDBG_TARGET_AMD64=1)
add_definitions(-DDBG_TARGET_WIN64=1)
if (CLR_CMAKE_HOST_WIN32)
add_definitions(-DSOS_TARGET_ARM64=1)
endif(CLR_CMAKE_HOST_WIN32)
Expand All @@ -43,43 +40,26 @@ elseif(CLR_CMAKE_HOST_ARCH_I386)
add_definitions(-DSOS_TARGET_X86=1)
add_definitions(-D_TARGET_X86_=1)
add_definitions(-DTARGET_X86)
add_definitions(-DDBG_TARGET_X86=1)
add_definitions(-DDBG_TARGET_32BIT=1)
if (CLR_CMAKE_HOST_WIN32)
add_definitions(-DSOS_TARGET_ARM=1)
endif(CLR_CMAKE_HOST_WIN32)
elseif(CLR_CMAKE_HOST_ARCH_ARM)
message(STATUS "CLR_CMAKE_HOST_ARCH_ARM")
add_definitions(-DSOS_TARGET_ARM=1)
add_definitions(-D_TARGET_WIN32_=1)
add_definitions(-D_TARGET_ARM_=1)
add_definitions(-DDBG_TARGET_ARM=1)
add_definitions(-DDBG_TARGET_32BIT=1)
elseif(CLR_CMAKE_HOST_ARCH_ARM64)
message(STATUS "CLR_CMAKE_HOST_ARCH_ARM64")
add_definitions(-DSOS_TARGET_ARM64=1)
add_definitions(-D_TARGET_WIN64_=1)
add_definitions(-DDBG_TARGET_64BIT=1)
add_definitions(-DDBG_TARGET_ARM64=1)
add_definitions(-DDBG_TARGET_WIN64=1)
elseif(CLR_CMAKE_HOST_ARCH_MIPS64)
add_definitions(-DSOS_TARGET_MIPS64=1)
add_definitions(-D_TARGET_WIN64_=1)
add_definitions(-DDBG_TARGET_64BIT=1)
add_definitions(-DDBG_TARGET_MIPS64=1)
add_definitions(-DDBG_TARGET_WIN64=1)
elseif(CLR_CMAKE_HOST_ARCH_RISCV64)
add_definitions(-DSOS_TARGET_RISCV64=1)
add_definitions(-D_TARGET_WIN64_=1)
add_definitions(-DDBG_TARGET_64BIT=1)
add_definitions(-DDBG_TARGET_RISCV64=1)
add_definitions(-DDBG_TARGET_WIN64=1)
elseif(CLR_CMAKE_HOST_ARCH_LOONGARCH64)
add_definitions(-DSOS_TARGET_LOONGARCH64=1)
add_definitions(-D_TARGET_WIN64_=1)
add_definitions(-DDBG_TARGET_64BIT=1)
add_definitions(-DDBG_TARGET_LOONGARCH64=1)
add_definitions(-DDBG_TARGET_WIN64=1)
endif()

add_definitions(-DSTRIKE)
Expand Down
4 changes: 3 additions & 1 deletion src/SOS/Strike/clrma/managedanalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ ClrmaManagedAnalysis::QueryDebugClient(IUnknown* pUnknown)
}
switch (m_processorType)
{
case IMAGE_FILE_MACHINE_ARM64:
case IMAGE_FILE_MACHINE_AMD64:
case IMAGE_FILE_MACHINE_ARM64:
case IMAGE_FILE_MACHINE_ARM64X:
case IMAGE_FILE_MACHINE_ARM64EC:
case IMAGE_FILE_MACHINE_LOONGARCH64:
case IMAGE_FILE_MACHINE_RISCV64:
m_pointerSize = 8;
Expand Down
9 changes: 1 addition & 8 deletions src/SOS/Strike/clrma/managedanalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <clrma.h> // IDL
#include <clrmaservice.h>
#include <dbgtargetcontext.h>
#include <ntimageex.h>
#include <corhdr.h>
#include <cordebug.h>
#include <xclrdata.h>
Expand All @@ -21,14 +22,6 @@
#include <runtime.h>
#include <vector>

#ifndef IMAGE_FILE_MACHINE_RISCV64
#define IMAGE_FILE_MACHINE_RISCV64 0x5064 // RISCV64
#endif

#ifndef IMAGE_FILE_MACHINE_LOONGARCH64
#define IMAGE_FILE_MACHINE_LOONGARCH64 0x6264 // LOONGARCH64
#endif

enum ClrmaGlobalFlags
{
LoggingEnabled = 0x01, // CLRMA logging enabled
Expand Down
24 changes: 22 additions & 2 deletions src/SOS/Strike/dbgengservices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,30 @@ DbgEngServices::GetDebuggeeType(
}

HRESULT
DbgEngServices::GetExecutingProcessorType(
DbgEngServices::GetProcessorType(
PULONG type)
{
return m_control->GetExecutingProcessorType(type);
ULONG executingType;
HRESULT hr = m_control->GetExecutingProcessorType(&executingType);
if (FAILED(hr))
{
return hr;
}
*type = executingType;
#if defined(SOS_TARGET_AMD64) || defined(SOS_TARGET_ARM64)
if (executingType == IMAGE_FILE_MACHINE_ARM64X || executingType == IMAGE_FILE_MACHINE_ARM64EC)
{
ULONG actualType;
if (SUCCEEDED(m_control->GetActualProcessorType(&actualType)))
{
if (actualType == IMAGE_FILE_MACHINE_AMD64 || actualType == IMAGE_FILE_MACHINE_ARM64)
{
*type = actualType;
}
}
}
#endif // defined(SOS_TARGET_AMD64) || defined(SOS_TARGET_ARM64)
return S_OK;
}

HRESULT
Expand Down
2 changes: 1 addition & 1 deletion src/SOS/Strike/dbgengservices.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class DbgEngServices : public IDebuggerServices, public IRemoteMemoryService, pu
PULONG debugClass,
PULONG qualifier);

HRESULT STDMETHODCALLTYPE GetExecutingProcessorType(
HRESULT STDMETHODCALLTYPE GetProcessorType(
PULONG type);

HRESULT STDMETHODCALLTYPE AddCommand(
Expand Down
9 changes: 8 additions & 1 deletion src/SOS/Strike/disasmX86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,14 @@ void
//

#ifdef _WIN64
ExtOut("%08x`%08x ", (ULONG)(InstrAddr >> 32), (ULONG)InstrAddr);
if (GetHost()->GetHostType() == IHost::HostType::DbgEng)
{
ExtOut("%08x`%08x ", (ULONG)(InstrAddr >> 32), (ULONG)InstrAddr);
}
else
{
ExtOut("%016llx ", InstrAddr);
}
#else
ExtOut("%08x ", (ULONG)InstrAddr);
#endif
Expand Down
41 changes: 39 additions & 2 deletions src/SOS/Strike/exts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,27 @@ GetTargetMachine(ULONG processorType)
targetMachine = ARM64Machine::GetInstance();
}
#endif // SOS_TARGET_ARM64
#if defined(SOS_TARGET_AMD64) || defined(SOS_TARGET_ARM64)
if (processorType == IMAGE_FILE_MACHINE_ARM64X || processorType == IMAGE_FILE_MACHINE_ARM64EC)
{
ULONG actualType;
if (SUCCEEDED(g_ExtControl->GetActualProcessorType(&actualType)))
{
#ifdef SOS_TARGET_AMD64
if (actualType == IMAGE_FILE_MACHINE_AMD64)
{
targetMachine = AMD64Machine::GetInstance();
}
#endif // SOS_TARGET_AMD64
#ifdef SOS_TARGET_ARM64
if (actualType == IMAGE_FILE_MACHINE_ARM64)
{
targetMachine = ARM64Machine::GetInstance();
}
#endif // SOS_TARGET_ARM64
}
}
#endif // defined(SOS_TARGET_AMD64) || defined(SOS_TARGET_ARM64)
#ifdef SOS_TARGET_RISCV64
if (processorType == IMAGE_FILE_MACHINE_RISCV64)
{
Expand Down Expand Up @@ -193,15 +214,31 @@ ArchQuery(void)
case IMAGE_FILE_MACHINE_ARM64:
architecture = "arm64";
break;
case IMAGE_FILE_MACHINE_ARM64EC:
architecture = "arm64ec";
break;
case IMAGE_FILE_MACHINE_ARM64X:
architecture = "arm64x";
break;
case IMAGE_FILE_MACHINE_RISCV64:
architecture = "riscv64";
break;
case IMAGE_FILE_MACHINE_LOONGARCH64:
architecture = "loongarch64";
break;
}
ExtErr("SOS does not support the current target architecture '%s' (0x%04x). A 32 bit target may require a 32 bit debugger or vice versa. In general, try to use the same bitness for the debugger and target process.\n",
architecture, processorType);
const char* message = "";
#if defined(SOS_TARGET_AMD64) || defined(SOS_TARGET_ARM64)
if (processorType == IMAGE_FILE_MACHINE_ARM64X || processorType == IMAGE_FILE_MACHINE_ARM64EC)
{
message = "arm64x/arm64ec targets require a x64 SOS and debugger.";
}
else
#endif
{
message = "A 32 bit target may require a 32 bit debugger or vice versa. In general, try to use the same bitness for the debugger and target process.";
}
ExtErr("SOS does not support the current target architecture '%s' (0x%04x). %s\n", architecture, processorType, message);
return E_FAIL;
}
return S_OK;
Expand Down
10 changes: 1 addition & 9 deletions src/SOS/Strike/exts.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@
// printing CDA values.
#define CDA_TO_UL64(cda) ((ULONG64)(TO_TADDR(cda)))

#ifndef IMAGE_FILE_MACHINE_RISCV64
#define IMAGE_FILE_MACHINE_RISCV64 0x5064 // RISCV64
#endif // !IMAGE_FILE_MACHINE_RISCV64

#ifndef IMAGE_FILE_MACHINE_LOONGARCH64
#define IMAGE_FILE_MACHINE_LOONGARCH64 0x6264 // LOONGARCH64
#endif // !IMAGE_FILE_MACHINE_LOONGARCH64

typedef struct _TADDR_RANGE
{
TADDR start;
Expand Down Expand Up @@ -417,7 +409,7 @@ extern IMachine* g_targetMachine;
inline BOOL IsDbgTargetX86() { return g_targetMachine->GetPlatform() == IMAGE_FILE_MACHINE_I386; }
inline BOOL IsDbgTargetAmd64() { return g_targetMachine->GetPlatform() == IMAGE_FILE_MACHINE_AMD64; }
inline BOOL IsDbgTargetArm() { return g_targetMachine->GetPlatform() == IMAGE_FILE_MACHINE_ARMNT; }
inline BOOL IsDbgTargetArm64() { return g_targetMachine->GetPlatform() == IMAGE_FILE_MACHINE_ARM64; }
inline BOOL IsDbgTargetArm64() { return g_targetMachine->GetPlatform() == IMAGE_FILE_MACHINE_ARM64 || g_targetMachine->GetPlatform() == IMAGE_FILE_MACHINE_ARM64EC || g_targetMachine->GetPlatform() == IMAGE_FILE_MACHINE_ARM64X; }
inline BOOL IsDbgTargetRiscV64(){ return g_targetMachine->GetPlatform() == IMAGE_FILE_MACHINE_RISCV64; }
inline BOOL IsDbgTargetLoongArch64(){ return g_targetMachine->GetPlatform() == IMAGE_FILE_MACHINE_LOONGARCH64; }
inline BOOL IsDbgTargetWin64() { return IsDbgTargetAmd64(); }
Expand Down
Loading

0 comments on commit 9e6e688

Please sign in to comment.