diff options
6 files changed, 200 insertions, 48 deletions
diff --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h index cdd402b83aa..ed4aa92d179 100644 --- a/lldb/include/lldb/lldb-forward.h +++ b/lldb/include/lldb/lldb-forward.h @@ -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; diff --git a/lldb/source/Plugins/Process/Windows/CMakeLists.txt b/lldb/source/Plugins/Process/Windows/CMakeLists.txt index 96f4e2a9c7e..dd16e094321 100644 --- a/lldb/source/Plugins/Process/Windows/CMakeLists.txt +++ b/lldb/source/Plugins/Process/Windows/CMakeLists.txt @@ -7,5 +7,6 @@ add_lldb_library(lldbPluginProcessWindows DebuggerThread.cpp LocalDebugDelegate.cpp ProcessWindows.cpp + TargetThreadWindows.cpp ) diff --git a/lldb/source/Plugins/Process/Windows/ProcessWindows.cpp b/lldb/source/Plugins/Process/Windows/ProcessWindows.cpp index da61ba9d193..5ad671e1541 100644 --- a/lldb/source/Plugins/Process/Windows/ProcessWindows.cpp +++ b/lldb/source/Plugins/Process/Windows/ProcessWindows.cpp @@ -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 diff --git a/lldb/source/Plugins/Process/Windows/ProcessWindows.h b/lldb/source/Plugins/Process/Windows/ProcessWindows.h index 0956f882fbd..8e529aba298 100644 --- a/lldb/source/Plugins/Process/Windows/ProcessWindows.h +++ b/lldb/source/Plugins/Process/Windows/ProcessWindows.h @@ -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 uint32_t - GetPluginVersion(); - - virtual void - GetPluginCommandHelp(const char *command, lldb_private::Stream *strm); + virtual lldb_private::ConstString GetPluginName() override; - virtual lldb_private::Error - ExecutePluginCommand(lldb_private::Args &command, - lldb_private::Stream *strm); + virtual uint32_t GetPluginVersion() override; - 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; diff --git a/lldb/source/Plugins/Process/Windows/TargetThreadWindows.cpp b/lldb/source/Plugins/Process/Windows/TargetThreadWindows.cpp new file mode 100644 index 00000000000..33b5fd1973c --- /dev/null +++ b/lldb/source/Plugins/Process/Windows/TargetThreadWindows.cpp @@ -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; +} diff --git a/lldb/source/Plugins/Process/Windows/TargetThreadWindows.h b/lldb/source/Plugins/Process/Windows/TargetThreadWindows.h new file mode 100644 index 00000000000..3db46f8722b --- /dev/null +++ b/lldb/source/Plugins/Process/Windows/TargetThreadWindows.h @@ -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
\ No newline at end of file |