From 275abfda0a2ba0bf70ca6d16a1fc13b9453c2b49 Mon Sep 17 00:00:00 2001 From: Jonghyun Park Date: Tue, 29 Aug 2017 10:11:24 +0900 Subject: [PATCH 15/29] Cherry-pick #13586 --- src/ToolBox/SOS/Strike/strike.cpp | 31 ++++++++++++++++++------------- src/ToolBox/SOS/Strike/util.h | 7 +++++-- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/ToolBox/SOS/Strike/strike.cpp b/src/ToolBox/SOS/Strike/strike.cpp index 7e01635..2e20b28 100644 --- a/src/ToolBox/SOS/Strike/strike.cpp +++ b/src/ToolBox/SOS/Strike/strike.cpp @@ -320,15 +320,20 @@ DECLARE_API(IP2MD) // (MAX_STACK_FRAMES is also used by x86 to prevent infinite loops in _EFN_StackTrace) #define MAX_STACK_FRAMES 1000 -#ifdef _TARGET_WIN64_ +#if defined(_TARGET_WIN64_) +#define DEBUG_STACK_CONTEXT AMD64_CONTEXT +#elif defined(_TARGET_ARM_) // _TARGET_WIN64_ +#define DEBUG_STACK_CONTEXT ARM_CONTEXT +#endif // _TARGET_ARM_ +#ifdef DEBUG_STACK_CONTEXT // I use a global set of frames for stack walking on win64 because the debugger's // GetStackTrace function doesn't provide a way to find out the total size of a stackwalk, // and I'd like to have a reasonably big maximum without overflowing the stack by declaring // the buffer locally and I also want to get a managed trace in a low memory environment // (so no dynamic allocation if possible). DEBUG_STACK_FRAME g_Frames[MAX_STACK_FRAMES]; -AMD64_CONTEXT g_X64FrameContexts[MAX_STACK_FRAMES]; +DEBUG_STACK_CONTEXT g_FrameContexts[MAX_STACK_FRAMES]; static HRESULT GetContextStackTrace(PULONG pnumFrames) @@ -339,7 +344,7 @@ GetContextStackTrace(PULONG pnumFrames) // Do we have advanced capability? if ((hr = g_ExtControl->QueryInterface(__uuidof(IDebugControl4), (void **)&debugControl4)) == S_OK) { - // GetContextStackTrace fills g_X64FrameContexts as an array of + // GetContextStackTrace fills g_FrameContexts as an array of // contexts packed as target architecture contexts. We cannot // safely cast this as an array of CROSS_PLATFORM_CONTEXT, since // sizeof(CROSS_PLATFORM_CONTEXT) != sizeof(TGT_CONTEXT) @@ -348,7 +353,7 @@ GetContextStackTrace(PULONG pnumFrames) 0, g_Frames, MAX_STACK_FRAMES, - g_X64FrameContexts, + g_FrameContexts, MAX_STACK_FRAMES*g_targetMachine->GetContextSize(), g_targetMachine->GetContextSize(), pnumFrames); @@ -358,7 +363,7 @@ GetContextStackTrace(PULONG pnumFrames) return hr; } -#endif // _TARGET_WIN64_ +#endif // DEBUG_STACK_CONTEXT /**********************************************************************\ * Routine Description: * @@ -12040,7 +12045,7 @@ public: return; } -#ifdef _TARGET_WIN64_ +#ifdef DEBUG_STACK_CONTEXT PDEBUG_STACK_FRAME currentNativeFrame = NULL; ULONG numNativeFrames = 0; if (bFull) @@ -12053,7 +12058,7 @@ public: } currentNativeFrame = &g_Frames[0]; } -#endif // _TARGET_WIN64_ +#endif // DEBUG_STACK_CONTEXT unsigned int refCount = 0, errCount = 0; ArrayHolder pRefs = NULL; @@ -12079,7 +12084,7 @@ public: if (SUCCEEDED(frameDataResult) && FrameData.frameAddr) sp = FrameData.frameAddr; -#ifdef _TARGET_WIN64_ +#ifdef DEBUG_STACK_CONTEXT while ((numNativeFrames > 0) && (currentNativeFrame->StackOffset <= sp)) { if (currentNativeFrame->StackOffset != sp) @@ -12089,7 +12094,7 @@ public: currentNativeFrame++; numNativeFrames--; } -#endif // _TARGET_WIN64_ +#endif // DEBUG_STACK_CONTEXT // Print the stack pointer. out.WriteColumn(0, sp); @@ -12138,14 +12143,14 @@ public: } while (pStackWalk->Next() == S_OK); -#ifdef _TARGET_WIN64_ +#ifdef DEBUG_STACK_CONTEXT while (numNativeFrames > 0) { PrintNativeStackFrame(out, currentNativeFrame, bSuppressLines); currentNativeFrame++; numNativeFrames--; } -#endif // _TARGET_WIN64_ +#endif // DEBUG_STACK_CONTEXT } static HRESULT PrintManagedFrameContext(IXCLRDataStackWalk *pStackWalk) @@ -13321,7 +13326,7 @@ HRESULT CALLBACK ImplementEFNStackTrace( { // below we cast the i-th AMD64_CONTEXT to CROSS_PLATFORM_CONTEXT AppendContext (pTransitionContexts, *puiTransitionContextCount, - &transitionContextCount, uiSizeOfContext, (CROSS_PLATFORM_CONTEXT*)(&(g_X64FrameContexts[i]))); + &transitionContextCount, uiSizeOfContext, (CROSS_PLATFORM_CONTEXT*)(&(g_FrameContexts[i]))); } else { @@ -13354,7 +13359,7 @@ HRESULT CALLBACK ImplementEFNStackTrace( if (puiTransitionContextCount) { AppendContext (pTransitionContexts, *puiTransitionContextCount, - &transitionContextCount, uiSizeOfContext, (CROSS_PLATFORM_CONTEXT*)(&(g_X64FrameContexts[i]))); + &transitionContextCount, uiSizeOfContext, (CROSS_PLATFORM_CONTEXT*)(&(g_FrameContexts[i]))); } else { diff --git a/src/ToolBox/SOS/Strike/util.h b/src/ToolBox/SOS/Strike/util.h index 6d0e796..bbf97b9 100644 --- a/src/ToolBox/SOS/Strike/util.h +++ b/src/ToolBox/SOS/Strike/util.h @@ -2519,8 +2519,8 @@ typedef struct{ /// ARM Context #define ARM_MAX_BREAKPOINTS_CONST 8 -#define ARM_MAX_WATCHPOINTS_CONST 4 -typedef struct { +#define ARM_MAX_WATCHPOINTS_CONST 1 +typedef DECLSPEC_ALIGN(8) struct { DWORD ContextFlags; @@ -2544,6 +2544,7 @@ typedef struct { DWORD Cpsr; DWORD Fpscr; + DWORD Padding; union { M128A_XPLAT Q[16]; ULONGLONG D[32]; @@ -2555,6 +2556,8 @@ typedef struct { DWORD Wvr[ARM_MAX_WATCHPOINTS_CONST]; DWORD Wcr[ARM_MAX_WATCHPOINTS_CONST]; + DWORD Padding2[2]; + } ARM_CONTEXT; // On ARM this mask is or'ed with the address of code to get an instruction pointer -- 2.7.4