Change HostThread::GetNativeThread() to return a derived reference.
authorZachary Turner <zturner@google.com>
Mon, 17 Nov 2014 22:42:57 +0000 (22:42 +0000)
committerZachary Turner <zturner@google.com>
Mon, 17 Nov 2014 22:42:57 +0000 (22:42 +0000)
Previously using HostThread::GetNativeThread() required an ugly
cast to most-derived type.  This solves the issue by simply returning
the derived type directly.

llvm-svn: 222185

lldb/include/lldb/Host/HostNativeThread.h
lldb/include/lldb/Host/HostNativeThreadForward.h [new file with mode: 0644]
lldb/include/lldb/Host/HostThread.h
lldb/source/API/SBHostOS.cpp
lldb/source/Host/common/HostThread.cpp
lldb/source/Plugins/Process/Windows/DebuggerThread.cpp
lldb/source/Plugins/Process/Windows/ProcessWindows.cpp
lldb/source/Plugins/Process/Windows/TargetThreadWindows.cpp

index 4100e24..f39c775 100644 (file)
 #ifndef lldb_Host_HostNativeThread_h_
 #define lldb_Host_HostNativeThread_h_
 
+#include "HostNativeThreadForward.h"
+
 #if defined(_WIN32)
 #include "lldb/Host/windows/HostThreadWindows.h"
-namespace lldb_private
-{
-typedef HostThreadWindows HostNativeThread;
-}
 #elif defined(__linux__)
 #include "lldb/Host/linux/HostThreadLinux.h"
-namespace lldb_private
-{
-typedef HostThreadLinux HostNativeThread;
-}
 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 #include "lldb/Host/freebsd/HostThreadFreeBSD.h"
-namespace lldb_private
-{
-typedef HostThreadFreeBSD HostNativeThread;
-}
 #elif defined(__APPLE__)
 #include "lldb/Host/macosx/HostThreadMacOSX.h"
-namespace lldb_private
-{
-typedef HostThreadMacOSX HostNativeThread;
-}
 #endif
 
 #endif
diff --git a/lldb/include/lldb/Host/HostNativeThreadForward.h b/lldb/include/lldb/Host/HostNativeThreadForward.h
new file mode 100644 (file)
index 0000000..e6bd426
--- /dev/null
@@ -0,0 +1,30 @@
+//===-- HostNativeThreadForward.h -------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef lldb_Host_HostNativeThreadForward_h_
+#define lldb_Host_HostNativeThreadForward_h_
+
+namespace lldb_private
+{
+#if defined(_WIN32)
+class HostThreadWindows;
+typedef HostThreadWindows HostNativeThread;
+#elif defined(__linux__)
+class HostThreadLinux;
+typedef HostThreadLinux HostNativeThread;
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+class HostThreadFreeBSD;
+typedef HostThreadFreeBSD HostNativeThread;
+#elif defined(__APPLE__)
+class HostThreadMacOSX;
+typedef HostThreadMacOSX HostNativeThread;
+#endif
+}
+
+#endif
index 61dde4f..9fdf9f9 100644 (file)
@@ -11,6 +11,7 @@
 #define lldb_Host_HostThread_h_
 
 #include "lldb/Core/Error.h"
+#include "lldb/Host/HostNativeThreadForward.h"
 #include "lldb/lldb-types.h"
 
 #include <memory>
@@ -41,8 +42,8 @@ class HostThread
     lldb::thread_t Release();
 
     bool IsJoinable() const;
-    HostNativeThreadBase &GetNativeThread();
-    const HostNativeThreadBase &GetNativeThread() const;
+    HostNativeThread &GetNativeThread();
+    const HostNativeThread &GetNativeThread() const;
     lldb::thread_result_t GetResult() const;
 
     bool EqualsThread(lldb::thread_t thread) const;
index 4a65eee..008ca4d 100644 (file)
 #include "lldb/Core/Log.h"
 #include "lldb/Host/Host.h"
 #include "lldb/Host/HostInfo.h"
+#include "lldb/Host/HostNativeThread.h"
 #include "lldb/Host/HostThread.h"
 #include "lldb/Host/ThreadLauncher.h"
 
-#if !defined(_WIN32)
-#include "lldb/Host/HostNativeThread.h"
-#endif
-
 using namespace lldb;
 using namespace lldb_private;
 
