From: Zachary Turner Date: Mon, 17 Nov 2014 22:42:57 +0000 (+0000) Subject: Change HostThread::GetNativeThread() to return a derived reference. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c30189921e45c303d0a5b2ae26573fa7991bdfd4;p=platform%2Fupstream%2Fllvm.git 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. llvm-svn: 222185 --- diff --git a/lldb/include/lldb/Host/HostNativeThread.h b/lldb/include/lldb/Host/HostNativeThread.h index 4100e24..f39c775 100644 --- a/lldb/include/lldb/Host/HostNativeThread.h +++ b/lldb/include/lldb/Host/HostNativeThread.h @@ -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 diff --git a/lldb/include/lldb/Host/HostNativeThreadForward.h b/lldb/include/lldb/Host/HostNativeThreadForward.h new file mode 100644 index 0000000..e6bd426 --- /dev/null +++ b/lldb/include/lldb/Host/HostNativeThreadForward.h @@ -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 diff --git a/lldb/include/lldb/Host/HostThread.h b/lldb/include/lldb/Host/HostThread.h index 61dde4f..9fdf9f9 100644 --- a/lldb/include/lldb/Host/HostThread.h +++ b/lldb/include/lldb/Host/HostThread.h @@ -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 @@ -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; diff --git a/lldb/source/API/SBHostOS.cpp b/lldb/source/API/SBHostOS.cpp index 4a65eee..008ca4d 100644 --- a/lldb/source/API/SBHostOS.cpp +++ b/lldb/source/API/SBHostOS.cpp @@ -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 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(); diff --git a/lldb/source/Host/common/HostThread.cpp b/lldb/source/Host/common/HostThread.cpp index 1739732..7757477 100644 --- a/lldb/source/Host/common/HostThread.cpp +++ b/lldb/source/Host/common/HostThread.cpp @@ -53,16 +53,16 @@ HostThread::IsJoinable() const return m_native_thread->IsJoinable(); } -HostNativeThreadBase & +HostNativeThread & HostThread::GetNativeThread() { - return *m_native_thread; + return static_cast(*m_native_thread); } -const HostNativeThreadBase & +const HostNativeThread & HostThread::GetNativeThread() const { - return *m_native_thread; + return static_cast(*m_native_thread); } lldb::thread_result_t diff --git a/lldb/source/Plugins/Process/Windows/DebuggerThread.cpp b/lldb/source/Plugins/Process/Windows/DebuggerThread.cpp index 2c3ca6f..c10fb79 100644 --- a/lldb/source/Plugins/Process/Windows/DebuggerThread.cpp +++ b/lldb/source/Plugins/Process/Windows/DebuggerThread.cpp @@ -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(info.lpBaseOfImage); diff --git a/lldb/source/Plugins/Process/Windows/ProcessWindows.cpp b/lldb/source/Plugins/Process/Windows/ProcessWindows.cpp index 17083ac..84fd23a 100644 --- a/lldb/source/Plugins/Process/Windows/ProcessWindows.cpp +++ b/lldb/source/Plugins/Process/Windows/ProcessWindows.cpp @@ -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(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(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(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); diff --git a/lldb/source/Plugins/Process/Windows/TargetThreadWindows.cpp b/lldb/source/Plugins/Process/Windows/TargetThreadWindows.cpp index 33b5fd1..2ca55d7 100644 --- a/lldb/source/Plugins/Process/Windows/TargetThreadWindows.cpp +++ b/lldb/source/Plugins/Process/Windows/TargetThreadWindows.cpp @@ -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) { }