[Lldb-commits] [lldb] r344729 - [Windows] Fix threads comparison on Windows

Aleksandr Urakov via lldb-commits lldb-commits at lists.llvm.org
Thu Oct 18 00:52:56 PDT 2018


Author: aleksandr.urakov
Date: Thu Oct 18 00:52:56 2018
New Revision: 344729

URL: http://llvm.org/viewvc/llvm-project?rev=344729&view=rev
Log:
[Windows] Fix threads comparison on Windows

Summary:
This patch makes Windows threads to compare by a thread ID, not by a handle.
It's because the same thread can have different handles on Windows
(for example, `GetCurrentThread` always returns the fake handle `-2`).
This leads to some incorrect behavior. For example, in `Process::GetRunLock`
always `m_public_run_lock` is returned without this patch.

Reviewers: zturner, clayborg, stella.stamenova

Reviewed By: stella.stamenova

Subscribers: stella.stamenova, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D53357

Modified:
    lldb/trunk/include/lldb/Host/HostNativeThreadBase.h
    lldb/trunk/include/lldb/Host/windows/HostThreadWindows.h
    lldb/trunk/source/Host/common/HostNativeThreadBase.cpp
    lldb/trunk/source/Host/common/HostThread.cpp
    lldb/trunk/source/Host/windows/HostThreadWindows.cpp

Modified: lldb/trunk/include/lldb/Host/HostNativeThreadBase.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/HostNativeThreadBase.h?rev=344729&r1=344728&r2=344729&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/HostNativeThreadBase.h (original)
+++ lldb/trunk/include/lldb/Host/HostNativeThreadBase.h Thu Oct 18 00:52:56 2018
@@ -35,6 +35,7 @@ public:
   virtual Status Cancel() = 0;
   virtual bool IsJoinable() const;
   virtual void Reset();
+  virtual bool EqualsThread(lldb::thread_t thread) const;
   lldb::thread_t Release();
 
   lldb::thread_t GetSystemHandle() const;

Modified: lldb/trunk/include/lldb/Host/windows/HostThreadWindows.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/windows/HostThreadWindows.h?rev=344729&r1=344728&r2=344729&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/windows/HostThreadWindows.h (original)
+++ lldb/trunk/include/lldb/Host/windows/HostThreadWindows.h Thu Oct 18 00:52:56 2018
@@ -29,6 +29,7 @@ public:
   virtual Status Join(lldb::thread_result_t *result);
   virtual Status Cancel();
   virtual void Reset();
+  virtual bool EqualsThread(lldb::thread_t thread) const;
 
   lldb::tid_t GetThreadId() const;
 

Modified: lldb/trunk/source/Host/common/HostNativeThreadBase.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/HostNativeThreadBase.cpp?rev=344729&r1=344728&r2=344729&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/HostNativeThreadBase.cpp (original)
+++ lldb/trunk/source/Host/common/HostNativeThreadBase.cpp Thu Oct 18 00:52:56 2018
@@ -41,6 +41,10 @@ void HostNativeThreadBase::Reset() {
   m_result = 0;
 }
 
+bool HostNativeThreadBase::EqualsThread(lldb::thread_t thread) const {
+  return m_thread == thread;
+}
+
 lldb::thread_t HostNativeThreadBase::Release() {
   lldb::thread_t result = m_thread;
   m_thread = LLDB_INVALID_HOST_THREAD;

Modified: lldb/trunk/source/Host/common/HostThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/HostThread.cpp?rev=344729&r1=344728&r2=344729&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/HostThread.cpp (original)
+++ lldb/trunk/source/Host/common/HostThread.cpp Thu Oct 18 00:52:56 2018
@@ -43,5 +43,5 @@ lldb::thread_result_t HostThread::GetRes
 }
 
 bool HostThread::EqualsThread(lldb::thread_t thread) const {
-  return m_native_thread->GetSystemHandle() == thread;
+  return m_native_thread->EqualsThread(thread);
 }

Modified: lldb/trunk/source/Host/windows/HostThreadWindows.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/HostThreadWindows.cpp?rev=344729&r1=344728&r2=344729&view=diff
==============================================================================
--- lldb/trunk/source/Host/windows/HostThreadWindows.cpp (original)
+++ lldb/trunk/source/Host/windows/HostThreadWindows.cpp Thu Oct 18 00:52:56 2018
@@ -69,3 +69,7 @@ void HostThreadWindows::Reset() {
 
   HostNativeThreadBase::Reset();
 }
+
+bool HostThreadWindows::EqualsThread(lldb::thread_t thread) const {
+  return GetThreadId() == ::GetThreadId(thread);
+}




More information about the lldb-commits mailing list