Add array of managed assembly objects to StackFrameHelper class:
authorJohn Salem <josalem@microsoft.com>
Tue, 19 Feb 2019 23:20:06 +0000 (15:20 -0800)
committerJohn Salem <josalem@microsoft.com>
Wed, 20 Feb 2019 00:28:37 +0000 (16:28 -0800)
 * 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.Private.CoreLib/src/System/Diagnostics/StackFrameHelper.cs
src/vm/debugdebugger.cpp
src/vm/debugdebugger.h

index e8d7ef5..c86a90f 100644 (file)
@@ -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]);
                     }
index 3402a8b..a839340 100644 (file)
@@ -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.
index 35758e1..e608ebd 100644 (file)
@@ -48,6 +48,7 @@ public:
     PTRARRAYREF dynamicMethods;
     BASEARRAYREF rgMethodHandle;
     PTRARRAYREF rgAssemblyPath;
+    PTRARRAYREF rgAssembly;
     BASEARRAYREF rgLoadedPeAddress;
     I4ARRAYREF rgiLoadedPeSize;
     BASEARRAYREF rgInMemoryPdbAddress;