From 8c808737cacc0a361186022a25915701b64c7ab4 Mon Sep 17 00:00:00 2001 From: SaeHie Park Date: Fri, 22 Apr 2016 15:36:28 +0900 Subject: [PATCH] ARM, SOS: Fix fail to load libsos.so while debugging with lldb Related issue: #4428 With minor fix for ARM compile in SOS ARM: Fix ARM-Linux in SOS with lldb Fix ARM architecture type in SOS so that it works for ARM-Linux. Before this patch, lldb stops with architecture not supported. SOS ARM-Linux works with LLDB-3.8 and higher. Actual SOS commands for ARM may need testing and fixing. --- src/ToolBox/PdbTypeMatch/PdbTypeMatch.cpp | 1 + src/ToolBox/SOS/Strike/CMakeLists.txt | 1 + src/ToolBox/SOS/Strike/datatarget.cpp | 7 +++++++ src/ToolBox/SOS/Strike/disasm.h | 7 ++++--- src/ToolBox/SOS/Strike/disasmARM.cpp | 16 +++++++++++----- src/ToolBox/SOS/Strike/util.cpp | 2 ++ src/ToolBox/SOS/lldbplugin/inc/lldbservices.h | 1 + src/ToolBox/SOS/lldbplugin/services.cpp | 4 ++++ src/debug/daccess/datatargetadapter.cpp | 6 +++++- 9 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/ToolBox/PdbTypeMatch/PdbTypeMatch.cpp b/src/ToolBox/PdbTypeMatch/PdbTypeMatch.cpp index 08118452e7e4..052e9e0d1d12 100644 --- a/src/ToolBox/PdbTypeMatch/PdbTypeMatch.cpp +++ b/src/ToolBox/PdbTypeMatch/PdbTypeMatch.cpp @@ -458,6 +458,7 @@ bool LoadDataFromPdb( case IMAGE_FILE_MACHINE_I386 : g_dwMachineType = CV_CFL_80386; break; case IMAGE_FILE_MACHINE_IA64 : g_dwMachineType = CV_CFL_IA64; break; case IMAGE_FILE_MACHINE_AMD64 : g_dwMachineType = CV_CFL_AMD64; break; + case IMAGE_FILE_MACHINE_ARMNT : g_dwMachineType = CV_CFL_ARM7; break; } } diff --git a/src/ToolBox/SOS/Strike/CMakeLists.txt b/src/ToolBox/SOS/Strike/CMakeLists.txt index 124fe979b3e5..11c75843d971 100644 --- a/src/ToolBox/SOS/Strike/CMakeLists.txt +++ b/src/ToolBox/SOS/Strike/CMakeLists.txt @@ -28,6 +28,7 @@ elseif(CLR_CMAKE_PLATFORM_ARCH_I386) elseif(CLR_CMAKE_PLATFORM_ARCH_ARM) add_definitions(-DSOS_TARGET_ARM=1) add_definitions(-D_TARGET_WIN32_=1) + add_definitions(-D_TARGET_ARM_=1) add_definitions(-DDBG_TARGET_32BIT) elseif(CLR_CMAKE_PLATFORM_ARCH_ARM64) add_definitions(-DSOS_TARGET_ARM64=1) diff --git a/src/ToolBox/SOS/Strike/datatarget.cpp b/src/ToolBox/SOS/Strike/datatarget.cpp index 869ae674ab64..0e981dd53788 100644 --- a/src/ToolBox/SOS/Strike/datatarget.cpp +++ b/src/ToolBox/SOS/Strike/datatarget.cpp @@ -81,7 +81,14 @@ HRESULT STDMETHODCALLTYPE DataTarget::GetPointerSize( /* [out] */ ULONG32 *size) { +#if defined(SOS_TARGET_AMD64) || defined(SOS_TARGET_ARM64) *size = 8; +#elif defined(SOS_TARGET_ARM) + *size = 4; +#elif + #error Unsupported architecture +#endif + return S_OK; } diff --git a/src/ToolBox/SOS/Strike/disasm.h b/src/ToolBox/SOS/Strike/disasm.h index d3c13fee3ffa..6972c39ccbc7 100644 --- a/src/ToolBox/SOS/Strike/disasm.h +++ b/src/ToolBox/SOS/Strike/disasm.h @@ -108,9 +108,9 @@ eTargetType GetFinalTarget(DWORD_PTR callee, DWORD_PTR* finalMDorIP); //----------------------------------------------------------------------------------------- #ifndef THUMB_CODE -#define THUMB_CODE 1; +#define THUMB_CODE 1 #endif -#define STACKWALK_CONTROLPC_ADJUST_OFFSET 2; +#define STACKWALK_CONTROLPC_ADJUST_OFFSET 2 #ifdef SOS_TARGET_X86 @@ -186,7 +186,7 @@ class ARMMachine : public IMachine typedef ARM_CONTEXT TGT_CTXT; static IMachine* GetInstance() - { static ARMMachine s_ARMMachineInstance; return &s_ARMMachineInstance; } + { return &s_ARMMachineInstance; } ULONG GetPlatform() const { return IMAGE_FILE_MACHINE_ARMNT; } ULONG GetContextSize() const { return sizeof(ARM_CONTEXT); } @@ -238,6 +238,7 @@ class ARMMachine : public IMachine static LPCSTR s_DSOHeading; static LPCSTR s_GCRegs[14]; static LPCSTR s_SPName; + static ARMMachine s_ARMMachineInstance; }; // class ARMMachine #endif // SOS_TARGET_ARM diff --git a/src/ToolBox/SOS/Strike/disasmARM.cpp b/src/ToolBox/SOS/Strike/disasmARM.cpp index acdd633d4ab2..80dce7189042 100644 --- a/src/ToolBox/SOS/Strike/disasmARM.cpp +++ b/src/ToolBox/SOS/Strike/disasmARM.cpp @@ -48,6 +48,8 @@ namespace ARMGCDump #error This file should be used to support SOS targeting ARM debuggees #endif +#ifdef SOS_TARGET_ARM +ARMMachine ARMMachine::s_ARMMachineInstance; // Decodes the target label of the immediate form of bl and blx instructions. The PC given is that of the // start of the instruction. @@ -334,6 +336,8 @@ static void HandleValue(TADDR value) } } +#endif // !FEATURE_PAL + /**********************************************************************\ * Routine Description: * * * @@ -351,6 +355,7 @@ void ARMMachine::Unassembly ( BOOL bSuppressLines, BOOL bDisplayOffsets) const { +#ifndef FEATURE_PAL ULONG_PTR PC = PCBegin; char line[1024]; char *ptr; @@ -524,11 +529,12 @@ void ARMMachine::Unassembly ( ExtOut ("\n"); } +#endif // !FEATURE_PAL } +#if 0 // @ARMTODO: Figure out how to extract this information under CoreARM static void ExpFuncStateInit (TADDR *PCRetAddr) { -#if 0 // @ARMTODO: Figure out how to extract this information under CoreARM ULONG64 offset; if (FAILED(g_ExtSymbols->GetOffsetByName("ntdll!KiUserExceptionDispatcher", &offset))) { return; @@ -541,10 +547,9 @@ static void ExpFuncStateInit (TADDR *PCRetAddr) PCRetAddr[i++] = (TADDR)offset; } } -#endif // 0 } +#endif // 0 -#endif // !FEATURE_PAL // @ARMTODO: Figure out how to extract this information under CoreARM BOOL ARMMachine::GetExceptionContext (TADDR stack, TADDR PC, TADDR *cxrAddr, CROSS_PLATFORM_CONTEXT * cxr, @@ -598,13 +603,13 @@ BOOL ARMMachine::GetExceptionContext (TADDR stack, TADDR PC, TADDR *cxrAddr, CRO #endif // 0 } -#ifndef FEATURE_PAL /// /// Dump ARM GCInfo table /// void ARMMachine::DumpGCInfo(BYTE* pTable, unsigned methodSize, printfFtn gcPrintf, bool encBytes, bool bPrintHeader) const { +#ifndef FEATURE_PAL if (bPrintHeader) { ExtOut("Pointer table:\n"); @@ -614,6 +619,7 @@ void ARMMachine::DumpGCInfo(BYTE* pTable, unsigned methodSize, printfFtn gcPrint gcDump.gcPrintf = gcPrintf; gcDump.DumpGCTable(pTable, methodSize, 0); +#endif // !FEATURE_PAL } -#endif // !FEATURE_PAL +#endif // SOS_TARGET_ARM diff --git a/src/ToolBox/SOS/Strike/util.cpp b/src/ToolBox/SOS/Strike/util.cpp index 6f115b0c0a61..b77c1d26ad6d 100644 --- a/src/ToolBox/SOS/Strike/util.cpp +++ b/src/ToolBox/SOS/Strike/util.cpp @@ -4548,6 +4548,8 @@ class SOSDataTarget : public ICorDebugMutableDataTarget *pPlatform = CORDB_PLATFORM_POSIX_X86; else if(platformKind == IMAGE_FILE_MACHINE_AMD64) *pPlatform = CORDB_PLATFORM_POSIX_AMD64; + else if(platformKind == IMAGE_FILE_MACHINE_ARMNT) + *pPlatform = CORDB_PLATFORM_POSIX_ARM; else return E_FAIL; #else diff --git a/src/ToolBox/SOS/lldbplugin/inc/lldbservices.h b/src/ToolBox/SOS/lldbplugin/inc/lldbservices.h index 925b6c432788..6c713141f3e3 100644 --- a/src/ToolBox/SOS/lldbplugin/inc/lldbservices.h +++ b/src/ToolBox/SOS/lldbplugin/inc/lldbservices.h @@ -68,6 +68,7 @@ extern "C" { #define DEBUG_CLASS_IMAGE_FILE 3 #define IMAGE_FILE_MACHINE_I386 0x014c // Intel 386. +#define IMAGE_FILE_MACHINE_ARMNT 0x01c4 // ARM Thumb-2 Little-Endian #define IMAGE_FILE_MACHINE_AMD64 0x8664 // AMD64 (K8) // Execution status codes used for waiting, diff --git a/src/ToolBox/SOS/lldbplugin/services.cpp b/src/ToolBox/SOS/lldbplugin/services.cpp index 21d1a2c13c95..f6b42139c4ca 100644 --- a/src/ToolBox/SOS/lldbplugin/services.cpp +++ b/src/ToolBox/SOS/lldbplugin/services.cpp @@ -401,7 +401,11 @@ HRESULT LLDBServices::GetExecutingProcessorType( PULONG type) { +#ifdef DBG_TARGET_AMD64 *type = IMAGE_FILE_MACHINE_AMD64; +#elif DBG_TARGET_ARM + *type = IMAGE_FILE_MACHINE_ARMNT; +#endif return S_OK; } diff --git a/src/debug/daccess/datatargetadapter.cpp b/src/debug/daccess/datatargetadapter.cpp index 2378951dd61a..f2a1cc652a53 100644 --- a/src/debug/daccess/datatargetadapter.cpp +++ b/src/debug/daccess/datatargetadapter.cpp @@ -122,8 +122,12 @@ DataTargetAdapter::GetPlatform( platform = CORDB_PLATFORM_POSIX_AMD64; break; - case IMAGE_FILE_MACHINE_IA64: case IMAGE_FILE_MACHINE_ARMNT: + ulExpectedPointerSize = 4; + platform = CORDB_PLATFORM_POSIX_ARM; + break; + + case IMAGE_FILE_MACHINE_IA64: case IMAGE_FILE_MACHINE_ARM64: _ASSERTE_MSG(false, "Not supported platform."); return E_NOTIMPL;