From 614876ade8dc6cb966932036c9a5adeba1769e0d Mon Sep 17 00:00:00 2001 From: John Salem Date: Tue, 19 Feb 2019 15:20:06 -0800 Subject: [PATCH] Add array of managed assembly objects to StackFrameHelper class: * allows for more robust caching of source info (in CoreFX) in light of unloadability * allows dynamic and regular assemblies to use the same key for source info caching (in CoreFX) #20179 --- .../src/System/Diagnostics/StackFrameHelper.cs | 8 +++++--- src/vm/debugdebugger.cpp | 10 ++++++++++ src/vm/debugdebugger.h | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/System.Private.CoreLib/src/System/Diagnostics/StackFrameHelper.cs b/src/System.Private.CoreLib/src/System/Diagnostics/StackFrameHelper.cs index e8d7ef5..c86a90f 100644 --- a/src/System.Private.CoreLib/src/System/Diagnostics/StackFrameHelper.cs +++ b/src/System.Private.CoreLib/src/System/Diagnostics/StackFrameHelper.cs @@ -34,6 +34,7 @@ namespace System.Diagnostics private IntPtr[] rgMethodHandle; private string[] rgAssemblyPath; + private Assembly[] rgAssembly; private IntPtr[] rgLoadedPeAddress; private int[] rgiLoadedPeSize; private IntPtr[] rgInMemoryPdbAddress; @@ -47,8 +48,8 @@ namespace System.Diagnostics private int iFrameCount; #pragma warning restore 414 - private delegate void GetSourceLineInfoDelegate(string assemblyPath, IntPtr loadedPeAddress, int loadedPeSize, - IntPtr inMemoryPdbAddress, int inMemoryPdbSize, int methodToken, int ilOffset, + private delegate void GetSourceLineInfoDelegate(Assembly assembly, string assemblyPath, IntPtr loadedPeAddress, + int loadedPeSize, IntPtr inMemoryPdbAddress, int inMemoryPdbSize, int methodToken, int ilOffset, out string sourceFile, out int sourceLine, out int sourceColumn); private static GetSourceLineInfoDelegate s_getSourceLineInfo = null; @@ -64,6 +65,7 @@ namespace System.Diagnostics rgiOffset = null; rgiILOffset = null; rgAssemblyPath = null; + rgAssembly = null; rgLoadedPeAddress = null; rgiLoadedPeSize = null; rgInMemoryPdbAddress = null; @@ -138,7 +140,7 @@ namespace System.Diagnostics // ENC or the source/line info was already retrieved, the method token is 0. if (rgiMethodToken[index] != 0) { - s_getSourceLineInfo(rgAssemblyPath[index], rgLoadedPeAddress[index], rgiLoadedPeSize[index], + s_getSourceLineInfo(rgAssembly[index], rgAssemblyPath[index], rgLoadedPeAddress[index], rgiLoadedPeSize[index], rgInMemoryPdbAddress[index], rgiInMemoryPdbSize[index], rgiMethodToken[index], rgiILOffset[index], out rgFilename[index], out rgiLineNumber[index], out rgiColumnNumber[index]); } diff --git a/src/vm/debugdebugger.cpp b/src/vm/debugdebugger.cpp index 3402a8b..a839340 100644 --- a/src/vm/debugdebugger.cpp +++ b/src/vm/debugdebugger.cpp @@ -402,6 +402,12 @@ FCIMPL4(void, DebugStackTrace::GetStackFramesInternal, SetObjectReference( (OBJECTREF *)&(pStackFrameHelper->rgAssemblyPath), (OBJECTREF)assemblyPathArray, pStackFrameHelper->GetAppDomain()); + // Allocate memory for the array of assemblies + MethodTable * pAssemblyMT = MscorlibBinder::GetClass(CLASS__ASSEMBLY); + PTRARRAYREF assemblyArray = (PTRARRAYREF) AllocateObjectArray(data.cElements, pAssemblyMT); + SetObjectReference( (OBJECTREF *)&(pStackFrameHelper->rgAssembly), (OBJECTREF)assemblyArray, + pStackFrameHelper->GetAppDomain()); + // Allocate memory for the LoadedPeAddress BASEARRAYREF loadedPeAddressArray = (BASEARRAYREF) AllocatePrimitiveArray(ELEMENT_TYPE_I, data.cElements); SetObjectReference( (OBJECTREF *)&(pStackFrameHelper->rgLoadedPeAddress), (OBJECTREF)loadedPeAddressArray, @@ -512,6 +518,10 @@ FCIMPL4(void, DebugStackTrace::GetStackFramesInternal, I4 *pILI4 = (I4 *)((I4ARRAYREF)pStackFrameHelper->rgiILOffset)->GetDirectPointerToNonObjectElements(); pILI4[iNumValidFrames] = data.pElements[i].dwILOffset; + // Assembly + OBJECTREF *pAssemblyArray = pStackFrameHelper->rgAssembly->GetDataPtr(); + pAssemblyArray[iNumValidFrames] = pFunc->GetAssembly()->GetDomainAssembly()->GetExposedAssemblyObject(); + if (data.fDoWeHaveAnyFramesFromForeignStackTrace) { // Set the BOOL indicating if the frame represents the last frame from a foreign exception stack trace. diff --git a/src/vm/debugdebugger.h b/src/vm/debugdebugger.h index 35758e1..e608ebd 100644 --- a/src/vm/debugdebugger.h +++ b/src/vm/debugdebugger.h @@ -48,6 +48,7 @@ public: PTRARRAYREF dynamicMethods; BASEARRAYREF rgMethodHandle; PTRARRAYREF rgAssemblyPath; + PTRARRAYREF rgAssembly; BASEARRAYREF rgLoadedPeAddress; I4ARRAYREF rgiLoadedPeSize; BASEARRAYREF rgInMemoryPdbAddress; -- 2.7.4