Fix UpdateCallStackPop().
authorMikhail Kurinnoi <m.kurinnoi@samsung.com>
Wed, 15 Jul 2020 16:07:29 +0000 (19:07 +0300)
committerAlexander Soldatov/AI Compiler Lab /SRR/Staff Engineer/Samsung Electronics <soldatov.a@samsung.com>
Fri, 17 Jul 2020 13:56:15 +0000 (16:56 +0300)
Fix SIGABRT during stack unwind if CodeGen::genProfilingEnterCallback and CodeGen::genProfilingLeaveCallback no implemented in CoreCLR.

src/trace/executiontrace.cpp

index 9cef883beb6b5691c272064596f121584d20a457..8cd836b9f04a92aa62b520c86c21b7ec2116bb48 100644 (file)
@@ -375,12 +375,20 @@ void ExecutionTrace::UpdateCallStackPop() noexcept
 {
     SamplingSharedState state = {};
     state.stackWillBeChanged = true;
+    bool needPrintWarning = false;
     m_profiler.GetCommonTrace().InterruptSampling(
         state,
         {},
-        [](ThreadInfo &thrInfo, SamplingSharedState &state)
+        [&needPrintWarning](ThreadInfo &thrInfo, SamplingSharedState &state)
         {
-            thrInfo.eventChannel.Pop();
+            // AArch64 CoreCLR versions till 5.0 don't have CodeGen::genProfilingEnterCallback and CodeGen::genProfilingLeaveCallback
+            // implemented, CoreCLR will not call EnterNaked3(), LeaveNaked3() and TailcallNaked3(). As result, we don't have full callstack.
+            // Note, ICorProfilerInfo3::SetEnterLeaveFunctionHooks3() don't provide any errors connected to issue above.
+            if (thrInfo.eventChannel.GetStackSize() > 0)
+                thrInfo.eventChannel.Pop();
+            else
+                needPrintWarning = true;
+
             if (thrInfo.maxRestoreIpIdx > 0)
             {
                 --thrInfo.maxRestoreIpIdx;
@@ -389,6 +397,8 @@ void ExecutionTrace::UpdateCallStackPop() noexcept
             state.stackWillBeChanged = false;
         }
     );
+    if (needPrintWarning)
+        LOG().Warn() << "More callstack pop requests, than data was pushed.";
 }
 
 UINT_PTR ExecutionTrace::FunctionIDMap(