Fix exception.StackTrace race condition. Issue dotnet/coreclr#12467. (dotnet/coreclr...
authorMike McLaughlin <mikem@microsoft.com>
Fri, 28 Oct 2016 02:31:45 +0000 (19:31 -0700)
committerJan Kotas <jkotas@microsoft.com>
Fri, 28 Oct 2016 02:31:45 +0000 (19:31 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/3e2dde0f36948e148cb645a75794ea07efc4ba80

src/coreclr/src/debug/ee/functioninfo.cpp

index 83c185c..aa75b30 100644 (file)
@@ -890,7 +890,6 @@ DebuggerJitInfo::~DebuggerJitInfo()
     LOG((LF_CORDB,LL_EVERYTHING, "DJI::~DJI : deleted at 0x%p\n", this));
 }
 
-
 // Lazy initialize the Debugger-Jit-Info
 void DebuggerJitInfo::LazyInitBounds()
 {
@@ -903,24 +902,22 @@ void DebuggerJitInfo::LazyInitBounds()
         PRECONDITION(!g_pDebugger->HasDebuggerDataLock());
     } CONTRACTL_END;
 
-    //@todo: this method is not synchronized. Mei-chin's recent work should cover this one
+    LOG((LF_CORDB, LL_EVERYTHING, "DJI::LazyInitBounds: this=0x%x m_fAttemptInit %s\n", this, m_fAttemptInit == true ? "true": "false"));
+
     // Only attempt lazy-init once
-    // new LOG message
-    LOG((LF_CORDB,LL_EVERYTHING, "DJI::LazyInitBounds: this=0x%x m_fAttemptInit %s\n", this, m_fAttemptInit == true? "true": "false"));
     if (m_fAttemptInit)
     {
         return;
     }
-    m_fAttemptInit = true;
 
     EX_TRY
     {
-        LOG((LF_CORDB,LL_EVERYTHING, "DJI::LazyInitBounds: this=0x%x Initing\n", this));
+        LOG((LF_CORDB, LL_EVERYTHING, "DJI::LazyInitBounds: this=0x%x Initing\n", this));
+
         // Should have already been jitted
         _ASSERTE(this->m_jitComplete);
 
         MethodDesc * mdesc = this->m_fd;
-
         DebugInfoRequest request;
 
         _ASSERTE(this->m_addrOfCode != NULL); // must have address to disambguate the Enc cases.
@@ -928,7 +925,6 @@ void DebuggerJitInfo::LazyInitBounds()
         // Note the MethodDesc may not yet have the jitted info, so we'll also use the starting address we got in the jit complete callback.
         request.InitFromStartingAddr(mdesc, (PCODE)this->m_addrOfCode);
 
-
         // Bounds info.
         ULONG32 cMap = 0;
         ICorDebugInfo::OffsetMapping *pMap = NULL;
@@ -940,12 +936,26 @@ void DebuggerJitInfo::LazyInitBounds()
             InteropSafeNew, NULL, // allocator
             &cMap, &pMap,
             &cVars, &pVars);
+
         LOG((LF_CORDB,LL_EVERYTHING, "DJI::LazyInitBounds: this=0x%x GetBoundariesAndVars success=0x%x\n", this, fSuccess));
-        if (fSuccess)
+
+        Debugger::DebuggerDataLockHolder debuggerDataLockHolder(g_pDebugger);
+
+        if (!m_fAttemptInit)
         {
-            this->SetBoundaries(cMap, pMap);
-            this->SetVars(cVars, pVars);
+            if (fSuccess)
+            {
+                this->SetBoundaries(cMap, pMap);
+                this->SetVars(cVars, pVars);
+            }
+            m_fAttemptInit = true;
         }
+        else
+        {
+            DeleteInteropSafe(pMap);
+            DeleteInteropSafe(pVars);
+        }
+        // DebuggerDataLockHolder out of scope - release implied
     }
     EX_CATCH
     {
@@ -963,10 +973,7 @@ void DebuggerJitInfo::SetVars(ULONG32 cVars, ICorDebugInfo::NativeVarInfo *pVars
 {
     LIMITED_METHOD_CONTRACT;
 
-    if (m_varNativeInfo)
-    {
-        return;
-    }
+    _ASSERTE(m_varNativeInfo == NULL);
 
     m_varNativeInfo = pVars;
     m_varNativeInfoCount = cVars;
@@ -1020,15 +1027,11 @@ void DebuggerJitInfo::SetBoundaries(ULONG32 cMap, ICorDebugInfo::OffsetMapping *
 
     LOG((LF_CORDB,LL_EVERYTHING, "DJI::SetBoundaries: this=0x%x cMap=0x%x pMap=0x%x\n", this, cMap, pMap));
     _ASSERTE((cMap == 0) == (pMap == NULL));
+    _ASSERTE(m_sequenceMap == NULL);
 
     if (cMap == 0)
         return;
 
-    if (m_sequenceMap)
-    {
-        return;
-    }
-
     ULONG ilLast = 0;
 #ifdef _DEBUG
     // We assume that the map is sorted by native offset