Skip to content

Commit

Permalink
Remove main thread detection at attach.
Browse files Browse the repository at this point in the history
  • Loading branch information
viewizard authored and gbalykov committed Dec 11, 2023
1 parent 1f18f7e commit f411402
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/debugger/managedcallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/debugger/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/debugger/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f411402

Please sign in to comment.