[ProcessWindows] Create a TargetThreadWindows class.

This creates a TargetThreadWindows class and updates the thread
list of the Process with the main thread.  Additionally, we
fill out a few more overrides of Process base class methods.  We
do not yet update the thread list as threads are created and/or
destroyed, and we do not yet propagate stop reasons to threads as
their states change.

llvm-svn: 222148
This commit is contained in:
Zachary Turner
2014-11-17 17:46:43 +00:00
parent a2fc3a4090
commit 119767db85
6 changed files with 200 additions and 48 deletions

View File

@@ -370,6 +370,7 @@ namespace lldb {
typedef std::shared_ptr<lldb_private::SearchFilter> SearchFilterSP;
typedef std::shared_ptr<lldb_private::Settings> SettingsSP;
typedef std::shared_ptr<lldb_private::StackFrame> StackFrameSP;
typedef std::unique_ptr<lldb_private::StackFrame> StackFrameUP;
typedef std::weak_ptr<lldb_private::StackFrame> StackFrameWP;
typedef std::shared_ptr<lldb_private::StackFrameList> StackFrameListSP;
typedef std::shared_ptr<lldb_private::StopInfo> StopInfoSP;

View File

@@ -7,5 +7,6 @@ add_lldb_library(lldbPluginProcessWindows
DebuggerThread.cpp
LocalDebugDelegate.cpp
ProcessWindows.cpp
TargetThreadWindows.cpp
)

View File

@@ -20,6 +20,7 @@
#include "lldb/Host/Host.h"
#include "lldb/Host/HostProcess.h"
#include "lldb/Host/HostNativeProcessBase.h"
#include "lldb/Host/HostNativeThreadBase.h"
#include "lldb/Host/MonitoringProcessLauncher.h"
#include "lldb/Host/ThreadLauncher.h"
#include "lldb/Host/windows/ProcessLauncherWindows.h"
@@ -32,6 +33,7 @@
#include "ExceptionRecord.h"
#include "LocalDebugDelegate.h"
#include "ProcessWindows.h"
#include "TargetThreadWindows.h"
using namespace lldb;
using namespace lldb_private;
@@ -197,23 +199,6 @@ ProcessWindows::GetPluginVersion()
return 1;
}
void
ProcessWindows::GetPluginCommandHelp(const char *command, Stream *strm)
{
}
Error
ProcessWindows::ExecutePluginCommand(Args &command, Stream *strm)
{
return Error(1, eErrorTypeGeneric);
}
Log *
ProcessWindows::EnablePluginLogging(Stream *strm, Args &command)
{
return NULL;
}
Error
ProcessWindows::DoDetach(bool keep_stopped)
{
@@ -255,6 +240,22 @@ ProcessWindows::IsAlive()
}
}
Error
ProcessWindows::DoHalt(bool &caused_stop)
{
Error error;
StateType state = GetPrivateState();
if (state == eStateStopped)
caused_stop = false;
else
{
caused_stop = ::DebugBreakProcess(m_session_data->m_debugger->GetProcess().GetNativeProcess().GetSystemHandle());
if (!caused_stop)
error.SetError(GetLastError(), eErrorTypeWin32);
}
return error;
}
size_t
ProcessWindows::DoReadMemory(lldb::addr_t vm_addr,
void *buf,
@@ -289,6 +290,18 @@ ProcessWindows::DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size
return bytes_written;
}
lldb::addr_t
ProcessWindows::GetImageInfoAddress()
{
Target &target = GetTarget();
ObjectFile *obj_file = target.GetExecutableModule()->GetObjectFile();
Address addr = obj_file->GetImageInfoAddress(&target);
if (addr.IsValid())
return addr.GetLoadAddress(&target);
else
return LLDB_INVALID_ADDRESS;
}
bool
ProcessWindows::CanDebug(Target &target, bool plugin_specified_by_name)
{
@@ -315,6 +328,10 @@ ProcessWindows::OnDebuggerConnected(lldb::addr_t image_base)
ModuleSP module = GetTarget().GetExecutableModule();
bool load_addr_changed;
module->SetLoadAddress(GetTarget(), image_base, false, load_addr_changed);
DebuggerThreadSP debugger = m_session_data->m_debugger;
ThreadSP main_thread(new TargetThreadWindows(*this, debugger->GetMainThread()));
m_thread_list.AddThread(main_thread);
}
ExceptionResult
@@ -365,6 +382,7 @@ ProcessWindows::OnDebugException(bool first_chance, const ExceptionRecord &recor
void
ProcessWindows::OnCreateThread(const HostThread &thread)
{
SuspendThread(thread.GetNativeThread().GetSystemHandle());
}
void

View File

@@ -63,54 +63,44 @@ public:
~ProcessWindows();
virtual lldb_private::Error
DoDetach(bool keep_stopped);
virtual lldb_private::Error DoDetach(bool keep_stopped) override;
virtual bool
DetachRequiresHalt() { return true; }
DetachRequiresHalt() override
{
return true;
}
virtual bool
UpdateThreadList(lldb_private::ThreadList &old_thread_list, lldb_private::ThreadList &new_thread_list);
virtual bool UpdateThreadList(lldb_private::ThreadList &old_thread_list, lldb_private::ThreadList &new_thread_list) override;
virtual lldb_private::Error
DoLaunch (lldb_private::Module *exe_module,
lldb_private::ProcessLaunchInfo &launch_info);
virtual lldb_private::Error DoLaunch(lldb_private::Module *exe_module, lldb_private::ProcessLaunchInfo &launch_info) override;
virtual lldb_private::Error
DoResume ();
virtual lldb_private::Error DoResume() override;
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
virtual lldb_private::ConstString
GetPluginName();
virtual lldb_private::ConstString GetPluginName() override;
virtual uint32_t
GetPluginVersion();
virtual uint32_t GetPluginVersion() override;
virtual void
GetPluginCommandHelp(const char *command, lldb_private::Stream *strm);
virtual lldb_private::Error
ExecutePluginCommand(lldb_private::Args &command,
lldb_private::Stream *strm);
virtual lldb_private::Log *
EnablePluginLogging(lldb_private::Stream *strm,
lldb_private::Args &command);
virtual bool CanDebug(lldb_private::Target &target, bool plugin_specified_by_name) override;
virtual lldb_private::Error DoDestroy() override;
virtual bool
CanDebug(lldb_private::Target &target, bool plugin_specified_by_name);
DestroyRequiresHalt() override
{
return false;
}
virtual lldb_private::Error
DoDestroy ();
virtual void RefreshStateAfterStop() override;
virtual void
RefreshStateAfterStop ();
virtual bool IsAlive() override;
virtual bool
IsAlive ();
virtual lldb_private::Error DoHalt(bool &caused_stop) override;
virtual lldb::addr_t GetImageInfoAddress() override;
virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, lldb_private::Error &error) override;
virtual size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size, lldb_private::Error &error) override;

