Remove main thread detection at attach.
authorMikhail Kurinnoi <m.kurinnoi@samsung.com>
Thu, 23 Nov 2023 09:50:06 +0000 (12:50 +0300)
committerGleb Balykov/Advanced System SW Lab /SRR/Staff Engineer/Samsung Electronics <g.balykov@samsung.com>
Mon, 11 Dec 2023 10:10:50 +0000 (13:10 +0300)
src/debugger/managedcallback.cpp
src/debugger/threads.cpp
src/debugger/threads.h

index 1f015338db16f3543f2f4dbd8f41a450872da360..c48d3dc6009ae0e203de3b1ab094c355afeba255 100644 (file)
@@ -259,7 +259,7 @@ HRESULT STDMETHODCALLTYPE ManagedCallback::CreateThread(ICorDebugAppDomain *pApp
         LOGW("Thread was created by user code during evaluation with implicit user code execution.");
 
     ThreadId threadId(getThreadId(pThread));
-    m_debugger.m_sharedThreads->Add(threadId);
+    m_debugger.m_sharedThreads->Add(threadId, m_debugger.m_startMethod == StartAttach);
 
     m_debugger.pProtocol->EmitThreadEvent(ThreadEvent(ManagedThreadStarted, threadId, m_debugger.m_interopDebugging));
     return m_sharedCallbacksQueue->ContinueAppDomain(pAppDomain);
index 20b094bad6bc3be9b54efae9a82a2b0fa33cf9e4..2d2e8ed9632b53a9d434d9023df8a48e3bac46c9 100644 (file)
@@ -20,13 +20,13 @@ ThreadId getThreadId(ICorDebugThread *pThread)
     return SUCCEEDED(res) && threadId != 0 ? ThreadId{threadId} : ThreadId{};
 }
 
-void Threads::Add(const ThreadId &threadId)
+void Threads::Add(const ThreadId &threadId, bool processAttached)
 {
     std::unique_lock<Utility::RWLock::Writer> write_lock(m_userThreadsRWLock.writer);
 
     m_userThreads.emplace(threadId);
-    // First added user thread is Main thread for sure.
-    if (!MainThread)
+    // First added user thread during start is Main thread for sure.
+    if (!processAttached && !MainThread)
         MainThread = threadId;
 }
 
@@ -43,9 +43,6 @@ void Threads::Remove(const ThreadId &threadId)
 
 std::string Threads::GetThreadName(ICorDebugProcess *pProcess, const ThreadId &userThread)
 {
-    if (MainThread == userThread)
-        return "Main Thread";
-
     std::string threadName = "<No name>";
 
     if (m_sharedEvaluator)
@@ -82,6 +79,9 @@ std::string Threads::GetThreadName(ICorDebugProcess *pProcess, const ThreadId &u
         }
     }
 
+    if (MainThread && MainThread == userThread && threadName == "<No name>")
+        return "Main Thread";
+
     return threadName;
 }
 
index a091b3c433203766e5a07c34c7cc57274fd7760b..532966998bf1f08887f1dc4320e7a969770f23c4 100644 (file)
@@ -32,7 +32,7 @@ class Threads
 
 public:
 
-    void Add(const ThreadId &threadId);
+    void Add(const ThreadId &threadId, bool processAttached);
     void Remove(const ThreadId &threadId);
     HRESULT GetThreadsWithState(ICorDebugProcess *pProcess, std::vector<Thread> &threads);
 #ifdef INTEROP_DEBUGGING