Fix SIGSEGV on Ctrl+C right after `r` command in CLI.
authorMikhail Kurinnoi <m.kurinnoi@samsung.com>
Mon, 23 Sep 2024 15:52:20 +0000 (18:52 +0300)
committerGleb Balykov/Advanced System SW Lab /SRR/Staff Engineer/Samsung Electronics <g.balykov@samsung.com>
Thu, 26 Sep 2024 14:23:06 +0000 (17:23 +0300)
src/debugger/callbacksqueue.cpp

index d1f178fd488c216d91306b2e052aad5ed5099ae4..fb74d870562da94e6c014a733125556790182ffe 100644 (file)
@@ -415,19 +415,31 @@ HRESULT CallbacksQueue::Pause(ICorDebugProcess *pProcess, ThreadId lastStoppedTh
     }
     else if (eventFormat == EventFormat::CLI)
     {
+        ThreadId threadId;
+        if (threads.empty())
+        {
+            DWORD pid = 0;
+            IfFailRet(pProcess->GetID(&pid));
+            threadId = ThreadId(pid);
+        }
+        else
+        {
+            threadId = threads[0].id;
+        }
+
         // CLI protocol provide ThreadId::AllThreads as lastStoppedThread, stop at main thread with real top frame in event.
-        m_debugger.SetLastStoppedThreadId(threads[0].id);
+        m_debugger.SetLastStoppedThreadId(threadId);
 
         int totalFrames = 0;
+        StoppedEvent event(StopPause, threadId);
         std::vector<StackFrame> stackFrames;
-        if (SUCCEEDED(m_debugger.GetStackTrace(threads[0].id, FrameLevel(0), 1, stackFrames, totalFrames)))
+        if (SUCCEEDED(m_debugger.GetStackTrace(threadId, FrameLevel(0), 1, stackFrames, totalFrames)) && !stackFrames.empty())
         {
-            StoppedEvent event(StopPause, threads[0].id);
             event.frame = stackFrames[0];
-            m_debugger.pProtocol->EmitStoppedEvent(event);
-            m_debugger.m_ioredirect.async_cancel();
-            return S_OK;
         }
+        m_debugger.pProtocol->EmitStoppedEvent(event);
+        m_debugger.m_ioredirect.async_cancel();
+        return S_OK;
     }
     else
     {