View File

@@ -0,0 +1,95 @@
//===-- TargetThreadWindows.cpp----------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "TargetThreadWindows.h"
#include "ProcessWindows.h"
#include "lldb/Host/HostNativeThreadBase.h"
#include "lldb/Host/windows/HostThreadWindows.h"
#include "lldb/Host/windows/windows.h"
using namespace lldb;
using namespace lldb_private;
TargetThreadWindows::TargetThreadWindows(ProcessWindows &process, const HostThread &thread)
: Thread(process, ((HostThreadWindows &)thread.GetNativeThread()).GetThreadId())
, m_host_thread(thread)
{
}
TargetThreadWindows::~TargetThreadWindows()
{
DestroyThread();
}
void
TargetThreadWindows::RefreshStateAfterStop()
{
}
void
TargetThreadWindows::WillResume(lldb::StateType resume_state)
{
}
void
TargetThreadWindows::DidStop()
{
}
RegisterContextSP
TargetThreadWindows::GetRegisterContext()
{
return RegisterContextSP();
}
RegisterContextSP
TargetThreadWindows::CreateRegisterContextForFrame(StackFrame *frame)
{
return RegisterContextSP();
}
bool
TargetThreadWindows::CalculateStopInfo()
{
return false;
}
bool
TargetThreadWindows::DoResume()
{
StateType resume_state = GetResumeState();
StateType current_state = GetState();
if (resume_state == current_state)
return true;
bool success = false;
DWORD suspend_count = 0;
switch (resume_state)
{
case eStateRunning:
SetState(resume_state);
do
{
suspend_count = ::ResumeThread(m_host_thread.GetNativeThread().GetSystemHandle());
} while (suspend_count > 1 && suspend_count != (DWORD)-1);
success = (suspend_count != (DWORD)-1);
break;
case eStateStopped:
case eStateSuspended:
if (current_state != eStateStopped && current_state != eStateSuspended)
{
suspend_count = SuspendThread(m_host_thread.GetNativeThread().GetSystemHandle());
success = (suspend_count != (DWORD)-1);
}
break;
default:
success = false;
}
return success;
}

View File

@@ -0,0 +1,47 @@
//===-- TargetThreadWindows.h -----------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_Plugins_Process_Windows_TargetThreadWindows_H_
#define liblldb_Plugins_Process_Windows_TargetThreadWindows_H_
#include "ForwardDecl.h"
#include "lldb/lldb-forward.h"
#include "lldb/Host/HostThread.h"
#include "lldb/Target/Thread.h"
class ProcessWindows;
namespace lldb_private
{
class HostThread;
class StackFrame;
class TargetThreadWindows : public lldb_private::Thread
{
public:
TargetThreadWindows(ProcessWindows &process, const HostThread &thread);
virtual ~TargetThreadWindows();
virtual void RefreshStateAfterStop() override;
virtual void WillResume(lldb::StateType resume_state) override;
virtual void DidStop() override;
virtual lldb::RegisterContextSP GetRegisterContext() override;
virtual lldb::RegisterContextSP CreateRegisterContextForFrame(StackFrame *frame) override;
virtual bool CalculateStopInfo() override;
bool DoResume();
private:
lldb::StackFrameUP m_stack_frame;
HostThread m_host_thread;
};
}
#endif