@@ -105,7 +102,7 @@ SBHostOS::ThreadDetach (lldb::thread_t thread, SBError *error_ptr)
         error_ptr->SetErrorString("ThreadDetach is not supported on this platform");
 #else
     HostThread host_thread(thread);
-    error = ((HostThreadPosix &)host_thread.GetNativeThread()).Detach();
+    error = host_thread.GetNativeThread().Detach();
     if (error_ptr)
         error_ptr->SetError(error);
     host_thread.Release();
index 1739732..7757477 100644 (file)
@@ -53,16 +53,16 @@ HostThread::IsJoinable() const
     return m_native_thread->IsJoinable();
 }
 
-HostNativeThreadBase &
+HostNativeThread &
 HostThread::GetNativeThread()
 {
-    return *m_native_thread;
+    return static_cast<HostNativeThread &>(*m_native_thread);
 }
 
-const HostNativeThreadBase &
+const HostNativeThread &
 HostThread::GetNativeThread() const
 {
-    return *m_native_thread;
+    return static_cast<const HostNativeThread &>(*m_native_thread);
 }
 
 lldb::thread_result_t
index 2c3ca6f..c10fb79 100644 (file)
@@ -185,7 +185,7 @@ DebuggerThread::HandleCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO &info,
     m_process = HostProcess(info.hProcess);
     ((HostProcessWindows &)m_process.GetNativeProcess()).SetOwnsHandle(false);
     m_main_thread = HostThread(info.hThread);
-    ((HostThreadWindows &)m_main_thread.GetNativeThread()).SetOwnsHandle(false);
+    m_main_thread.GetNativeThread().SetOwnsHandle(false);
     m_image_file = info.hFile;
 
     lldb::addr_t load_addr = reinterpret_cast<lldb::addr_t>(info.lpBaseOfImage);
index 17083ac..84fd23a 100644 (file)
@@ -365,7 +365,7 @@ ProcessWindows::OnDebuggerConnected(lldb::addr_t image_base)
     module->SetLoadAddress(GetTarget(), image_base, false, load_addr_changed);
 
     DebuggerThreadSP debugger = m_session_data->m_debugger;
-    const HostThreadWindows &wmain_thread = static_cast<const HostThreadWindows &>(debugger->GetMainThread().GetNativeThread());
+    const HostThreadWindows &wmain_thread = debugger->GetMainThread().GetNativeThread();
     m_session_data->m_new_threads[wmain_thread.GetThreadId()] = debugger->GetMainThread();
 }
 
@@ -417,7 +417,7 @@ ProcessWindows::OnDebugException(bool first_chance, const ExceptionRecord &recor
 void
 ProcessWindows::OnCreateThread(const HostThread &new_thread)
 {
-    const HostThreadWindows &wnew_thread = static_cast<const HostThreadWindows &>(new_thread.GetNativeThread());
+    const HostThreadWindows &wnew_thread = new_thread.GetNativeThread();
     m_session_data->m_new_threads[wnew_thread.GetThreadId()] = new_thread;
 }
 
@@ -426,7 +426,7 @@ ProcessWindows::OnExitThread(const HostThread &exited_thread)
 {
     // A thread may have started and exited before the debugger stopped allowing a refresh.
     // Just remove it from the new threads list in that case.
-    const HostThreadWindows &wexited_thread = static_cast<const HostThreadWindows &>(exited_thread.GetNativeThread());
+    const HostThreadWindows &wexited_thread = exited_thread.GetNativeThread();
     auto iter = m_session_data->m_new_threads.find(wexited_thread.GetThreadId());
     if (iter != m_session_data->m_new_threads.end())
         m_session_data->m_new_threads.erase(iter);
index 33b5fd1..2ca55d7 100644 (file)
@@ -17,7 +17,7 @@ using namespace lldb;
 using namespace lldb_private;
 
 TargetThreadWindows::TargetThreadWindows(ProcessWindows &process, const HostThread &thread)
-    : Thread(process, ((HostThreadWindows &)thread.GetNativeThread()).GetThreadId())
+    : Thread(process, thread.GetNativeThread().GetThreadId())
     , m_host_thread(thread)
 {
 }