From 7daba7932c9246b15c5b0527f76c11bb5e6a4b91 Mon Sep 17 00:00:00 2001 From: Juan Hoyos Date: Tue, 8 Feb 2022 16:04:57 -0800 Subject: [PATCH] Add IMAGE_FILE_MACHINE_ARM64X and IMAGE_FILE_MACHINE_ARM64EC Issue: https://github.com/dotnet/diagnostics/issues/4430 --- .../TargetFromFromDebuggerServices.cs | 2 ++ .../DbgEng/Interop/Enums/ImageFileMachine.cs | 2 ++ src/SOS/SOS.Hosting/SOSHost.cs | 34 ++++++------------- src/SOS/Strike/clrma/managedanalysis.cpp | 4 ++- src/SOS/Strike/clrma/managedanalysis.h | 9 +---- src/SOS/Strike/disasmX86.cpp | 9 ++++- src/SOS/Strike/exts.cpp | 10 ++++-- src/SOS/Strike/exts.h | 10 +----- src/SOS/Strike/platformspecific.h | 9 +---- src/dbgshim/debugshim.cpp | 19 ++++++----- src/inc/ntimageex.h | 29 ++++++++++++++++ 11 files changed, 75 insertions(+), 62 deletions(-) create mode 100644 src/inc/ntimageex.h diff --git a/src/SOS/SOS.Extensions/TargetFromFromDebuggerServices.cs b/src/SOS/SOS.Extensions/TargetFromFromDebuggerServices.cs index aa8b378258..fa84a684f8 100644 --- a/src/SOS/SOS.Extensions/TargetFromFromDebuggerServices.cs +++ b/src/SOS/SOS.Extensions/TargetFromFromDebuggerServices.cs @@ -55,6 +55,8 @@ 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}"), diff --git a/src/SOS/SOS.Hosting/DbgEng/Interop/Enums/ImageFileMachine.cs b/src/SOS/SOS.Hosting/DbgEng/Interop/Enums/ImageFileMachine.cs index da1a4881e2..a8524a388f 100644 --- a/src/SOS/SOS.Hosting/DbgEng/Interop/Enums/ImageFileMachine.cs +++ b/src/SOS/SOS.Hosting/DbgEng/Interop/Enums/ImageFileMachine.cs @@ -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 diff --git a/src/SOS/SOS.Hosting/SOSHost.cs b/src/SOS/SOS.Hosting/SOSHost.cs index e78234871a..5a8cfb48b4 100644 --- a/src/SOS/SOS.Hosting/SOSHost.cs +++ b/src/SOS/SOS.Hosting/SOSHost.cs @@ -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; } diff --git a/src/SOS/Strike/clrma/managedanalysis.cpp b/src/SOS/Strike/clrma/managedanalysis.cpp index 04df2f2760..6adb3fa73a 100644 --- a/src/SOS/Strike/clrma/managedanalysis.cpp +++ b/src/SOS/Strike/clrma/managedanalysis.cpp @@ -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; diff --git a/src/SOS/Strike/clrma/managedanalysis.h b/src/SOS/Strike/clrma/managedanalysis.h index a78852e9ef..02a80a3304 100644 --- a/src/SOS/Strike/clrma/managedanalysis.h +++ b/src/SOS/Strike/clrma/managedanalysis.h @@ -9,6 +9,7 @@ #include // IDL #include #include +#include #include #include #include @@ -21,14 +22,6 @@ #include #include -#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 diff --git a/src/SOS/Strike/disasmX86.cpp b/src/SOS/Strike/disasmX86.cpp index 11750ab77c..21db6e526a 100644 --- a/src/SOS/Strike/disasmX86.cpp +++ b/src/SOS/Strike/disasmX86.cpp @@ -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 diff --git a/src/SOS/Strike/exts.cpp b/src/SOS/Strike/exts.cpp index 81f304fd47..f314c48503 100644 --- a/src/SOS/Strike/exts.cpp +++ b/src/SOS/Strike/exts.cpp @@ -147,9 +147,13 @@ GetTargetMachine(ULONG processorType) } #endif // SOS_TARGET_ARM #ifdef SOS_TARGET_ARM64 - if (processorType == IMAGE_FILE_MACHINE_ARM64) + switch (processorType) { - targetMachine = ARM64Machine::GetInstance(); + case IMAGE_FILE_MACHINE_ARM64: + case IMAGE_FILE_MACHINE_ARM64X: + case IMAGE_FILE_MACHINE_ARM64EC: + targetMachine = ARM64Machine::GetInstance(); + break; } #endif // SOS_TARGET_ARM64 #ifdef SOS_TARGET_RISCV64 @@ -191,6 +195,8 @@ ArchQuery(void) architecture = "arm32"; break; case IMAGE_FILE_MACHINE_ARM64: + case IMAGE_FILE_MACHINE_ARM64EC: + case IMAGE_FILE_MACHINE_ARM64X: architecture = "arm64"; break; case IMAGE_FILE_MACHINE_RISCV64: diff --git a/src/SOS/Strike/exts.h b/src/SOS/Strike/exts.h index 31a15fd92c..42a671a69f 100644 --- a/src/SOS/Strike/exts.h +++ b/src/SOS/Strike/exts.h @@ -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; @@ -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(); } diff --git a/src/SOS/Strike/platformspecific.h b/src/SOS/Strike/platformspecific.h index 6a66df890d..88ac1a7368 100644 --- a/src/SOS/Strike/platformspecific.h +++ b/src/SOS/Strike/platformspecific.h @@ -14,6 +14,7 @@ // The main debugger code already has target platform definitions for CONTEXT. #include +#include #ifndef FEATURE_PAL @@ -42,14 +43,6 @@ struct DT_UNICODE_STRING #define DT_GDI_HANDLE_BUFFER_SIZE32 34 #define DT_GDI_HANDLE_BUFFER_SIZE64 60 -#ifndef IMAGE_FILE_MACHINE_ARMNT -#define IMAGE_FILE_MACHINE_ARMNT 0x01c4 // ARM Thumb-2 Little-Endian -#endif - -#ifndef IMAGE_FILE_MACHINE_ARM64 -#define IMAGE_FILE_MACHINE_ARM64 0xAA64 // ARM64 Little-Endian -#endif - #ifdef _TARGET_WIN64_ typedef ULONG DT_GDI_HANDLE_BUFFER[DT_GDI_HANDLE_BUFFER_SIZE64]; #else diff --git a/src/dbgshim/debugshim.cpp b/src/dbgshim/debugshim.cpp index 06cbe5f8af..83eb318c85 100644 --- a/src/dbgshim/debugshim.cpp +++ b/src/dbgshim/debugshim.cpp @@ -11,16 +11,9 @@ #include "dbgutil.h" #include #include //has the CLR_ID_V4_DESKTOP guid in it +#include #include "palclr.h" -#ifndef IMAGE_FILE_MACHINE_ARMNT -#define IMAGE_FILE_MACHINE_ARMNT 0x01c4 // ARM Thumb-2 Little-Endian -#endif - -#ifndef IMAGE_FILE_MACHINE_ARM64 -#define IMAGE_FILE_MACHINE_ARM64 0xAA64 // ARM64 Little-Endian -#endif - //***************************************************************************** // CLRDebuggingImpl implementation (ICLRDebugging) //***************************************************************************** @@ -789,10 +782,18 @@ HRESULT CLRDebuggingImpl::FormatLongDacModuleName(_Inout_updates_z_(cchBuffer) W { pTargetArch = W("arm"); } - else if(targetImageFileMachine == IMAGE_FILE_MACHINE_ARM64) + else if(targetImageFileMachine == IMAGE_FILE_MACHINE_ARM64 || targetImageFileMachine == IMAGE_FILE_MACHINE_ARM64X || targetImageFileMachine == IMAGE_FILE_MACHINE_ARM64EC) { pTargetArch = W("arm64"); } + else if (targetImageFileMachine == IMAGE_FILE_MACHINE_RISCV64) + { + pTargetArch = W("riscv64"); + } + else if (targetImageFileMachine == IMAGE_FILE_MACHINE_LOONGARCH64) + { + pTargetArch = W("loongarch64"); + } else { _ASSERTE(!"Unknown target image file machine type"); diff --git a/src/inc/ntimageex.h b/src/inc/ntimageex.h new file mode 100644 index 0000000000..b249b74a4c --- /dev/null +++ b/src/inc/ntimageex.h @@ -0,0 +1,29 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#pragma once + +#ifndef IMAGE_FILE_MACHINE_ARMNT +#define IMAGE_FILE_MACHINE_ARMNT 0x01c4 // ARM Thumb-2 Little-Endian +#endif + +#ifndef IMAGE_FILE_MACHINE_ARM64 +#define IMAGE_FILE_MACHINE_ARM64 0xAA64 // ARM64 Little-Endian +#endif + +#ifndef IMAGE_FILE_MACHINE_ARM64EC +#define IMAGE_FILE_MACHINE_ARM64EC 0xA641 +#endif + +#ifndef IMAGE_FILE_MACHINE_ARM64X +#define IMAGE_FILE_MACHINE_ARM64X 0xA64E +#endif + +#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 +