[Lldb-commits] [lldb] r222185 - Change HostThread::GetNativeThread() to return a derived reference.
Zachary Turner
zturner at google.com
Mon Nov 17 14:42:57 PST 2014
Author: zturner
Date: Mon Nov 17 16:42:57 2014
New Revision: 222185
URL: http://llvm.org/viewvc/llvm-project?rev=222185&view=rev
Log:
Change HostThread::GetNativeThread() to return a derived reference.
Previously using HostThread::GetNativeThread() required an ugly
cast to most-derived type. This solves the issue by simply returning
the derived type directly.
Added:
lldb/trunk/include/lldb/Host/HostNativeThreadForward.h
- copied, changed from r222182, lldb/trunk/include/lldb/Host/HostNativeThread.h
Modified:
lldb/trunk/include/lldb/Host/HostNativeThread.h
lldb/trunk/include/lldb/Host/HostThread.h
lldb/trunk/source/API/SBHostOS.cpp
lldb/trunk/source/Host/common/HostThread.cpp
lldb/trunk/source/Plugins/Process/Windows/DebuggerThread.cpp
lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp
lldb/trunk/source/Plugins/Process/Windows/TargetThreadWindows.cpp
Modified: lldb/trunk/include/lldb/Host/HostNativeThread.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/HostNativeThread.h?rev=222185&r1=222184&r2=222185&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/HostNativeThread.h (original)
+++ lldb/trunk/include/lldb/Host/HostNativeThread.h Mon Nov 17 16:42:57 2014
@@ -10,30 +10,16 @@
#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
Copied: lldb/trunk/include/lldb/Host/HostNativeThreadForward.h (from r222182, lldb/trunk/include/lldb/Host/HostNativeThread.h)
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/HostNativeThreadForward.h?p2=lldb/trunk/include/lldb/Host/HostNativeThreadForward.h&p1=lldb/trunk/include/lldb/Host/HostNativeThread.h&r1=222182&r2=222185&rev=222185&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/HostNativeThread.h (original)
+++ lldb/trunk/include/lldb/Host/HostNativeThreadForward.h Mon Nov 17 16:42:57 2014
@@ -1,4 +1,4 @@
-//===-- HostNativeThread.h --------------------------------------*- C++ -*-===//
+//===-- HostNativeThreadForward.h -------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,33 +7,24 @@
//
//===----------------------------------------------------------------------===//
-#ifndef lldb_Host_HostNativeThread_h_
-#define lldb_Host_HostNativeThread_h_
+#ifndef lldb_Host_HostNativeThreadForward_h_
+#define lldb_Host_HostNativeThreadForward_h_
-#if defined(_WIN32)
-#include "lldb/Host/windows/HostThreadWindows.h"
namespace lldb_private
{
+#if defined(_WIN32)
+class HostThreadWindows;
typedef HostThreadWindows HostNativeThread;
-}
#elif defined(__linux__)
-#include "lldb/Host/linux/HostThreadLinux.h"
-namespace lldb_private
-{
+class HostThreadLinux;
typedef HostThreadLinux HostNativeThread;
-}
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
-#include "lldb/Host/freebsd/HostThreadFreeBSD.h"
-namespace lldb_private
-{
+class HostThreadFreeBSD;
typedef HostThreadFreeBSD HostNativeThread;
-}
#elif defined(__APPLE__)
-#include "lldb/Host/macosx/HostThreadMacOSX.h"
-namespace lldb_private
-{
+class HostThreadMacOSX;
typedef HostThreadMacOSX HostNativeThread;
-}
#endif
+}
#endif
Modified: lldb/trunk/include/lldb/Host/HostThread.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/HostThread.h?rev=222185&r1=222184&r2=222185&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/HostThread.h (original)
+++ lldb/trunk/include/lldb/Host/HostThread.h Mon Nov 17 16:42:57 2014
@@ -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;
Modified: lldb/trunk/source/API/SBHostOS.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBHostOS.cpp?rev=222185&r1=222184&r2=222185&view=diff
==============================================================================
--- lldb/trunk/source/API/SBHostOS.cpp (original)
+++ lldb/trunk/source/API/SBHostOS.cpp Mon Nov 17 16:42:57 2014
@@ -13,13 +13,10 @@
#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 t
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();
Modified: lldb/trunk/source/Host/common/HostThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/HostThread.cpp?rev=222185&r1=222184&r2=222185&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/HostThread.cpp (original)
+++ lldb/trunk/source/Host/common/HostThread.cpp Mon Nov 17 16:42:57 2014
@@ -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
Modified: lldb/trunk/source/Plugins/Process/Windows/DebuggerThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/DebuggerThread.cpp?rev=222185&r1=222184&r2=222185&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/DebuggerThread.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Windows/DebuggerThread.cpp Mon Nov 17 16:42:57 2014
@@ -185,7 +185,7 @@ DebuggerThread::HandleCreateProcessEvent
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);
Modified: lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp?rev=222185&r1=222184&r2=222185&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp Mon Nov 17 16:42:57 2014
@@ -365,7 +365,7 @@ ProcessWindows::OnDebuggerConnected(lldb
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 fi
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 HostT
{
// 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);
Modified: lldb/trunk/source/Plugins/Process/Windows/TargetThreadWindows.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/TargetThreadWindows.cpp?rev=222185&r1=222184&r2=222185&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/TargetThreadWindows.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Windows/TargetThreadWindows.cpp Mon Nov 17 16:42:57 2014
@@ -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)
{
}
More information about the lldb-commits
mailing list