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
This commit is contained in:
parent
5453933867
commit
c30189921e
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue